How do you reduce the allocated storage size of a virtual machine?

Questions about virtualization software
Forum rules
Before you post please read how to get help
Post Reply
mintyfreshuser
Level 2
Level 2
Posts: 83
Joined: Sat Dec 30, 2017 10:14 pm

How do you reduce the allocated storage size of a virtual machine?

Post by mintyfreshuser » Fri Feb 16, 2018 6:35 pm

Hi all.

Does anyone know how to reduce the allocated storage size of a virtual machine? I think I overestimated the number of gigabytes I needed to allocate. Is there a way to take back unused storage space allocated to a virtual machine after the virtual machine has already been created without deleting the entire virtual machine and starting over?

The distro of Linux Mint that I'm using is Linux 18.3 Sylvia and the desktop environment is Cinnamon 3.6.6 and I'm running VirtualBox Graphical User Interface Version 5.1.32 r120294 (Qt5.5.1) by Oracle.

Thank you.

Cosmo.
Level 23
Level 23
Posts: 17830
Joined: Sat Dec 06, 2014 7:34 am

Re: How do you reduce the allocated storage size of a virtual machine?

Post by Cosmo. » Fri Feb 16, 2018 6:42 pm

Reducing the size of a virtual hard drive is not possible.

User avatar
absque fenestris
Level 5
Level 5
Posts: 536
Joined: Sat Nov 12, 2016 8:42 pm
Location: Confoederatio Helvetica

Re: How do you reduce the allocated storage size of a virtual machine?

Post by absque fenestris » Fri Feb 16, 2018 7:19 pm

Does anyone know how to reduce the allocated storage size of a virtual machine?
Pure curiosity: How many gigabytes have you assigned to Mint? By the way, you can dynamically or permanently allocate space.
Linux Mint 18.3 Sylvia (Mate) 32-bit - Acer D250 Netbook (Intel Atom N270, 2 GB RAM, 120 GB SSD)

mintyfreshuser
Level 2
Level 2
Posts: 83
Joined: Sat Dec 30, 2017 10:14 pm

Re: How do you reduce the allocated storage size of a virtual machine?

Post by mintyfreshuser » Fri Feb 16, 2018 7:36 pm

absque fenestris wrote:
Fri Feb 16, 2018 7:19 pm
Does anyone know how to reduce the allocated storage size of a virtual machine?
Pure curiosity: How many gigabytes have you assigned to Mint? By the way, you can dynamically or permanently allocate space.
I'm not sure how to check how many gigabytes I have assigned to Mint, but my SSD is 500.1 gigabytes in total. I allocated 75 gigabytes across two virtual machines (way more than I needed apparently) and across both of them I've used 34 gigabytes. I have the virtual machines for running programs that don't work with Wine (which has been unreliable for me so far). Right now it says that I have 399.7 gigabytes free on my SSD.

So I want to say I have about 425 gigabytes assigned to Mint, but I don't know. Maybe there's a way to check using the terminal?

User avatar
catweazel
Level 14
Level 14
Posts: 5445
Joined: Fri Oct 12, 2012 9:44 pm
Location: Australian Antarctic Territory

Re: How do you reduce the allocated storage size of a virtual machine?

Post by catweazel » Fri Feb 16, 2018 7:46 pm

Cosmo. wrote:
Fri Feb 16, 2018 6:42 pm
Reducing the size of a virtual hard drive is not possible.
That's not correct. VBoxManage will do it, provided that the virtual disk is a .vdi, but it's not recommended for newcomers.
A new scientific truth does not triumph by convincing its opponents and making them see the light, but rather because its opponents eventually die, and a new generation grows up that is familiar with it. - Max Planck

User avatar
catweazel
Level 14
Level 14
Posts: 5445
Joined: Fri Oct 12, 2012 9:44 pm
Location: Australian Antarctic Territory

Re: How do you reduce the allocated storage size of a virtual machine?

Post by catweazel » Fri Feb 16, 2018 7:50 pm

mintyfreshuser wrote:
Fri Feb 16, 2018 7:36 pm
I'm not sure how to check how many gigabytes I have assigned to Mint, but my SSD is 500.1 gigabytes in total. I allocated 75 gigabytes across two virtual machines (way more than I needed apparently) and across both of them I've used 34 gigabytes. I have the virtual machines for running programs that don't work with Wine (which has been unreliable for me so far). Right now it says that I have 399.7 gigabytes free on my SSD.
Unfortunately that doesn't answer the most pressing question, which is, How much space are the two VMs using together on your linux host? Alternsatively, how big are the disk files themselves?
A new scientific truth does not triumph by convincing its opponents and making them see the light, but rather because its opponents eventually die, and a new generation grows up that is familiar with it. - Max Planck

