summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xcreate-new-vm.sh87
-rwxr-xr-xqinit2
-rw-r--r--setup-arch-vm55
3 files changed, 137 insertions, 7 deletions
diff --git a/create-new-vm.sh b/create-new-vm.sh
new file mode 100755
index 0000000..dd4a4ed
--- /dev/null
+++ b/create-new-vm.sh
@@ -0,0 +1,87 @@
+#!/bin/bash
+
+set -e
+
+name=$1
+size=20G
+
+TMPDIR="`mktemp -d "/tmp/fb-client-up.XXXXXX"`"
+trap "rm -rf '${TMPDIR}'" EXIT TERM
+cd "$TMPDIR"
+
+cat <<EOF >vm.xml
+<domain type='kvm'>
+ <name>$name</name>
+ <memory unit='KiB'>1048576</memory>
+ <currentMemory unit='KiB'>1048576</currentMemory>
+ <vcpu placement='static'>4</vcpu>
+ <os>
+ <type arch='x86_64' machine='pc-i440fx-1.7'>hvm</type>
+ <boot dev='hd'/>
+ <boot dev='network'/>
+ <bootmenu enable='no'/>
+ </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/sbin/qemu-system-x86_64</emulator>
+ <disk type='file' device='disk'>
+ <driver name='qemu' type='qcow2'/>
+ <source file='/mnt/data/libvirt/storage/${name}.img'/>
+ <target dev='vda' bus='virtio'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
+ </disk>
+ <controller type='usb' index='0'>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
+ </controller>
+ <controller type='pci' index='0' model='pci-root'/>
+ <controller type='ide' index='0'>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
+ </controller>
+ <controller type='scsi' index='0'>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
+ </controller>
+ <controller type='scsi' index='1' model='virtio-scsi'>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
+ </controller>
+ <interface type='network'>
+ <source network='mynet'/>
+ <model type='virtio'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
+ </interface>
+ <serial type='pty'>
+ <target port='0'/>
+ </serial>
+ <console type='pty'>
+ <target type='serial' port='0'/>
+ </console>
+ <input type='mouse' bus='ps2'/>
+ <graphics type='vnc' port='-1' autoport='yes'/>
+ <sound model='ich6'>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
+ </sound>
+ <video>
+ <model type='cirrus' 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='0x05' function='0x0'/>
+ </memballoon>
+ </devices>
+</domain>
+EOF
+
+virsh vol-create-as nfs ${name}.img $size --format qcow2
+virsh define vm.xml
+
+vmmac=$(virsh domiflist $name | grep -oE "[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}")
+echo "$name" > /srv/http/vms/hostnames/"$vmmac"
+
+virsh start $name
diff --git a/qinit b/qinit
index 599b827..fa636ce 100755
--- a/qinit
+++ b/qinit
@@ -32,7 +32,7 @@ declare imgroot=$config_root
### Defaults #############################
declare mem="-m 1024"
declare cpus="-cpu host -smp 4"
-declare net="-netdev bridge,br=virbr0,id=mynet0 -device virtio-net,netdev=mynet0"
+declare net="-netdev bridge,br=virbr1,id=mynet0 -device virtio-net,netdev=mynet0"
cdrom+=("-boot" "d")
#declare cdrom="-cdrom $isoroot/archlinux-2012.11.01-dual.iso -boot d"
diff --git a/setup-arch-vm b/setup-arch-vm
index 2314645..4444591 100644
--- a/setup-arch-vm
+++ b/setup-arch-vm
@@ -4,12 +4,32 @@ set -e
newuser="flo"
disk=/dev/vda
+server=192.168.123.1
die() {
echo "$@"
exit 1
}
+get_url() {
+ local url=$1
+ local default=$2
+ wget -q -O - "$url" || echo "$default"
+}
+
+cmdline_arg() {
+ local name=$1
+ local default=$2
+ local param
+ for param in $(< /proc/cmdline); do
+ case "${param}" in
+ $name=*) echo "${param##*=}" ; return 0 ;;
+ esac
+ done
+
+ echo $default
+}
+
grep -qE '^flags\s+: .* hypervisor( |$)' /proc/cpuinfo || die "Not running in hypervisor. aborting automatic setup"
dhcpcd eth0
@@ -22,9 +42,12 @@ cat <<EOF >/etc/pacman.d/mirrorlist
Server = http://mirror.server-speed.net/\$repo/os/\$arch
EOF
-pacstrap /mnt base syslinux sudo openssh haveged htop git zsh screen dnsutils vim
+pacstrap /mnt base syslinux sudo openssh haveged htop git zsh screen dnsutils vim net-tools avahi
genfstab -p /mnt >> /mnt/etc/fstab
-echo "archvm" > /mnt/etc/hostname
+
+mymac=$(ip addr show dev eth0 | sed -rn 's#^\s+link/ether ([0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}).*$#\1#p')
+
+get_url "http://$server/hostnames/$mymac" "archvm" > /mnt/etc/hostname
ln -s /usr/share/zoneinfo/Europe/Athens /mnt/etc/localtime
echo "en_US.UTF-8 UTF-8" > /mnt/etc/locale.gen
arch-chroot /mnt locale-gen
@@ -44,12 +67,32 @@ TIMEOUT 50
LABEL arch
MENU LABEL Arch Linux
LINUX ../vmlinuz-linux
- APPEND root=${disk}1 ro logo.nologo elevator=deadline console=tty0 console=ttyS0 nomodeset
+ APPEND root=${disk}1 rw logo.nologo elevator=deadline console=tty0 console=ttyS0 nomodeset
INITRD ../initramfs-linux.img
EOF
-cat <<EOF > /mnt/etc/modprobe.d/modprobe.conf
-blacklist cirrus
+cat <<EOF >/mnt/etc/avahi/avahi-daemon.conf
+[server]
+browse-domains=
+use-ipv4=yes
+use-ipv6=yes
+ratelimit-interval-usec=1000000
+ratelimit-burst=1000
+
+[wide-area]
+enable-wide-area=no
+
+[publish]
+
+[reflector]
+
+[rlimits]
+rlimit-core=0
+rlimit-data=4194304
+rlimit-fsize=0
+rlimit-nofile=768
+rlimit-stack=4194304
+rlimit-nproc=3
EOF
arch-chroot /mnt mkinitcpio -p linux
@@ -73,7 +116,7 @@ arch-chroot /mnt passwd -d $newuser
curl https://git.server-speed.net/users/flo/bin/plain/init_new_user.sh | arch-chroot /mnt sudo -u $newuser bash
arch-chroot /mnt chsh -s /bin/zsh $newuser
-arch-chroot /mnt systemctl enable sshd multi-user.target haveged dhcpcd.service
+arch-chroot /mnt systemctl enable multi-user.target sshd haveged dhcpcd avahi-daemon
sync
systemctl reboot