]>
git.ipfire.org Git - people/trikolon/ipfire-2.x.git/blob - tools/mkflash/mkflash
87c51f2b9023bd3c2d192cd4289b41c02cfd25dc
3 # This file is part of the IPCop Firewall.
5 # IPCop is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # IPCop is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with IPCop; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 # Originally by Guy Ellis and Steve Bauer
20 # Copyright 2001 Traverse Technologies Australia - http://www.traverse.com.au/
22 # Copyright (C) 2002-04-08 Mark Wormgoor <mark@wormgoor.com>
23 # - Modified to use loopback filesystem
24 # - Modified to easily change partition sizes
25 # Copyright (C) 2003-04-04 Nick Shore <nick.shore@multithread.co.uk>
26 # - Added disksize calculations
27 # Copyright (C) 2003-04-09 Simon Turner <simont@angledata.co.uk>
28 # - Modified to easily change partition sizes and fix
30 # Copyright (C) 2004-01-29 Mark Wormgoor <mark@wormgoor.com>
31 # - Modified for IPCop 1.4 (grub, etc)
32 # Copyright (C) 2004-08-17 Dale Haag <dhaag@net-defender.net>
33 # - Fixed grub stage2 problem for CF disks
34 # - Added command line option to select target CF drive
35 # - Modified for creating 256mb, 512mb and 1gb CF disks
36 # - Modified routines for building sym links
37 # - Added ability to define kernel loading parameters needed for large CF disks
38 # - Added ability to define grub install parameters needed for large CF disks
39 # - Flash file is created as /tmp/[size]flash.img to allow storing multiple development images
40 # Copyright (C) 2004-08-30 Dale Haag <dhaag@net-defender.net>
41 # - Fixed issue with ramdisk sym link not properly being created for rc.flash.up
42 # - Added ability to configure ethernet settings for a LEX with 3 RTL8139 during flash build
43 # Copyright (C) 2005-08-13 Gilles Espinasse <g.esp.ipcop@free.fr>
44 # - Use a bigger /boot partition to allow easier kernel upgrade and support smp kernel
45 # - Define zlog_MB at 30MB for 512 and 1gb like with 256 flash
48 # - auto grub install to CF
49 # - compressed logs on flash + log to ramdisk
51 # Some SiS chipset don't like ide=nodma parameter (bug SF 1098510), remove in case of problem
57 # See what we're supposed to do
58 # 32 & 64 are too small now for this current script and IPCop 1.4.0
61 # echo "`date '+%b %e %T'`: Creating 32MB Compact Flash"
66 # root_MB=$(( $flash_MB - $boot_MB - $zlog_MB ))
71 # echo "`date '+%b %e %T'`: Creating 64MB Compact Flash"
76 # root_MB=$(( $flash_MB - $boot_MB - $zlog_MB ))
81 echo "`date '+%b %e %T'`: Creating 128MB Compact Flash"
86 root_MB
=$
(( $flash_MB - $boot_MB - $zlog_MB ))
91 echo "`date '+%b %e %T'`: Creating 256MB Compact Flash"
96 root_MB
=$
(( $flash_MB - $boot_MB - $zlog_MB ))
99 #kernel_PARMS="idebus=100 ide=nodma ide0=0x177-0x177,0x376" #specific to LEX with CF on secondary master
100 #kernel_PARMS="" # Sis chipset workaround, don't use nodma
101 kernel_PARMS
="ide=nodma" # Generic
102 grub_PARMS
="--force-lba"
105 echo "`date '+%b %e %T'`: Creating 512MB Compact Flash"
110 root_MB
=$
(( $flash_MB - $boot_MB - $zlog_MB ))
113 #kernel_PARMS="idebus=100 ide=nodma ide0=0x177-0x177,0x376" #specific to LEX with CF on secondary master
114 #kernel_PARMS="" # Sis chipset workaround, don't use nodma
115 kernel_PARMS
="ide=nodma" # Generic
116 grub_PARMS
="--force-lba"
119 echo "`date '+%b %e %T'`: Creating 1 Gigabyte Compact Flash"
124 root_MB
=$
(( $flash_MB - $boot_MB - $zlog_MB ))
127 #kernel_PARMS="idebus=100 ide=nodma ide0=0x177-0x177,0x376" #specific to LEX with CF on secondary master
128 #kernel_PARMS="" # Sis chipset workaround, don't use nodma
129 kernel_PARMS
="ide=nodma" Generic
130 grub_PARMS
="--force-lba"
134 # echo "Usage: $0 {32|64|128|256|512|1gb} {hda|hdb|hdc|hdd}"
135 echo "Usage: $0 {128|256|512|1gb} {hda|hdb|hdc|hdd}"
142 echo "`date '+%b %e %T'`: Creating hda Compact Flash"
146 echo "`date '+%b %e %T'`: Creating hdb Compact Flash"
150 echo "`date '+%b %e %T'`: Creating hdc Compact Flash"
154 echo "`date '+%b %e %T'`: Creating hdd Compact Flash"
158 echo "Usage: $0 {32|64|128|256|512|1gb} {hda|hdb|hdc|hdd}"
164 # Calculate all the required derived variables...
165 bs
=512 # do not change!
167 flash_blocks
=$
(( $flash_MB * 1024 * 1024 / $bs ))
169 boot_blocks
=$
(( $boot_MB * 1024 * 1024 / $bs - 1 ))
170 zlog_blocks
=$
(( $zlog_MB * 1024 * 1024 / $bs ))
171 root_blocks
=$
(( $root_MB * 1024 * 1024 / $bs ))
174 zlog_block_offset
=$
(( $boot_block_offset + $boot_blocks ))
175 root_block_offset
=$
(( $zlog_block_offset + $zlog_blocks ))
177 boot_byte_offset
=$
(( $boot_block_offset * $bs ))
178 zlog_byte_offset
=$
(( $zlog_block_offset * $bs ))
179 root_byte_offset
=$
(( $root_block_offset * $bs ))
181 cylinders
=$
(( $flash_blocks / $heads / $sectors ))
184 ramdisk_KB
=$
(( $ramdisk_MB * 1024 ))
186 ############################################################################
188 # Loading loopback kernel module #
190 ############################################################################
191 echo "`date '+%b %e %T'`: Loading loopback kernel module"
195 ############################################################################
197 # Creating empty flash image in /tmp/cf-image #
199 ############################################################################
200 echo "`date '+%b %e %T'`: Creating empty flash image in /tmp"
201 dd if=/dev
/zero of
=/tmp
/flash.img bs
=$bs count
=$flash_blocks >/dev
/null
202 dd if=/dev
/zero of
=/var
/log
/part1.img bs
=$bs count
=$boot_blocks >/dev
/null
203 dd if=/dev
/zero of
=/var
/log
/part2.img bs
=$bs count
=$zlog_blocks >/dev
/null
204 dd if=/dev
/zero of
=/var
/log
/part3.img bs
=$bs count
=$root_blocks >/dev
/null
207 ############################################################################
209 # Making filesystems #
211 ############################################################################
212 echo "`date '+%b %e %T'`: Making filesystems"
213 mke2fs
-F -j -m 0 -b 1024 /var
/log
/part1.img
>/dev
/null
214 mke2fs
-F -j -m 0 -b 1024 /var
/log
/part2.img
>/dev
/null
215 mke2fs
-F -j -m 0 -b 1024 /var
/log
/part3.img
>/dev
/null
218 ############################################################################
220 # Creating and partitioning Compact Flash image #
222 ############################################################################
223 echo "`date '+%b %e %T'`: Creating and partitioning Compact Flash image"
224 sfdisk
-H $heads -S $sectors -C $cylinders -uM /tmp
/flash.img
<<EOF >/dev/null 2>&1
225 # Start Size Type Bootable
227 ,$zlog_MB,, # /var/log_compressed
231 dd if=/var
/log
/part1.img of
=/tmp
/flash.img seek
=$boot_block_offset bs
=$bs
232 dd if=/var
/log
/part2.img of
=/tmp
/flash.img seek
=$zlog_block_offset bs
=$bs
233 dd if=/var
/log
/part3.img of
=/tmp
/flash.img seek
=$root_block_offset bs
=$bs
234 rm -f /var
/log
/part?.img
237 ############################################################################
239 # Mounting loopback flash image under /mnt #
241 ############################################################################
242 echo "`date '+%b %e %T'`: Mounting loopback flash image under /mnt"
245 mount
-o loop
,offset
=$root_byte_offset /tmp
/flash.img
/mnt
/flash
246 mkdir
-p /mnt
/flash
/boot
247 mount
-o loop
,offset
=$boot_byte_offset /tmp
/flash.img
/mnt
/flash
/boot
248 mkdir
-p /mnt
/flash
/var
/log_compressed
249 mount
-o loop
,offset
=$zlog_byte_offset /tmp
/flash.img
/mnt
/flash
/var
/log_compressed
252 ############################################################################
254 # Creating flash image directory structure #
256 ############################################################################
257 echo "`date '+%b %e %T'`: Creating flash image directory structure"
258 mkdir
-p /mnt
/flash
/{ram
/,proc
/,mnt
/}
261 ############################################################################
263 # Copying files into flash image #
265 ############################################################################
266 echo "`date '+%b %e %T'`: Copying files into flash image"
268 cp -a /boot
/mnt
/flash
/
271 mkdir
-p /mnt
/flash
/var
/{log
,log_compressed
,spool
,www
/icons
}
272 cp -a /var
/ipcop
/var
/lib
/var
/state
/var
/lock
/var
/log
/mnt
/flash
/var
274 #######################################################################################
275 # Configure flash image ethernet settings #
276 # this allows you to stage on one system and build flash for LEX with 3 RTL8139 NIC's #
277 # if a settings file named settings.8139 is placed in your /root directory it will be #
278 # used to configure the flash image with the correct ethernet settings for the LEX #
279 # a default settings.8139 file is provided for your use #
280 #######################################################################################
281 if [ -f /root
/settings
.8139 ]
284 /bin
/echo "Configuring Flash With LEX RTL8139 Ethernet Settings"
287 cat /root
/settings
.8139 > /mnt
/flash
/var
/ipcop
/ethernet
/settings
290 /bin
/echo "Flash Is Using Build System Ethernet Settings"
296 rm -rf /mnt
/flash
/var
/log
/lost
+found
297 cp -a /var
/run
/var
/empty
/mnt
/flash
/var
298 cp -a /var
/spool
/cron
/mnt
/flash
/var
/spool
299 ln -s /tmp
/mnt
/flash
/var
/patches
300 ln -sf /ram
/squid
/var
/log
/cache
301 rm -f /mnt
/flash
/var
/lib
/logrotate.status
302 rm -f /mnt
/flash
/var
/state
/dhcp
/*
303 touch /mnt
/flash
/var
/state
/dhcp
/dhcpd.leases
304 find /mnt
/flash
/var
/run \
( -type f
-o -type s \
) -exec rm -f {} \
;
305 touch /mnt
/flash
/var
/run
/utmp
306 chmod 644 /mnt
/flash
/var
/run
/utmp
307 chown root
:utmp
/mnt
/flash
/var
/run
/utmp
308 touch /mnt
/flash
/var
/log
/wtmp
309 chmod 664 /mnt
/flash
/var
/log
/wtmp
310 chown root
:utmp
/mnt
/flash
/var
/log
/wtmp
313 rm -rf /mnt
/flash
/var
/log
/snort
/*
314 find /mnt
/flash
/var
/log
-type f
-exec rm -f {} \
;
315 tar -C /mnt
/flash
-czf /mnt
/flash
/var
/log_compressed
/log.tgz var
/log
/
316 rm -rf /mnt
/flash
/var
/log
/
317 ln -sf /ram
/log
/mnt
/flash
/var
/log
320 cp -a /sbin
/mnt
/flash
/
321 cp -a /bin
/mnt
/flash
/
322 cp -a /lib
/mnt
/flash
/
323 cp -a /dev
/mnt
/flash
/
325 # create the symlinks
326 echo "`date '+%b %e %T'`: Creating $CF Sym Link"
327 ln -sf /dev
/"$CF" /mnt
/flash
/dev
/harddisk
329 echo "`date '+%b %e %T'`: Creating "$CF'1'" Sym Link"
330 ln -sf /dev
/$CF'1' /mnt
/flash
/dev
/harddisk1
332 echo "`date '+%b %e %T'`: Creating "$CF'2'" Sym Link"
333 ln -sf /dev
/$CF'2' /mnt
/flash
/dev
/harddisk2
335 echo "`date '+%b %e %T'`: Creating "$CF'3'" Sym Link"
336 ln -sf /dev
/$CF'3' /mnt
/flash
/dev
/harddisk3
338 echo "`date '+%b %e %T'`: Creating "$CF'4'" Sym Link"
339 ln -sf /dev
/$CF'4' /mnt
/flash
/dev
/harddisk4
342 cp -a /root
/mnt
/flash
/
343 rm -f /mnt
/flash
/root
/.bash_history
344 cp -a /etc
/mnt
/flash
/
345 rm -rf /mnt
/flash
/etc
/{httpd
/conf
/ssl
*,makedev.d
/}
346 rm -f /mnt
/flash
/etc
/ssh
/*key
347 rm -f /mnt
/flash
/etc
/httpd
/server.
*
348 cp -a /home
/mnt
/flash
/
349 rm -f /home
/httpd
/html
/graphs
/*
350 rm -f /home
/httpd
/html
/sgraph
/*
351 cp -a /usr
/mnt
/flash
352 rm -rf /mnt
/flash
/{tmp
/,usr
/tmp
/,var
/tmp
/}
353 ln -sf /ram
/tmp
/ /mnt
/flash
/tmp
354 ln -sf /ram
/tmp
/ /mnt
/flash
/usr
/tmp
355 ln -sf /ram
/tmp
/ /mnt
/flash
/var
/tmp
356 ln -sf /dev
/ram0
/mnt
/flash
/dev
/ramdisk
358 ############################################################################
360 # Installing log backup cron job #
362 ############################################################################
363 echo "`date '+%b %e %T'`: Installing log backup cron job"
364 cat >> /mnt
/flash
/var
/spool
/cron
/root.orig
<<EOF
366 # Backup logs to flash
367 02 * * * * /etc/rc.d/rc.flash.down
369 chroot
/mnt
/flash
/usr
/bin
/fcrontab
-z >/dev
/null
2>&1
372 ############################################################################
374 # Reconfiguring logrotate #
376 ############################################################################
377 echo "`date '+%b %e %T'`: Reconfiguring logrotate"
378 cp -pf logrotate.conf
/mnt
/flash
/etc
/
381 ############################################################################
383 # Installing new fstab #
385 ############################################################################
386 echo "`date '+%b %e %T'`: Installing new fstab"
387 cat /etc
/fstab |
sed -e 's/log\t/log_compressed/' > /mnt
/flash
/etc
/fstab
391 ############################################################################
393 # Touching /etc/FLASH #
395 ############################################################################
396 echo "`date '+%b %e %T'`: Touching /etc/FLASH"
397 touch /mnt
/flash
/etc
/FLASH
399 ############################################################################
401 # Create the Grub.conf file with our parameters #
403 ############################################################################
404 cat > /mnt
/flash
/boot
/grub
/grub.conf
<<EOF
409 splashimage (hd0,0)/grub/ipcop.xpm.gz
412 kernel /vmlinuz root=/dev/$drive_ID panic=10 acpi=off ro $kernel_PARMS ramdisk_size=$ramdisk_KB
416 kernel /vmlinuz-smp root=/dev/$drive_ID panic=10 acpi=off ro $kernel_PARMS ramdisk_size=$ramdisk_KB
418 title IPCop (ACPI enabled)
420 kernel /vmlinuz root=/dev/$drive_ID panic=10 ro $kernel_PARMS ramdisk_size=$ramdisk_KB
422 title IPCop SMP (ACPI HT enabled)
424 kernel /vmlinuz-smp root=/dev/$drive_ID panic=10 acpi=ht ro $kernel_PARMS ramdisk_size=$ramdisk_KB
429 ############################################################################
433 ############################################################################
434 echo "`date '+%b %e %T'`: Installing Grub"
436 /usr
/sbin
/grub
--batch <<EOF >/dev/null 2>&1
437 device (hd0) /tmp/flash.img
441 install $grub_PARMS (hd0,0)/grub/stage1 (hd0) (hd0,0)/grub/stage2 0x8000 p /grub/grub.conf
445 ############################################################################
449 ############################################################################
450 echo "`date '+%b %e %T'`: Cleaning up"
452 umount
/mnt
/flash
/var
/log_compressed
453 umount
/mnt
/flash
/boot
455 losetup
-d /dev
/loop0
456 losetup
-d /dev
/loop1
457 losetup
-d /dev
/loop2
458 mv /tmp
/flash.img
/tmp
/$SIZE'flash.img'
460 echo "`date '+%b %e %T'`: Mkflash For $SIZE Flash Drive On $CF Complete"