Proxmox – Adding disk space to a Live Root partition

TL:DR Increase the disk in Proxmox, delete the live root / main partition, recreate partition, reboot, grow disk. Done

We use Ansible to spin up new servers on Proxmox and our most used template is Centos Stream 9. It is a nice compact image that is secured with the utilities we need and ready to use. However, it has a relatively small root / main partition and this has challenges. One option is to add a second disk and use Linux symlinks that work rather well. However, there is a better way that sounds a bit destructive but works well. You delete the live partition in fdisk or parted while the system is running and resize it on the fly. Once rebooted you can grow the file system into the new space. You read correctly, delete the live partition on the fly. There are a few guides on the Internet and Youtube how to do it but here are the condensed version that just works.

The primary commands needed:

parted (print free)
lsblk
df -hT
fdisk (p, d, n, t (8e), w)
reboot
pvresize /dev/sda2
lvresize /dev/mapper/cs-root /dev/sda2
xfs_growfs /dev/mapper/cs-root

The details (simplified output – extra info removed):

Step 1: Get the required information for later.

parted
GNU Parted 3.5
Using /dev/sda
(parted) print free
Model: QEMU QEMU HARDDISK (scsi)
Disk /dev/sda: 107GB
Number  Start   End     Size    Type     File system  Flags
        1024B   1049kB  1048kB           Free Space
 1      1049kB  1075MB  1074MB  primary  xfs          boot
 2      1075MB  107GB   106GB   primary               lvm

lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sda           8:0    0  350G  0 disk
├─sda1        8:1    0    1G  0 part /boot
└─sda2        8:2    0  349G  0 part
  ├─cs-root 253:0    0 95.1G  0 lvm  /
  └─cs-swap 253:1    0  3.9G  0 lvm  [SWAP]

df -hT
Filesystem          Type      Size  Used Avail Use% Mounted on
devtmpfs            devtmpfs  4.0M     0  4.0M   0% /dev
tmpfs               tmpfs     1.8G  280K  1.8G   1% /dev/shm
tmpfs               tmpfs     732M  776K  732M   1% /run
/dev/mapper/cs-root xfs        95G  9.0G   87G  10% /
/dev/sda1           xfs       960M  347M  614M  37% /boot
tmpfs               tmpfs     366M     0  366M   0% /run/user/1000

fdisk /dev/sda

Welcome to fdisk (util-linux 2.37.4).
Command (m for help): p

Disk /dev/sda: 350 GiB, 375809638400 bytes, 734003200 sectors
Disk model: QEMU HARDDISK
Device     Boot   Start       End   Sectors Size Id Type
/dev/sda1  *       2048   2099199   2097152   1G 83 Linux
/dev/sda2       2099200 209715199 207616000  99G 8e Linux LVM

Step 2: Increase the disk size in Proxmox.

It is just easier to use the GUI for this post although the command line is available.

This adds to the total disk so the sum would be 100GB + 250GB = 350GB.

You must now reboot

Step3: The main procedure: – delete and recreate the partition

Check for free space

parted
print free

fdisk /dev/sda
p
Command (m for help): d
Partition number (1,2, default 2): 2
Partition 2 has been deleted.

Command (m for help): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2): 2
First sector (2099200-734003199, default 2099200):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2099200-734003199, default 734003199):

Created a new partition 2 of type 'Linux' and of size 349 GiB.
Partition #2 contains a LVM2_member signature.

Do you want to remove the signature? [Y]es/[N]o: N
Don't mess up at this point!!! Keep the signature to avoid a very bad day.

Command (m for help): p
Change the new partition to Linux LVM
Command (m for help): t
Partition number (1,2, default 2): 2
Hex code or alias (type L to list all): 8e
Changed type of partition 'Linux' to 'Linux LVM'.

Command (m for help): p
If you feel comfortable with what you have done then use w to write the changes. A point of NO return
Command (m for help): W

Now reboot the Linux System.

Step 4: – Grow the File system after resizing.

pvresize /dev/sda2
  Physical volume "/dev/sda2" changed
  1 physical volume(s) resized or updated / 0 physical volume(s) not resized

lvresize /dev/mapper/cs-root /dev/sda2
  Size of logical volume cs/root changed from <95.06 GiB (24335 extents) to <345.06 GiB (88335 extents).
  Logical volume cs/root successfully resized.

xfs_growfs /dev/mapper/cs-root
df -hT
Filesystem          Type      Size  Used Avail Use% Mounted on
devtmpfs            devtmpfs  4.0M     0  4.0M   0% /dev
tmpfs               tmpfs     1.8G  280K  1.8G   1% /dev/shm
tmpfs               tmpfs     732M  776K  732M   1% /run
/dev/mapper/cs-root xfs       345G   11G  335G   4% /
/dev/sda1           xfs       960M  347M  614M  37% /boot
tmpfs               tmpfs     366M     0  366M   0% /run/user/1000

Done!

Leave a Reply

Your email address will not be published. Required fields are marked *