Understanding Linux partition layout

Setup

Create a Virtual box disk
M:\VM>VBoxManage createhd --filename M:\VM\GRAC_OEL64_11204\asm3_1G_NEW_test.vdi --size 1024 --format VDI --variant Fixed
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Disk image created. UUID: cfa2b73e-73c0-4007-a9eb-4c1dff86c918

[root@grac41 ~]# ./check_wwid.sh 
/dev/sda  WWID:   1ATA_VBOX_HARDDISK_VBcd7c99fa-dc59f9dd
/dev/sda1  WWID:   1ATA_VBOX_HARDDISK_VBcd7c99fa-dc59f9dd
/dev/sda2  WWID:   1ATA_VBOX_HARDDISK_VBcd7c99fa-dc59f9dd
/dev/sda3  WWID:   1ATA_VBOX_HARDDISK_VBcd7c99fa-dc59f9dd
/dev/sdb  WWID:   1ATA_VBOX_HARDDISK_VB81c4f844-94203a15
/dev/sdc  WWID:   1ATA_VBOX_HARDDISK_VB2ed83c09-e66dbcfb
/dev/sdd  WWID:   1ATA_VBOX_HARDDISK_VBa794068c-f0466d76
/dev/sde  WWID:   1ATA_VBOX_HARDDISK_VBd3b6af8f-7dda2f15
/dev/sdf  WWID:   1ATA_VBOX_HARDDISK_VB62e93743-c292014b
/dev/sdg  WWID:   1ATA_VBOX_HARDDISK_VB2c6d9003-321de832
/dev/sdh  WWID:   1ATA_VBOX_HARDDISK_VB494a7fe8-012a2df6
/dev/sdi  WWID:   1ATA_VBOX_HARDDISK_VB4c9e5394-fac4fb34
/dev/sdj  WWID:   1ATA_VBOX_HARDDISK_VB309532df-52fac9ce
/dev/sdk  WWID:   1ATA_VBOX_HARDDISK_VBcc5fe5d0-e4f525a0
/dev/sdl  WWID:   1ATA_VBOX_HARDDISK_VBcfa2b73e-18c986ff
/dev/sdm  WWID:   1ATA_VBOX_HARDDISK_VB35a80438-d12106a8
/dev/sdn  WWID:   1ATA_VBOX_HARDDISK_VB8f7de517-88f51599
/dev/sdo  WWID:   1ATA_VBOX_HARDDISK_VB5d740a37-5fd39649
/dev/sdp  WWID:   1ATA_VBOX_HARDDISK_VB70911962-e022d0cf
/dev/sdq  WWID:   1ATA_VBOX_HARDDISK_VB1726c4c7-b3bcaccd

Create a new partiton aligned to 1MB border
Fdisk options
-c     Switch off DOS-compatible mode. (Recommended)
-u     When listing partition tables, give sizes in sectors instead of cylinders

[root@grac41 ~]# fdisk -cu /dev/sdl
Command (m for help): p
Disk /dev/sdl: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders, total 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xd500de27
   Device Boot      Start         End      Blocks   Id  System
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First sector (2048-2097151, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-2097151, default 2097151): 
Using default value 2097151
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

Reading in  Partition table

Check partition table location

Partition table is located in the first 512 of the disk device /dev/sdl:
[root@grac41 ~]#  dd if=/dev/sdl  bs=510 count=1 2>/dev/null|tail -c 64 |hexdump -C
00000000  00 20 21 00 83 8a 08 82  00 08 00 00 00 f8 1f 00  |. !.............|
00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
-> maxiumn 4 lines == 4 primary paratitons
-> one line translates to one partition 
-> 83 means we have e a single linux partition !

Check the partition itself
[root@grac41 ~]# dd if=/dev/sdl1  bs=510 count=1 2>/dev/null|tail -c 64 |hexdump -C
00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000040
--> No partition table found ( as expected )

Check partition OFFSET

Verify the disk layout by writing a dummy message to the start of the partition :
Note this is a destructive test - don't do this in a production env
[root@grac41 ~]# echo helmut > /dev/sdl1
[root@grac41 ~]# od -c  /dev/sdl1
0000000   h   e   l   m   u   t  \n  \0  \0  \0  \0  \0  \0  \0  \0  \0
0000020  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
*

Now check the position of the string reading for disk device /dev/sdl
[root@grac41 ~]#  od -c  /dev/sdl
0000000  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
*
4000000   h   e   l   m   u   t  \n  \0  \0  \0  \0  \0  \0  \0  \0  \0
4000020  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0

--> The string is  address 4000000 octal ( 1024 * 1024 = 1048576 ) 

Verify partition table with fdisk
[root@grac41 ~]# fdisk -lu /dev/sdl
Disk /dev/sdl: 1073 MB, 1073741824 bytes
139 heads, 8 sectors/track, 1885 cylinders, total 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xd500de27
   Device Boot      Start         End      Blocks   Id  System
/dev/sdl1            2048     2097151     1047552   83  Linux

Partition Offset can be calculated with  : 512 * 2048 = 1048576
--> This value matches perfectly the above od -c Output ! 

 

Check partition size

[root@grac41 ~]# cat /proc/part*
major minor  #blocks  name

  11        0      63252 sr0
   8        0   49152000 sda
...
   8       64    2097152 sde
   8       65    2096128 sde1

--> As we have only a single partition the partition size should be be calculated as: 
     2097152 ( sde ) - 1024 =   ( 2096128 sde1)
    Note the 1024 blocks  are from out partition offset ( see fdisk output )

Reference

Leave a Reply

Your email address will not be published. Required fields are marked *