Pages

2017-01-19

Raspberry Pi - sdb2 super block corruption


* Superblock : bad magic number (dump file link)

$ sudo dd if=/dev/sdb2 bs=1024 count=2 | hexdump -C
00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000380  b0 c9 0e 00 80 19 3b 00  98 6d 02 00 17 26 22 00  |......;..m...&".|
00000390  fc 5d 0b 00 00 00 00 00  02 00 00 00 02 00 00 00  |.]..............|
000003a0  00 80 00 00 00 80 00 00  d0 1f 00 00 3e d2 2f 58  |............>./X|
000003b0  03 00 00 00 03 00 ff ff  53 ef 03 00 01 00 00 00  |........S.......|
000003c0  2d c4 2f 58 b0 c9 0e 00  80 19 3b 00 98 6d 02 00  |-./X......;..m..|
000003d0  53 25 22 00 fc 5d 0b 00  00 00 00 00 02 00 00 00  |S%"..]..........|
000003e0  02 00 00 00 00 80 00 00  00 80 00 00 d0 1f 00 00  |................|
000003f0  bf d2 2f 58 03 00 00 00  05 00 ff ff 53 ef 03 00  |../X........S...|
00000400  01 00 00 00 3d d2 2f 58  00 00 00 00 00 00 00 00  |....=./X........|
00000410  01 00 00 00 00 00 00 00  0b 00 00 00 00 01 00 00  |................|
00000420  3c 00 00 00 42 02 00 00  73 00 00 00 ad 62 03 a1  |<...B...s....b..|
00000430  ec 50 4f 44 a1 c0 e6 c3  dd 4c 92 02 00 00 00 00  |.POD.....L......|
00000440  00 00 00 00 00 00 00 00  00 00 00 00 2f 00 65 64  |............/.ed|
00000450  69 61 2f 63 6d 6a 6f 2f  61 64 36 32 30 33 61 31  |ia/cmjo/ad6203a1|
00000460  2d 65 63 35 30 2d 34 66  34 34 2d 61 31 63 30 2d  |-ec50-4f44-a1c0-|
00000470  65 36 63 33 64 64 34 63  39 32 30 32 00 00 00 00  |e6c3dd4c9202....|
00000480  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000490  00 00 e6 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000004a0  00 00 00 00 08 00 00 00  00 00 00 00 00 00 00 00  |................|
000004b0  58 e2 0c f7 9d 8c 4c 05  8d eb a6 52 51 90 7e 3c  |X.....L....RQ.~<|
000004c0  01 01 00 00 0c 00 00 00  00 00 00 00 6e c8 50 56  |............n.PV|
000004d0  0a f3 01 00 04 00 00 00  00 00 00 00 00 00 00 00  |................|
000004e0  00 40 00 00 00 80 06 00  00 00 00 00 00 00 00 00  |.@..............|
000004f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000510  00 00 00 04 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000520  1c 00 1c 00 02 00 00 00  f1 7f 00 00 00 00 00 00  |................|
00000530  00 00 00 00 00 00 00 00  04 00 00 00 ba 7b cc 02  |.............{..|
00000540  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000550  00 00 00 00 00 00 00 00  01 00 00 00 11 00 00 00  |................|
00000560  6b 54 00 00 00 00 00 00  00 00 00 00 65 78 74 34  |kT..........ext4|
00000570  5f 69 67 65 74 00 00 00  00 00 00 00 00 00 00 00  |_iget...........|
00000580  00 00 00 00 00 00 00 00  00 00 00 00 a6 10 00 00  |................|
00000590  11 00 00 00 6b 54 00 00  a6 10 00 00 00 00 00 00  |....kT..........|
000005a0  00 00 00 00 65 78 74 34  5f 69 67 65 74 00 00 00  |....ext4_iget...|
000005b0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|




* Superblock : after fsck (dump file link)

$ sudo fsck /dev/sdb2
fsck from util-linux 2.27.1
e2fsck 1.42.13 (17-May-2015)
ext2fs_open2: Bad magic number in super-block
fsck.ext2: Superblock invalid, trying backup blocks...
/dev/sdb2: recovering journal
fsck.ext2: unable to set superblock flags on /dev/sdb2


/dev/sdb2: ***** FILE SYSTEM WAS MODIFIED *****

/dev/sdb2: ********** WARNING: Filesystem still has errors **********
 

$ sudo fsck /dev/sdb2
fsck from util-linux 2.27.1
e2fsck 1.42.13 (17-May-2015)
Setting free inodes count to 744873 (was 744872)
/dev/sdb2: clean, 224263/969136 files, 1620552/3873152 blocks


$ sudo dd if=/dev/sdb2 bs=1024 count=2 | hexdump -C
2+0 records in
2+0 records out
2048 bytes (2.0 kB, 2.0 KiB) copied, 0.00621587 s, 329 kB/s
00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000380  b0 c9 0e 00 80 19 3b 00  98 6d 02 00 17 26 22 00  |......;..m...&".|
00000390  fc 5d 0b 00 00 00 00 00  02 00 00 00 02 00 00 00  |.]..............|
000003a0  00 80 00 00 00 80 00 00  d0 1f 00 00 3e d2 2f 58  |............>./X|
000003b0  03 00 00 00 03 00 ff ff  53 ef 03 00 01 00 00 00  |........S.......|
000003c0  2d c4 2f 58 b0 c9 0e 00  80 19 3b 00 98 6d 02 00  |-./X......;..m..|
000003d0  53 25 22 00 fc 5d 0b 00  00 00 00 00 02 00 00 00  |S%"..]..........|
000003e0  02 00 00 00 00 80 00 00  00 80 00 00 d0 1f 00 00  |................|
000003f0  bf d2 2f 58 03 00 00 00  05 00 ff ff 53 ef 03 00  |../X........S...|
00000400  b0 c9 0e 00 80 19 3b 00  98 6d 02 00 38 5f 22 00  |......;..m..8_".|
00000410  a9 5d 0b 00 00 00 00 00  02 00 00 00 02 00 00 00  |.]..............|
00000420  00 80 00 00 00 80 00 00  d0 1f 00 00 1e 6c 20 57  |.............l W|
00000430  bc 48 80 58 03 00 ff ff  53 ef 01 00 01 00 00 00  |.H.X....S.......|
00000440  67 75 20 57 00 00 00 00  00 00 00 00 01 00 00 00  |gu W............|
00000450  00 00 00 00 0b 00 00 00  00 01 00 00 3c 00 00 00  |............<...|
00000460  42 02 00 00 73 00 00 00  ad 62 03 a1 ec 50 4f 44  |B...s....b...POD|
00000470  a1 c0 e6 c3 dd 4c 92 02  00 00 00 00 00 00 00 00  |.....L..........|
00000480  00 00 00 00 00 00 00 00  2f 00 6e 74 2f 73 64 63  |......../.nt/sdc|
00000490  61 72 64 00 64 65 76 2f  70 69 2d 67 65 6e 2f 65  |ard.dev/pi-gen/e|
000004a0  78 70 6f 72 74 2d 6a 65  73 73 69 65 2f 72 6f 6f  |xport-jessie/roo|
000004b0  74 66 73 00 00 00 00 00  00 00 00 00 00 00 00 00  |tfs.............|
000004c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 e6 00  |................|
000004d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000004e0  08 00 00 00 00 00 00 00  00 00 00 00 58 e2 0c f7  |............X...|
000004f0  9d 8c 4c 05 8d eb a6 52  51 90 7e 3c 01 01 00 00  |..L....RQ.~<....|
00000500  0c 00 00 00 00 00 00 00  6e c8 50 56 0a f3 01 00  |........n.PV....|
00000510  04 00 00 00 00 00 00 00  00 00 00 00 00 40 00 00  |.............@..|
00000520  00 80 06 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000530  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000540  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 04  |................|
00000550  00 00 00 00 00 00 00 00  00 00 00 00 1c 00 1c 00  |................|
00000560  02 00 00 00 f1 7f 00 00  00 00 00 00 00 00 00 00  |................|
00000570  00 00 00 00 04 00 00 00  06 57 cc 02 00 00 00 00  |.........W......|
00000580  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000800



