# HG changeset patch # User Pascal Bellard # Date 1249718844 -7200 # Node ID ba395fa660a83655fa6669efb13f72bf98397aa3 # Parent 9b31f28a4eb06e3ab2635242944284e9459c5207 Add tazlito merge diff -r 9b31f28a4eb0 -r ba395fa660a8 tazlito --- a/tazlito Fri Aug 07 11:57:01 2009 +0200 +++ b/tazlito Sat Aug 08 10:07:24 2009 +0200 @@ -88,6 +88,7 @@ gen-distro Generate a Live distro and ISO from a list of packages. clean-distro Remove all files generated by gen-distro. check-distro Help to check if distro is ready to release. + merge Merge multiple rootfs into one iso. burn-iso Burn ISO image to a cdrom using Wodim.\n" } @@ -102,6 +103,7 @@ echo -en "\\033[1;31mFailed" fi echo -e "\\033[0;39m ]" + return $CHECK } yesorno() @@ -226,6 +228,19 @@ fi } +create_iso() +{ + genisoimage -R -o $1 -b boot/isolinux/isolinux.bin \ + -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 \ + -V "$VOLUM_NAME" -p "$PREPARED" -input-charset iso8859-1 \ + -boot-info-table $2 + if [ -x /usr/bin/isohybrid ]; then + echo -n "Create hybrid ISO..." + /usr/bin/isohybrid $1 2> /dev/null + status + fi +} + # Generate a new ISO image using isolinux. gen_livecd_isolinux() { @@ -251,15 +266,7 @@ echo "" echo -e "\033[1mGenerating ISO image\033[0m" echo "================================================================================" - genisoimage -R -o $ISO_NAME.iso -b boot/isolinux/isolinux.bin \ - -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 \ - -V "$VOLUM_NAME" -p "$PREPARED" -input-charset iso8859-1 \ - -boot-info-table $ROOTCD - if [ -x /usr/bin/isohybrid ]; then - echo -n "Create hybrid ISO..." - /usr/bin/isohybrid $ISO_NAME.iso 2> /dev/null - status - fi + create_iso $ISO_NAME.iso $ROOTCD echo -n "Creating the ISO md5sum..." md5sum $ISO_NAME.iso > $ISO_NAME.md5 status @@ -268,6 +275,22 @@ genisohooks final } +# Pack rootfs +pack_rootfs() +{ + ( cd $1 ; find . -print | cpio -o -H newc ) | \ + if [ "$COMPRESSION" = "none" ]; then + echo -n "Generating uncompressed initramfs... " + cat > $2 + elif [ -x /usr/bin/lzma -a "$COMPRESSION" != "gzip" ]; then + echo -n "Generating lzma'ed initramfs... " + lzma e -si -so -d24 > $2 + else + echo -n "Generating gziped initramfs... " + gzip -9 > $2 + fi +} + # Generate a new initramfs from the root filesystem. gen_initramfs() { @@ -296,16 +319,7 @@ ) # Use lzma if installed - if [ "$COMPRESSION" = "none" ]; then - echo -n "Generating uncompressed initramfs... " - find . -print | cpio -o -H newc > $DISTRO/$INITRAMFS - elif [ -x /usr/bin/lzma -a "$COMPRESSION" != "gzip" ]; then - echo -n "Generating lzma'ed initramfs... " - find . -print | cpio -o -H newc | lzma e -si -so -d24 > $DISTRO/$INITRAMFS - else - echo -n "Generating gziped initramfs... " - find . -print | cpio -o -H newc | gzip -9 > $DISTRO/$INITRAMFS - fi + pack_rootfs . $DISTRO/$INITRAMFS cd $DISTRO mv $INITRAMFS $ROOTCD/boot } @@ -367,6 +381,51 @@ EOF } +# extract rootfs.gz somewhere +extract_rootfs() +{ + (zcat $1 || unlzma -c $1 || cat $1) 2>/dev/null | \ + (cd $2; cpio -idm > /dev/null) +} + +# Remove duplicate files +mergefs() +{ + # merge symlinks files and devices + ( cd $1; find ) | while read file; do + if [ -L $1/$file ]; then + [ -L $2/$file ] && + [ "$(readlink $1/$file)" == "$(readlink $2/$file)" ] && + rm -f $2/$file + elif [ -f $1/$file ]; then + [ -f $2/$file ] && + cmp $1/$file $2/$file > /dev/null 2>&1 && rm -f $2/$file + [ -f $2/$file ] && + [ "$(basename $file)" == "volatile.cpio.gz" ] && + [ "$(dirname $(dirname $file))" == \ + "./var/lib/tazpkg/installed" ] && rm -f $2/$file + elif [ -b $1/$file ]; then + [ -b $2/$file ] && rm -f $2/$file + elif [ -c $1/$file ]; then + [ -c $2/$file ] && rm -f $2/$file + fi + done + + # cleanup directories + ( cd $1; find ) | while read file; do + if [ -d $1/$file ]; then + [ -d $2/$file ] && rmdir $2/$file 2> /dev/null + fi + done + true +} + +cleanup_merge() +{ + rm -rf $TMP_DIR + exit 1 +} + #################### # Tazlito commands # #################### @@ -532,9 +591,7 @@ # Extract initramfs. cd $TARGET/rootfs echo -n "Extracting the rootfs... " - ( zcat ../rootcd/boot/rootfs.gz 2>/dev/null || \ - lzma d ../rootcd/boot/rootfs.?z -so 2>/dev/null || \ - cat ../rootcd/boot/rootfs.gz ) | cpio -id + extract_rootfs ../rootcd/boot/rootfs.gz $TARGET/rootfs # unpack /usr for i in etc/tazlito/*.extract; do [ -f "$i" ] && . $i ../rootcd @@ -1043,6 +1100,144 @@ fi echo "" ;; + merge) + # Merge multiple rootfs into one iso. + # + if [ -z "$2" ]; then + cat << EOT +Usage: tazlito merge size1 iso size2 rootfs2 [sizeN rootfsN]... + +Merge multiple rootfs into one iso. Rootfs are like russian doll +i.e: rootfsN is a subset of rootfsN-1 +rootfs1 is found in iso, sizeN is the RAM size need to launch rootfsN. +The boot loader will select the rootfs according to the RAM size detected. + +Example: +$ tazlito merge 160M slitaz-core.iso 96M rootfs-justx.gz 32M rootfs-base.gz + +Will start slitaz-core with 160M+ RAM, slitaz-justX with 96M-160M RAM, +slitaz-base with 32M-96M RAM and display an error message if RAM < 32M. +EOT + exit 2 + fi + + shift # skip merge + append="append $(( (${1%M} - 3) * 1024 )) slitaz1" + shift # skip size1 + mkdir -p $TMP_DIR/mnt $TMP_DIR/rootfs1 + + ISO=$1.merged + # Extract filesystems + echo -n "Mount $1" + mount -o loop,ro $1 $TMP_DIR/mnt 2> /dev/null + status || cleanup_merge + cp -a $TMP_DIR/mnt $TMP_DIR/iso + rm -f $TMP_DIR/iso/boot/bzImage + ln $TMP_DIR/iso/boot/vmlinuz* $TMP_DIR/iso/boot/bzImage + umount -d $TMP_DIR/mnt + if [ -f $TMP_DIR/iso/boot/rootfs1.gz ]; then + echo "$1 is already a merged iso. Abort." + cleanup_merge + fi + if [ ! -f $TMP_DIR/iso/boot/isolinux/ifmem.c32 ]; then + if [ ! -f /boot/isolinux/ifmem.c32 ]; then + cat <= i; j--) { + initrd=initrd ",/boot/rootfs" j ".gz"; + } + printf "\tappend %s%s\n",initrd,append; + print ""; + } + print; +} +else print; +}' < $file > $file.$$ + mv -f $file.$$ $file + done + cat >> $TMP_DIR/iso/boot/isolinux/common.cfg <> $TMP_DIR/iso/boot/isolinux/noram.cfg <