Introduction
Are you working with Ubuntu in a Proxmox virtual environment and finding yourself running out of disk space? You’re not alone. Expanding disk space is a common necessity for developers and IT professionals. In this blog, we’ll walk you through the steps to increase your disk space within Proxmox OS using Ubuntu as your virtual machine system.
Step 1: Increase size from disk size with web GUI
First things first, let’s increase the size of the disk from the Proxmox web interface.
- Choose VM, go to
Hardware > Hardisk
- Click on
Disk Action > Resize
and enter the number to add to current size disk
Step 2: Extend physical drive partition
Once you’ve increased the disk size, it’s time to extend the physical drive partition.
sudo fdisk -l
to check disk free space
$ sudo fdisk -l
...
Disk /dev/sda: 40 GiB, 42949672960 bytes, 83886080 sectors
Disk model: QEMU HARDDISK
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 55C6ECCB-5BD2-4C84-BA3F-8EF2BA6F23D4
Device Start End Sectors Size Type
/dev/sda1 2048 4095 2048 1M BIOS boot
/dev/sda2 4096 3674111 3670016 1.8G Linux filesystem
/dev/sda3 3674112 73400286 69726175 33.2G Linux filesystem
...
sudo growpart /dev/sda 3
to extend physical drive partition with3
as indication of the partition number on the disk that you want to resize
$ sudo growpart /dev/sda 3
CHANGED: partition=3 start=3674112 old: size=69726175 end=73400287 new: size=80211935 end=83886047
sudo pvdisplay
to see physical drive
$ sudo pvdisplay
--- Physical volume ---
PV Name /dev/sda3
VG Name ubuntu-vg
PV Size <33.25 GiB / not usable 16.50 KiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 8511
Free PE 0
Allocated PE 8511
PV UUID ...
sudo pvresize /dev/sda3
to instruct LVM that disk size has changed
$ sudo pvresize /dev/sda3
Physical volume "/dev/sda3" changed
1 physical volume(s) resized or updated / 0 physical volume(s) not resized
After this step, your disk will display this when run sudo pvdisplay
:
--- Physical volume ---
PV Name /dev/sda3
VG Name ubuntu-vg
PV Size <38.25 GiB / not usable 16.50 KiB
Allocatable yes
PE Size 4.00 MiB
Total PE 9791
Free PE 1280
Allocated PE 8511
PV UUID ...
Step 3: Extend physical volume
After extending your physical volume, it’s time to focus on the logical volume.
lvdisplay
to view current logical volume
$ sudo lvdisplay
--- Logical volume ---
LV Path /dev/ubuntu-vg/ubuntu-lv
LV Name ubuntu-lv
VG Name ubuntu-vg
LV UUID ...
LV Write Access read/write
LV Creation host, time ...
LV Status available
# open 1
LV Size <33.25 GiB
Current LE 8511
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
to resize logical volume of disk with/dev/ubuntu-vg/ubuntu-lv
being the logical volume of the disk
$ sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
Size of logical volume ubuntu-vg/ubuntu-lv changed from <33.25 GiB (8511 extents) to <38.25 GiB (9791 extents).
Logical volume ubuntu-vg/ubuntu-lv successfully resized.
This step will extend the logical space of the disk
$ sudo lvdisplay
--- Logical volume ---
LV Path /dev/ubuntu-vg/ubuntu-lv
LV Name ubuntu-lv
VG Name ubuntu-vg
LV UUID ...
LV Write Access read/write
LV Creation host, time ...
LV Status available
# open 1
LV Size <38.25 GiB
Current LE 9791
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
Step 4: Resize filesystem
The final step is to resize the filesystem to utilize the entire space of the logical volume.
resize2fs /dev/ubuntu-vg/ubuntu-lv
to enlarge logical volume to occupied all of the physical volume
$ resize2fs /dev/ubuntu-vg/ubuntu-lv
resize2fs 1.46.5 (<...>)
Filesystem at /dev/ubuntu-vg/ubuntu-lv is mounted on /; on-line resizing required
old_desc_blocks = 5, new_desc_blocks = 5
The filesystem on /dev/ubuntu-vg/ubuntu-lv is now 10025984 (4k) blocks long.
To check file system, use sudo fdisk -l
to confirm disk space
$ sudo fdisk -l
...
Disk /dev/sda: 40 GiB, 42949672960 bytes, 83886080 sectors
Disk model: QEMU HARDDISK
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: ...
Device Start End Sectors Size Type
/dev/sda1 2048 4095 2048 1M BIOS boot
/dev/sda2 4096 3674111 3670016 1.8G Linux filesystem
/dev/sda3 3674112 83886046 80211935 38.2G Linux filesystem
...
Conclusion
Command used in this document:
# Extend physical drive partition
sudo growpart /dev/sda 3
sudo pvresize /dev/sda3
pvdisplay
# Extend Logical volume
sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
lvdisplay
# Resize Filesystem
resize2fs /dev/ubuntu-vg/ubuntu-lv
fdisk -l
There you have it – a straightforward guide to expanding your disk space in a Proxmox environment running Ubuntu. These steps will help you manage your virtual machine’s storage more effectively, ensuring you have the space you need for your applications and data. Remember, regular maintenance and monitoring of your virtual environment are key to smooth operations. Stay tuned for more tips and tricks in managing your virtual infrastructure!
Work with us!
TopSquad provides comprehensive DevOps Engineer services, tailored to meet the unique technological needs of businesses today. Our deep insight into the tech industry and understanding of essential DevOps skills helps companies find and integrate skilled DevOps professionals seamlessly. Our approach includes creating detailed role descriptions, conducting thorough vetting processes, and offering continuous support. By choosing TopSquad, businesses can efficiently enhance their operations with skilled DevOps Engineers, paving the way for innovation and streamlined success