Saturday, August 17, 2013

Install Linux to USB from Windows (actual install, not just live Linux)

If you're looking to install Linux to a USB key from within Windows, and not just to create a Linux Live USB key, then this will be of interest to you.

I started with a laptop with Windows 8, no CD drive, and 1 blank USB disk on key. I wanted to install Linux to the USB key. I wanted that USB key to be bootable.

1. Download and install Oracle Virtual Box.
2. Download ISO of Linux version that you want to install.
3. Create raw vmdk that points to USB:
Go to Virtual Box installation folder in an administrative command prompt:
VBoxManage.exe internalcommands createrawvmdk -filename "c:\Users\<Username>\VirtualBox VMs\USB.vmdk" -rawdisk \\.\PhysicalDriveX
The PhysicalDrive # comes from the disk #. To find the appropriate value go to Disk Management and find what disk is the USB key. For example Disk 2 maps to \\.\PhysicalDrive2, Disk 3 would be \\.\PhysicalDrive3.
4. Load Virtual Box as an administrator. Create new VM. I chose Debian as that was the distribution I was installing. Do not allocate a new virtual disk. Instead select "Choose existing". Choose the vmdk file you created above.
Now you have a virtual machine that uses your USB key as it's hard disk.
5. Run the installation through Virtual Box. Make sure your USB key is not being used. Close all windows to it. Be prepared to lose any data that is on it, as this process WILL format the USB key.

If you finish the installation, you should now be able to use the same USB key to boot your system with. That's what I did. It's a great way to get Linux installed to USB without needing a CD or CD ROM drive (or an extra USB key for the installation).

I can now boot my laptop on from USB. The nice thing is that while I was debugging wireless I would sometimes want to add packages. I could reboot into Windows and download packages from there on the USB key. I then reboot back to a non-vm run and I can then debug and attempt to get wireless working. Not only is wireless working now, but the desktop environment I installed (XFCE) from the non-vm boot is actually working fine when loaded within Virtual Box.

Nachum