Difference between revisions of "Resizing you Virtual Disk"
(→Resizing the Logical File System) |
(→Make a Clone) |
||
(16 intermediate revisions by the same user not shown) | |||
Line 4: | Line 4: | ||
First shut down the guest operating system - the Centos. | First shut down the guest operating system - the Centos. | ||
− | The free and open version of VirtualBox does not - yet - have the capability to resize the .vmdk disk's. Therefore you have to convert the present harddisk to another format, vdi. | + | The free and open version of VirtualBox does not - yet - have the capability to resize the .vmdk disk's. Therefore you have to convert the present harddisk to another format, vdi. So if your disk is in format VMDK convert to VDI format. If already in VDI format jump to next section. |
<source lang=bash> | <source lang=bash> | ||
− | $ vboxmanage clonehd " | + | $ vboxmanage clonehd "Centos-disk2.vmdk" "clone.vdi" --format vdi |
</source> | </source> | ||
− | here put in your diskname | + | here put in your diskname if different from above. |
===Resizing=== | ===Resizing=== | ||
+ | |||
+ | ====Linux Host==== | ||
Now, after a short waiting time, we are ready to perform the actual resizing. | Now, after a short waiting time, we are ready to perform the actual resizing. | ||
Line 20: | Line 22: | ||
Here the disk is resized to 80 GB ~ 80000MB | Here the disk is resized to 80 GB ~ 80000MB | ||
+ | ====Windows Host==== | ||
+ | This will work for VirtualBox version >=6 | ||
+ | |||
+ | Execute this command in cmd | ||
+ | |||
+ | Navigate to the installation folder for VirtualBox - typically C:\Program Files\Oracle\VirtualBox | ||
+ | |||
+ | <source lang=bash> | ||
+ | VBoxManage modifymedium disk "<path to your disk>.vdi" --resize <wanted size e.g. 40000> | ||
+ | </source> | ||
===Mount the Resized Disk=== | ===Mount the Resized Disk=== | ||
One could think that we now need to clone the disk back to the vmdk-format. But that is not necessary. Just delete the present disk in the VirtualBox Manager - click Settings for the particular machine and move down to '''Storage'''. Delete the attached disk, e.g. Centos.vmdk and insert the "clone.vdi" instead. | One could think that we now need to clone the disk back to the vmdk-format. But that is not necessary. Just delete the present disk in the VirtualBox Manager - click Settings for the particular machine and move down to '''Storage'''. Delete the attached disk, e.g. Centos.vmdk and insert the "clone.vdi" instead. | ||
− | + | [[File:Settings.png|500px]] | |
− | + | ||
− | + | '''Before deleting the disk''' | |
+ | |||
+ | [[File:Settings1.png|500px]] | ||
+ | |||
+ | '''After the newly cloned disk has been attached''' | ||
+ | |||
+ | ===Resizing inside Linux=== | ||
+ | The next step is to resize the partition within the virtual machine. This can only be done, when the Linux that is using the disk is not running. How can one change something when it is not running? Think of you virtual PC as an ordinary PC. You know that you can use a CD or DVD or even a USB memory stick to boot your ordinary PC in order to manipulate the hard disk. The same goes for your virtual PC. Therefore you have to boot the virtual machine using a LiveDVD. I downloaded the "Swiss knife" from [http://ftp.klid.dk/ftp/knoppix/ Knoppix] a Live DVD - pick one of the newest down the page - newer than January 2017. You need a new image in order to resize the LogicalVolume - LVM, that the Centos resides in. | ||
In the VirtualBox manager attach the Live DVD to the Optical disk controller using the CD/DVD button to the right of the '''Storage''' settings. | In the VirtualBox manager attach the Live DVD to the Optical disk controller using the CD/DVD button to the right of the '''Storage''' settings. | ||
Line 34: | Line 52: | ||
===Booting using another Linux=== | ===Booting using another Linux=== | ||
− | + | Boot the system, but use the Live DVD as boot medium - strat the virtual machine and wait a few seconds. It will boot automagically. | |
− | + | ||
When Knoppix is up running start a console and in the console type | When Knoppix is up running start a console and in the console type | ||
Line 41: | Line 58: | ||
$ sudo gparted | $ sudo gparted | ||
</source> | </source> | ||
− | and resize the main partition to the new size. | + | and resize by extending the main partition to the new size. |
+ | |||
+ | [[File:Settings2.png|500px]] | ||
+ | |||
+ | '''Remember to commit by clicking on the green check mark button''' | ||
Shut down the Knoppix. | Shut down the Knoppix. | ||
− | ''Be sure to unmount the | + | ''Be sure to unmount the DVD after shut down to prevent booting from it once again.'' |
If needed, take a look at this [https://www.youtube.com/watch?v=b5mdnzQ0nuw video] if you need to move your swap partition, but it should not be necessary in the standard "Software-in-a-Box" solution. | If needed, take a look at this [https://www.youtube.com/watch?v=b5mdnzQ0nuw video] if you need to move your swap partition, but it should not be necessary in the standard "Software-in-a-Box" solution. | ||
− | ===Resizing the Logical File System=== | + | ===Resizing the Logical Volume File System=== |
Next you'll boot the Centos again and star a shell. Issue these two commands in order to resize the logical volume file system. | Next you'll boot the Centos again and star a shell. Issue these two commands in order to resize the logical volume file system. | ||
Line 73: | Line 94: | ||
here is the size 13G, but shall be approximately the size you have chosen above. | here is the size 13G, but shall be approximately the size you have chosen above. | ||
− | + | Check that everything work as it did prior to the resizing. | |
− | + | ||
===Clean up=== | ===Clean up=== | ||
− | The very last thing to do is to delete the original vmdk file, that housed the original disk for the virtual machine and of course if you don't need the Swiss knife any more delte the Knoppix iso. | + | The very last thing to do is to delete the original vmdk file, that housed the original disk for the virtual machine and, of course, if you don't need the Swiss knife any more delte the Knoppix iso. |
Latest revision as of 13:39, 12 November 2019
This is a short description of how you can resize your harddisk to the virtual PC.
Contents
Make a Clone
First shut down the guest operating system - the Centos.
The free and open version of VirtualBox does not - yet - have the capability to resize the .vmdk disk's. Therefore you have to convert the present harddisk to another format, vdi. So if your disk is in format VMDK convert to VDI format. If already in VDI format jump to next section.
$ vboxmanage clonehd "Centos-disk2.vmdk" "clone.vdi" --format vdi
here put in your diskname if different from above.
Resizing
Linux Host
Now, after a short waiting time, we are ready to perform the actual resizing.
$ vboxmanage modifyhd "clone.vdi" --resize 80000
Here the disk is resized to 80 GB ~ 80000MB
Windows Host
This will work for VirtualBox version >=6
Execute this command in cmd
Navigate to the installation folder for VirtualBox - typically C:\Program Files\Oracle\VirtualBox
VBoxManage modifymedium disk "<path to your disk>.vdi" --resize <wanted size e.g. 40000>
Mount the Resized Disk
One could think that we now need to clone the disk back to the vmdk-format. But that is not necessary. Just delete the present disk in the VirtualBox Manager - click Settings for the particular machine and move down to Storage. Delete the attached disk, e.g. Centos.vmdk and insert the "clone.vdi" instead.
Before deleting the disk
After the newly cloned disk has been attached
Resizing inside Linux
The next step is to resize the partition within the virtual machine. This can only be done, when the Linux that is using the disk is not running. How can one change something when it is not running? Think of you virtual PC as an ordinary PC. You know that you can use a CD or DVD or even a USB memory stick to boot your ordinary PC in order to manipulate the hard disk. The same goes for your virtual PC. Therefore you have to boot the virtual machine using a LiveDVD. I downloaded the "Swiss knife" from Knoppix a Live DVD - pick one of the newest down the page - newer than January 2017. You need a new image in order to resize the LogicalVolume - LVM, that the Centos resides in.
In the VirtualBox manager attach the Live DVD to the Optical disk controller using the CD/DVD button to the right of the Storage settings.
Booting using another Linux
Boot the system, but use the Live DVD as boot medium - strat the virtual machine and wait a few seconds. It will boot automagically.
When Knoppix is up running start a console and in the console type
$ sudo gparted
and resize by extending the main partition to the new size.
Remember to commit by clicking on the green check mark button
Shut down the Knoppix.
Be sure to unmount the DVD after shut down to prevent booting from it once again.
If needed, take a look at this video if you need to move your swap partition, but it should not be necessary in the standard "Software-in-a-Box" solution.
Resizing the Logical Volume File System
Next you'll boot the Centos again and star a shell. Issue these two commands in order to resize the logical volume file system.
]$ sudo lvextend -L+80G /dev/mapper/cl_jdoe-root ]$ sudo xfs_growfs /dev/mapper/cl_jdoe-root
The -L+80G can be the size you have chosen to extend the disk.
Finally check that your disk and logical volume has been resize correctly issue
]$ df -h
Look for the size of the root partition
$ df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/cl_jdoe-root 13G 11G 2.3G 83% / ......
here is the size 13G, but shall be approximately the size you have chosen above.
Check that everything work as it did prior to the resizing.
Clean up
The very last thing to do is to delete the original vmdk file, that housed the original disk for the virtual machine and, of course, if you don't need the Swiss knife any more delte the Knoppix iso.