​vdi-on-a-stick, or how I gave up on "liveboot"

Floz wrote 06/23/2015 at 02:40 1 point

Liveboot is still useful, small utilities can liveboot and run wonderfully as a system to learn on, sandbox small projects on, or even to install from or repair systems with.  We've even got some hacks for persistence, where your settings stay the way you want from time to time.

Making your own liveboot is a tricky suggestion.  There are TONS of guides, most of which are outdated.  Some may work, given that you have the same software configuration they were using at the time.  To generate an ISO type file that can be understood as a liveboot by tools such as unetbootin or cd burning utilities can be very tricky.

What if I told you there's a better way?

VDI's are all the rage nowadays.  With hardware costs continually dropping and hardware capabilities continually increasing, the ability to virtualize a system has become commonplace.  A VDI, as I know it, is a Virtualized Desktop Instance.  Let's examine this further...

    Virtualized - meaning it is not directly tied to any hardware, but instead rides on a hypervisor.
    Desktop - full desktop environment, likely tuned to do one or several tasks well.
    Instance - As it is virtualized, its existence is dependant upon the hypervisor and instructions (VHD/iso/files).

A VDI can be run or cloned from a "master" image over and over, to produce a large number of standardized desktops for a pool of users.
A VDI can be tuned to allow specialized applications to run that current deployment desktop environments are hostile to.
A VDI can be used as a server, allowing one physical machine to perform many uniquely threaded and managed tasks. (IaaS)

Different hypervisors are good at different things for different people.  Regardless of how you run the VDI, the storage solution should be VHD for this purpose.  VHD format is easy to clone to a USB stick and it just boots.  With a small utility I lucked upon after much searching called clonedisk, I was able to crack the problem.  

A persistent liveboot is exactly that, a persistent liveboot.  It's a carefully crafted semi-complete system.  It's a chroot with almost everything in place, and a bit of space dedicated to saving settings.  Upon trying to build one, I find that this is a gross oversimplification, and I find that I dislike liveboot a little more.

What if we virtualize a system to build it exactly how we want, get it stable and ready to deploy, then clone it over and make it bootable on bare-metal... will it work?  It's kind of a liveboot, but it's really just a desktop built for a few tasks and cloned to a bootable storage with tons of drivers on standby.  It should persist from boot to boot, so if I apt-get a package, then shut down, it's still there when I boot it again.  Lastly, it can be cloned to the USB media in about 30 minutes or less depending upon bus throughput.  It's not a novel concept, but again we find a number of guides, most of which may or may not work...  this one included.

We're gonna use Ubuntu 14.04 netboot .iso attached to a 1 vCpu 1024 mb ram Oracle VM VirtualBox.  This VirtualBox will have a dynamically-sized (max 8gb) VHD storage attached at /dev/sda | /home/me/vdi/gamer/gamer.vhd  For our host OS, well, it doesn't matter because VirtualBox runs on almost anything.  But, the cloning process calls for a Win32 tool (it's available as 64 bit too).  At the time of this writing, it does not function well under wine.

Ubuntu can be configured to boot on nearly anything that matches the build architecture.  I'm using i386, because when we're done, it will literally boot on almost any PC I walk up to that can boot from USB.  If we install certain guest os extensions for virtualization, it can run Virtualized quite well, allowing you to configure the "liveboot" from within it live.  Wow, it's like inception or something...

"Wait, so I design my bootable environment from within the environment as a Virtualized System?"

Yes!  that's exactly what you do.

"Well, that sounds a lot easier than UCK and similar tools."

It is.


We're going to build with Ubuntu, as I said...  

I assume you know how to get a VM booted from .iso, set the hostname, input method and so-on...

If you're using a dynamically allocated VHD, just do guided - use entire disk, it's easy and actually pretty darn stable when you clone it like we're going to.  This allows the hypervisor to have a suitable size limit (8gb) for USB deployment, but only use up what it needs of physical storage from the host system.  As a result, your VHD may be much smaller than the 8gb limit when you clone it.  This is normal.

If you're like I am, and stingy with resources while building your VDI, it takes a WHILE to retrieve and unpack everything...  Go have a beer and check on it later... it will wait when it wants you to answer something.

On automagical updates:
    You can...  I don't (for various reasons).  All depends on what you want to do with your VDI on a stick.

...once it's finally done installing the base system, we get to pick packages.  This is why I chose the netboot iso instead of desktop.

I usually install xubuntu or lubuntu... I have plans to experiment with this method and a fluxbuntu installer in the future, since I invariably put fluxbox on any machine I can.  I like a clean, small windowmanager.  Your mileage may vary, but I find Unity to be a bit much for a VDI.

The key thing is to make sure we install everything we're going to want from this list now.  Yes, you can go from a bare-bones ubuntu server and install a desktop environment, and so-on... but why?  We're going to have plenty of packages to install once the base desktop is installed and your VDI boots and settles... which will be a while, so go have another beer and come back to it later.

Oh, now we need to install a bootloader.  Let it drop GRUB on the MBR of /dev/sda.  That was easy, huh?

One more VM bump in the road, sometimes they don't ACPI reboot cleanly...  just trigger it to reboot from VirtualBox.

A word on additional packages.  Once the VDI is installed, configured, reboots, and has settled... You will be tempted to apt-get everything you want to have on this vdi-on-a-stick.  

Wait.

Install the VirtualBox extensions first... You'll thank me later.  It's such a pain using xfce or even flux at 800x600 or smaller.

Now you can dpkg -i, and apt-get to your hearts content.  Install, tweak, customize, hack.  Once you've got everything how you like it, then go about using clonedisk to:

first, attach the VHD
second, insert the USB drive to a port
third, clone with VHD as source, USB as target.
fourth, go have another beer, it takes 15-30 minutes to clone a drive using this utility on Win7 with a halfway decent workstation.

Once it's cloned, pop the USB stick into another computer and reboot, then trigger to boot from USB.

TADA!