morpheus

suckless linux distro
git clone git://git.2f30.org/morpheus
Log | Files | Refs | Submodules | README | LICENSE

qemu-mk-overlay (1323B)


      1 #!/bin/sh
      2 
      3 # creates an overlay qemu image using another image as base
      4 # also prepares a script to boot the image
      5 # depends: qemu
      6 #
      7 # configure the br0 interface as global bridge:
      8 # https://wiki.archlinux.org/index.php/Bridge_with_netctl
      9 #
     10 # /etc/qemu-ifup:
     11 # sudo ifconfig $1 0.0.0.0 promisc up
     12 # sudo brctl addif br0 $1
     13 # sleep 2
     14 #
     15 # /etc/qemu-ifdown:
     16 # sudo brctl delif br0 $1
     17 #
     18 # on the console set the vnc password:
     19 # change vnc password xxx
     20 
     21 USAGE() {
     22     echo "Usage: $(basename $0) base [n [mem]]" 1>&2
     23     exit 1
     24 }
     25 
     26 BASE=$(test -n "$1" && echo "$1")
     27 N=$(test -n "$2" && echo "$2" || echo 1)
     28 MEM=$(test -n "$3" && echo "$3" || echo 128M)
     29 
     30 test -f "$BASE" ||
     31     { echo "File $BASE does not exist" 1>&2 && USAGE; }
     32 test "$N" -ge 0 && test "$N" -le 99 ||
     33     { echo "Provide a number in 0--99 for n" 1>&2 && USAGE; }
     34 
     35 NN=$(printf "%02d" $N)
     36 IMAGE=vm${NN}.img
     37 INITSH=vm${NN}.sh
     38 MACADDR="52:54:ff:12:34:$NN"
     39 
     40 test -f "$IMAGE" &&
     41     { echo "File $IMAGE exists" 1>&2 && USAGE; }
     42 test -f "$INITSH" &&
     43     { echo "File $INITSH exists" 1>&2 && USAGE; }
     44 
     45 MKBOOT() {
     46 cat << EOF > $INITSH
     47 #!/bin/sh
     48 
     49 qemu-system-x86_64 \\
     50     -enable-kvm \\
     51     -m $MEM \\
     52     -hda $IMAGE \\
     53     -net nic,macaddr=$MACADDR -net tap \\
     54     -vnc :$N,password -monitor stdio
     55 EOF
     56 }
     57 
     58 qemu-img create -f qcow2 -b $BASE $IMAGE
     59 MKBOOT
     60 chmod +x $INITSH