* Superblock : after RPi more fixed (only dump file link)


* Analysis
 - According to the Ext4 disk layout,
   first 1024 byte (if the disk size is 16GB) must be 0 padded.
 - But, the real data was not. (0x400 = 1024)
 - And the magic signature, 0x0438 and 0x0439 is not 0xEF53 before fixing.


* Question
 - Why the first 1024 byte is not 0 padded?
 - What causes this corruption?


2017-01-18

Raspberry Pi MBR - Partition Expansion



* SD Card is SanDisk 16GB


* Before Expansion (linux partition is about 9GB)

  $ hexdump -C t20r18-mbr-20161031.img
00000000  fa b8 00 10 8e d0 bc 00  b0 b8 00 00 8e d8 8e c0  |................|
00000010  fb be 00 7c bf 00 06 b9  00 02 f3 a4 ea 21 06 00  |...|.........!..|
00000020  00 be be 07 38 04 75 0b  83 c6 10 81 fe fe 07 75  |....8.u........u|
00000030  f3 eb 16 b4 02 b0 01 bb  00 7c b2 80 8a 74 01 8b  |.........|...t..|
00000040  4c 02 cd 13 ea 00 7c 00  00 eb fe 00 00 00 00 00  |L.....|.........|
00000050  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001b0  00 00 00 00 00 00 00 00  1f da 06 00 00 00 00 82  |................|
000001c0  03 00 0c 28 20 08 00 20  00 00 00 e0 01 00 00 00  |...( .. ........|
000001d0  01 00 83 fe ff ff 00 00  02 00 00 00 fa
00 00 00  |................|
000001e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............U.|
00000200  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000400




* After Expansion (linux partition is about 15GB)

  $ hexdump -C sd_fixed.img
00000000  fa b8 00 10 8e d0 bc 00  b0 b8 00 00 8e d8 8e c0  |................|
00000010  fb be 00 7c bf 00 06 b9  00 02 f3 a4 ea 21 06 00  |...|.........!..|
00000020  00 be be 07 38 04 75 0b  83 c6 10 81 fe fe 07 75  |....8.u........u|
00000030  f3 eb 16 b4 02 b0 01 bb  00 7c b2 80 8a 74 01 8b  |.........|...t..|
00000040  4c 02 cd 13 ea 00 7c 00  00 eb fe 00 00 00 00 00  |L.....|.........|
00000050  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001b0  00 00 00 00 00 00 00 00  1f da 06 00 00 00 00 82  |................|
000001c0  03 00 0c 28 20 08 00 20  00 00 00 e0 01 00 00 00  |...( .. ........|
000001d0  01 00 83 03 d0 2f 00 00  02 00 00 cc d8 01
00 00  |...../..........|
000001e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............U.|
00000200  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000400



* Analysis
  - 0x01ce | Status         | Value 0x00   => Valid (0x00 or 0x80)
  - 0x01cf | Head           | Value 0x00
  - 0x01d0 | Sector         | Value 0x01
  - 0x01d1 | Cylinder       | Value 0x00
  - 0x01d2 | Partition Type | Value 0x83   => Linux
    =================== below values are different =====================
  - 0x01d3 | Head           | Value 0x03
  - 0x01d4 | Sector         | Value 0xd0
  - 0x01d5 | Cylinder       | Value 0x2f
  - 0x01d6 ~ 0x01d9 : LBA of first absolute sector in the partition
  - 0x01da ~ 0x01dd : Number of sectors in partition