As mentioned in my previous [entry], I am writing this post to explain how to resize a partition without losing any data with
gdisk. By this, I mean resizing the
physical partition itself, not the physical volume.
archisoon the VM with QEMU. If you have installed grub on ESP partition, chances are you will be dropped to the installed grub bootloader as shown in [this image] instead of the one that comes with the archiso. In this case, press '
c' for a command-line and run commands as indicated in the image below in order to be able to boot into it:-
shrinkingmy physical partition. Should there be a need for you to
enlargeyour physical partition, the order of the steps will be in the reverse/opposite sequence. In that case, you have to resize the involved partition with
gdiskfirst, followed by
Logical Volumecontaining the
/partition). One way to know is by running '
lsblk' command. It will list information about all available block devices including the
MOUNTPOINTof those devices. If
MOUNTPOINTreturns no output for the device, that means it is not mounted.
Logical Volumeand its file system all at once (with '
-r' option) by running this command:
lvresize -L new-size -r vgname>/lvname
pvresizewith the below command:-
pvresize --setphysicalvolumesize new-size /dev/vdaX
PVis advisable to be slightly bigger than the shrunken
LV'sotherwise it may prompt you an error.
gdisk /dev/vda', enter '
p' to print the partition table, and enter '
i' to obtain the information of the partition that we want to resize where we will take note of its
Partition unique GUID.
d' and the number of the partition we want to delete. Create a new partition by entering '
n', enter a new size which I recommend being slightly bigger than the resized
Physical Volume'sand change the type of partition to
Linux LVM(8e00) which is of the same type to the previous partition prior to deletion. Enter '
x' for expert command followed by letter '
c' to key in the
partition's unique GUIDwhich we took note of previously. Be careful with this action and ensure that the unique GUID is identical before writing the changes or otherwise you may encounter data loss.
Well, actually! There is an easier way to have this exact purpose done without all these hassles (with the exception of
pvresize. They are still required to be done before you execute the task with any partitioning tool of your choice, if you are shrinking it).
I however, prefer
gdisk over these two partitioning tools due to:
partedand the way the sizing is managed is just complicated. Or maybe it's just me who wants to think so.
BONUS. The radio buttons below feature the complete steps I did to add a new partition with the remaining free space gained as a result of shrinking the physical partition, in the form of screenshots. This new partition parks the
archiso that I can boot into by adding a menuentry in the grub config file.