mirror of
git://git.2f30.org/morpheus.git
synced 2024-06-16 12:48:34 +00:00
61 lines
1.3 KiB
Bash
Executable File
61 lines
1.3 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
# creates an overlay qemu image using another image as base
|
|
# also prepares a script to boot the image
|
|
# depends: qemu
|
|
#
|
|
# configure the br0 interface as global bridge:
|
|
# https://wiki.archlinux.org/index.php/Bridge_with_netctl
|
|
#
|
|
# /etc/qemu-ifup:
|
|
# sudo ifconfig $1 0.0.0.0 promisc up
|
|
# sudo brctl addif br0 $1
|
|
# sleep 2
|
|
#
|
|
# /etc/qemu-ifdown:
|
|
# sudo brctl delif br0 $1
|
|
#
|
|
# on the console set the vnc password:
|
|
# change vnc password xxx
|
|
|
|
USAGE() {
|
|
echo "Usage: $(basename $0) base [n [mem]]" 1>&2
|
|
exit 1
|
|
}
|
|
|
|
BASE=$(test -n "$1" && echo "$1")
|
|
N=$(test -n "$2" && echo "$2" || echo 1)
|
|
MEM=$(test -n "$3" && echo "$3" || echo 128M)
|
|
|
|
test -f "$BASE" ||
|
|
{ echo "File $BASE does not exist" 1>&2 && USAGE; }
|
|
test "$N" -ge 0 && test "$N" -le 99 ||
|
|
{ echo "Provide a number in 0--99 for n" 1>&2 && USAGE; }
|
|
|
|
NN=$(printf "%02d" $N)
|
|
IMAGE=vm${NN}.img
|
|
INITSH=vm${NN}.sh
|
|
MACADDR="52:54:ff:12:34:$NN"
|
|
|
|
test -f "$IMAGE" &&
|
|
{ echo "File $IMAGE exists" 1>&2 && USAGE; }
|
|
test -f "$INITSH" &&
|
|
{ echo "File $INITSH exists" 1>&2 && USAGE; }
|
|
|
|
MKBOOT() {
|
|
cat << EOF > $INITSH
|
|
#!/bin/sh
|
|
|
|
qemu-system-x86_64 \\
|
|
-enable-kvm \\
|
|
-m $MEM \\
|
|
-hda $IMAGE \\
|
|
-net nic,macaddr=$MACADDR -net tap \\
|
|
-vnc :$N,password -monitor stdio
|
|
EOF
|
|
}
|
|
|
|
qemu-img create -f qcow2 -b $BASE $IMAGE
|
|
MKBOOT
|
|
chmod +x $INITSH
|