目录
Extend Linux OS Volume in Cloud
"Whenever the OS disk is expanded in cloud environment, the partition table should be corrected in the OS and filesystem needs to be extended as well."
Here are steps to extend Linux Volume. This may be applied to all Linux distros.
Part 1 MBR Partition Table
- SSH to the VM.
- Check the name of disk you expand in Cloud Provider Console. In this scenario, I expand the /dev/sda from 30GB to 50GB.
sudo fdisk -l
(If there is an error like bellow, that means the disk has GPT partition table. Please jump to Part 2 to continue.)
3.Check the filesystem of the last disk partition. Usually there are two types “ext4” and “xfs”. In my scenario, /dev/sda has "xfs" filesystem.
df -Th
4.Modify partition table.
sudo fdisk /dev/sda
- Command: d (This will delete the partition table but it won’t delete data on the disk)
- Partition number: (Press Enter if to keep default value)
- Command: n (Create a new partition)
- Select: P
- Partition number: (Press Enter if to keep default value)
- First Sector: (Press Enter if to keep default value)
- Last sector: (Press Enter to keep default value if don’t need to create more partitions)
- Command: p (Verify the partition table and check if the partition is in the new size)
-
Command: w (Save the partition table, before this you can quit at any time to discard all modifications)
5.Reboot the VM.
6.Extend the file system.
- If the filesystem is “xfs” in step 3, run command bellow:
sudo xfs_growfs /dev/sda2
- If the filesystem is “ext4” in step 3, run command bellow:
sudo resize2fs /dev/sda2
(If there is an error “/dev/sda2 is not a mounted XFS filesystem”, please use mount point like ‘/’ instead of disk name)
7.Verify the filesystem.
Part 2 GPT Partition Table
- SSH to the VM
- Check the label of disk you expand. In this scenario, I expand the /dev/sda from 30GB to 70GB.
sudo fdisk -l
3.Check the filesystem of the last disk partition. Usually there are two types “ext4” and “xfs”. In this scenario, /dev/sda has "xfs" filesystem.
df -Th
4.Fix the GPT table.
sudo parted /dev/sda unit s print
- Fix/Ignore/Cancel? Fix
- Fix/Ignore? Fix
(If there is no error displayed, that means it succeeds.)
5.Modify partition table.
sudo fdisk /dev/sda
- Command: d (This will delete the partition table but it won’t delete data on the disk)
- Partition number: (Press Enter if to keep default value)
- Command: n (Create a new partition)
- Select: P
- Partition number: (Press Enter if to keep default value)
- First Sector: (Press Enter if to keep default value)
- Last sector: (Press Enter to keep default value if don’t need create more partitions)
- Command: p (Verify the partition table and check if the partition is in the new size)
- Command: w (Save the partition table, before this you can quit at any time to discard all modifications)
6.Reboot the VM
7.Extend the file system.
- If the file system is “xfs” in step 3, run command bellow:
sudo xfs_growfs /
(Don’t use disk name here. If the partition was not mounted on ‘/’, please change ‘/’ to the right mount point)
- If the file system is “ext4” in step 3, run command bellow:
sudo resize2fs /
(Don’t use disk name here. If the partition was not mounted on ‘/’, please change ‘/’ to the right mount point)
8.Verify the file system
df -Th