tazlito rev 123

Add command writiso (use current fs as it) and tmp fix lzma dictionary size
author Christophe Lincoln <pankso@slitaz.org>
date Fri Jan 22 15:11:34 2010 +0100 (2010-01-22)
parents 4b92240ff36f
children 88bc2c555e8c
files tazlito
line diff
     1.1 --- a/tazlito	Fri Jan 22 09:47:54 2010 +0100
     1.2 +++ b/tazlito	Fri Jan 22 15:11:34 2010 +0100
     1.3 @@ -71,7 +71,7 @@
     1.4  usage ()
     1.5  {
     1.6  	echo -e "\nSliTaz Live Tool - Version: $VERSION\n
     1.7 -\033[1mUsage: \033[0m `basename $0` [command] [list|iso|flavor] [dir]
     1.8 +\033[1mUsage: \033[0m `basename $0` [command] [list|iso|flavor|compression] [dir|iso]
     1.9  \033[1mCommands: \033[0m\n
    1.10    usage           Print this short usage.
    1.11    stats           View Tazlito and distro configuration statistics.
    1.12 @@ -92,6 +92,7 @@
    1.13    gen-distro      Generate a Live distro and ISO from a list of packages.
    1.14    clean-distro    Remove all files generated by gen-distro.
    1.15    check-distro    Help to check if distro is ready to release.
    1.16 +  writeiso        Use running system to generate a bootable ISO (with /home).
    1.17    merge           Merge multiple rootfs into one iso.
    1.18    repack          Recompress rootfs into iso with maximum ratio.
    1.19    emu-iso         Emulate an ISO image with Qemu.
    1.20 @@ -283,15 +284,20 @@
    1.21  
    1.22  lzma_history_bits()
    1.23  {
    1.24 -	local n
    1.25 -	local sz
    1.26 -	n=20	# 1Mb
    1.27 -	sz=$(du -sk $1 | cut -f1)
    1.28 -	while [ $sz -gt 1024 -a $n -lt 28 ]; do
    1.29 -		n=$(( $n + 1 ))
    1.30 -		sz=$(( $sz / 2 ))
    1.31 -	done
    1.32 -	echo $n
    1.33 +	#
    1.34 +	# This genertae ISO who boot with Qemu but give
    1.35 +	# rootfs errors in frugal or liveUSB mode.
    1.36 +	#
    1.37 +	#local n
    1.38 +	#local sz
    1.39 +	#n=20	# 1Mb
    1.40 +	#sz=$(du -sk $1 | cut -f1)
    1.41 +	#while [ $sz -gt 1024 -a $n -lt 28 ]; do
    1.42 +		#n=$(( $n + 1 ))
    1.43 +		#sz=$(( $sz / 2 ))
    1.44 +	#done
    1.45 +	#echo $n
    1.46 +	echo 24
    1.47  }
    1.48  
    1.49  lzma_switches()
    1.50 @@ -1459,6 +1465,135 @@
    1.51  		echo "================================================================================"
    1.52  		echo ""
    1.53  		;;
    1.54 +	writeiso)
    1.55 +		# Writefs to ISO image including /home unlike gen-distro we dont use
    1.56 +		# packages to generate a rootfs, we build a compressed rootfs with all 
    1.57 +		# current filesystem similar to 'tazusb writefs'.
    1.58 +		#
    1.59 +		DISTRO="/home/slitaz/distro"
    1.60 +		ROOTCD="$DISTRO/rootcd"
    1.61 +		if [ -z $2 ]; then
    1.62 +			COMPRESSION=none
    1.63 +		else
    1.64 +			COMPRESSION=$2
    1.65 +		fi
    1.66 +		if [ -z $3 ]; then
    1.67 +			ISO_NAME="slitaz"
    1.68 +		else
    1.69 +			ISO_NAME="$3"
    1.70 +		fi
    1.71 +		check_root
    1.72 +		# Start info
    1.73 +		echo ""
    1.74 +		echo -e "\033[1mWrite filesystem to ISO\033[0m
    1.75 +===============================================================================
    1.76 +The command writeiso will write all the current filesystem into a suitable cpio 
    1.77 +archive (rootfs.gz) and generate a bootable ISO image (slitaz.iso). 
    1.78 +
    1.79 +Archive compression: $COMPRESSION"
    1.80 +		echo ""
    1.81 +		
    1.82 +		# Save some space
    1.83 +		rm /var/cache/tazpkg/* -r -f
    1.84 +		rm -rf /home/slitaz/distro
    1.85 +
    1.86 +		# Optionally remove sound card selection
    1.87 +		echo -n "Do you wish to remove the sound card selection (No/yes/exit) ? "
    1.88 +		read anser
    1.89 +		case $anser in
    1.90 +			e|E|"exit"|Exit)
    1.91 +				exit 0 ;;
    1.92 +			y|Y|yes|Yes)
    1.93 +				echo -n "Removing current sound card selection..."
    1.94 +				rm -f /var/lib/sound-card-driver
    1.95 +				rm -f /etc/asound.state ;;
    1.96 +			*)
    1.97 +				echo -n "Keeping current sound card selection..." ;;
    1.98 +		esac
    1.99 +		status
   1.100 +		
   1.101 +		# Optionally remove screen resolution
   1.102 +		echo -n "Do you wish to remove the screen resolution (No/yes/exit) ? "
   1.103 +		read anser
   1.104 +		case $anser in
   1.105 +			e|E|"exit"|Exit)
   1.106 +				exit 0 ;;
   1.107 +			y|Y|yes|Yes)
   1.108 +				echo -n "Removing current screen resolution..."
   1.109 +				rm -f /etc/X11/screen.conf 
   1.110 +				rm -f /etc/X11/xorg.conf ;;
   1.111 +			*)
   1.112 +				echo -n "Keeping current screen resolution..." ;;
   1.113 +		esac
   1.114 +		status
   1.115 +		
   1.116 +		# Create list of files including default user files since it is defined in /etc/passwd
   1.117 +		# and some new users might have been added.
   1.118 +		find /bin /etc /init /sbin /var /dev /lib /root /usr /home >/tmp/list
   1.119 +
   1.120 +		for dir in /proc /sys /tmp /mnt /media /media/cdrom /media/flash /media/usbdisk
   1.121 +		do
   1.122 +			echo $dir >>/tmp/list
   1.123 +		done
   1.124 +
   1.125 +		# Generate initramfs with specified compression
   1.126 +		if [ "$COMPRESSION" = "lzma" ]; then
   1.127 +			echo -n "Creating rootfs.gz with lzma compression... "
   1.128 +			cat /tmp/list | cpio -o -H newc | lzma e -si -so > /rootfs.gz
   1.129 +
   1.130 +		elif [ "$COMPRESSION" = "gzip" ]; then
   1.131 +			echo -n "Creating rootfs.gz with gzip compression... "
   1.132 +			cat /tmp/list | cpio -o -H newc | gzip -9 > /rootfs.gz
   1.133 +
   1.134 +		else
   1.135 +			echo -n "Creating rootfs.gz without compression... "
   1.136 +			cat /tmp/list | cpio -o -H newc > /rootfs.gz
   1.137 +		fi
   1.138 +		status
   1.139 +
   1.140 +		# Move freshly generated rootfs to the cdrom.
   1.141 +		mkdir -p $ROOTCD/boot
   1.142 +		mv /rootfs.gz $ROOTCD/boot
   1.143 +		
   1.144 +		# Now we need the kernel and isolinux files.
   1.145 +		if mount /dev/cdrom /media/cdrom 2>/dev/null; then
   1.146 +			cp /media/cdrom/boot/bzImage $ROOTCD/boot
   1.147 +			cp -a /media/cdrom/boot/isolinux $ROOTCD/boot
   1.148 +			umount /media/cdrom
   1.149 +		else
   1.150 +			echo -e "\nUnable to mount the cdrom to copy the Kernel and needed files.\n"
   1.151 +			exit 1
   1.152 +		fi
   1.153 +		
   1.154 +		# Generate the iso image.
   1.155 +		cd $DISTRO
   1.156 +		echo "Generating ISO image..."
   1.157 +		genisoimage -R -o $ISO_NAME.iso -b boot/isolinux/isolinux.bin \
   1.158 +		-c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
   1.159 +		-V "SliTaz" -input-charset iso8859-1 -boot-info-table $ROOTCD
   1.160 +		if [ -x /usr/bin/isohybrid ]; then
   1.161 +			echo -n "Create hybrid ISO..."
   1.162 +			/usr/bin/isohybrid $ISO_NAME.iso 2> /dev/null
   1.163 +			status
   1.164 +		fi
   1.165 +		echo -n "Creating the ISO md5sum..."
   1.166 +		md5sum $ISO_NAME.iso > $ISO_NAME.md5
   1.167 +		status
   1.168 +
   1.169 +		echo "==============================================================================="
   1.170 +		echo "ISO image: `du -sh /home/slitaz/distro/$ISO_NAME.iso`"
   1.171 +		echo ""
   1.172 +		echo -n "Exit or burn ISO to cdrom (Exit|burn)? "; read anser
   1.173 +		case $anser in
   1.174 +			burn)
   1.175 +				eject
   1.176 +				echo -n "Please insert a blank cdrom and press ENTER..."
   1.177 +				read i && sleep 2
   1.178 +				tazlito burn-iso /home/slitaz/distro/$ISO_NAME.iso
   1.179 +				echo -en "----\nENTER to continue..."; read i ;;
   1.180 +			*)
   1.181 +				exit 0 ;;
   1.182 +		esac ;;
   1.183  	burn-iso)
   1.184  		# Guess cdrom device, ask user and burn the ISO.
   1.185  		#