November 16th, 2012
During the development of my Linux From Scratch I was searching for a way to test the boot process using Virtual Box instead of rebooting my development computer again and again. I found some articles on how to achive this using Windows, but I use Linux on my computer. Finally I did it using
VBoxManage internalcommands. Here comes a short howto:
1. Plug in your usb stick. The usb stick MUST contain a bootable operating system. This can be anything that boots from an usb stick.
2. Open a terminal to find out how the kernel named your usb device. (Or more accurat, its partion(s))
/dev/sdb2 on / type ext3 (rw,relatime,errors=remount-ro)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
none on /sys/fs/fuse/connections type fusectl (rw)
none on /sys/kernel/debug type debugfs (rw)
none on /sys/kernel/security type securityfs (rw)
udev on /dev type devtmpfs (rw,mode=0755)
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755)
none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880)
none on /run/shm type tmpfs (rw,nosuid,nodev)
/dev/sdb5 on /tmp type ext3 (rw,relatime)
/dev/sdb7 on /usr type ext3 (rw,relatime)
/dev/sdb8 on /var type ext3 (rw,relatime)
binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noexec,nosuid,nodev)
/dev/md_d0 on /home type ext3 (rw)
gvfs-fuse-daemon on /home/thorsten/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev,user=thorsten)
/dev/sdd1 on /home/thorsten/lfs type ext3 (rw)
Your output will look different from mine, but you should be able to find the partition(s). In my case it is
3. Unmount all partitions of the usb stick. (This may require root privileges, depending on your system and settings). In my case it is only one partition
4. Now comes the interesting part – creating the vmdk file. To achive this I’ll use
VBoxManage the console interface provided by VirtualBox. The
internalcommands providing a command called
createdrawvmdk. The command creates a .vmdk file using a raw disk from the host system. This file can be used later as a *harddisk* for a virtual machine. Yes!, that’s exactly what I want, the raw host disk in this case should be my usb stick.
internalcommands createrawvmdk \
-rawdisk /dev/sdd \
RAW host disk access VMDK file /home/thorsten/Desktop/lfs.vmdk created successfully.
5. Create a new virtual machine that uses the my_usb_stick.vmdk as harddisk. This can be done on command line too, sure. To not confuse readers I’ll use the more regular graphical interface.
5a. Start Virtualbox
/dev/sdd, in my case)
5b. Click the ‚New‘ button.
5b. Click ‚Next‘ and choose a name for the virtual machine. I used ‚Boot From Stick‘, as it can be everything that is installed on stick (and this may change).
5c. Click ‚Next‘ and select the memory size for the virtual machine. I selected 1024MB / 1GB in this example.
5d. Click ‚Next‘ and choose ‚Use existing harddisk‘
5e. Click the folder item next to the list box with images. Then select the vmdk file created before.
5f. Click ‚Open‘
5g. Click ‚Create‘ to finish the process.
6. Start the Virtual Machine. It should boot from the usb stick
VBoxManage internalcommands createrawvmdk is a nice tool when debugging boot problems or just run your portable usb stick linux in parallel with your home system – maybe be in order to transfer files. In addition
createrawvmdk works with regular harddisks or other mediums too. So it might not ever beeing requested to boot from that media but to mount it during runtime – no problem.
You can access the help for this command by typing :
You’ll find options to in/exclude partitions from being visible to the Virtual Machine, but you’ll find the alert on end of this output too:
WARNING: This is a development tool and shall only be used to analyse
problems. It is completely unsupported and will change in
incompatible ways without warning.
I hope they will not remove this feature in upcoming versions.