Skip to content

Build a VM from scratch

red667 edited this page Nov 7, 2012 · 6 revisions

To build a VM image from scratch you can use makeimage.sh. The script creates a disk image file and prepares it for installation using makestick.sh.

Build a bootable disk image

Create the directory "./vmfs" so makeimage.sh can automatically mount the disk image to that directory.

$ mkdir -p ./vmfs

Generate the disk image "screeninvader.dd" with a size of 1000MB and mount it to "./vmfs".

$ sudo ./makeimage.sh -c ./vmfs -s 1000 test.dd
Mountpoint ./vmfs is unused: ok
Creating disk image file /home/elchaschab/devel/ScreenInvader/test.dd of size 1000 MB: ok
Setting up disk image file on loopback device /dev/loop0: ok
'extlinux' installed: ok
'parted' installed: ok
Make disk label: ok
Make partition: ok
Make filesystem: ok
Enable writeback mode: ok
Disable journaling: ok
Make temporary mount dir: ok
Mount file system: ok
Prune syslinux dir: ok
Install extlinux: ok
Make syslinux.cfg: ok
Umount file system: ok
Remove temporary mount dir: ok
Install syslinux mbr: ok
Check file system: ok
Run makestick.sh -s 1000 /dev/loop0: ok
Read partition offset: ok
Sync: ok
Detaching disk image file: ok
Mounting screen invader partition on ./vmfs: ok

Note: If makeimage fails on "Make partition" your loop kernel module may not be configured to support partitions. You can fix that by configuring the loop module accordingly.

echo "options loop max_part=63" > /etc/modprobe.d/loop_max_part.conf

You should either reboot or reload the loop module for the settings to take effect.


Note: If makeimage fails on "Make partition" and loop is built into the kernel it can be configured at startup with grub. Edit /etc/default/grub and add:

...
GRUB_CMDLINE_LINUX="loop.max_part=63"
...

To take effect you will need to remake the grub-config and reboot:

sudo grub2-mkconfig
sudo reboot

Bootstrap the file system.

$ sudo ./bootstrap.sh ./vmfs

and unmount it.

$ sudo umount ./vmfs

Boot the image with qemu

$ ./runimage.sh