mintyfreshuser
Level 2
Level 2
Posts: 83
Joined: Sat Dec 30, 2017 10:14 pm

Re: How do you reduce the allocated storage size of a virtual machine?

Post by mintyfreshuser » Fri Feb 16, 2018 8:28 pm

catweazel wrote:
Fri Feb 16, 2018 7:50 pm
mintyfreshuser wrote:
Fri Feb 16, 2018 7:36 pm
I'm not sure how to check how many gigabytes I have assigned to Mint, but my SSD is 500.1 gigabytes in total. I allocated 75 gigabytes across two virtual machines (way more than I needed apparently) and across both of them I've used 34 gigabytes. I have the virtual machines for running programs that don't work with Wine (which has been unreliable for me so far). Right now it says that I have 399.7 gigabytes free on my SSD.
Unfortunately that doesn't answer the most pressing question, which is, How much space are the two VMs using together on your linux host? Alternsatively, how big are the disk files themselves?
One VM disk file is 50 gibabytes big and the other one is 25 gigabytes big. I have 34 gigabytes of installed files across the two VMs.

User avatar
absque fenestris
Level 5
Level 5
Posts: 536
Joined: Sat Nov 12, 2016 8:42 pm
Location: Confoederatio Helvetica

Re: How do you reduce the allocated storage size of a virtual machine?

Post by absque fenestris » Fri Feb 16, 2018 8:29 pm

Funny: Which system do you use?

Me on Mac: Virtualbox asks me how big the virtual disk should be. I say 15 GB. Virtualbox asks me dynamically growing or fixed size? I have to decide that. Then the virtual hard disk is created... but I know exactly how big I have chosen the hard disk.
Linux Mint 18.3 Sylvia (Mate) 32-bit - Acer D250 Netbook (Intel Atom N270, 2 GB RAM, 120 GB SSD)

User avatar
catweazel
Level 14
Level 14
Posts: 5445
Joined: Fri Oct 12, 2012 9:44 pm
Location: Australian Antarctic Territory

Re: How do you reduce the allocated storage size of a virtual machine?

Post by catweazel » Fri Feb 16, 2018 8:36 pm

mintyfreshuser wrote:
Fri Feb 16, 2018 8:28 pm
One VM disk file is 50 gibabytes big and the other one is 25 gigabytes big. I have 34 gigabytes of installed files across the two VMs.
WARNING

The link below contains dangerous commands. If you don't understand the article, don't do it.

The fix requires your VM files to be .vdi

Next time you might consider setting the VM disks up as dynamically allocated.
A new scientific truth does not triumph by convincing its opponents and making them see the light, but rather because its opponents eventually die, and a new generation grows up that is familiar with it. - Max Planck

mintyfreshuser
Level 2
Level 2
Posts: 83
Joined: Sat Dec 30, 2017 10:14 pm

Re: How do you reduce the allocated storage size of a virtual machine?

Post by mintyfreshuser » Fri Feb 16, 2018 8:39 pm

absque fenestris wrote:
Fri Feb 16, 2018 8:29 pm
Funny: Which system do you use?

Me on Mac: Virtualbox asks me how big the virtual disk should be. I say 15 GB. Virtualbox asks me dynamically growing or fixed size? I have to decide that. Then the virtual hard disk is created... but I know exactly how big I have chosen the hard disk.
I have two virtual machines installed right now. The first one is Windows 10 (64-bit) which I allocated 50 gigabytes to. The other virtual machine is Windows XP Professional (32-bit) which I allocated 25 gigabytes to.

Both of them are set to grow dynamically.

User avatar
catweazel
Level 14
Level 14
Posts: 5445
Joined: Fri Oct 12, 2012 9:44 pm
Location: Australian Antarctic Territory

Re: How do you reduce the allocated storage size of a virtual machine?

Post by catweazel » Fri Feb 16, 2018 8:41 pm

mintyfreshuser wrote:
Fri Feb 16, 2018 8:39 pm
Both of them are set to grow dynamically.
Odd. That doesn't seem correct based on your description above.
A new scientific truth does not triumph by convincing its opponents and making them see the light, but rather because its opponents eventually die, and a new generation grows up that is familiar with it. - Max Planck

User avatar
thx-1138
Level 5
Level 5
Posts: 714
Joined: Fri Mar 10, 2017 12:15 pm
Location: Athens, Greece

