In my Vagrantfile, using VirtualBox, I'm trying to dynamically create/mount arbitrary storage devices on the same storage controller (e.g. for persistence on a readonly filesystem) to specific paths on the VM (not using Guest Additions, nfs, etc). Currently jumping through a lot of hoops (see the gist below) trying to accomplish this. For example, here's the workflow I'm attempting:
- Use provided image path (VDI, VMDK, etc on the host filesystem) to
VBoxManage createhd
if doesn't exist (working) - Attach storage device from #1 to the storage controller via
VBoxManage storageattach
(working) - Mount the attached storage device's primary partition at the specified mountpoint (not working)
The step-by-step so far for each device is thus (see this gist, partially pseudocode):
- Get device UUID (according to VBox)
- Get the real path to the device on the guest (via
/dev/disk/by-uuid/<uuid>
) - Create primary partition if the device was just created
- Mount the device (optionally, add to
/etc/fstab
for persistence)
The problem is that, since I don't want to assume/predict that a particular device will be available at /dev/sdX
, I can't come up with a reliable way to get a reference to the unmounted device (in order to mount it) on the guest because the VBox UUID and the guest OS device UUID don't seem to match, which is key. Are they supposed to be the same? If not, how would I reliably get the device path on the guest, only having the VBox information? Is there a better way to accomplish this?
As an aside, I am testing with CoreOS (which has a readonly root mount), and don't want to use Guest Additions or NFS from the host for this particular purpose - I am intentionally trying to use storage devices.