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