A use case I use quite a bit and which would be useful for more easily supporting certain ARM devices such as the Raspberry Pi is the ability to automatically reorder partitions on a disk to disk order. At the moment I use the following work flow and manually edit the order/partition numbers in vi. The ability to be able to it with a single command line option would make it easier to script without error due to other possible issues. [root@host ~]# sfdisk -d /dev/mmcblk0 > dp.txt [root@host ~]# vi dp.txt [root@host ~]# sfdisk -f /dev/mmcblk0 < dp.txt Checking that no-one is using this disk right now ... OK Disk /dev/mmcblk0: 14.7 GiB, 15720251392 bytes, 30703616 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 Disklabel type: dos Disk identifier: 0xbcdd5210 Old situation: Device Boot Start End Sectors Size Id Type /dev/mmcblk0p1 104448 690175 585728 286M 83 Linux /dev/mmcblk0p2 690176 1087487 397312 194M 83 Linux /dev/mmcblk0p3 1087488 3432447 2344960 1.1G 83 Linux /dev/mmcblk0p4 2048 104447 102400 50M b W95 FAT32 Partition table entries are not in disk order. >>> Script header accepted. >>> Script header accepted. >>> Script header accepted. >>> Script header accepted. >>> Created a new DOS disklabel with disk identifier 0xbcdd5210. Created a new partition 1 of type 'W95 FAT32' and of size 50 MiB. /dev/mmcblk0p2: Created a new partition 2 of type 'Linux' and of size 286 MiB. /dev/mmcblk0p3: Created a new partition 3 of type 'Linux' and of size 194 MiB. /dev/mmcblk0p4: Created a new partition 4 of type 'Linux' and of size 1.1 GiB. All partitions used. New situation: Device Boot Start End Sectors Size Id Type /dev/mmcblk0p1 2048 104447 102400 50M b W95 FAT32 /dev/mmcblk0p2 104448 690175 585728 286M 83 Linux /dev/mmcblk0p3 690176 1087487 397312 194M 83 Linux /dev/mmcblk0p4 1087488 3432447 2344960 1.1G 83 Linux The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks. [root@host ~]#
I have added --reorder command line option to sfdisk. The feature will be available in v2.28 (probably f24). Thanks. https://github.com/karelzak/util-linux/commit/b17431e6a048829bf2852ec5b50db48862c98d77
That's really awesome! Thank you!