There are many ways to mount a data partition at boot, of which this is perhaps the simplest. It produces only a single entry in the home folder, for the data partition itself, but that’s fine for this scenario. Don't be intimidated by the length of the instructions. Doesn't take long to do.
0. Before doing anything, make sure you have a current Timeshift snapshot, just in case.
1. Open File Manager. Create a folder in home to which we will mount the data partition. Call it just VirtualBox
2. Create partition. Open GParted
. Select appropriate device from drop-down at upper-right. Right-click sdc1
; select Move/Resize; using the slider, create as much space as you want to give the new VBox partition.* Click the check mark to Apply the change. Resizing a large partition takes a long time (an hour to two),** as lots of files have to be reconfigured to “move” them to the left (it's kind of like a defrag in Windows), so find something else to do in the meantime. Once complete, click Partition on Menu and select New. By default, the app will assume you want to give the new partition all the available space, which in this case you do. Tab to Format (or select with mouse) and select NTFS from drop-down. Tab to Label and enter VirtualBox.*** Hit Apply again. Unlike resize, this will run very quickly.
* For reference, I generally give test box VMs a virtual hard drive of 40 GB. So, a 500 GB partition would have room for ten VMs, leaving enough free space for a reasonable buffer. If you want to use one (or more) of the VMs to do stuff, that might require a larger virtual hard drive and reduce the number of VMs a partition of a given size can accommodate. FYI, partition sizes are specified in MiB in GParted. For example, 500 GiB = 512,000 MiB (500 x 1024).
** This issue only arises when shrinking or moving a partition. Resize to the right without moving (enlarging the partition) takes very little time. By the way, all these operations require the partition to be unmounted, so sometimes you need to do this stuff from a live session.
*** There’s an advantage in Linux to avoiding spaces in label names, as spaces mean something functional in Terminal and have to be “quoted” to be read as spaces. So, if you want to call the partition VirtualBox VMs, use a hyphen or underscore, VirtualBox-VMs or VirtualBox_VMs. I use plain VirtualBox; not like it’s ambiguous.
3. Edit fstab
to mount the partition at boot. First, make a copy: sudo cp /etc/fstab /etc/fstab-old
. Now open the file with administrative privileges. I prefer to use nano
(a simple terminal text editor), but you also can use xed
(the default GUI text editor). For the former, run sudo nano /etc/fstab
; for the latter, run xed admin:///etc/fstab
. Enter password when prompted (which will happen twice for the second option). Go to the end of the file and hit Enter twice to get a new line. Insert the following (use copy-and-paste):
Code: Select all
# Mount VirtualBox partition into Home folder
LABEL=VirtualBox /home/bfg/VirtualBox ntfs-3g defaults,windows_names,locale=en_US.utf8 0 0
If using nano
, click Ctrl-O to write-out, Enter to overwrite current file, and Ctrl-X to exit and return to Terminal. . If using xed
, click Ctrl-S to save, then Ctrl-X to exit; you’ll see an error message about location not mounted; it’s a bug, harmless and can be ignored.
Note: The partition being mounted can be identified by label or UUID; I use the former here, but the latter might be more suitable in other situations. Also, be aware the paramters for an ext4 partition would be very different. You can read more about fstab at Ubuntu Help. Even more useful, albeit very technical, is the man page (manual) for the mount command, which is what actually uses the parameters set in fstab. See also this tutorial for how to set up more complex data partitions than we're doing here.
4. Confirm. Still in Terminal, run sudo mount -a
. If no error is reported, you should be good. If there's an error, restore fstab
and report back. So, rename the edited fstab file (sudo mv etc/fstab /etc/fstab-new
) and restore the old one (sudo mv /etc/fstab-old /etc/fstab
). Then post here the contents of the edited file, cat /etc/fstab-new
, so we can figure out what went sideways.
[Edited to add sudo to the move/rename commands.]
5. When you install VirtualBox
, it will create a separate folder in home called VirtualBox VMs
(with a space, dammit). Open File > Preferences > Default Machine Folder. Change that to the VirtualBox folder we set up. Open File Manager and delete the folder VBox created. Now all VM files will end up in the data partition and, so, can be shared by both operating systems.
FYI, something I forgot to mention when we first started down this path. The one annoying quirk about sharing VMs between Windows and Linux is that the shared folder settings will be incompatible. Shared folders are what you use to give the VM access to files on the computer. So, if you use shared folders (and you probably will), you’re gonna get a warning every time you boot a VM and there’s no way I’ve found to turn that off. OTOH, the VM will run fine, including the shared folder for the OS acting as host (the other OS’s shared folder won’t work, of course), so the warning is merely an annoyance.
That should do it. Apologies for any typos or omissions. I know this works, as I’ve done it, but it’s always difficult to proofread one’s own text.