As you use a Linux virtual machine more and more, it may become necessary to enlarge its virtual hard disk.
However, it will also be necessary to enlarge the file system available on it. Which is more or less complicated on Linux.
In the tutorial below, we will show you how to enlarge the file system of the virtual hard disk where Linux is installed.
Important : if Linux was installed in LVM mode, the procedure to use will be different.
So you'll see that in the next tutorial.
Currently, our Linux virtual machine running Ubuntu 20.04.3 x64 has a 20 GB virtual hard drive.
To see the different mount points present in your Linux virtual machine, open a terminal and obtain root rights.
To do this, use this command under Ubuntu and provide your password.
Note that your account must be part of the sudoers file (of which the one created during the Ubuntu installation is part).
Bash
sudo su
Next, view your mount points by typing the command:
Bash
df -h
In our case, we can see the partition "/dev/sda5" has a size of 20 GB.
The "sda5" partition is therefore partition no. 5 of the 1st hard disk (sda).
To enlarge (expand) the virtual hard disk of your Linux virtual machine, turn it off, then click on the icon: Edit Settings.
Currently our virtual hard disk size is 20 GB.
Specify a value greater than the one currently indicated to enlarge it.
In our case, we indicated "30 GB" instead of "20 GB".
Note that you cannot reduce the size (capacity) of a virtual hard disk.
If you attempt to do so by specifying a value less than the current size (capacity), an error message will appear: Enter disk capacity which is larger than its original capacity.
As you can see in the VM hardware of your Linux virtual machine, the size of the virtual hard disk has increased.
However, if you start the virtual machine and use the previous command again, you will see that the file system in the guest operating system has not been updated.
This additional storage space is therefore not usable at the moment.
Bash
df -h
Currently, you can see that the size of partition 5 (sda5) of our 1st virtual hard disk (sda) has a size of 20 G:
Bash
df -h
Plain Text
Filesystem Size Used Avail Use% Mounted on ... /dev/sda5 20G 6.5G 12G 36% / ... /dev/sda1 511M 4.0K 511M 1% /boot/efi
To enlarge the file system of this partition, you will therefore have to enlarge the "sda5" partition (/dev/sda5), then enlarge the file system located there.
To do this, use the "GNU Parted" program present by default under Ubuntu and indicate as a parameter that you wish to modify the partition table of the 1st virtual hard disk (sda).
Bash
parted /dev/sda
Which will display this:
Plain Text
GNU Parted 3.3 Using /dev/sda Welcome to GNU Parted ! Type « help » to view a list of commands. (parted)
View the partition table of this hard drive using the command:
Bash
As you can see in the "Disk /dev/sda" line, the new capacity of this hard drive is 32.2 GB.
In the list of partitions you will find:
Plain Text
Model: VMware Virtual disk (scsi) Disk /dev/sda: 32.2GB Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags: Number Start End Size Type File system Flags 1 1049kB 538MB 537MB primary fat32 boot 2 539MB 21.5GB 20.9GB extended 5 539MB 21.5GB 20.9GB logical ext4
To be able to use the full capacity of this virtual hard disk, you will need to use the "resizepart" command to resize the 2 partitions (the extended partition "sda2", then the logical disk "sda5").
To begin, resize the "sda2" extended partition by indicating the new size of your hard drive as a parameter:
Bash
resizepart 2 32.2GB
Since this partition is currently in use, you will need to confirm by entering the letter "O".
Plain Text
Warning: Partition /dev/sda2 is being used. Are you sure you want to continue? Yes/No? y
For the end of this partition, enter the new size of your hard drive again.
Plain Text
End ? [21.5GB]? 32.2GB
Redisplay the partition table of your "sda" hard drive using the "print" command.
Bash
As expected, the "sda2" partition was enlarged.
Note that the size will be a little smaller than what you indicated. Indeed, part of the disk space is used by partition 1, as well as for the file system itself (storing the partition table, ...).
Plain Text
Model: VMware Virtual disk (scsi) Disk /dev/sda : 32.2GB Sector size (logical/physical) : 512B/512B Partition Table: msdos Disk Flags: Number Start End Size Type File system Flags 1 1049kB 538MB 537MB primary fat32 boot 2 539MB 32.2GB 31.7GB extended 5 539MB 21.5GB 20.9GB logical ext4
Now that you know the new size of the extended partition, you can resize the logical drive on it to fill all the available space on it.
To do this, resize the logical disk (partition no. 5 = sda5) by indicating the size of the extended partition (partition no. 2 = sda2) as a parameter:
Bash
resizepart 5 31,7GB
As before, confirm the resizing of this "sda5" partition even though it is in use and indicate the same size when Linux asks you for the new position of the end of this partition.
Plain Text
Warning: Partition /dev/sda5 is being used. Are you sure you want to continue? Yes/No? y End ? [21.5GB]? 31.7GB
View the partition table of this hard drive again to verify that the logical drive has been enlarged:
Bash
As expected, the logical disk (which corresponds to the sda5 partition) has been enlarged.
Plain Text
Model: VMware Virtual disk (scsi) Disk /dev/sda: 32,2GB Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags: Number Start End Size Type File system Flags 1 1049kB 538MB 537MB primary fat32 boot 2 539MB 32.2GB 31.7GB extended 5 539MB 31.7GB 31.2GB logical ext4
Now, you can close the "parted" program by typing "quit".
Bash
quit
When you close the "parted" program, this will be displayed.
Plain Text
Information: Don't forget to update /etc/fstab if necessary.
Then you will have access to the terminal again.
If you check the list of mount points for your file system, you will see that the size of the file system on the "sda5" partition will not have changed.
Indeed, we have enlarged our partition 5, but not its file system.
Bash
df -h
Plain Text
Filesystem Size Used Avail Use% Mounted on ... /dev/sda5 20G 6,5G 12G 36% / ... /dev/sda1 511M 4,0K 511M 1% /boot/efi ...
To enlarge the file system of this partition so that it takes up all the disk space available on it, you will need to use the command:
Bash
resize2fs /dev/sda5
Which will display:
Plain Text
resize2fs 1.45.5 (07-Jan-2020) Filesystem at /dev/sda5 is mounted on / ; on-line resizing required old_desc_blocks = 3, new_desc_blocks = 4 The file system on /dev/sda5 is now 7607673 blocks (4k) long.
Use the command again:
Bash
df -h
And you will see that the size of the "sda5" partition has been updated.
Plain Text
Filesystem Size Used Avail Use% Mounted on ... /dev/sda5 29G 6,5G 21G 24% / ... /dev/sda1 511M 4,0K 511M 1% /boot/efi ...
VMware 6/22/2022
VMware 8/9/2024
VMware 7/10/2024
VMware 8/23/2024
Pinned content
Contact
® InformatiWeb-Pro.net - InformatiWeb.net 2008-2022 - © Lionel Eppe - All rights reserved.
Total or partial reproduction of this site is prohibited and constitutes an infringement punishable by articles L.335-2 and following of the intellectual property Code.
You must be logged in to post a comment