http://www.livemoon.org/life/2012/03/openstackimage.html
Install Ubuntu 11.10
# apt-get install kvm-pxe# qemu-img create -f raw ubuntu11.10.img 10G
# kvm -m 1024 -cdrom ubuntu-11.10-server-amd64.iso --drive file=ubuntu11.10.img,if=virtio, -boot d -net nic,model=virtio -net user -nographic -vnc :0
# kvm -m 1024 -drive file=ubuntu11.10.img,if=virtio,boot=on -boot c -net nic,model=virtio -net user -nographic -vnc :0
in vm:
# apt-get update
# apt-get upgrade
# apt-get install openssh cloud-init
# rm -f /etc/udev/rules.d/70-persistent.net.rules
in kvm host
- Extracting the EXT4 partition
# loseup -a
it will show like this:
/dev/loop0: [0802]:3932164 (/data/image/ubuntu11.10.img)
# fdisk -c -u -l /dev/loop0
it will show:
Disk /dev/loop0: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders, total 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0005a31d
Device Boot Start End Blocks Id System
/dev/loop0p1 * 2048 20969471 10483712 83 Linux
2048 x 512 = 1048576
# losetup -d /dev/loop0
# losetup -f -o 1048576 ubuntu11.10.img
# losetup -a
it will show:
/dev/loop0: [0802]:3932164 (/data/image/ubuntu11.10.img), offset 1048576
# dd if=/dev/loop0 of=ubuntu11.10final.img
# losetup -d /dev/loop0
# mount -o loop ubuntu11.10final.img /mnt
# vi /mnt/etc/fstab
change:
UUID=fb3715a5-ef6b-4ec0-84e8-cbda0550e97f / ext4 errors=remount-ro 0 1
to:
UUID=uec-rootfs / ext4 defaults 0 0
# cp /mnt/boot/vmlinuz-3.0.0-12-server .
# cp /mnt/boot/initrd.img-3.0.0-12-server .
# umount /mnt
# tune2fs -L uec-rootfs ubuntu11.10final.img
Upload image using glance
# glance add name="Ubuntu11.10--kernel" is_public=true container_format=aki disk_format=aki < vmlinuz-3.0.0-12-server
# glance add name="Ubuntu11.10--ramdisk" is_public=true container_format=ari disk_format=ari < initrd.img-3.0.0-12-server
# glance add name="ubuntu11.10" is_public=true container_format=ami disk_format=ami kernel_id=be9af538-ad66-4e01-aa84-9115a04b48ec ramdisk_id=f4e66feb-0a9f-4a13-9ff3-e4cd0a21aaa6 < ubuntu11.10final.img
Install CentOS 6.2
# qemu-img create -f qcow2 centos6U2.qcow 10G
# kvm -m 1024 -cdrom /data/iso/CentOS-6.2-x86_64-bin-DVD1.iso --drive file=centos6U2.qcow,if=virtio, -boot d -net nic,model=virtio -net user -nographic -vnc :0
# kvm -m 1024 -drive file=centos6U2.qcow,if=virtio,boot=on -boot c -net nic,model=virtio -net user -nographic -vnc :0
Install windows2008
# qemu-img create -f qcow2 windows2008.qcow 10G
# kvm -m 1024 -cdrom /data/iso/2008EN.iso --drive file=windows2008.qcow,if=ide, -boot d -net nic -net user -nographic -vnc :0
# qemu-img create -f qcow2 test 1G
# kvm -hda windows2008.qcow -drive file=test,if=virtio -drive file=/data/iso/virtio-win-0.1-22.iso,media=cdrom,index=1 -net nic,model=virtio -net user -boot d -nographic -vnc :0
Then Install virtio driver in windows
Install FreeBSD9
# qemu-img create -f qcow2 FreeBSD9.qcow 10G
# kvm -m 1024 -cdrom /data/iso/ FreeBSD -9.0-RELEASE-amd64-bootonly.iso --drive file=FreeBSD9.qcow,if=ide, -boot d -net nic -net user -nographic -vnc :0
After installing freebsd base system, it need to install virtio
in FreeBSD
# cd /usr/ports/emulators/virtio-kmod/# kvm -m 1024 -drive file=FreeBSD-9.0.qcow,if=virtio,boot=on -net nic,model=virtio -net user -nographic -vnc :0
# make
# make install clean
add the following to /boot/loader.conf
virtio_load="YES"
virtio_pci_load="YES"
virtio_blk_load="YES"
if_vtnet_load="YES"
virtio_balloon_load="YES"
and edit fstab and interface config in rc.conf
# sed -i.bak -Ee 's|/dev/ada?|/dev/vtbd|' /etc/fstab
# sed -i.bak -e 's|em0|vtnet0|' /etc/rc.conf
Glance upload image
# glance add name="FreeBSD-9.0-x86_64" is_public=true container_format=ovf disk_format=qcow2 distro="FreeBSD" < FreeBSD-9.0.qcow