Diff markup
001 001
002 002
003 003
004 004
005 005
006 006
007 007
008 008
009 009
010 010
011 011
012 012
013 013
014 014
015 015
016 016
017 017
018 018
019 019
020 020
021 021
022 022
023 023
024 024
025 025
026 026
027 027
028 028
029 029
030 030
031 031
032 032
033 033
034 034
035 035
036 036
037 037
038 038
039 039
040 040
041 041
042 042
043 043
044 044
045 print_usage () { 045 print_usage () {
046 echo "Usage: $0 [X:|image] path/to/loader op 046 echo "Usage: $0 [X:|image] path/to/loader option path/to/modules..."
047 echo " where X: is a valid floppy driv 047 echo " where X: is a valid floppy drive on your computer"
048 echo " where image is any file name" 048 echo " where image is any file name"
049 exit 1 049 exit 1
050 } 050 }
051 051
052 grub_dirs_common="/usr/local/share/grub/i386-f 052 grub_dirs_common="/usr/local/share/grub/i386-freebsd /usr/local/share/grub/i386-pc /usr/share/grub/i386-pc /usr/lib/grub/i386-pc /usr/local/grub /usr/share/grub/i386-redhat /usr/local/src/grub-0.5.94 $HOME/share/grub/i386-pc/"
053 sbin_grub_path="/usr/local/sbin /usr/sbin /sbi 053 sbin_grub_path="/usr/local/sbin /usr/sbin /sbin $HOME/sbin"
054 054
055 PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin 055 PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin
056 export PATH 056 export PATH
057 057
058 MTOOLSRC=mtoolsrc 058 MTOOLSRC=mtoolsrc
059 export MTOOLSRC 059 export MTOOLSRC
060 060
061 061
062 FLOPPY_DRIVE=A: 062 FLOPPY_DRIVE=A:
063 IMG_FNAME=fd.img 063 IMG_FNAME=fd.img
064 064
065 065
066 066
067 067
068 init_image () { 068 init_image () {
069 echo "Initialize disk image $IMG_FILE..." 069 echo "Initialize disk image $IMG_FILE..."
070 if [ ! -f $IMG_FNAME ] ; then 070 if [ ! -f $IMG_FNAME ] ; then
071 dd if=/dev/zero of=$IMG_FNAME bs=18k count 071 dd if=/dev/zero of=$IMG_FNAME bs=18k count=80 1>/dev/null 2>&1
072 fi 072 fi
073 073
074 rm -f $MTOOLSRC 074 rm -f $MTOOLSRC
075 echo "drive u: file=\"$IMG_FNAME\" 1.44M fil 075 echo "drive u: file=\"$IMG_FNAME\" 1.44M filter" > $MTOOLSRC
076 076
077 if mformat U: ; then : ; else 077 if mformat U: ; then : ; else
078 rm -f $MTOOLSRC 078 rm -f $MTOOLSRC
079 echo "drive u: file=\"$IMG_FNAME\" 1.44M" 079 echo "drive u: file=\"$IMG_FNAME\" 1.44M" > $MTOOLSRC
080 if mformat U: ; then : ; else 080 if mformat U: ; then : ; else
081 rm -f $MTOOLSRC 081 rm -f $MTOOLSRC
082 echo "drive u: file=\"$IMG_FNAME\"" > $M 082 echo "drive u: file=\"$IMG_FNAME\"" > $MTOOLSRC
083 mformat U: 083 mformat U:
084 fi 084 fi
085 fi 085 fi
086 } 086 }
087 087
088 088
089 089
090 090
091 091
092 init_floppy () { 092 init_floppy () {
093 echo "Formatting floppy..." 093 echo "Formatting floppy..."
094 mformat $FLOPPY_DRIVE || exit 1 094 mformat $FLOPPY_DRIVE || exit 1
095 } 095 }
096 096
097 097
098 lookup_grub () { 098 lookup_grub () {
099 099
100 for d in $grub_dirs_common ; do 100 for d in $grub_dirs_common ; do
101 if [ -d $d ] ; then 101 if [ -d $d ] ; then
102 GRUBDIR=$d 102 GRUBDIR=$d
103 break 103 break
104 fi 104 fi
105 done 105 done
106 106
>> 107
>> 108 if [ ! -d "$GRUBDIR" ] ; then
>> 109 GRUBDIR=`whereis grub | awk '{ print "find "$3" -name stage2" }' | sh | xargs dirname 2>/dev/null`
>> 110 fi
>> 111
107 112
108 if [ ! -d "$GRUBDIR" ] ; then 113 if [ ! -d "$GRUBDIR" ] ; then
109 GRUBDIR=`locate stage2 | head -1 | xargs d !! 114 GRUBDIR=`locate stage2 | head -1 | xargs dirname 2>/dev/null`
110 fi 115 fi
111 116
112 117
113 for d in $sbin_grub_path ; do 118 for d in $sbin_grub_path ; do
114 if [ -x $d/grub ] ; then 119 if [ -x $d/grub ] ; then
115 SBIN_GRUB=$d/grub 120 SBIN_GRUB=$d/grub
116 break 121 break
117 fi 122 fi
118 done 123 done
119 124
120 if [ -d "$GRUBDIR" -a -x "$SBIN_GRUB" ] ; th 125 if [ -d "$GRUBDIR" -a -x "$SBIN_GRUB" ] ; then
121 echo "Found correct grub installation in $ 126 echo "Found correct grub installation in $GRUBDIR"
122 echo "Found correct /sbin/grub at $SBIN_GR 127 echo "Found correct /sbin/grub at $SBIN_GRUB"
123 else 128 else
124 echo "Couldn't find a correct grub install 129 echo "Couldn't find a correct grub installation."
125 exit 1 130 exit 1
126 fi 131 fi
127 } 132 }
128 133
129 134
130 135
131 136
132 137
133 setup_disk () { 138 setup_disk () {
134 echo "Setup destination disk..." 139 echo "Setup destination disk..."
135 140
136 mmd $1/boot 141 mmd $1/boot
137 mmd $1/boot/grub 142 mmd $1/boot/grub
138 143
139 if [ -d $GRUBDIR/stage1 ] ; then 144 if [ -d $GRUBDIR/stage1 ] ; then
140 mcopy $GRUBDIR/stage1/stage1 $1/boot/grub/ 145 mcopy $GRUBDIR/stage1/stage1 $1/boot/grub/
141 mcopy $GRUBDIR/stage2/stage2 $1/boot/grub/ 146 mcopy $GRUBDIR/stage2/stage2 $1/boot/grub/
142 else 147 else
143 mcopy $GRUBDIR/stage1 $1/boot/grub/ 148 mcopy $GRUBDIR/stage1 $1/boot/grub/
144 mcopy $GRUBDIR/stage2 $1/boot/grub/ 149 mcopy $GRUBDIR/stage2 $1/boot/grub/
145 fi 150 fi
146 mmd $1/system 151 mmd $1/system
147 mmd $1/modules 152 mmd $1/modules
148 153
149 $SBIN_GRUB --batch <<EOT 1>/dev/null 2>/dev/ !! 154 $SBIN_GRUB --batch --no-floppy <<EOT 1>/dev/null 2>/dev/null || exit 1
150 device (fd0) $IMG_FNAME 155 device (fd0) $IMG_FNAME
151 install (fd0)/boot/grub/stage1 (fd0) (fd0)/boo 156 install (fd0)/boot/grub/stage1 (fd0) (fd0)/boot/grub/stage2 p (fd0)/boot/grub/menu.txt
152 quit 157 quit
153 EOT 158 EOT
154 } 159 }
155 160
156 161
157 162
158 163
159 164
160 165
161 166
162 167
163 lookup_grub 168 lookup_grub
164 169
165 dest="$1" ; shift 170 dest="$1" ; shift
166 loader_fname="$1" ; shift 171 loader_fname="$1" ; shift
167 options="$1" ; shift 172 options="$1" ; shift
168 modules="$*" 173 modules="$*"
169 174
170 175
171 case x$dest in 176 case x$dest in
172 x*:) 177 x*:)
173 drive=$dest 178 drive=$dest
174 IMG_FNAME=$dest 179 IMG_FNAME=$dest
175 FLOPPY_DRIVE=$dest 180 FLOPPY_DRIVE=$dest
176 init_floppy 181 init_floppy
177 ;; 182 ;;
178 x*) 183 x*)
179 drive=U: 184 drive=U:
180 IMG_FNAME=$dest 185 IMG_FNAME=$dest
181 init_image 186 init_image
182 ;; 187 ;;
183 esac 188 esac
184 189
185 190
186 setup_disk $drive 191 setup_disk $drive
187 192
188 193
189 mcopy -bo $loader_fname $drive/system/`basenam 194 mcopy -bo $loader_fname $drive/system/`basename $loader_fname`
190 195
191 196
192 rm -f menu.txt 197 rm -f menu.txt
193 cat <<EOF > menu.txt 198 cat <<EOF > menu.txt
194 timeout 0 199 timeout 0
195 default 0 200 default 0
196 title Simple OS 201 title Simple OS
197 root (fd0) 202 root (fd0)
198 kernel /system/`basename $loader_fname` $optio 203 kernel /system/`basename $loader_fname` $options
199 EOF 204 EOF
200 205
201 206
202 for f in $modules ; do 207 for f in $modules ; do
203 if [ ! -f $f ] ; then 208 if [ ! -f $f ] ; then
204 echo "ERROR: module $f not correctly c 209 echo "ERROR: module $f not correctly compiled in."
205 exit 1 210 exit 1
206 fi 211 fi
207 if ! mcopy -bo $f $drive/modules/`basename 212 if ! mcopy -bo $f $drive/modules/`basename $f` ; then
208 echo "ERROR: module $f could not be tr 213 echo "ERROR: module $f could not be transferred to floppy."
209 exit 1 214 exit 1
210 fi 215 fi
211 echo module /modules/`basename $f` >> menu 216 echo module /modules/`basename $f` >> menu.txt
212 done 217 done
213 218
214 219
215 mcopy -bo menu.txt $drive/boot/grub/ 220 mcopy -bo menu.txt $drive/boot/grub/