vendredi 13 avril 2012

LFS : hard drive partition as virtual vmdk drive in Virtual Box 4.1.12

I built LFS on a usb key, Kubuntu as a host. To run it I have to `halt` and then boot the usb key. I wanted to see how it runs on bare metal sort of. But now I want to tinker the system so I tried to see what virtualbox can offert. Turns out they support that (virtualbox do a lot of things, dhcp, port forward, you name it).

version used: 
Virtual Box, `VBoxManager --version` => 4.1.12r77245
Kubuntu 12.04b2 ~ 13/04/2012

1) create the vmdk file that represent your real partition:
VBoxManage internalcommands createrawvmdk -filename $path/$name.vmdk -rawdisk /dev/$disk -partitions $partition-number


for my needs it turned out like this:
VBoxManage internalcommands createrawvmdk -filename /home/foobar/VM/lfs.vmdk -rawdisk /dev/sdc -partitions 1


1.5) There's a permission issue, it seems that /dev/sda is only accessible for root, and forbids virtualbox to load the vmdk that points to /dev/sda2. For now run virtualbox as root. Maybe `chown` and `chmod` can correct the problem. I may try that later.


2) create a virtual machine, choose 'use an existing disk' and points to the vmdk. There might be another vmdk beside (name contains '-pt', partition tables ?? maybe), ignore it.


3) adjust the drives

When I boot the usb key on my laptop, remember:
- the lfs system is stored on partition 2 (counting from 1)
- For grub, the internal sata drives is hd0, the usb key is hd1 => grub run `linux (hd1,2)/boot/vmlinuz root=...`
- For linux kernel, the internal sata drives gets 'sda', the usb key gets 'sdb'. => we have to be sure to pass /dev/sdb2 as root for the kernel.

But in virtualbox, at first there's only one drive, the vmdk. So you need to create sata drives to match the configuration in the lfs partition. I added an old vdi virtual image drive, anyone will do, it's just a dummy placeholder that won't be used. Now I got 2 disks, vmdk and vdi. The vmdk being inserted first is plugged on sata port 0, the vdi on port 1. To swap this order, put the vmdk on 2, then the vdi on 0, then vmdk on 1. Now you're virtual boot time config is isomorphic to the real laptop system.


Now it should boot the kernel and reach init without issues. Right now my main problem is that the network interface isn't working. I suck at using `ip` but I got to fix this in order to build blfs.

Aucun commentaire:

Enregistrer un commentaire