paul@31 | 1 | #!/bin/sh |
paul@22 | 2 | |
paul@63 | 3 | # Copyright (C) 2010, 2011, 2012, 2013 Paul Boddie <paul@boddie.org.uk> |
paul@63 | 4 | # |
paul@63 | 5 | # This program is free software; you can redistribute it and/or modify it under |
paul@63 | 6 | # the terms of the GNU General Public License as published by the Free Software |
paul@63 | 7 | # Foundation; either version 3 of the License, or (at your option) any later |
paul@63 | 8 | # version. |
paul@63 | 9 | # |
paul@63 | 10 | # This program is distributed in the hope that it will be useful, but WITHOUT |
paul@63 | 11 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paul@63 | 12 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
paul@63 | 13 | # details. |
paul@63 | 14 | # |
paul@63 | 15 | # You should have received a copy of the GNU General Public License along with |
paul@63 | 16 | # this program. If not, see <http://www.gnu.org/licenses/>. |
paul@63 | 17 | |
paul@22 | 18 | # Configuration: |
paul@22 | 19 | if [ -e userinstall-defaults-uml ]; then |
paul@31 | 20 | . "$PWD/userinstall-defaults-uml" |
paul@22 | 21 | elif [ -e /etc/default/userinstall-uml ]; then |
paul@31 | 22 | . /etc/default/userinstall-uml |
paul@22 | 23 | else |
paul@31 | 24 | echo "No defaults found for userinstall (UML)." 1>&2 |
paul@22 | 25 | exit 1 |
paul@22 | 26 | fi |
paul@22 | 27 | |
paul@31 | 28 | PROGNAME=`basename "$0"` |
paul@31 | 29 | |
paul@34 | 30 | if [ ! "$1" ] || [ "$1" = '--help' ]; then |
paul@72 | 31 | echo "Usage: $PROGNAME <memory-with-unit> [ --net ] [ --initrd <initrd-file> [ --root <device> ] <filesystem-image> ]" 1>&2 |
paul@25 | 32 | exit 1 |
paul@25 | 33 | fi |
paul@25 | 34 | |
paul@31 | 35 | UML_MEMORY="$1" |
paul@22 | 36 | |
paul@27 | 37 | # Discard the memory argument. |
paul@27 | 38 | |
paul@27 | 39 | shift 1 |
paul@27 | 40 | |
paul@27 | 41 | # Test for networking. |
paul@27 | 42 | |
paul@31 | 43 | if [ "$1" = '--net' ]; then |
paul@77 | 44 | UML_NETWORKING="$NETDEVICE=tuntap,$TUNDEVICE,,$HOSTADDRESS" |
paul@30 | 45 | xhost +"$GUESTADDRESS" |
paul@27 | 46 | shift 1 |
paul@27 | 47 | fi |
paul@27 | 48 | |
paul@42 | 49 | # Test for initrd. |
paul@42 | 50 | |
paul@42 | 51 | if [ "$1" = '--initrd' ]; then |
paul@72 | 52 | INITRD=$2 |
paul@72 | 53 | shift 2 |
paul@72 | 54 | if [ "$1" = '--root' ]; then |
paul@72 | 55 | ROOTDEVICE=$2 |
paul@72 | 56 | shift 2 |
paul@72 | 57 | else |
paul@72 | 58 | ROOTDEVICE=/dev/ram |
paul@72 | 59 | fi |
paul@72 | 60 | ISOIMAGE=$1 |
paul@72 | 61 | INITRD_OPTIONS="initrd=$INITRD root=$ROOTDEVICE load_ramdisk=1 ubd2=$ISOIMAGE" |
paul@42 | 62 | shift 1 |
paul@42 | 63 | else |
paul@42 | 64 | INITRD_OPTIONS= |
paul@42 | 65 | fi |
paul@42 | 66 | |
paul@72 | 67 | # Now we start the virtual machine. |
paul@72 | 68 | # Note that con0 is not necessarily a login console, so a login prompt may not |
paul@72 | 69 | # appear on standard input/output. |
paul@25 | 70 | |
paul@44 | 71 | ./linux ubd0="$IMAGE" rw ubd1="$SWAPIMAGE" rw mem="$UML_MEMORY" con0=fd:0,fd:1 con=pts "$UML_NETWORKING" $INITRD_OPTIONS $* |