Increase Disk Size for a Linux Virtual Machine
If your virtual machine
is running out of disk space, you can opt to increase the storage accordingly as long as the host machine has enough disk space to accommodate your VM.
Follow the below pre-defined
steps to guide you through the storage resizing process. The snapshots provided
herein are for Oracle Linux 6 VM running on Windows 10 Operating System. You
can also use the same steps to resize VMs running on Windows 7 or Windows 8.
NB: If your virtual machine has snapshots, then, you can opt to clone your VM first, then increase disk space for the cloned machine. Click https://fdba-activities.blogspot.com/2021/06/how-to-clone-virtual-machine-on-windows.html to see a post on how to clone a virtual machine.
The steps below will only work
for a machine without snapshots.
- Then run cmd as an administrator to open a command prompt or ensure your logged-on to a user who has administrator privileges before invoking the command prompt.
On the command prompt, navigate to C:\Program Files\Oracle\VirtualBox>; then, execute VBoxManage.exe modifyhd followed by your actual VirtualBox vdi/vhd path, then --resize option and the new hard disk size (indicated in MBs). In my case, I executed the following to resize my VM to 110GB.
NB:1GB = 1024mbs. I arrived at 112640 after multiplying 110 by 1024.
C:\Program Files\Oracle\VirtualBox>VBoxManage.exe modifyhd “%USERPROFILE%\VirtualBox VMs\oraclelinux6 clone-disk.vdi” -- resize 112640
4. After successfully resizing the virtual machine on the host OS, go ahead and start the virtual machine.
Login as root on the VM. You can also opt to log in as a normal user and then su – root. You will be prompted to enter the root password.
How to create a disk partition in Linux.
List Mounted File systems in Linux.
Run df -h to list the currently mounted file systems. Pay attention to the file system we want to resize. In my case, am aiming to increase the size of /dev/mapper/vg_srv1-lv_root.Creating an LVM Physical Volume in Linux
Execute pvcreate
/dev/sda3 to create a physical volume out of our newly created
partition.
How to Extend a Volume Group in Linux.
Run vgextend vg_svr1 /dev/sda3 to extend the volume group vg_svr1 to include the physical volume /dev/sda3. Remember to use the volume group name obtained in the previous step.
Type vgdisplay again. Note the Free PE/Size has now changed.
Extending root logical volume to maximum space
Execute lvextend -l +6841 /dev/mapper/vg_srv1-lv_root
to extend the logical volume /dev/mapper/vg_srv1-lv_root to the maximum
available space.
Run df
-h. Note that the size of the file system /dev/mapper/vg_srv1-lv_root is
yet to be increased.
Resize the Linux LVM file system
Execute resize2fs
/dev/mapper/vg_srv1-lv_root to resize the file system.
You can now happily make use of the increased disk space
accordingly J.
Comments
Post a Comment