Wednesday, May 6, 2015

resize by sfdisk

The last week released util-linux v2.26.2 contains improved (fixed:-) sfdisk. The most visible change is that the new version supports partition resize and start offset move.

For example 1GiB disk with GPT:

        echo ", +10M" | ./sfdisk -N 1 /dev/sdc
        ...
       
        Old situation:
       
        Device     Start    End Sectors  Size Type
        /dev/sdc1   2048 206847  204800  100M Linux filesystem
       
        New situation:
       
        Device     Start    End Sectors  Size Type
        /dev/sdc1   2048 227327  225280  110M Linux filesystem
the first partition (-N 1) has been enlarged from 100MiB to 110MiB.

You can also move begin of the partition:

        echo "+2M" | ./sfdisk -N 1 /dev/sdc
        ...
        Old situation:
       
        Device     Start    End Sectors  Size Type
        /dev/sdc1   2048 227327  225280  110M Linux filesystem
       
        New situation:
       
        Device     Start    End Sectors  Size Type
        /dev/sdc1   6144 231423  225280  110M Linux filesystem
and it's possible to enalarge as much as possible:
       
        echo ", +" | ./sfdisk -N 1 /dev/sdc
        ...
        Old situation:
       
        Device     Start    End Sectors  Size Type
        /dev/sdc1   6144 231423  225280  110M Linux filesystem
       
        New situation:
 
        Device     Start     End Sectors  Size Type
        /dev/sdc1   6144 2047966 2041823  997M Linux filesystem
the '+' means "all available space". And vice-versa you can reduce the size of the partition; it's possioble to specify the size in absolute numbers (without +/- signs), or in sectors. The next example reduce size to 100MiB and move to old good offset 2048:
       
        echo "2048,100M" | ./sfdisk -N 1 /dev/sdc
        ...
        Old situation:
       
        Device     Start     End Sectors  Size Type
        /dev/sdc1   6144 2047966 2041823  997M Linux filesystem
       
        New situation:
 
        Device     Start    End Sectors  Size Type
        /dev/sdc1   2048 206847  204800  100M Linux filesystem
Note that fdisks are too low-level to care about filesystems when resize, it's all about partition tables only.

3 comments:

  1. These features saved my life where I was unable to use any GUI tool. Thanks a lot.

    ReplyDelete
  2. Thank you, helped me with a win10 imaging project for work

    ReplyDelete