From: Serge L. <sma...@us...> - 2008-06-26 17:44:50
|
Update of /cvsroot/devil-linux/build/scripts/scripts In directory sc8-pr-cvs12.sourceforge.net:/tmp/cvs-serv29486 Modified Files: install-on-usb Log Message: - added initramfs support, set inode-size to 128 for ext2/3 (grub's requirements), added an option to format/not format partitions, "smart" initrd/initramfs modification (to reduce size of initrd/initramfs) Index: install-on-usb =================================================================== RCS file: /cvsroot/devil-linux/build/scripts/scripts/install-on-usb,v retrieving revision 1.23 retrieving revision 1.24 diff -u -d -r1.23 -r1.24 --- install-on-usb 11 Apr 2008 12:14:53 -0000 1.23 +++ install-on-usb 26 Jun 2008 17:44:45 -0000 1.24 @@ -10,7 +10,7 @@ # # -TMPDIR="./tmp-install2usb" +TMPDIR="$(pwd)/tmp-install2usb" # You should set $EDITOR or make an editor soft link if you don't like these choices [ -z "$EDITOR" ] && EDITOR=`which editor` @@ -121,6 +121,9 @@ grub_shell=$TMPDIR/iso-mnt/sbin/grub device_map=grub-tmp-map force_lba="" + if [ "$INITRD_TYPE" != "INITRAMFS" ]; then + KERNEL_OPTIONS="root=/dev/ram0 init=/linuxrc $RAMDISK" + fi if [ ! -f "$grub_shell" ]; then echo "Grub not found in ISO image - was it included in the DL build?" @@ -147,16 +150,17 @@ # type device names. title Devil-Linux - Serial Console root (hd0,$2) - kernel /boot/vmlinuz rw root=/dev/ram0 init=/linuxrc $RAMDISK console=tty0 console=ttyS0,${SERIALSPEED}n8 + kernel /boot/vmlinuz rw $KERNEL_OPTIONS $RAMDISK console=tty0 console=ttyS0,${SERIALSPEED}n8 initrd /boot/initrd.gz title Devil-Linux - Standard VGA root (hd0,$2) - kernel /boot/vmlinuz rw root=/dev/ram0 init=/linuxrc $RAMDISK + kernel /boot/vmlinuz rw $KERNEL_OPTIONS initrd /boot/initrd.gz EOF else cat > $TMPDIR/grub.conf <<-EOF timeout=10 + default 3 splashimage=(hd0,$2)/boot/grub/devil-linux.xpm.gz # Devil-Linux Boot Line options: # DL_config=/dev/discs/disc0/part1 - loads the etc.tar.bz2 form that device @@ -167,25 +171,25 @@ # Note: "/dev/hda1" type devices are not supported! Use /dev/discs/... or /dev/ide/... # type device names. title Devil-Linux - Standard VGA - root (hd0,$2) - kernel /boot/vmlinuz rw root=/dev/ram0 init=/linuxrc $RAMDISK - initrd /boot/initrd.gz - title Devil-Linux - VESA Frame Buffer 640x480 - root (hd0,$2) - kernel /boot/vmlinuz rw root=/dev/ram0 init=/linuxrc $RAMDISK vga=769 - initrd /boot/initrd.gz + root (hd0,$2) + kernel /boot/vmlinuz rw $KERNEL_OPTIONS + initrd /boot/initrd.gz + title Devil-Linux - VESA Frame Buffer 640x480 + root (hd0,$2) + kernel /boot/vmlinuz rw $KERNEL_OPTIONS vga=769 + initrd /boot/initrd.gz title Devil-Linux - VESA Frame Buffer 800x600 - root (hd0,$2) - kernel /boot/vmlinuz rw root=/dev/ram0 init=/linuxrc $RAMDISK vga=771 - initrd /boot/initrd.gz + root (hd0,$2) + kernel /boot/vmlinuz rw $KERNEL_OPTIONS vga=771 + initrd /boot/initrd.gz title Devil-Linux - VESA Frame Buffer 1024x768 - root (hd0,$2) - kernel /boot/vmlinuz rw root=/dev/ram0 init=/linuxrc $RAMDISK vga=773 - initrd /boot/initrd.gz + root (hd0,$2) + kernel /boot/vmlinuz rw $KERNEL_OPTIONS vga=773 + initrd /boot/initrd.gz title Devil-Linux - Other - root (hd0,$2) - kernel /boot/vmlinuz rw root=/dev/ram0 init=/linuxrc $RAMDISK vga=ask - initrd /boot/initrd.gz + root (hd0,$2) + kernel /boot/vmlinuz rw $KERNEL_OPTIONS vga=ask + initrd /boot/initrd.gz EOF fi @@ -234,12 +238,6 @@ mkdir -p $TMPDIR/iso-mnt || return 1 mkdir -p $TMPDIR/disk-mnt || return 1 -# echo "Available USB storage devices: " -# for device in $(allAttachedScsiUsb) -# do -# echo -n "$(scsiDevFromScsiUsb $device) " -# done - echo read -p "Enter DL ISO source (disk file or CD device) -> " DLISO @@ -267,6 +265,7 @@ fi echo + read -p "Enter DEVICE name of disk device (i.e. /dev/sda) -> " DEVICE [ "$FDISK" = "cfdisk" ] && $FDISK -Ps $DEVICE @@ -320,13 +319,14 @@ echo " Can not find partition \"$ETC_PART\"" return 1 else - echo;echo -n "All data on device $ETC_PART will be lost, continue ? " - ask_yes_no || return 1 - echo;echo -n "Last chance, do you really want to continue ? " - ask_yes_no || return 1 - - mkfs.ext2 $ETC_PART > /dev/null || return 1 + echo;echo -n "Would you like to format $ETC_PART ? " + if ask_yes_no ; then + format_partition $ETC_PART || return 1 + else + # Try to mount $DEVICE + mount -t auto $ETC_PART $TMPDIR/etc-mnt || ( echo "Unable to mount $ETC_PART"; return 1 ) + fi fi fi fi @@ -334,14 +334,21 @@ echo echo "This will install DL on \"$DEVICE\" using the \"$BOOTLOADER\" bootloader. " - echo;echo -n "All data on device $PARTITION will be lost, continue ? " - ask_yes_no || return 1 - - echo;echo -n "Last chance, do you really want to continue ? " - ask_yes_no || return 1 +# Check the initrd type (INITRAMFS) + # Decompress image + gunzip $TMPDIR/iso-mnt/boot/initrd.gz -d -c > $TMPDIR/initrd || return 1 + if file -b $TMPDIR/initrd | grep -i "cpio archive" > /dev/null 2>&1; then + INITRD_TYPE=INITRAMFS + fi if [ "$BOOTLOADER" = "syslinux" ]; then + echo;echo -n "All data on device $PARTITION will be lost, continue ? " + ask_yes_no || return 1 + + echo;echo -n "Last chance, do you really want to continue ? " + ask_yes_no || return 1 + mkdosfs $PARTITION > /dev/null || return 1 echo "Installing syslinux MBR" @@ -362,17 +369,27 @@ copy_iso_file $DLISO $TMPDIR/disk-mnt/bootcd.iso not_save_permissions || return 1 elif [ "$BOOTLOADER" = "grub" ] || [ "$BOOTLOADER" = "lilo" ]; then - - mkfs.ext2 $PARTITION > /dev/null || return 1 - tune2fs -c 0 $PARTITION - - mount -t auto $PARTITION $TMPDIR/disk-mnt || return 1 + echo;echo -n "Would you like to format $PARTITION ? " + if ask_yes_no ; then + format_partition $PARTITION || return 1 + fi +# Try to mount $DEVICE + mkdir -p $TMPDIR/etc-mnt + mount -t auto $PARTITION $TMPDIR/disk-mnt || ( echo "Unable to mount $PARTITION"; return 1 ) echo "copying files" cp -a $TMPDIR/iso-mnt/boot/ $TMPDIR/disk-mnt/ > /dev/null || return 1 cp -p $TMPDIR/iso-mnt/{DEVIL-LINUX,LICENSE} $TMPDIR/disk-mnt/ > /dev/null || return 1 copy_iso_file $DLISO $TMPDIR/disk-mnt/bootcd.iso || return 1 + if [ -f "/DEVIL-LINUX" ]; then + echo;echo -n "Would you like to modify initrd image (it's mandatory if you have chosen not ext2 fs)?" + if ask_yes_no ; then + echo "Initrd image modifying..." + modify_initrd && mv -f $TMPDIR/initrd.gz $TMPDIR/disk-mnt/boot || return 1 + fi + fi + if [ "$BOOTLOADER" = "grub" ]; then GRUBPART=$(expr $(basename ${PARTITION} | sed -e 's/^part//' -e 's/^[hs]d[a-z]//') - 1) install_grub $DEVICE $GRUBPART || return 1 @@ -388,7 +405,6 @@ fi if [ -n "$ETC_FILE" ]; then - mkdir -p $TMPDIR/etc-mnt mount -t auto $ETC_PART $TMPDIR/etc-mnt echo echo "Copying $ETC_FILE to $TMPDIR/etc-mnt/etc.tar.bz2" @@ -400,6 +416,102 @@ return 0; } +format_partition () { + local PARTITION=$1 + + echo -e "Your system supports the following fs:\n$(ls $(which mkfs).* | sed 's,.*\.,,')" + read -p "Enter file system format you want to use (ext2 is preferable) -> " FORMAT + if [ -x $(which mkfs).$FORMAT ] ; then + + echo;echo -n "All data on device $PARTITION will be lost, continue ? " + ask_yes_no || return 1 + + echo;echo -n "Last chance, do you really want to continue ? " + ask_yes_no || return 1 + if echo $FORMAT | grep ext > /dev/null; then + local OPTION="-I 128" + fi + mkfs.$FORMAT $OPTION -F $PARTITION > /dev/null || return 1 + + else + echo "Unknown FS format : $FORMAT" + return 1 + fi +} + +modify_initrd () { +#=========================================================================== +# echo "Modifying of the initial ramdisk (initrd) image.... " + mkdir -p $TMPDIR/initrd-{old,new} + + # Mount old initrd + if [ "$INITRD_TYPE" = "INITRAMFS" ]; then + pushd $TMPDIR/initrd-old > /dev/null && ( cat $TMPDIR/initrd | cpio -ivd 2> /dev/null ) || return 1 + else + mount $TMPDIR/initrd $TMPDIR/initrd-old -o loop || return 1 + fi + + popd > /dev/null + + # Add marker (load all ata/sata/scsi modules). N.B. it's a workaround because + # mdev doesn't load necessary modules :-( + touch $TMPDIR/initrd-old/tmp/PROBE_ALL_MODULES + + cp -ar $TMPDIR/initrd-old/* $TMPDIR/initrd-new || return 1 + +# Intelligently add modules to initrd image + rm -rf $TMPDIR/initrd-new/lib/modules/*/kernel/drivers/{ata,scsi,message} || return 1 + + for i in $( modinfo -F filename `lsmod | awk '{ print $1}'` 2>/dev/null | grep "fs\|ata\|scsi\|message" ) + do + if [ ! -d $TMPDIR/initrd-new/$(dirname $i) ]; then + mkdir -p $TMPDIR/initrd-new/$(dirname $i) + fi + cp -a $TMPDIR/iso-mnt/$i $TMPDIR/initrd-new/$(dirname $i) + done + + if [ "$INITRD_TYPE" != "INITRAMFS" ]; then + # find out how much space we need. + ISIZE=`du -s -k $TMPDIR/initrd-new/ | awk '{print $1}'` + + ISIZE=`expr $ISIZE + 2048` + + # create a file of 4MB (4096 KB) + dd if=/dev/zero of=$TMPDIR/ramdisk bs=1k count=$ISIZE + + # make an ext2 filesystem on it. We set the amount of unused space to 0% + # and turn down the number of inodes to save space + yes | mkfs -t ext2 -m 0 -i 1024 $TMPDIR/ramdisk + tune2fs -c 0 -i 0 $TMPDIR/ramdisk + + # unmount old initrd + umount $TMPDIR/initrd-old || return 1 + + # we mount it ... + mount -t ext2 $TMPDIR/ramdisk $TMPDIR/initrd-old -o loop || ( echo "Unable to mount $TMPDIR/ramdisk " ; return 1) + + # ... and delete the lost+found directory + rm -rf $TMPDIR/initrd-old/lost+found + + # then we copy the contents of our initrdtree to this filesystem + cp -ar $TMPDIR/initrd-new/* $TMPDIR/initrd-old/ || return 1 + + # and unmount and divorce /dev/loop4 + umount $TMPDIR/initrd-old/ + #losetup -d /dev/loop4 + + # compressing the initial ramdisk (initrd) image + gzip -c $TMPDIR/ramdisk > $TMPDIR/initrd.gz || return 1 + else + pushd $TMPDIR/initrd-new > /dev/null + find . | cpio -H newc -o | gzip -9 > $TMPDIR/initrd.gz || return 1 + popd > /dev/null + fi + + # cleaning up working dirs + rm -rf $TMPDIR/initrd-{old,new} + +} ########################################################################## echo |