Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- VM=$1
- set -e
- # Force interaction
- lvremove /dev/virt/${VM}-root || true
- # Don't care if there isn't one
- virsh --connect qemu:///system undefine $VM || true
- lvcreate -L2G -s /dev/virt/template-squeeze -n ${VM}-root
- echo Made LV
- ROOTFS=$(mktemp -d /tmp/mk_sqeeze_XXXXXXXXXX) || exit 1
- mount /dev/virt/${VM}-root $ROOTFS
- trap "umount $ROOTFS;rmdir $ROOTFS" INT TERM EXIT
- #echo NETCONFIG_DNS_POLICY=\"\" >> $ROOTFS/etc/sysconfig/network/config
- cp /etc/resolv.conf $ROOTFS/etc/resolv.conf
- #echo default $ROUTER_IP > $ROOTFS/etc/sysconfig/network/routes
- echo /dev/vdb swap swap defaults 0 0 >> $ROOTFS/etc/fstab
- mkdir -p $ROOTFS/root/.ssh/
- chmod 700 $ROOTFS/root/.ssh/
- cp /root/.ssh/authorized_keys $ROOTFS/root/.ssh/authorized_keys
- echo $VM > $ROOTFS/etc/hostname
- echo "send host-name \"$VM\";" >> $ROOTFS/etc/dhcp/dhclient.conf
- ls -laF $ROOTFS/etc/udev/rules.d/
- sed -i -e '/SUBSYSTEM/d' $ROOTFS/etc/udev/rules.d/70-persistent-net.rules
- umount $ROOTFS
- rmdir $ROOTFS
- trap - EXIT
- echo Customised LV
- cat <<EOF > /etc/libvirt/qemu/$VM.xml
- <domain type='kvm'>
- <name>$VM</name>
- <memory>524288</memory>
- <currentMemory>524288</currentMemory>
- <vcpu>1</vcpu>
- <os>
- <type arch='x86_64' machine='pc-0.12'>hvm</type>
- <kernel>/kvmboot/vmlinuz-2.6.32-5-amd64</kernel>
- <initrd>/kvmboot/initrd.img-2.6.32-5-amd64</initrd>
- <cmdline>root=/dev/vda read-only</cmdline>
- <boot dev='fd'/>
- </os>
- <features>
- <acpi/>
- <apic/>
- <pae/>
- </features>
- <clock offset='utc'/>
- <on_poweroff>destroy</on_poweroff>
- <on_reboot>restart</on_reboot>
- <on_crash>restart</on_crash>
- <devices>
- <emulator>/usr/bin/kvm</emulator>
- <disk type='block' device='disk'>
- <driver name='qemu' type='raw'/>
- <source dev='/dev/virt/$VM-root'/>
- <target dev='vda' bus='virtio'/>
- </disk>
- <interface type='bridge'>
- <source bridge='br0'/>
- <model type='virtio'/>
- </interface>
- <serial type='pty'>
- <target port='0'/>
- </serial>
- <console type='pty'>
- <target port='0'/>
- </console>
- <input type='mouse' bus='ps2'/>
- <graphics type='vnc' port='-1' autoport='yes' keymap='en-gb'/>
- <video>
- <model type='vga' vram='9216' heads='1'/>
- <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
- </video>
- <memballoon model='virtio'>
- <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
- </memballoon>
- </devices>
- </domain>
- EOF
- virsh --connect qemu:///system define /etc/libvirt/qemu/$VM.xml
- echo Customised VM
- # To make a suse initrd for virtio you need a running suse system:
- # edit /etc/sysconfig/kernel
- # INITRD_MODULES="thermal ata_piix ata_generic processor fan virtio_blk virtio_pci virtio_net"
- #
- # then
- # mkinitrd -B -v -L -k vmlinuz-2.6.34-12-desktop -i initrd-img-2.6.34-12-desktop-virtio
- #
- # Ensure the template has the correct kernel modules installed
Add Comment
Please, Sign In to add comment