liminix

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

mips-vm.sh (1768B)


      1 #!/usr/bin/env bash
      2 
      3 cleanup(){
      4     test -n "$rootfs" && test -f $rootfs && rm $rootfs
      5 }
      6 trap 'exit 1' INT HUP QUIT TERM ALRM USR1
      7 trap 'cleanup' EXIT
      8 
      9 usage(){
     10     echo "usage: $(basename $0) [--background /path/to/state_directory] kernel rootimg [initramfs]"
     11     echo -e "\nWithout --background, use C-p c (not C-a c) to switch to the monitor"
     12     exit 1
     13 }
     14 
     15 if test "$1" = "--background" ; then
     16     statedir=$2
     17     if test -z "$statedir" || ! test -d $statedir ; then
     18 	usage
     19     fi
     20     pid="${statedir}/pid"
     21     socket="${statedir}/console"
     22     monitor="${statedir}/monitor"
     23     echo "running in background, socket is $socket, pid $pid"
     24     flags="--daemonize --pidfile $pid -serial unix:$socket,server,nowait -monitor unix:$monitor,server,nowait"
     25     shift;shift
     26 else
     27     flags="-serial mon:stdio"
     28 fi
     29 
     30 test -n "$2" || usage
     31 
     32 lan=${LAN-"socket,mcast=230.0.0.1:1235,localaddr=127.0.0.1"}
     33 
     34 rootfs=$(mktemp mips-vm-fs-XXXXXX)
     35 dd if=/dev/zero of=$rootfs bs=1M count=16 conv=sync
     36 dd if=$2 of=$rootfs bs=65536 conv=sync,nocreat,notrunc
     37 
     38 if test -n "$3"; then
     39     initramfs="-initrd $3"
     40 fi
     41 
     42 
     43 INIT=${INIT-/bin/init}
     44 echo $QEMU_OPTIONS
     45 qemu-system-mips \
     46     -M malta -m 256 \
     47     -echr 16 \
     48     -append "liminix default console=ttyS0,38400n8 panic=10 oops=panic init=$INIT loglevel=8 root=/dev/mtdblock0 block2mtd.block2mtd=/dev/vda,65536" \
     49     -drive file=$rootfs,format=raw,readonly=off,if=virtio,index=0 \
     50     ${initramfs} \
     51     -netdev socket,id=access,mcast=230.0.0.1:1234,localaddr=127.0.0.1 \
     52     -device virtio-net,disable-legacy=on,disable-modern=off,netdev=access,mac=ba:ad:1d:ea:21:02 \
     53     -netdev ${lan},id=lan \
     54     -device virtio-net,disable-legacy=on,disable-modern=off,netdev=lan,mac=ba:ad:1d:ea:21:01 \
     55     -kernel $1 -display none $flags ${QEMU_OPTIONS}