Skip to content

Instantly share code, notes, and snippets.

@grintor
Created February 24, 2022 16:24
Show Gist options
  • Save grintor/9048a9d89ed9a3dd94f681856ba48630 to your computer and use it in GitHub Desktop.
Save grintor/9048a9d89ed9a3dd94f681856ba48630 to your computer and use it in GitHub Desktop.
Converting a Sangoma FreePBX swap partition to a swap file and resizing the root partition to fill the drive
# look at the free space of "/"
df -h
# install a swap file instead of a swap partition
dd if=/dev/zero of=/swapfile count=2048 bs=1MiB
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
# turn off the swap partition (moves all of the memory to the swap file, may take a minute)
swapoff /dev/SangomaVG/swaplv1
# delete the swap partition
lvm lvremove /dev/SangomaVG/swaplv1
# edit fstab and delete the line mentioning the Sangoma swap partition (second-to-last line)
nano /etc/fstab
# grow the lvm partition to consume all space on the disk
yum install cloud-utils-growpart
growpart /dev/nvme0n1 2
# grow the lvm physical volume to consume all the space on the lvm partition
pvresize /dev/nvme0n1p2
# grow the logical volume and partition to consume all the space on the lvm volume
lvextend -r -l +100%FREE /dev/SangomaVG/root
# now this command shows lots of free space for "/":
df -h
The system now has the free space it needs, but cannot boot up without an error because there are still refrences in initramfs and grub to the old swap partition which is no longer there (if you reboot now, you will be thrown into a recovery shell, but you can continue the boot process by typing "exit" at the shell using the aws serial console). To fix boot, we need to do the following:
# delete "rd.lvm.lv=SangomaVG/swaplv1 " from the grub config
nano /etc/default/grub
# rebuild grub
grub2-mkconfig -o /boot/grub2/grub.cfg
# rebuild initramfs
dracut --force --regenerate-all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment