Skip to main content

Spawning many VirtualBox machines from a single VDI

What I'm taking about here is a way to have many VirtualBox machines based upon a single hard drive image. There are many reasons why you might like to do this, but the most compelling is probably saving time by not having to install an OS over and over again, especially useful if you do anything like software testing.

Our goal is a single vdi (virtual disk) file which contains a vanilla installation of our favourite OS which we can then use to conjure up a fresh new machine in a jiffy.

Assuming you already have VirtualBox installed our first step is (maybe for the last time ever!) to install our OS into a new virtual machine. Now I shan't go through this as it's pretty straight forward and if you're reading this it's the sort of thing you have probably done a hundred times before.

One thing of note during the initial setup is the 'Virtual Hard Disk' configuration. Be sure to allocate enough space to allow for all potential applications of the image. It would be wise to select 'Dynamically expanding storage' so that your vdi will only be as big as it needs to be.

Once you have your new machine in a state suitable to spawn other machine from (patched, base software installed etc) shut it down and we can move on.

Now unregister the vdi from the virtual machine used to constuct it, you can do this on the command line using VBoxManage, or a number of ways through the gui. I use the gui 'Virtual Media Manager' (found under the 'file' menu in your VirtualBox interface).

Now this is where we run out of functionality in the VirtualBox gui and we'll have to resort to the command line. We need to change the type of our vdi from 'normal' to 'immutable' by running:
VBoxManage modifyhd /full/path/to/my/vdi --type immutable

Back in the gui interface, in the machine storage configuration, reallocate the now immutable vdi file to the original build machine. You should now be able to boot this again just as before. Excellent!

Now create a new machine, but this time when selecting a hard disk choose to use an existing disk and select our immutable vdi. Awesome it works! (hopefully)

That is almost it! Just one more thing to be very aware of. Going back into the Virtual Media Manager your'll notice you can now expand a list against the immutable vdi. Inspecting these will show you that they are 'differencing' disks, associated to our machines using the immutable vdi above. These differencing disks allow our machine to diverge in state.

HOWEVER the default configuration of these differencing disks is to RESET each time the machine is powered on. This may be just what you want, to be able to boot a clean state each time, perfect for testing software. However if you want your new machines to preserve their states there is one more command to run.

From the media manager note the id of the differencing disk you want to preserve state, it's contained in the Location path at the bottom of the window and is enclosed in {}. It'll look a bit like this,
3f80ade2-0380-4087-88e8-21edc3a8d85

Now run,
VBoxManage modifyhd Your-Disk-Id-In_Here --autoreset off

This will be remember from here on in for this machine and all snapshots taken from it in the future.

Comments

  1. Very easy to understand Paul! I like this idea, might just have to implement it ;)

    ReplyDelete
  2. I think the behaviour of the differencing disk might've changed in recent versions, as it seems to not be autoreseting for me

    ReplyDelete
  3. with 3.1.6, no worries about autoresetting:

    From the help file:
    'snip'
    The differencing image is only reset when the machine is powered on from within VirtualBox, not when you reboot by requesting a reboot from within the machine.
    'snip'

    so if you reboot from your guest os, you're ok. Tried it myself and it works.

    ReplyDelete
  4. Yes, state is preserved for REBOOTS, but not if you shutdown. Therefore you'll need to set the autoreset property if you expect that the VM will ever be cold booted again and you don't want to loose state... which it will.

    ReplyDelete
  5. Hi, one hint which could help linux-like sysadmins. You may type in console:

    VBoxManage list hdds

    Newly created drives should be at the bottom. Than you may just use cmd above.

    For example:
    UUID: b8ac13a3-8ce3-4e0d-886f-511cebe1693e
    Parent UUID: base
    Format: VDI
    Location: /kaplajir/centos6_fix/centos_6.vdi
    State: locked read
    Type: immutable

    UUID: 9b11e4d8-f507-4e89-9021-ed9df599bbf2
    Parent UUID: b8ac13a3-8ce3-4e0d-886f-511cebe1693e
    Format: VDI
    Location: /centos6_test11/Snapshots/{9b11e4d8-f507-4e89-9021-ed9df599bbf2}.vdi
    State: locked write
    Type: normal
    Usage: centos6_test1 (UUID: 7558d7ab-6381-465f-bbc7-99f820d789a9)

    VBoxManage modifyhd 9b11e4d8-f507-4e89-9021-ed9df599bbf2 --autoreset off

    And if you have many vbox drives I advice to use grep functionality. This will show info about all immutable devices:

    VBoxManage list hdds | grep -B 5 immutable

    With UUID of immutable drive you may use

    VBoxManage list hdds | grep Your-Disk-Id-In_Here -A 5

    Sorry for long comment and thank you for you nice article :)
    Jiri Kaplan

    ReplyDelete
  6. Hey Paul! Just wanted to say thank you so much for writing this post. I desperately need this feature and you made it so easy to implement. Thanks

    ReplyDelete
  7. Being able to share your digital data safely is a must if you want your company to be in cleint's good books.
    Richard Brown vdr data room

    ReplyDelete
  8. Thanks a lot for this info, it helped me becoming unstuck in a course I'm doing :)

    ReplyDelete
  9. Play Live Casino Game Online - XN Entertainment
    Play 카지노사이트 Live Casino games at XN gioco digitale Entertainment. Play the best live dealer games and more at XN Entertainment. 온카지노 Sign up now and get up to a 100% welcome

    ReplyDelete
  10. Grosvenor Hotel Casino & Spa: Luxury Hotel in Israel - Air
    Grosvenor Hotel Casino & Spa is situated on the top 365 bet level 먹튀검증소 of Israel's renowned Gold Coast and 프로토 features over 2,000 guest rooms. air jordan 18 retro red order Located in air jordan 18 retro men clearance the centre of

    ReplyDelete
  11. Thank you for this article, Paul. It was very useful to me.

    ReplyDelete

Post a Comment

Popular posts from this blog

Moodle on Centos or Red Hat 7 (with SELinux!)

Why the need for another 'Installing Moodle' guide? Two reasons, Systemd and SELinux. The steps are presented as a Bash script, which may be run on a virgin system, installing a complete working Moodle stack in one go, including enforcing SELinux. In addition to the absolute basics it also includes adding ClamAV virus for file uploads and Memcached for sessions and 'MUC'. It does not cover any extras you will need to get your site up to production, e.g. securing your database  or updating your virus definitions automatically. Neither does it do any extra PHP configuration (upload limits, execution time etc.) or any extra complexities that might be desirable. For all of this you should goto  docs.moodle.org .

Row a Concept2 on Zwift with a $10 Raspberry Pi!

Short story, I made a program. Instructions and download here:  https://github.com/mrverrall/go-row Despite there being an appetite for rowing in Zwift the fact is a rowing machine is not a bicycle and a Concept2 rower won't connect directly to Zwift. The Zwift gods tease a rowing release every now and again, but it's been coming 'soon' for years now. Don't hold your breath. But people do row in Zwift, so how do they do it? To get the data from the rowers computer, the PM5, into something Zwift recognises as a bicycle you need a device that translates between the rower and the device running Zwift. There are solutions already available to do this. Some are expensive like the  NPE CABLE (about £90 in the UK) and some are 'free' like the  RowedBiker  app. The downside with RowedBiker is that it needs to run on a extra device separate from the one running Zwift. If you have a compatible device lying around, great, otherwise you'll need to buy one. Meanwh...