So I have been digging in my old content that I scrapped for the relaunch and have been deciding which pieces of work well with my new format and which pieces. Don’t. When I do find a better option, I have been cleaning up the SEO, providing some editing and redoing less than pretty pictures. I ran into a problem that gave me another problem. That problem was the virtual hard drive was too small so how does one go about a resize of a vhd in VirtualBox? Read on to find out.
As part of the pretty picture section, I decided several of my later pictures in my Ubertooth series were not up to snuff. I tried a new screen capture program and have decided it just did not do as good of a job. Rather than leave some substandard imagery, I decide to redo some of the pictures.
I am redoing a 2019.2 VM of Kali Linux and following my own directions. I am doing this both as a test of the instructions and as a chance to grab better screen shots. Unfortuately, the versions are slightly different and I get some warnings about obsolete versions. Hopefully, it won’t break anything. Anyway, enough about that let’s dig into it.
How to resize a virtual hard drive in VirtualBox
First make sure the VM is off. I don’t know if that is actually important but it seems like a good idea. Also make a backup of the VM hard drive. It will be extension, VMI or VHD. In my case I am using a VHD. In the VirtualBox Main screen you want to opne File->Virtual Media Manager.
This will get you a new dialog, titled Virtual Media Manager.
In this screen, we have an option of which Hard Disks we want to resize, along with an attributes tab. These are the things we are looking for to resize the drive. Select the drive you want, which for me is the second drive and enter the value you want in the textbox, in this case with text of 20GB. I selected 50 GB.
Press the Apply button. Now it will not give you any dialog saying “Hi, I am done.” Just give it a second and hit the close button.
Kick on your instance you just increased and open the terminal. If you can get to the desktop, everything is probably pretty good. Except there is still a problem.
Kali does not see the space expanded in the system partition.
Don’t freak out if you get a screen like this. We will resolve it.
Just dismiss it, it is an old warning. In the terminal screen type lsblk and hit enter.
You will get a results screen that will look like this. If you are operating with only one hard drive on the VM then look for the item that has type disk and make sure the size says what you put in the textbox in the above resizing step. In my case 50g.
So now we know that the OS can see the size of the drive. We still have an issue. This is not a VirtualBox issue but a resize issue Kali has virtual drive. We need to focus on the partitions on the drive we have identified as the expanded drive. The partitions are those lined out things, sda1, sd2 and sda5.
Generally this will be the biggest partition on your drive. Now we need to expand the partition to take up the available room. We will use GParted. To get to the program click on the programs list button.
In the search bar type GPart and it should come up below. Click on it.
GParted
Now we cannot just resize. See the unallocated part. That is what we created. See the yellow section labeled /dev/sda1. That is our partition. The red square in the middle is the evil SWAP drive. Ok, it is not evil but it cannot exist if we want to merge the two other boxes. So it has to be moved.
Now if you cannot figure this out. We are about to do some bad juju to the drive. Back it up if it has anything you value on it. There is a real danger of blowing up the outside world, Dr Evil stuff happening to the drive. One misstep, one different setting and your drive will go boom.
Consider yourself warned.
Now lets play with the evil scientist’s nuclear weapons! I even know the game. We are going to play musical chairs only with sandboxes!
Bring SWAP And Unallocated Together.
Select the second partition. Right click and select the Resize/Move option.
We need to get the yellow bar, which is the partition on the other side of the dialog. Drag the arrow to the edge and select the Resize/Move button.
As the teal line around the red box and unallocated space reveals, we have brought everyone in the partition into the same sandbox. Let’s move the red part. Select it and select the Resize Move Option from the context menu. If you don’t see it, make sure to right click on /dev/sda5.
Now we need to move the arrows to the other end. I am also going to expand my swap size to about twice as big as we started. I figure that will not hurt anything since I should have the space and I like big swap files.
Now do the same thing to the other arrow. This time try to match as best you can to your new value. I just doubled 4096 to 8192.
Now you are going to get a scary ass error like the one below. Just embrace the destruction and press Apply.
So we have half the battle won at this point. The red SWAP is at the other end of the pool. I do have a single megabyte mocking me but I accept it as the devil’s cut of the new drive and move on to getting our unallocated space into the same sandbox as our system drive. So press the checkbox. Accept whatever scary error it may tell you and enjoy the show for the music has stopped.. Reboot the system.
You should come back to your login screen. Login, get to your desktop and open GParted like we did earlier. We still have work to do so the music starts up again.
We need to get the teal box removed from the unallocated space.
Right click on the partition that has the unallocated space in it and select Resize/Move. In this instance it is sda2.
We need to move the right most arrow to the yellow space.
When you have it arranged. Press the Resize/Move button.
We have everything back to the same level but this time unallocated is next to /dev/sda1. We can now merge them together. Right click on /dev/sda1 in this case and Resize/Move.
Stretch the arrow to the other side and press Resize button.
Again, the devil got his due with an extra megabyte lost. Finally enjoy the chaos you caused and press the green check mark. You will likely get a scary error. Accept it and let it do its thing for the music stops again.
After all that reboot your VM and hopefully everything comes back up. After you get logged in and back to the desktop. Select the terminal screen and type lsblk. You should now see that your drive has been expanded to its new size. For instance mine when from 16G to 42 GB and 4G to 8G respectively.
That was a crap load of steps. But most importantly, you won musical chairs and VirtualBox virtual hard drive resize was successful. Why they made it so difficult, I don’t know. 2MB lost through the transfer, not bad for a Windows guy, if I say so myself.
As usual, if you have a question or comment about VirtualBox, virtual hard drives or how to resize a virtual hard drive in other technologies, drop it below.
Thank you so much. I was stuck. I could not find any instructions to fix this.