Attached is a patch (2 lines of code) that adds an additional option to sfdisk that allows the size of a partition to be specified as the maximum available size. By default, omitting a size parameter means that the maximum sized partition is used. However, this option is not available in conjunction with the -N flag, as under such circumstances the default is the current size of the partition. This patch allows a size to be specified as "+" in which case the maximum sized partition is used, irrespective of the setting of the -N flag. This allows partitions to be programatically resized to their maximum size, by (for instance): echo ",+," | sfdisk -N1 /dev/sdaThis is non-trivial to do without the patch, as -N makes the default size the existing size. As there is (without this patch) no way of reading the maximum size, the only option is to delete the partition and recreate it.
This is undesirable for a number of reasons (e.g. errors between delete and recreate). The specific use case for this is resizing cloud based images designed for arbitrary sized disk to take up the whole disk, prior to resizing the file system. As I am working with the Ubuntu folks on getting this working, this patch is also at: https://bugs.launchpad.net/ubuntu/+source/util-linux/+bug/686124 Please consider this for inclusion in the next util-linux release. A manpage patch is also included. -- Alex Bligh
Attachment:
util-linux-ng-2.18-sfdisk-maxsize.patch
Description: Binary data