Guest User

Untitled

a guest
Jan 19th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. #!/bin/bash
  2. VM=$1
  3.  
  4. set -e
  5.  
  6. # Force interaction
  7. lvremove /dev/virt/${VM}-root || true
  8.  
  9. # Don't care if there isn't one
  10. virsh --connect qemu:///system undefine $VM || true
  11.  
  12. lvcreate -L2G -s /dev/virt/template-squeeze -n ${VM}-root
  13.  
  14. echo Made LV
  15.  
  16. ROOTFS=$(mktemp -d /tmp/mk_sqeeze_XXXXXXXXXX) || exit 1
  17.  
  18. mount /dev/virt/${VM}-root $ROOTFS
  19. trap "umount $ROOTFS;rmdir $ROOTFS" INT TERM EXIT
  20.  
  21. #echo NETCONFIG_DNS_POLICY=\"\" >> $ROOTFS/etc/sysconfig/network/config
  22. cp /etc/resolv.conf $ROOTFS/etc/resolv.conf
  23. #echo default $ROUTER_IP > $ROOTFS/etc/sysconfig/network/routes
  24. echo /dev/vdb swap swap defaults 0 0 >> $ROOTFS/etc/fstab
  25. mkdir -p $ROOTFS/root/.ssh/
  26. chmod 700 $ROOTFS/root/.ssh/
  27. cp /root/.ssh/authorized_keys $ROOTFS/root/.ssh/authorized_keys
  28. echo $VM > $ROOTFS/etc/hostname
  29. echo "send host-name \"$VM\";" >> $ROOTFS/etc/dhcp/dhclient.conf
  30. ls -laF $ROOTFS/etc/udev/rules.d/
  31. sed -i -e '/SUBSYSTEM/d' $ROOTFS/etc/udev/rules.d/70-persistent-net.rules
  32.  
  33. umount $ROOTFS
  34. rmdir $ROOTFS
  35. trap - EXIT
  36.  
  37. echo Customised LV
  38.  
  39. cat <<EOF > /etc/libvirt/qemu/$VM.xml
  40. <domain type='kvm'>
  41. <name>$VM</name>
  42. <memory>524288</memory>
  43. <currentMemory>524288</currentMemory>
  44. <vcpu>1</vcpu>
  45. <os>
  46. <type arch='x86_64' machine='pc-0.12'>hvm</type>
  47. <kernel>/kvmboot/vmlinuz-2.6.32-5-amd64</kernel>
  48. <initrd>/kvmboot/initrd.img-2.6.32-5-amd64</initrd>
  49. <cmdline>root=/dev/vda read-only</cmdline>
  50. <boot dev='fd'/>
  51. </os>
  52. <features>
  53. <acpi/>
  54. <apic/>
  55. <pae/>
  56. </features>
  57. <clock offset='utc'/>
  58. <on_poweroff>destroy</on_poweroff>
  59. <on_reboot>restart</on_reboot>
  60. <on_crash>restart</on_crash>
  61. <devices>
  62. <emulator>/usr/bin/kvm</emulator>
  63. <disk type='block' device='disk'>
  64. <driver name='qemu' type='raw'/>
  65. <source dev='/dev/virt/$VM-root'/>
  66. <target dev='vda' bus='virtio'/>
  67. </disk>
  68. <interface type='bridge'>
  69. <source bridge='br0'/>
  70. <model type='virtio'/>
  71. </interface>
  72. <serial type='pty'>
  73. <target port='0'/>
  74. </serial>
  75. <console type='pty'>
  76. <target port='0'/>
  77. </console>
  78. <input type='mouse' bus='ps2'/>
  79. <graphics type='vnc' port='-1' autoport='yes' keymap='en-gb'/>
  80. <video>
  81. <model type='vga' vram='9216' heads='1'/>
  82. <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
  83. </video>
  84. <memballoon model='virtio'>
  85. <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
  86. </memballoon>
  87. </devices>
  88. </domain>
  89. EOF
  90.  
  91. virsh --connect qemu:///system define /etc/libvirt/qemu/$VM.xml
  92.  
  93. echo Customised VM
  94.  
  95. # To make a suse initrd for virtio you need a running suse system:
  96. # edit /etc/sysconfig/kernel
  97. # INITRD_MODULES="thermal ata_piix ata_generic processor fan virtio_blk virtio_pci virtio_net"
  98. #
  99. # then
  100. # mkinitrd -B -v -L -k vmlinuz-2.6.34-12-desktop -i initrd-img-2.6.34-12-desktop-virtio
  101. #
  102. # Ensure the template has the correct kernel modules installed
Add Comment
Please, Sign In to add comment