Re: How do you reduce the allocated storage size of a virtual machine?

Post by thx-1138 » Fri Feb 16, 2018 8:59 pm

...the solution linked to / proposed above by catweasel will work just fine.

If you want a slightly more user friendly way (ie. without using vboxmanage), then:
1) Download sdelete onto your vm (32-bit or 64-bit, depending on what your vm is), and run sdelete -z C:.
Shutdown the vm afterwards (well, obviously...)
2) Get CompactVD from here, and select the vm image in question. Point & click really, not much more to explain there...

User avatar
catweazel
Level 14
Level 14
Posts: 5445
Joined: Fri Oct 12, 2012 9:44 pm
Location: Australian Antarctic Territory

Re: How do you reduce the allocated storage size of a virtual machine?

Post by catweazel » Fri Feb 16, 2018 9:15 pm

thx-1138 wrote:
Fri Feb 16, 2018 8:59 pm
2) Get CompactVD
Good find.
A new scientific truth does not triumph by convincing its opponents and making them see the light, but rather because its opponents eventually die, and a new generation grows up that is familiar with it. - Max Planck

Cosmo.
Level 23
Level 23
Posts: 17830
Joined: Sat Dec 06, 2014 7:34 am

Re: How do you reduce the allocated storage size of a virtual machine?

Post by Cosmo. » Sat Feb 17, 2018 7:14 am

catweazel wrote:
Fri Feb 16, 2018 7:46 pm
Cosmo. wrote:
Fri Feb 16, 2018 6:42 pm
Reducing the size of a virtual hard drive is not possible.
That's not correct. VBoxManage will do it, provided that the virtual disk is a .vdi, but it's not recommended for newcomers.
Enlighten us, how you do something, where the Oracle documentation says in chapter 8.23, that this is not possible:
This currently works only for VDI and VHD formats, and only for the dynamically allocated variants, and can only be used to expand (not shrink) the capacity.

User avatar
catweazel
Level 14
Level 14
Posts: 5445
Joined: Fri Oct 12, 2012 9:44 pm
Location: Australian Antarctic Territory

Re: How do you reduce the allocated storage size of a virtual machine?

Post by catweazel » Sat Feb 17, 2018 7:23 am

Cosmo. wrote:
Sat Feb 17, 2018 7:14 am
Enlighten us, how you do something, where the Oracle documentation says in chapter 8.23, that this is not possible:
I already provided the link and listed some of the limitations.

Edit: The quote refers to a feature of the VBox manager, which cannot be used to reduce the size of a disk. It does not say that disk cannot be so reduced.
Last edited by catweazel on Sat Feb 17, 2018 11:28 pm, edited 1 time in total.
A new scientific truth does not triumph by convincing its opponents and making them see the light, but rather because its opponents eventually die, and a new generation grows up that is familiar with it. - Max Planck

User avatar
AndyMH
Level 4
Level 4
Posts: 357
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: How do you reduce the allocated storage size of a virtual machine?

Post by AndyMH » Sat Feb 17, 2018 10:32 am

My notes from when I had to do it because my original was too small (mint 18.3 host, win7 guest):

Resizing a Virtual Disk
Resizing the virtual disk. Searched on-line and tried messing around in terminal, managed to screw it up so that VB wouldn’t boot windows and had to do a complete restore of Mint to get back to a working windows system. To resize the disk:
(a) In VB manager right click on the guest OS (Windows), from the menu select clone.
(b) Accept the defaults, give the clone a name like Windows7xx without spaces (easier for what you do in terminal below and you can change it later). VB will generate a clone which will then appear in the VB window. This takes some time.
(c) Shut down VB.
(d) Open a terminal and navigate to the new folder containing the VDI, e.g.
/home/andy/VirtualBox VMs/Windows71

(e) In the terminal enter, as an example:
VBoxManagemodifyhd Windows71.vdi --resize 30000

This will resize the image from whatever to 30GB.
(f) Re-start VB and run the guest OS, e.g. Windows 7.1. Goto control panel/admin computer management/storage/disk management and increase the size of C: to use the extra space. Unless this is done, windows will not see and use the additional space created. Note – while it may seem that you cannot change the size basically accept defaults and win will extend drive C:.
(g) Assume that the original guest OS image can now be deleted. Do this from VB manager (again right clicking on the guest OS that you want removed).
Thinkpad T430 i7-3632 Cinnamon 18.3, Thinkpad T410 Cinnamon 17.3, Thinkpad T60 18.0 Mate

Post Reply

Return to “Virtualization”