Expanding the size of a Red Hat Enterprise Linux Server Virtual Machine run by Oracle Virtualbox

Опубликовано: 04 Октябрь 2024
на канале: Tarek Radi
325
5

Expanding the size of a Red Hat Enterprise Server Virtual Machine. This VM is managed by Oracle VirtualBox. Expanding the VM storage using vboxmanage is not suficient. You need to also update your VM's partitions, physical volumes, volume groups and logical volumes to ensure that your filesystem makes use of that space.

I make use of multiple commands in Linux to manage Physical Volumes (e.g. pvs, pvcreate), Volume Groups (e.g. vgs, vgdisplay, and vgextend ), Logical Volumes (e.g. lvs and lvextend) and File Systems (e.g. xfs_growfs and df). I also use "GNOME disks" to view and create partitions.

Before starting, i already have:
a) 3 partitions (/dev/sda1, /dev/sda2 and /dev/sda3),
b) 2 physical volumes (/dev/sda2 and /dev/sda3) both of which connected to the Volume Group "rhel"
c) 1 volume group (called "rhel" to which 2 physical volumes sda2 and sda3 are already connected)
d) 2 logical volumes (one called "root" and the other called "swap", both of which are using the volume group "rhel"
e) the filesystem /dev/mapper/rhel-root which is mounted on / and using that logical volume "root"
d) 1 logical volume

Steps:
1) When your VM is shut down, expand it. In my case the VDI file for the VM is called "Red Hat Clond.vdi", and i want to expand it to 30GB
Command = vboxmanage modifyhd "Red Hat Clone.vdi" --resize 30000

2) Create a partition using the newly created free space (called it sda4)

3) create the Physical Volume
Command = pvcreate /dev/sda4

4) Extend your Volume Group to include the new physical volume
Command = vgextend rhel /dev/sda4

5) My logical volume /dev/mapper/rhel-root was already running on the volume group "rhel", so I just needed to extend the logical volume by the amount of free space available on the volume Group
Command = lvextend -l +1249 /dev/mapper/rhel-root

6) Grow the filesytem
Command = xfs_growfs -d /

To expand the size of Ubuntu VDI images, the steps are WAAY easier.
1) When your VM is shut down, expand it by running the following command, replacing Ubuntu.vdi with the full path of the VDI file you want to expand and replacing 30000 with the size you want. In my case, i wanted 30GB, hence the 30000
vboxmanage modifyhd "Ubuntu.vdi" " --resize 30000

2) Run GParted, right click on /dev/sda1 and chose to "Resize" and drag the bar to the right then click the "Resize" button, then click the checkbox to apply your changes.