Creating a image for testing ============================ In this document we cover how to build a hard disk image ready to run from a virtual-machine emulator. In the example we will use qemu with a Debian operating System. What we need ------------ We have first to install the 'qemu' virtual-machine emulator: -------------- apt-get install qemu kqemu-source -------------- If you want to enable the 'kqemu' acceleration (to increase emulation speed on x386 platforms), you will have to create the kernel module. Follow theses stemps: - Get your kernel version: -------------- # uname -r 2.6.21-1-686 -------------- - Search the kernel-headers for that version and install it: -------------- apt-cache search linux headers 2.6.21 [...] apt-get install linux-header-2.6-21-2-686 -------------- - Go to the linux-headers directory, build the deb package and install it: -------------- cd /usr/src/linux-headers... make-kpkg modules dpkg -i ../kqemu....deb -------------- Modprobe the the 'loop' mount, needed to mount disk and partition images: -------------- modprobe loop -------------- Finally, make sure that 'syslinux' and 'LILO' are installed: -------------- apt-get install syslinux lilo -------------- Creating the hard disk image ---------------------------- First create the empty file that we will use for our disk image. We will assume a disk geometry of #cylinders, 16 heads, 63 sectors/track, 512 bytes/sector, which means that each cylinder contains 516096 bytes (16*63*512). Decide how large you want your disk image to be, and choose an appropriate number of cylinders. Example: If you want a 500Mb disk, you would choose 1000 cylinders (approximation of (500*1000*1024)/516096). Write the disk image (I'll assume the filename 'test.img' throughout), mount the loop device and start 'fdisk': -------------- dd if=/dev/zero of=test.img bs=516096 count=1000 losetup /dev/loop0 test.img fdisk -C1000 -S63 -H16 /dev/loop0 -------------- Create a primary partition, mark as bootable, write and exit. Then mount this partition, format it (example with ext3, change if needed) and uncompress the 'debian-distro' tarball: -------------- losetup -o 32256 /dev/loop1 test.img mkfs.ext3 /dev/loop1 mount /dev/loop1 /mnt cd /mnt tar xvzf debian-distro.tgz -------------- Now we have to install the 'Master Boot Record' and 'LILO' using a special loop-lilo.conf file. The contents of loop-lilo.conf could be: -------------- # /etc/loop-lilo.conf: Manage special /dev/loop0 device boot=/dev/loop0 disk=/dev/loop0 bios=0x80 sectors=63 heads=16 cylinders=1000 partition=/dev/loop1 start=63 # offset from sector 0 map=/boot/map vga=normal image=/vmlinuz root=/dev/hda1 initrd=/initrd.img label=Linux read-only -------------- -------------- dd if=/usr/lib/syslinux/mbr.bin of=/dev/loop0 bs=512 cp loop-lilo.conf /mnt/etc lilo -r /mnt -C /etc/loop-lilo.conf -------------- Note that before running 'lilo', you have to copy the configuration file 'loop-lilo.conf', which is needed to handle the special '/dev/loop0' disk. Otherwise you will get an error from LILO ('I don't know how to handle device 0x700') And that's it. After that you can unmount everthing and the 'test.img' image should be bootable. -------------- umount /mnt losetup -d /dev/loop0 -------------- Testing the image ----------------- If you created the 'kqemu' module, load into the kernel before running 'qemu' to boost emulation. -------------- modprobe kqemu qemu -hda test.img -redir 2200:localhost:22 -------------- If the system booted, you can use the ssh redirection ('2200:localhost:22') to login into the virtual-machine: -------------- ssh -p2200 root@localhost --------------