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

Questions about virtualization software
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
mintyfreshuser

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

Post by mintyfreshuser »

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.
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Cosmo.
Level 24
Level 24
Posts: 22968
Joined: Sat Dec 06, 2014 7:34 am

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

Post by Cosmo. »

Reducing the size of a virtual hard drive is not possible.
User avatar
absque fenestris
Level 12
Level 12
Posts: 4124
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 »

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.
mintyfreshuser

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

Post by mintyfreshuser »

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 19
Level 19
Posts: 9763
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 »

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.
"There is, ultimately, only one truth -- cogito, ergo sum -- everything else is an assumption." - Me, my swansong.
User avatar
catweazel
Level 19
Level 19
Posts: 9763
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 »

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?
"There is, ultimately, only one truth -- cogito, ergo sum -- everything else is an assumption." - Me, my swansong.
mintyfreshuser

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

Post by mintyfreshuser »

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 12
Level 12
Posts: 4124
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 »

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.
User avatar
catweazel
Level 19
Level 19
Posts: 9763
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 »

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.
"There is, ultimately, only one truth -- cogito, ergo sum -- everything else is an assumption." - Me, my swansong.
mintyfreshuser

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

Post by mintyfreshuser »

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 19
Level 19
Posts: 9763
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 »

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.
"There is, ultimately, only one truth -- cogito, ergo sum -- everything else is an assumption." - Me, my swansong.
User avatar
thx-1138
Level 8
Level 8
Posts: 2092
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 »

...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 19
Level 19
Posts: 9763
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 »

thx-1138 wrote: Fri Feb 16, 2018 8:59 pm 2) Get CompactVD
Good find.
"There is, ultimately, only one truth -- cogito, ergo sum -- everything else is an assumption." - Me, my swansong.
Cosmo.
Level 24
Level 24
Posts: 22968
Joined: Sat Dec 06, 2014 7:34 am

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

Post by Cosmo. »

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 19
Level 19
Posts: 9763
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 »

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.
"There is, ultimately, only one truth -- cogito, ergo sum -- everything else is an assumption." - Me, my swansong.
User avatar
AndyMH
Level 21
Level 21
Posts: 13503
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 »

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).
Thinkcentre M720Q - LM21.3 cinnamon, 4 x T430 - LM21.3 cinnamon, Homebrew desktop i5-8400+GTX1080 Cinnamon 19.0
Locked

Return to “Virtual Machines”