Introduction

I’ll be completely honest I really like Linux as a operating system. However, the one thing I really dislike about it is increasing disk space through CLI since there are so many ways it can be done and there are multiple of extensions to choose from. To make sure that I don’t forget about increasing disk spaces in Linux, I decided to create this article.

Please keep in mind that it has been some years since I worked with Linux servers…

Increase Disk Space

You can use the following commands to increase the disk space for the EXT4 extension.

StepDescriptionCommand
1View disk spacelsblk
2View filesystem typedf -Th /dev/sda1
3Grow partitionsudo growpart /dev/sda <PARTITION>
4Verify partition expansionlsblk /dev/sda
5Apply the growth on paritionsudo resize2fs /dev/sda1
6Verify expansiondf -h /dev/sda1
7Reboot rsyslogsystemctl restart rsyslog
8Reboot Azure Monitor Agentsystemctl restart azuremonitoragent

If you have any services running on the server, I would recommend rebooting them and they should start working without any issues.

Decreasing Disk Space

If you think increasing disk space is a-lot of work well… I got terrible news since in Linux to decrease the disk space it needs to be resized through a different VM.

StepDescriptionCommand
1View disk spacelsblk -f
2Check filesysteme2fsck -f /dev/sda2
3View minimum size requiredresize2fs -P /dev/sda2
4Shrink the sizeresize2fs /dev/sda2 60G
5Verify the shrink of partitione2fsck -f /dev/sda2
6View block and block sizetune2fs -l /dev/sda2 | grep -E 'Block (count|size)'
7Shrink the partitionparted /dev/sda
unit s
print
resizepart 2 <End>s

I also decided to include instructions to decrease size since it might help with reducing cost once you have figured out why the Linux VM consumes a-lot of disk space.

Conclusion

I primarily use Windows as a main operating system since it works out of the box. However, after writing this article, I realized that my Linux skills have been degrading and I’ll be focusing on improving the Linux skills going forward by using it as a primary operating system. Hopefully, this article is useful to someone who needs it.