Deleting Linux Swap Partition on KVM
From ProxCP Documentation
This page is in reference to the fact that cloud-init KVM templates cannot have any disk partition after the root "/" partition. In many cases, the Linux swap partition is after the root partition therefore it needs to be deleted as expected by cloud-init.
The root partition is important because cloud-init can grow the partition automatically from a template clone but only if it is the last partition on a disk.
Steps
- Delete the
swap
line from /etc/fstab - Run
swapoff -a
- Use fdisk on the disk in question, this is usually /dev/sda
fdisk /dev/sda
- Execute the following commands in fdisk:
- p (get partition number of the Linux swap partition)
- d (delete the swap partition by number)
- d (delete any other system partition; there should only be 1 partition left for "/")
- w (write the new partition table)
- Do one of the following to resize the file system to the maximum size:
resize2fs /dev/sdaX
where X is the number of the remaining partitiongrowroot /dev/sda X
where X is the number of the remaining partition- If cloud-init is installed with growroot support, simply
reboot
Notes
- The Linux swap partition is the main focus here, but any partition located after the root "/" partition needs to be deleted for cloud-init growroot to work correctly.