Learn the process for expanding virtual disks on Red Hat Enterprise Linux systems.
The benefits of virtualization are many: redundancy, faster delivery of operating systems and applications, snapshots for easy system recovery and the ability to quickly rearrange or expand resources are just a few examples.
Growing file systems is a common task in virtualized environments. While it's quite easy to do in Windows, it can be a bit harder in Linux. It's possible to expand a Linux file system via the command line, but this is tedious and sometimes unreliable, possibly leading to mangled partitions. It's better to streamline the process by booting a virtual machine using a utility called GParted which constitutes a bootable disc image in the form of an .iso file.
In this article I'll cover how to resize Red Hat Enterprise Linux partitions with GParted in either the Red Hat Virtualization or VMWare environments. The steps will be similar for other Linux distributions but may have some slight variance.
Here are the prerequisites to get started:
- Access to VMWare/Red Hat Virtualization (RHV) console
- Administrative rights in VMWare/RHV
- Administrative rights in Linux
- The bootable GParted .iso image.
- If using RHV, you need to load the .iso image into the RHV environment via the ISO Uploader Tool (see here for directions)
For this exercise, assume we are trying to resize /dev/vda2 from 75 Gb to 100 Gb and the current layout is:
/dev/vda1 - boot
/dev/vda2 - /
/dev/vda3 - swap
1. Power off the VM.
2. Grow the disk space as desired.
Click the VM in the RHV console, select the "Disks" tab then click Edit:
You cannot change the current size value but you can extend the size by a specified amount. In the example above, I'll extend the size by 25 Gb. Skip to step three.
Right-click the VM, choose "Edit Settings" then select the Hard Disk:
Adjust the provisioned size accordingly and click "OK." If the option to expand the disk is not available, check for and remove any snapshots then try again.
3. Mount the GParted disc image:
Right-click the VM and choose "Run Once":
As shown above, expand "Boot Options" then click "Attach CD" and select your operating system image file.
Under "Boot Sequence" select "CD-ROM" and then click the "Up" button to the right to make that the default boot device.
Click OK. The virtual machine will power up. Skip to step five.
If you are using VMware and the virtual machine is not set to boot from the CD-ROM first by default, follow these steps:
Now right-click the VM, choose "Edit Settings," and click the "Options" tab:
Check off the option to "The next time the virtual machine boots, force entry into the BIOS setup screen" under "Force BIOS Setup."
Power on the VM and access the console.
As shown in the screenshot above, use the right arrow key to go to the "Boot" tab and use the + sign to move CD-ROM Drive to the top.
Go to Exit and leave "Exit Saving Changes" highlighted then press enter. Answer "Yes" to save the changes.
5. The virtual machine will boot from the CD.
6. Attach to the console.
7. At the main GParted screen either hit enter or wait for the default option to load.
8. Hit enter at the "configuring console-data" box. ("Don't touch keymap").
9. Hit enter at the "Which language do you prefer?" prompt.
10. Hit enter at the "Which mode do you prefer?" prompt.
11. You'll see the main GParted screen:
Note the size of the swap volume (1 Gb).
12. In this example we'll extend the /dev/vda2 volume to 100 Gb, but we have to move that swap file to the far right before we can do so. Right-click the red swap volume (dev/vda3) and choose "Resize/Move."
13. In the next box enter "0" in the "Free space following (MiB)" field.
14. Hit tab then click "Resize/Move."
15. Click "OK" to the warning that moving the partition might cause the operating system to
16. You'll then see the swap partition moved to the end of the volume:
17. Right-click /dev/vda2 and choose "Resize."
18. Drag the right side of the partition all the way to the right to expand the volume.
19. Click "Resize."
20. Click "Apply."
21. When the operation(s) finish you should see an end result that looks like this:
22. Click "Close" when finished., then power off/on the VM and confirm the volume has been
expanded (run df -h after logging in or fdisk -l -u -s /dev/vda).
23. If you are using VMWare, you might want to revert the steps you followed in step four to
move the "CD-ROM" option back to its original spot in the boot order.
How to handle security risks in Red Hat virtualization environments
How to manage your Red Hat subscription on RHEL 7.3
5 data center-ready Linux distributions
How to monitor your Linux servers with nmon