Mounting a VDI File in a Different VirtualBox Guest
October 17, 2019
Today I wanted to check if a specific file was on an old Linux virtual disk image (VDI) I had on an external backup disk. I had already an Ubuntu guest up and running so I wanted to mount the VDI file located on the external harddisk as an additional virtual harddisk and access it from within the Ubuntu guest.
First, I stopped the Ubuntu guest. Next, I opened the Virtual Media Manager, and added the VDI file.
Next, I opened the settings for the Ubuntu guest and selected the storage tab. I selected the SATA controller and clicked the harddisk icon with a green plus symbol to add a new drive. In the dialog window I selected Choose existing disk.
Next, I started the Ubuntu virtual machine. I used the following command to find the name of the disk:
sudo fdisk -l | grep sd
This command gave the following output for my virtual machine:
Disk /dev/sda: 30 GiB, 32212254720 bytes, 62914560 sectors
/dev/sda1 * 2048 62912511 62910464 30G 83 Linux
Disk /dev/sdb: 50 GiB, 53687091200 bytes, 104857600 sectors
/dev/sdb1 * 2048 88082431 88080384 42G 83 Linux
/dev/sdb2 88084478 104855551 16771074 8G 5 Extended
/dev/sdb5 88084480 104855551 16771072 8G 82 Linux swap / Solaris
The drive added is /dev/sdb
and the partition I needed to mount is
/dev/sdb1
as /dev/sdb2
is an extended partition with /dev/sdb5
the swap partition.
So, I made a directory to mount the additional virtual harddrive under as follows:
sudo mkdir /old-hdd
Next, I used vi
to modify /etc/fstab
:
sudo vi /etc/fstab
And added the following to the end of this file:
/dev/sdb1 /old-hdd ext4 defaults 0 0
After this I could mount the virtual harddisk using:
sudo mount /old-hdd
When I was done with the old virtual harddisk I unmounted it as follows:
sudo umount /old-hdd
And removed the directory I used as a mount point using:
sudo rmdir /old-hdd
And removed the last line from /etc/fstab
using vi
.
Next, I stopped the virtual machine running Ubuntu so I could remove the virtual harddisk. In the settings for the Ubuntu virtual machine I removed the VDI file from the SATA controller.
Next, I opened the Virtual Media Manager and with the right VDI file selected I clicked the Remove button. A dialog opened which asked if I wanted to Keep the VDI file or Delete it. As I want to keep this specific VDI around I selected Keep.
Finally, I restarted the Ubuntu virtual machine.