Safe to recreate extended partition with new start sector?
by scporse from LinuxQuestions.org on (#4VBY0)
OS: Debian 10 x64 in VMware vSphere environment.
Context: I have extended the harddisk device on the Debian VM and now want to extend the extended partition on that disk, and the logical LVM partition contained therein, to use the new, larger disk size.
Before making any changes (I don't boot to Live OS), my partition table looks like so:
Code:Disk /dev/sda: 140 GiB, 150323855360 bytes, 293601280 sectors
Disk model: Virtual disk
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: 0xf8f0e693
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 499711 497664 243M 83 Linux
/dev/sda2 501758 125827071 125325314 59.8G 5 Extended
/dev/sda5 501760 125827071 125325312 59.8G 8e Linux LVMFirst I rescan the SCSI bus to make the OS see the new disk size:
Code:echo "1" > /sys/class/block/sda/device/rescanFrom fdisk, I then delete and recreate the extended partition (sda2) with new starting sector (499712 instead of 501758) just after /boot partition sda1, thus getting rid of pre-existing sector gap (this is done, just by selecting the default start and end sector values).
Now, I create a new logical partition (sda5) of type 8e/LVM within the extended partition container and select default start and end sectors (where the start sector matches the one as before making any changes to partition table) and finally I select to KEEP the existing LVM2_member signature.
Finally, I commit my changes to the partition table and then I do get this warning:
Failed to add partition 2 to system: Device or resource busy
The kernel still uses the old partitions. The new table will be used at the next reboot.
Syncing disks.
But in spite of this, I'm still able to successfully proceed with doing Code:partprobe -s to update the partition table and then resizing the physical volume in LVM with Code:pvresize /dev/sda5Can this process be considered acceptable safety-wise, or would I be better off following a different procedure - or just booting into a Live OS and making my changes from there?
Bonus question: What are your thoughts on following this procedure every time the existing VM harddisk device is extended, versus creating a new primary partition in the added disk space and committing that partition as a new physical volume to LVM, each time?


Context: I have extended the harddisk device on the Debian VM and now want to extend the extended partition on that disk, and the logical LVM partition contained therein, to use the new, larger disk size.
Before making any changes (I don't boot to Live OS), my partition table looks like so:
Code:Disk /dev/sda: 140 GiB, 150323855360 bytes, 293601280 sectors
Disk model: Virtual disk
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: 0xf8f0e693
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 499711 497664 243M 83 Linux
/dev/sda2 501758 125827071 125325314 59.8G 5 Extended
/dev/sda5 501760 125827071 125325312 59.8G 8e Linux LVMFirst I rescan the SCSI bus to make the OS see the new disk size:
Code:echo "1" > /sys/class/block/sda/device/rescanFrom fdisk, I then delete and recreate the extended partition (sda2) with new starting sector (499712 instead of 501758) just after /boot partition sda1, thus getting rid of pre-existing sector gap (this is done, just by selecting the default start and end sector values).
Now, I create a new logical partition (sda5) of type 8e/LVM within the extended partition container and select default start and end sectors (where the start sector matches the one as before making any changes to partition table) and finally I select to KEEP the existing LVM2_member signature.
Finally, I commit my changes to the partition table and then I do get this warning:
Failed to add partition 2 to system: Device or resource busy
The kernel still uses the old partitions. The new table will be used at the next reboot.
Syncing disks.
But in spite of this, I'm still able to successfully proceed with doing Code:partprobe -s to update the partition table and then resizing the physical volume in LVM with Code:pvresize /dev/sda5Can this process be considered acceptable safety-wise, or would I be better off following a different procedure - or just booting into a Live OS and making my changes from there?
Bonus question: What are your thoughts on following this procedure every time the existing VM harddisk device is extended, versus creating a new primary partition in the added disk space and committing that partition as a new physical volume to LVM, each time?