[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now


Delete .VDI file, Free up hard drive

Posted on 2011-02-28
Medium Priority
Last Modified: 2012-05-11

I have two .VDI files, one of which I'm no longer using. How do I safely remove the one I'm no longer using to free up disk space on my laptop? I run Ubuntu on VB and can access windows files.

Would this command work to safely remove the partition that was created via Virtual Box for ubuntu?

rm -rf BMG.vdi

Question by:faithless1
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
LVL 35

Expert Comment

ID: 34999054
A .vdi file must be deleted on the host system, not inside the guest.
If Windows is your host where you run VB, and Ubuntu is run inside that VB, then you have to delete the .vdi file in Windows. In Ubuntu, by the way, you wouldn't even be able to see it.

If you want to make sure that nothing is affected by deleting the .vdi file, rename it first, start VB and Ubuntu for a test, if everything still works fine, close VB and remove/delete the .vdi file.

I already gave you this solution in your other thread: http://www.experts-exchange.com/OS/Linux/Q_26811233.html?cid=1135#a34859212

The fact that you ask the same question again is the best proof for the fact that in the other thread you chose the wrong solution. I pointed this out to you, but you did not deem my questions worth an answer in more than two and a half weeks.

Choosing the wrong solution is not in the interest of E-E, and if you did so, it is not tragic because it can be corrected. Ignoring expert questions for clarification is a worse matter, and certainly impolite.
If you had a problem with understanding my solution in the other thread, simply asking (instead of closing choosing an obviously wrong solution) would have made me explain better and help you through the process.

Author Comment

ID: 34999767

Thank you for the response.

I might not have been clear in both postings. I understand that the '.vdi' file has to be deleted on the host machine or windows as you specified. In this posting I specified that I can access all windows files through the gnome terminal and I'm looking for a simple solution to delete the .VDI file through gnome terminal. By 'I can access all windows files through the gnome terminal' I mean that all 'host' files are mounted to 'guest'.

I do appreciate all efforts/responses provided to questions, and if this is a matter of not giving enough attention to your efforts in the previous post - I apologize. However, the solution was being overcomplicated based on specifications and renaming .vdi to .vdy would free up space.

The reason I chose gparted because it seemed as the safest way since it would free up space on the drive vs renaming and deleting which did not appear as the safest way to remove the partition considering previously I deleted .VDI file but the space on the hard drive which was allocated to the partition did not free up.

Lastly, while this question might appear similar to my previous question, in reality it's not since I'm looking for a way to quickly remove .VDI files with "rm -rf BMG.vdi". Essentially, I'm looking for a solution where I can safely delete any .vdi that I create quickly through command prompt.

For instance, if I have created 15 partitions through VB by following the setup process and I need to remove 2 .VDI files so the question is whether i can I simply use "rm -rf BMG.vdi" to remove partitions.

Hope this clarifies some of your questions/concerns. Thanks again

Author Comment

ID: 34999883
Also, if in fact I would be able rename .vdi to .vdy and delete it which will free up 16GB of space, in that case I can case your solution would work but by simply deleting a partition that is of use would not solve the problem of freeing up space.
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

LVL 35

Expert Comment

ID: 35000171
If you have mounted the complete host filesystem as a network drive in Ubuntu (which is certainly unusual), and you can access the .vdi files that way, and the .vdi file is not in use by the present virtual machine, then you should be able to delete an unused .vdi file using this command:

sudo rm -i BMG.vdi

Do not use the -r switch, and use the -i switch for security reasons: it will prompt you before deleting.
LVL 35

Expert Comment

ID: 35000267
My suggested solution in the other thread seemed "overcomplicated" for one single reason:

Since it was not at all clear what exactly you were after, and how your VMs were set up, I wanted to protect you from accidentally deleting a .vdi that was still in use and somehow required by your Ubuntu VM.
16 GB are too large for the recycle bin in most configurations, so simply deleteing a .vdi file would have been irrecoverable. Most askers here on E-E will not take necessary precautions: they will do exactly what experts tell them. I did not want to be made responsible if you deleted the wrong file.

I admit I still do not quite understand what you tried to explain to me above.

The question still stands: it is absolutely inconceivable that using GParted could help to get rid of a .vdi file. So did you use it? And did it do what you expected? If not, you chose a wrong solution. This must be corrected, because all closed threads on E-E are added to a knowledgebase of known working solutions.

Author Comment

ID: 35007378
this should clarify :
GParted is a program you can use to make changes to the partitions on your hard disk, such as deleting a partition, resizing a partition, or copying and partition.

Thanks for the previous response. Just to clarify: If I use this command, sudo rm -i BMG.vdi will it free up space? Deleting a .vdi file isn't really a problem, but deleting it in a way that it will free up partitioned space on the host is the main issue when dealing with a .vdi file.

Lastly, renaming the file to a different extension or simply deleting it without renaming an unused, unmounted .vdi drive is not a solution but would be if the .vdi file was 0KB.

LVL 35

Accepted Solution

torimar earned 2000 total points
ID: 35009169
I know quite well what GParted is because I use it all the time. That is why I also know that it cannot be used to get rid of a .vdi file. It is able to manipulate/delete partitions inside that .vdi file, not the virtual disk itself. Hence why it was evidently a wrong solution to choose in the other thread.

Quote: >>"If I use this command, sudo rm -i BMG.vdi will it free up space? Deleting a .vdi file isn't really a problem, but deleting it in a way that it will free up partitioned space on the host is the main issue when dealing with a .vdi file."

If you delete a .vdi file, it will free up space on the filesystem where this file was located, yes.
This is best done by directly deleting the file on the host (as I said above and in the other thread). If that host is Windows, you may have to also empty the recycle bin.
If you are trying to delete the vdi file from inside the guest (which is very unusual), and you receive an error, or the space on the host is not freed up, then this may be caused by the fact that this is not the usual procedure. The usual procedure is to do it on the host, not via the guest. Even if you cannot shutdown the VM for some reason, you should be able to task-switch to the host OS in order to delete the file.
If that isn't possible, and you have to delete the vdi from inside the guest, there should be ways to verify whether the space has actually been freed up, by checking the free diskspace before and after the removal using either the Ubuntu filemanager or the 'df' console command: http://linux.about.com/od/commands/l/blcmdl1_df.htm

Quote: >> "Lastly, renaming the file to a different extension or simply deleting it without renaming an unused, unmounted .vdi drive is not a solution but would be if the .vdi file was 0KB."

As much as I tried I do not understand what you mean.
Again: renaming the file was just a precaution, not a solution. It would help you to check whether the file was still required somehow. If everything would run well after renaming the file and restarting the VM, you would be safe to delete it. That last step was the solution.
Of course, you have to physically delete the .vdi file from where it is located on the host's filesystem (usually in ..\virtualbox\harddisks). It does not suffice to only 'remove' it from the VM by clicking the '-' (minus) inside the VB control panel.

Furthermore: you simply cannot delete a file that is in use, neither in Windows nor in Linux. So, of course, only unused VM files can be deleted. A mounted file also cannot be deleted, because it presently is in use. And a file that is presently unmounted (because the VM isn't running) but would be mounted/required by a VM should not be deleted because this will create problems with the VM. It needs to first be removed from the VM in the VB control panel, and can then be deleted - if no longer required by the VM.

Author Comment

ID: 35014278
I'm definitely not the best at explaining but thanks for clarifying and providing all the details.

I just thought that because I did not delete the file from the recycle bin after renaming it to .vdy and deleting it from \virtualbox\harddisk (it's not used by VM and is not mounted), that this was the issue.

However, I just selected 'disk cleanup' and 'recycle bin' contents and they only amount to 3.7MB with the .vdy file. However, when I move the file to my Desktop, select properties, it is showing that the 'size' is 2GB but the 'size on disk' is 56KB. The combined totals in the recycle bin are much lower but shouldn't the total in the recycle bin be greater than 2GB? This should be my last questions. Thanks again
LVL 35

Expert Comment

ID: 35024638
Sorry, I have been on baby-sitting duty yesterday.

So did it work and you actually managed to free up disk space as expected?
I'm a bit confused: wasn't it all about a 16 GB vdi file that you wanted to get rid of, not a 2 GB? This could, perhaps, be explained by the fact that there are 'static' and 'dynamic' virtual disks: you decide, on creating, of which type a disk should be. A static 16 GB vdi is always 16 GB large, no matter whether it contains data and how many. A 16 GB dynamic disk, however, will grow on demand, from just a couple of megabytes to 16 GB maximum, depending on the amount of data it actually holds.

But what really puzzles me is the discrepancy in size: a file with 'size' 2 GB should have a 'size on disk' of 2 GB +/- a couple of kilobytes. And it should not lose its size when moved to the recycle bin. I'm still not quite sure what to think of this.

Author Comment

ID: 35063138

Sorry for the delay, been very busy. I think the problem had to do with compressed disk space, since at some point the entire C: drive was compressed so the actual size was larger than what was showing.


Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It Is not possible to enable LLDP in vSwitch(at least is not supported by VMware), so in this article we will enable this, and also go trough how to enabled CDP and how to get this information in vSwitches and also in vDS.
David Varnum recently wrote up his impressions of PRTG, based on a presentation by my colleague Christian at Tech Field Day at VMworld in Barcelona. Thanks David, for your detailed and honest evaluation!
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
How to install and configure Citrix XenApp 6.5 - Part 1. In this video tutorial we have explained step by step installation of Citrix XenApp 6.5 Server on Windows Server 2008 R2 is explained in this video. We have explained the difference between…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question