Increasing the Size of the Disk of VM
Intro
As we are developing more and more projects on my VM, we might get a problem which is the disk would be full. Obviously, we can clean up our file system to free up more space. However, if you got the issue frequently, it is better to increase the size of your disk for your VM.
Pre-check for your disks
First of all, you need to know the status of your disks at beginning. To have a pre-check of your disks, you can use the command: sudo fdisk -l /dev/sdc
. The result would be similar like this:
wyu@wyu-vm01:~> sudo fdisk -l /dev/sdc
Disk /dev/sdc: 128 GiB, 137438953472 bytes, 268435456 sectors
Disk model: Virtual Disk
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 82719DF5-D3FE-4960-A694-DABB4556C3E9
Device Start End Sectors Size Type
/dev/sdc1 2048 134215679 134213632 64G Linux filesystem
Use command df -h
to check the general info of your disks.
wyu@wyu-vm01:~> df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 4.0M 0 4.0M 0% /dev
tmpfs 7.9G 23M 7.8G 1% /dev/shm
tmpfs 3.2G 9.9M 3.2G 1% /run
tmpfs 4.0M 0 4.0M 0% /sys/fs/cgroup
/dev/sdb4 127G 45G 83G 35% /
/dev/loop3 583M 583M 0 100% /snap/datagrip/162
/dev/loop4 185M 185M 0 100% /snap/gitkraken/201
/dev/loop2 64M 64M 0 100% /snap/core20/1778
/dev/loop0 586M 586M 0 100% /snap/datagrip/163
/dev/loop1 64M 64M 0 100% /snap/core20/1738
/dev/loop5 347M 347M 0 100% /snap/gnome-3-38-2004/115
/dev/loop6 185M 185M 0 100% /snap/gitkraken/202
/dev/loop7 56M 56M 0 100% /snap/core18/2667
/dev/loop11 128K 128K 0 100% /snap/bare/5
/dev/loop8 347M 347M 0 100% /snap/gnome-3-38-2004/119
/dev/loop9 92M 92M 0 100% /snap/gtk-common-themes/1535
/dev/loop10 56M 56M 0 100% /snap/core18/2654
/dev/loop13 1.2G 1.2G 0 100% /snap/intellij-idea-ultimate/401
/dev/loop12 1.2G 1.2G 0 100% /snap/intellij-idea-ultimate/398
/dev/loop15 744M 744M 0 100% /snap/pycharm-professional/314
/dev/loop14 674M 674M 0 100% /snap/phpstorm/307
/dev/loop16 668M 668M 0 100% /snap/phpstorm/310
/dev/loop17 757M 757M 0 100% /snap/pycharm-professional/316
/dev/loop18 263M 263M 0 100% /snap/redis-desktop-manager/626
/dev/loop19 50M 50M 0 100% /snap/snapd/17883
/dev/loop20 50M 50M 0 100% /snap/snapd/17950
/dev/loop22 605M 605M 0 100% /snap/webstorm/294
/dev/loop21 602M 602M 0 100% /snap/webstorm/291
/dev/sdc1 64G 36G 29G 57% /home
/dev/sdb3 1014M 98M 917M 10% /boot
/dev/sdb2 512M 3.0M 509M 1% /boot/efi
tmpfs 1.6G 60K 1.6G 1% /run/user/470
/dev/sda1 32G 24K 30G 1% /mnt
tmpfs 1.6G 76K 1.6G 1% /run/user/1000
As you can see above, I need to increase the size of my data disk, from 64G to 128G.
Increase the size of the data disk on Azure portal
To increase the size of the data disk, the first step is to increase it for my VM on Azure portal.
On the left panel of the Azure portal, click Disks
and then click the data disk you want to increase.
Then, click Size + performance
to choose the new size of your data disk.
Click “Save” button, the VM will resize your data disk with the new size.
Make the new size available for your data disk
Unfortunately, OpenSUSE will not automatically increase the file system. So the size will stay the same if you check your data disk. You need to resize file system to make the new free space available for use.
According the document from OpenSUSE (Resizing File Systems) , we can use this command to increase the file system: sudo xfs_growfs -d /dev/sdc1
. However, it did not work for me.
meta-data=/dev/sdc1 isize=512 agcount=4, agsize=4194176 blks
= sectsz=4096 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=0 bigtime=0 inobtcount=0
data = bsize=4096 blocks=16776704, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=8191, version=2
= sectsz=4096 sunit=1 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data size unchanged, skipping
After some research, the reason is that the OS did not expand the partition automatically. So, there was no more free space for the partition to increase. To make it happen, we need to grow the partition first.
For OpenSUSE, we can use growpart
to grow a partition. The command for the purpose is: sudo growpart /dev/sdc 1
.
The result of the command shows that the size of the partition is changed.
CHANGED: partition=1 start=2048 old: size=134213632 end=134215680 new: size=268433375 end=268435423
Now, let’s try to grow the file system with the previous command sudo xfs_growfs -d /home
:
sudo xfs_growfs -d /home
meta-data=/dev/sdc1 isize=512 agcount=4, agsize=4194176 blks
= sectsz=4096 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=0 bigtime=0 inobtcount=0
data = bsize=4096 blocks=16776704, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=8191, version=2
= sectsz=4096 sunit=1 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 16776704 to 33554171
It looks great! Let’s check the disk by df -h
:
wyu@wyu-vm01:~> df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 4.0M 0 4.0M 0% /dev
tmpfs 7.9G 23M 7.8G 1% /dev/shm
tmpfs 3.2G 9.9M 3.2G 1% /run
tmpfs 4.0M 0 4.0M 0% /sys/fs/cgroup
/dev/sdb4 127G 45G 83G 35% /
/dev/loop3 583M 583M 0 100% /snap/datagrip/162
/dev/loop4 185M 185M 0 100% /snap/gitkraken/201
/dev/loop2 64M 64M 0 100% /snap/core20/1778
/dev/loop0 586M 586M 0 100% /snap/datagrip/163
/dev/loop1 64M 64M 0 100% /snap/core20/1738
/dev/loop5 347M 347M 0 100% /snap/gnome-3-38-2004/115
/dev/loop6 185M 185M 0 100% /snap/gitkraken/202
/dev/loop7 56M 56M 0 100% /snap/core18/2667
/dev/loop11 128K 128K 0 100% /snap/bare/5
/dev/loop8 347M 347M 0 100% /snap/gnome-3-38-2004/119
/dev/loop9 92M 92M 0 100% /snap/gtk-common-themes/1535
/dev/loop10 56M 56M 0 100% /snap/core18/2654
/dev/loop13 1.2G 1.2G 0 100% /snap/intellij-idea-ultimate/401
/dev/loop12 1.2G 1.2G 0 100% /snap/intellij-idea-ultimate/398
/dev/loop15 744M 744M 0 100% /snap/pycharm-professional/314
/dev/loop14 674M 674M 0 100% /snap/phpstorm/307
/dev/loop16 668M 668M 0 100% /snap/phpstorm/310
/dev/loop17 757M 757M 0 100% /snap/pycharm-professional/316
/dev/loop18 263M 263M 0 100% /snap/redis-desktop-manager/626
/dev/loop19 50M 50M 0 100% /snap/snapd/17883
/dev/loop20 50M 50M 0 100% /snap/snapd/17950
/dev/loop22 605M 605M 0 100% /snap/webstorm/294
/dev/loop21 602M 602M 0 100% /snap/webstorm/291
/dev/sdc1 128G 36G 92G 29% /home
/dev/sdb3 1014M 98M 917M 10% /boot
/dev/sdb2 512M 3.0M 509M 1% /boot/efi
tmpfs 1.6G 60K 1.6G 1% /run/user/470
/dev/sda1 32G 24K 30G 1% /mnt
tmpfs 1.6G 76K 1.6G 1% /run/user/1000
As you can see, the size of my data disk increased. I will not be got the issue of disk is full in a short period of time.