Make QEMU image with kickstart
Overview
This article explains how to build a hands-free QEMU image by installing Fedora using kickstart. Enjoy the show.
Installing with the network installation CD
First download the netinst CD (here's the netinst CD for Fedora 9 i386). Verify its authenticity.
As a test, try booting the ISO image you downloaded with QEMU.
$ qemu -cdrom Fedora-9-i386-netinst.iso
Close qemu when you're sure it works.
Make the following kickstart file, and name it ks.cfg file.
install ## Use a Fedora mirror instead. url --url http://download.fedoraproject.org/pub/fedora/linux/releases/9/Fedora/i386/os lang en_US.UTF-8 keyboard us network --device eth0 --bootproto dhcp --hostname fedora9-i386.qemu-builder rootpw use_qemu firewall --enabled --ssh authconfig --enableshadow --passalgo=sha512 selinux --enforcing timezone --utc America/New_York bootloader --location=mbr --driveorder=sda text firstboot --disable logging --level=info reboot clearpart --all --drives=sda part /boot --fstype ext3 --size=200 --ondisk=sda part pv.1 --size=0 --grow --ondisk=sda volgroup VolGroup00 --pesize=32768 pv.1 logvol / --fstype ext3 --name=LogVol00 --vgname=VolGroup00 --size=2560 logvol swap --fstype swap --name=LogVol01 --vgname=VolGroup00 --size=256 --grow --maxsize=512 %packages @fedora-packager %end
Make a floppy image, and put the kickstart file on it.
dd if=/dev/zero of=fedora-9-i386.img bs=1440K count=1 /sbin/mkfs -F -t ext2 fedora-9-i386.img mkdir -p fedora-9-i386 sudo mount -o loop fedora-9-i386.img fedora-9-i386 cp -p ks.cfg fedora9-i386/ sudo umount fedora9-i386
Make a QEMU image.
qemu-img create fedora-9-i386.qcow 4G
Now install Fedora 9 to the QEMU image with kickstart.
qemu -cdrom Fedora-9-i386-netinst.iso -hda fedora-9-i386.qcow -fda fedora9-i386.img -boot d -net nic -net user -m 196 -localtime -append ks=floppy
The addition of "ks=floppy" to the kernel arguments, may not work. You may need to hit [Tab] in the GRUB boot loader, and add them by hand.
Using Cobbler
Alternatively, you can set this up with cobbler, which may be a good choice if you have a lab, datacenter, or a large number of machines to manage.
yum install cobbler cobbler check # make sure everything is configured correctly cobbler import --name=Fedora9 --mirror=/mnt/dvd # make the media available to servers that will want it cobbler profile edit --name=Fedora9-i386 --kickstart=/etc/cobbler/yourkickstart.ks --virt-type=qemu # make sure it won't use Xen by default
And on the remote machine where you want the VM installed
yum install koan koan --server=cobbler.example.com --profile=Fedora9-i386 --virt
By using cobbler you can centralize your installation parameters and kickstarts to share them between a wide array of users and machines. There are many more parameters you can edit and store centrally, including how much RAM to use, where to store the virtual disks, where to use LVM, etc. See the Cobbler Wiki linked above for further details.
Additinally this also helps with physical (baremetal) installations, among other things.