3

After shrinking a read only filesystem with resize2fs on GNU/Linux, how do i determine the correct partition entry for the shrunken filesystem?

Initial partition scheme of remote host:

Disk /dev/sda: 1,8 TiB, 1999844147200 bytes, 3905945600 sectors
Disk model: xxx       
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xf79ea8df

Device     Boot      Start        End    Sectors  Size Id Type
/dev/sda1  *          2048     487423     485376  237M 83 Linux
/dev/sda2           487424 3841943551 3841456128  1,8T 83 Linux
/dev/sda3       3841943552 3883886591   41943040   20G 83 Linux

Command (m for help):

Issuing resize command:

[root@home ~]# resize2fs /dev/sda2 200G
resize2fs 1.44.5 (15-Dec-2018)
Resizing the filesystem on /dev/sda2 to 52428800 (4k) blocks.
The filesystem on /dev/sda2 is now 52428800 (4k) blocks long.

When recreating the partition entry for /dev/sda2 with 487424 as start sector, and a size of 8 times 52428800 * 512 bytes blocks, does the created partition really cover the whole shrunken filesystem and how can that be proven ?

Disk /dev/sda: 1,8 TiB, 1999844147200 bytes, 3905945600 sectors
Disk model: xxx       
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xf79ea8df

Device     Boot      Start        End   Sectors  Size Id Type
/dev/sda1  *          2048     487423    485376  237M 83 Linux
/dev/sda2           487424  419917824 419430401  200G 83 Linux
/dev/sda3       3841943552 3883886591  41943040   20G 83 Linux

Command (m for help): 
3
  • 1
    Empirically, the size of a partition seems to be equal to or greater than "Block count" * "Block size" as reported by dumpe2fs -h. This is also the method used in the answer to this other question (you may even flag your question as a duplicate of that one if you feel yours is answered). Though I couldn't find any reference for the assertion that "Block count" represents the total size of the file system. Commented Oct 29, 2020 at 16:30
  • I thought of recognizing the last block of the filesystem on the last block covered by the partition as a way to be sure it fits - but how do i recognize the last block ? Commented Oct 29, 2020 at 16:36
  • Unfortunately, the other question does not have any answers providing information about how to calculate an related correct partition entry. Are there any alignment issues ? Does a partition entry provide some extra space for filesystem meta data ? Or is the correct partition size always exactly the filesystem size, regardless of alignment and other unknown factors? Commented Oct 29, 2020 at 16:43

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.