6816 shaares
To resize an LVM partition in VirtualBox, first increase the virtual disk size using the command VBoxManage modifyhd <UUID> --resize <new size in MB>. Then, within the virtual machine, use commands like lvextend to expand the logical volume and resize2fs to resize the filesystem.
Resizing LVM Partition in VirtualBox
To resize an LVM partition in a VirtualBox virtual machine, follow these steps:
Step 1: Resize the Virtual Disk
- Shutdown the VM: Ensure your virtual machine is powered off.
- Open Command Line: Navigate to the VirtualBox installation directory.
- Run Resize Command: Use the following command to resize the disk:
VBoxManage modifyhd <UUID> --resize <new size in MB>
Replace<UUID>with your virtual disk's UUID and<new size in MB>with the desired size.
Step 2: Modify the Partition
- Boot the VM: Start your virtual machine.
- Check Current Partitions: Use the command:
df -lh
Identify the partition you want to resize, typically/dev/mapper/ubuntu--vg-ubuntu--lv. - Use fdisk: Run:
fdisk /dev/sda- Type
nto create a new partition. - Use default values for the partition number and first sector.
- Set the last sector to use all available space.
- Type
- Write Changes: Type
wto write the changes.
Step 3: Resize the LVM
- Create Physical Volume: Run:
pvcreate /dev/sdaX
ReplacesdaXwith your new partition fromfdiskabove. - Extend the Volume Group: Use:
vgextend <vg-name> /dev/sdaX
Replace<vg-name>with your volume group name. - Extend the Logical Volume: Run:
lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
Step 4: Resize the Filesystem
- Resize the Filesystem: Finally, execute:
resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
After completing these steps, your LVM partition should be successfully resized, allowing you to utilize the additional space.