root/morphix/trunk/morph-scripts/convert_to_boot.img.sh

Revision 2, 5.2 kB (checked in by nextime, 2 years ago)

Initial import, branching from morphix svn

  • Property svn:executable set to
Line 
1 #!/bin/bash
2 #
3 # First Draft - Lots of thing to clean up, but lets get it working first.....
4 # Version: 1.1.1.1 Dates 2004-11-04
5 #
6 # Copyright (c) 2004, Brendan M. Sleight <bmsleight@morphix._REMOVE_SPAM_TRAP.org>
7 #
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2, or (at your option)
11 # any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; see the file COPYING.  If not, write to
20 # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
21 #
22
23 TEMPDIR="$1"
24 STARTISO="$2"
25 FINISHISO="$3"
26
27 if [ -z "$TEMPDIR" -o -z "$STARTISO" -o -z "$FINISHISO" ]; then
28     echo "Usage: $0 tmpdirectory starting.iso destination.iso"
29     echo
30     echo "e.g. $0 /tmp/ /mnt/hda5/lunix.iso/MorphixBase-0.5-pre2.iso /mnt/hda5/lunix.iso/MorphixTestConvert2.iso"
31     echo
32     echo "This script generates a new iso, with boot.img"
33     echo "based upon a iso with an uncompressed /boot"
34     echo
35     echo "In other words, Morphix_0.5 -> an iso with boot.img"
36     echo "Disk space is required to store a new iso"
37     echo "Requires GRUB to be installed"
38     echo
39     exit
40 fi
41
42 # Set up the working directories ....
43 mkdir $TEMPDIR/convert_morphix_base
44 mkdir $TEMPDIR/convert_morphix_base/base
45 mkdir $TEMPDIR/convert_morphix_base/iso
46 mkdir $TEMPDIR/convert_morphix_base/boot
47 mkdir $TEMPDIR/convert_morphix_base/misc
48
49 #Mount the old iso so that we can extract the boot files..
50 mount $STARTISO $TEMPDIR/convert_morphix_base/iso -o loop
51
52 # Make a new floopy image, with file-system and mount it for writing
53 dd if=/dev/zero of=$TEMPDIR/convert_morphix_base/base/boot.img bs=1k count=2880
54 #mke2fs -F /tmp/convert_morphix_base/base/boot.img
55 #mkfs.vfat -F /tmp/convert_morphix_base/base/boot.img
56 # Tried all of the above, boot.img from 0-4-1d is vfat
57 mkfs.msdos -C $TEMPDIR/convert_morphix_base/base/boot.img 2880
58 mount $TEMPDIR/convert_morphix_base/base/boot.img $TEMPDIR/convert_morphix_base/boot -o loop
59
60 #Create the grub directories
61 mkdir $TEMPDIR/convert_morphix_base/boot/boot
62 mkdir $TEMPDIR/convert_morphix_base/boot/boot/grub
63
64 #This is where grub is on my system
65 #  /usr/local/share/grub/i386-pc/
66 #  /boot/grub
67 GRUB_LOCATE=/boot/grub
68 cp $GRUB_LOCATE/stage1 $TEMPDIR/convert_morphix_base/boot/boot/grub
69 cp $GRUB_LOCATE/stage2 $TEMPDIR/convert_morphix_base/boot/boot/grub
70 # The following line appears to make no difference. Also stage 1_5 is not in 0.4-1d boot.img
71 # cp /usr/local/share/grub/i386-pc/e2fs_stage1_5 /tmp/convert_morphix_base/boot/boot/grub/
72
73
74 # Copy the files across.
75 cp $TEMPDIR/convert_morphix_base/iso/boot/miniroot.gz       $TEMPDIR/convert_morphix_base/boot/boot/
76 cp $TEMPDIR/convert_morphix_base/iso/boot/vmlinuz           $TEMPDIR/convert_morphix_base/boot/boot/
77 #cp /tmp/convert_morphix_base/iso/boot/grub/             /tmp/convert_morphix_base/boot/boot/ -R
78 # OK Anyone know how to do bash string or statements ?
79 for i in $(ls /tmp/convert_morphix_base/iso/boot/grub/);
80 do
81   if   [ "$i" == "stage1" ]
82   then
83         echo "Not copying file: $i"
84   elif [ "$i" == "stage2" ]
85   then
86         echo "Not copying file: $i"
87   elif [ "$i" == "iso9660_stage1_5" ]
88   then
89         echo "Not copying file: $i"
90   else
91         cp $TEMPDIR/convert_morphix_base/iso/boot/grub/$i             $TEMPDIR/convert_morphix_base/boot/boot/grub/  2>/dev/null
92   fi
93 done
94
95
96 # Will run out of space for text.*
97 # Note, we have not copied memtest - tough not enough space.
98 # We need to make new grub index lst files. Replace line of (cd) with (fd0)
99 # sed -e 's/(cd)/(fd0)/g' $TEMPDIR/convert_morphix_base/iso/boot/grub/menu.lst > $TEMPDIR/convert_morphix_base/boot/boot/grub/menu.lst
100 for i in $(ls $TEMPDIR/convert_morphix_base/iso/boot/grub/*.lst);
101 do
102     BASENAME=${i##*/}
103     sed -e 's/(cd)/(fd0)/g' $TEMPDIR/convert_morphix_base/iso/boot/grub/$BASENAME > $TEMPDIR/convert_morphix_base/boot/boot/grub/$BASENAME
104 done
105
106 for i in $(ls $TEMPDIR/convert_morphix_base/iso/boot/grub/texts.*);
107 do
108     BASENAME=${i##*/}
109     sed -e 's/(cd)/(fd0)/g' $TEMPDIR/convert_morphix_base/iso/boot/grub/$BASENAME > $TEMPDIR/convert_morphix_base/boot/boot/grub/$BASENAME
110 done
111
112 # Finished making the boot.img, unmounting
113 umount $TEMPDIR/convert_morphix_base/base/boot.img
114
115 #Write the GRUB to the boot.img
116 echo "device (fd0) $TEMPDIR/convert_morphix_base/base/boot.img " > $TEMPDIR/convert_morphix_base/misc/grub_commands
117 echo "root (fd0)"                                               >> $TEMPDIR/convert_morphix_base/misc/grub_commands
118 echo "setup (fd0) "                                             >> $TEMPDIR/convert_morphix_base/misc/grub_commands
119 echo "quit"                                                     >> $TEMPDIR/convert_morphix_base/misc/grub_commands
120 cat $TEMPDIR/convert_morphix_base/misc/grub_commands | grub --batch
121
122 #Write the new Iso with out having to copy ans extract the whole cd! (I like this command, note the -graft-points.)
123 mkisofs -graft-points -pad -l -r -J -v -V "Morphix LiveCD" -b base/boot.img -c base/boot.cat -hide -rr -moved -o  $FINISHISO $TEMPDIR/convert_morphix_base/iso /base/=$TEMPDIR/convert_morphix_base/base/
124
125 umount $STARTISO
126
127 #Clean-up
128 rm $TEMPDIR/convert_morphix_base/ -R
Note: See TracBrowser for help on using the browser.