1 #!/bin/sh 2 3 # Copyright (C) 2011, 2012, 2013 Paul Boddie <paul@boddie.org.uk> 4 # 5 # This program is free software; you can redistribute it and/or modify it under 6 # the terms of the GNU General Public License as published by the Free Software 7 # Foundation; either version 3 of the License, or (at your option) any later 8 # version. 9 # 10 # This program is distributed in the hope that it will be useful, but WITHOUT 11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 # details. 14 # 15 # You should have received a copy of the GNU General Public License along with 16 # this program. If not, see <http://www.gnu.org/licenses/>. 17 18 # Configuration: 19 if [ -e userinstall-defaults-uml ]; then 20 . "$PWD/userinstall-defaults-uml" 21 elif [ -e /etc/default/userinstall-uml ]; then 22 . /etc/default/userinstall-uml 23 else 24 echo "No defaults found for userinstall (UML)." 1>&2 25 exit 1 26 fi 27 28 if [ "$1" = '--help' ]; then 29 echo "Usage: `basename $0` [ --root ] [ --no-fs ] [ --do-not-populate ] <root image size in GB> <swap image size in MB>" 1>&2 30 exit 1 31 fi 32 33 if [ "$1" = '--root' ]; then 34 shift 1 35 AS_USER="sudo" 36 else 37 AS_USER= 38 fi 39 40 if [ "$1" = '--no-fs' ]; then 41 shift 1 42 NO_FS=$1 43 else 44 NO_FS= 45 fi 46 47 if [ "$1" = '--do-not-populate' ]; then 48 shift 1 49 DO_NOT_POPULATE=$1 50 else 51 DO_NOT_POPULATE= 52 fi 53 54 if [ ! "$1" ]; then 55 echo "Need a root image size in GB." 1>&2 56 exit 1 57 fi 58 59 if [ ! "$2" ]; then 60 echo "Need a swap image size in MB." 1>&2 61 exit 1 62 fi 63 64 IMAGESIZE=$1 65 SWAPSIZE=$2 66 THISDIR=`dirname "$0"` 67 68 if [ ! -e "$PACKAGEROOT" ] && [ ! "$NO_FS" ] && [ ! "$DO_NOT_POPULATE" ]; then 69 echo "A package root must first be made using user-setup." 1>&2 70 exit 1 71 fi 72 73 if [ ! "$IMAGEDIR" ]; then 74 echo "An image directory must be defined." 1>&2 75 exit 1 76 fi 77 78 # Make image files. 79 80 echo "Making the filesystem with size ${IMAGESIZE}GB..." 81 if dd if=/dev/zero of=$IMAGE bs=1024 count=1 seek=$(($IMAGESIZE*1024*1024-1024)) ; then 82 83 # Make a filesystem unless otherwise requested. 84 85 if [ ! "$NO_FS" ]; then 86 /sbin/mkfs.ext3 $IMAGE 87 fi 88 else 89 cat 1>&2 <<EOF 90 Unable to create an image file for the root partition. 91 See the error messages above for more information. 92 EOF 93 exit 1 94 fi 95 96 echo "Making the swap file with size ${SWAPSIZE}MB..." 97 if ! dd if=/dev/zero of=$SWAPIMAGE bs=1M count=$SWAPSIZE ; then 98 cat 1>&2 <<EOF 99 Unable to create an image file for the swap partition. 100 See the error messages above for more information. 101 EOF 102 exit 1 103 fi 104 105 # Image population activities. 106 107 if [ ! "$DO_NOT_POPULATE" ] && [ ! "$NO_FS" ]; then 108 $AS_USER "$THISDIR/uml-access-image" "$THISDIR/uml-populate-image" 109 $AS_USER "$THISDIR/uml-access-image" "$THISDIR/uml-make-network" 110 fi