Outils d'utilisateurs

Outils du Site


tips:ext2partitionsize

Recovering the partition size needed for an Ext filesystem

Things have gone wrong, and the partition table has been messed up. Fortunately, the Ext2 filesystem is still there. How to compute the partition size from the filesystem?

This assumes the approach describe here, and only details how to get the sizes right with recent tools. As two different types of blocks are used, they'll be called “fs-block” and “disk-block” when they refer to the filesystem or the disk's unit, respectively.

Filesystem size

The block count and size can be obtained through dumpe2fs.

$ sudo dumpe2fs /dev/sda1| grep "Block \(count\|size\)"
dumpe2fs 1.41.12 (17-May-2010)
Block count:              7323624
Block size:               4096

Here, this is obviously a filesystem of 7323624 fs-blocks of 4096 bytes each, that is 29997563904 B in total.

Converting the size into partition size

(This is obtained from a healthy disk to work out the retalions.)

$ sudo fdisk -l /dev/sda

Disk /dev/sda: 320.1 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 cylinders, total 625142448 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: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *          63    58589054    29294496   83  Linux
[...]

The disk-blocks that fdisk displays appear to be in KiB (1024 B). Multiplying 29294496 by 1024 gives the same value of 29997563904 B. Thus, it seems safe to assume that the filesystem size (in Bytes) can be converted into hard disk size (in disk-blocks) by dividing it by 1024.

disk-block-count = (fs-block-count * fs-block-size) / 1024

Converting the partition size into cylinders

Using the example above, the disk-block-count can be converted into sectors given their size (here, 1 sector = 512 disk-blocks),

sector-count = disk-block-count / ( cylinder-size / 1024)

This can be done directly from the filesystem size as

sector-count = (fs-block-count * fs-block-size) / sector-size .

tips/ext2partitionsize.txt · Dernière modification: 2013/11/15 06:06 (modification externe)