kern
annotate mkdiskimg @ 92:b4264d173aae
fixed the readme file
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Thu, 17 Apr 2014 12:30:02 +0300 |
parents | 4dd35ccceba1 |
children |
rev | line source |
---|---|
nuclear@83 | 1 #!/bin/sh |
nuclear@83 | 2 |
nuclear@85 | 3 SUDO=${SUDO:-sudo} |
nuclear@85 | 4 if [ `id -u` = 0 ]; then |
nuclear@85 | 5 unset SUDO |
nuclear@85 | 6 fi |
nuclear@85 | 7 |
nuclear@83 | 8 # mkdiskimg - prepare a disk image for the kernel |
nuclear@83 | 9 # usage: mkdiskimg [size in mb, default: 40] |
nuclear@83 | 10 |
nuclear@83 | 11 imgfile=disk.img |
nuclear@83 | 12 if [ -e $imgfile ]; then |
nuclear@83 | 13 echo "file '$imgfile' exists, will not overwrite, delete it first" >&2 |
nuclear@83 | 14 exit 1 |
nuclear@83 | 15 fi |
nuclear@83 | 16 |
nuclear@83 | 17 if [ -n "$1" ]; then |
nuclear@83 | 18 sizemb=$1 |
nuclear@83 | 19 else |
nuclear@83 | 20 sizemb=40 |
nuclear@83 | 21 fi |
nuclear@83 | 22 |
nuclear@83 | 23 # create the image file |
nuclear@83 | 24 echo 'creating image file ...' |
nuclear@83 | 25 dd if=/dev/zero of=$imgfile bs=1M count=$sizemb || exit 1 |
nuclear@83 | 26 |
nuclear@84 | 27 mkpart_linux() |
nuclear@84 | 28 { |
nuclear@84 | 29 sfdisk -q $imgfile <<EOF |
nuclear@84 | 30 ,,cc |
nuclear@84 | 31 EOF |
nuclear@84 | 32 } |
nuclear@84 | 33 |
nuclear@84 | 34 mkpart_fbsd() |
nuclear@84 | 35 { |
nuclear@85 | 36 devfile=`$SUDO mdconfig -a -t vnode -f $imgfile` |
nuclear@85 | 37 if [ $? != 0 ]; then |
nuclear@85 | 38 echo "failed to map $imgfile as a memory device, need root" >&2 |
nuclear@85 | 39 exit 1 |
nuclear@85 | 40 fi |
nuclear@85 | 41 |
nuclear@85 | 42 $SUDO fdisk -q -f - /dev/$devfile <<EOF |
nuclear@84 | 43 p 1 204 * * |
nuclear@84 | 44 EOF |
nuclear@85 | 45 $SUDO mdconfig -d -u $devfile |
nuclear@84 | 46 } |
nuclear@84 | 47 |
nuclear@83 | 48 # create partition table |
nuclear@84 | 49 echo 'creating partition table with a single partition ...' |
nuclear@85 | 50 sys=`uname -s` |
nuclear@84 | 51 if [ $sys = Linux ]; then |
nuclear@84 | 52 mkpart_linux |
nuclear@85 | 53 elif [ $sys = FreeBSD ]; then |
nuclear@85 | 54 mkpart_fbsd |
nuclear@84 | 55 else |
nuclear@84 | 56 echo "don't know how to partition the image on your system." |
nuclear@84 | 57 echo "please create a partition in the disk image ($imgfile) manually." |
nuclear@83 | 58 exit 0 |
nuclear@83 | 59 fi |
nuclear@84 | 60 |
nuclear@83 | 61 if [ $? != 0 ]; then |
nuclear@83 | 62 echo 'failed to create partition' >&2 |
nuclear@83 | 63 exit 1 |
nuclear@83 | 64 fi |
nuclear@83 | 65 |
nuclear@83 | 66 echo |
nuclear@83 | 67 echo 'done. happy hacking!' |