Learn to share

Recover Partition Table: CoreOS

| Comments

This is a firedrill post on how to recover partition table, if partition table was accidently deleted.

I have a CoreOS VM deployed in Azure. I manually deleted all partitions from the disk, as you notice from below output

1
Number  Start (sector)    End (sector)  Size       Code  Name

Don’t panic! This is not my production server.

Before we start recovering the partition table, let’s backup the MBR code

1
dd if=/dev/sda of=mbr.bin bs=446 count=1

To find the lost partitions, there is testdisk tool developed by Christophe Grenier. So, I have copied the package to the server and then extracted the files.

1
2
3
4
5
6
7
8
9
coreos-test2 testdisk-7.0 # tar xvf testdisk-7.0.linux26-x86_64.tar.bz2

coreos-test2 testdisk-7.0 # cd testdisk-7.0

coreos-test2 testdisk-7.0 # ls
AUTHORS     COPYING    INFO  README  VERSION             fidentify.8       icons  l           photorec_static  readme.txt  testdisk_static
Android.mk  ChangeLog  NEWS  THANKS  documentation.html  fidentify_static  jni    photorec.8  qphotorec.8      testdisk.8

coreos-test2 testdisk-7.0 # ./testdisk_static /dev/sda

After that, I ran testdisk command on /dev/sda and you will notice a screen similar to below screenshot

images

After clicking proceed, I choosed EFI GPT partition map (because I knew on my CoreOS VM it has GPT with hybrid MBR), then Analyse, then Quick Search, and it found partitions.

Looking at the partition table, there are some missing partitions. I took a copy of the found partition table and then added the partitions manually then pressed Enter to continue and then write out the partition table.

For CoreOS specific, we need to additionally

-> fix type codes

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
gdisk /dev/sda
  t
  1 
  EF00 (EFI System Partition)

  t
  2
  EF02 (BIOS Boot Partition)

  t
  3
  5DFBF5F4-2848-4BAC-AA5E-0D9A20B745A6 (Unknown / CoreOS Root)
  
  t
  4
  5DFBF5F4-2848-4BAC-AA5E-0D9A20B745A6 (Unknown / CoreOS Root)

  t
  5
  8300 (Linux Data)
  
  t
  6
  C95DC21A-DF0E-4340-8D7B-26CBFA9A03E0 (Unknown / CoreOS Reserved)
  
  t
  7
  3884DD41-8582-4404-B9A8-E9B84F2DF50E (Unknown / CoreOS undocumented/real root)
  
  
  p
  
  verify type codes for partitions: EF00, EF02, FFFF, FFFF, 8300, FFFF, FFFF

-> name the partitions

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
c
  1
  EFI-SYSTEM
  
  c
  2
  BIOS-BOOT

  c
  3
  USR-A
  
  c
  4
  USR-B
  
  c
  5
  OEM
      
  c
  6
  OEM-CONFIG

  c
  7
  ROOT

-> number the partitions

1
2
3
4
5
6
7
8
9
10
11
12
x
  t
  7
  9

  t
  6
  7

  t
  5
  6

-> change it to hybrid MBR

1
2
3
4
5
6
7
8
9
r
  h
  1
  N
  0C
  Y
  N
  w
  Y

-> set the required attributes

1
2
3
4
5
6
7
8
9
10
11
12
13
14
gdisk /dev/sda
        
  x
  a
  1
  2
  Enter
  a
  3
  48
  56
  Enter
  w
  Y

-> update the UUID of disk /dev/sda3

1
2
3
4
5
6
7
fdisk /dev/sda
        x
        u
        3
        7130C94A-213A-4E5A-8E26-6CCE9662F132 
        r
  w

Now, we are ready to restore the backed up MBR

1
dd if=mbr.bin of=/dev/sda

Finally, we have our lost partition table (~!~). I rebooted the server and ensured server is indeed booting successfully.

Comments