tazlito rev 170
tazlitobox: add loram tab
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Fri Mar 26 11:54:05 2010 +0100 (2010-03-26) |
parents | d38d94984c69 |
children | de2c740b24e1 |
files | tazlito tazlitobox |
line diff
1.1 --- a/tazlito Wed Mar 24 20:57:25 2010 +0100 1.2 +++ b/tazlito Fri Mar 26 11:54:05 2010 +0100 1.3 @@ -95,6 +95,7 @@ 1.4 writeiso Use running system to generate a bootable ISO (with /home). 1.5 merge Merge multiple rootfs into one iso. 1.6 repack Recompress rootfs into iso with maximum ratio. 1.7 + build-loram Generate a live-CD for low ram systems. 1.8 frugal-install Frugal install in /boot/frugal from a distro or ISO. 1.9 emu-iso Emulate an ISO image with Qemu. 1.10 burn-iso Burn ISO image to a cdrom using Wodim.\n" 1.11 @@ -238,6 +239,7 @@ 1.12 1.13 create_iso() 1.14 { 1.15 + echo "Generating $1" 1.16 genisoimage -R -o $1 -b boot/isolinux/isolinux.bin \ 1.17 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 \ 1.18 -V "$VOLUM_NAME" -p "$PREPARED" -input-charset iso8859-1 \ 1.19 @@ -600,6 +602,288 @@ 1.20 status 1.21 } 1.22 1.23 +# Install a missing package 1.24 +install_package() 1.25 +{ 1.26 + echo -n "Install package $1 " 1.27 + [ -n "$2" ] && echo -n "for kernel $2 " 1.28 + echo -n "?" 1.29 + read answer 1.30 + case "$answer" in 1.31 + y*|Y*|o*|O*) yes y | tazpkg get-install $1;; 1.32 + *) return 1;; 1.33 + esac 1.34 +} 1.35 + 1.36 +# Check iso for loram transformation 1.37 +check_iso_for_loram() 1.38 +{ 1.39 + [ -s $TMP_DIR/iso/boot/rootfs.gz ] || 1.40 + [ -s $TMP_DIR/iso/boot/rootfs1.gz ] 1.41 +} 1.42 + 1.43 +# Build initial rootfs for loram ISO ram/cdrom 1.44 +build_initfs() 1.45 +{ 1.46 + version=$(ls $TMP_DIR/iso/boot/vmlinuz-* | sed 's/.*vmlinuz-//') 1.47 + need_lib=false 1.48 + mkdir -p $TMP_DIR/initfs/bin $TMP_DIR/initfs/dev $TMP_DIR/initfs/lib \ 1.49 + $TMP_DIR/initfs/mnt $TMP_DIR/initfs/proc $TMP_DIR/initfs/tmp 1.50 + while [ ! -f /lib/modules/$version/kernel/fs/aufs/aufs.ko.gz ]; do 1.51 + install_package linux-aufs $version || return 1 1.52 + done 1.53 + cp /lib/modules/$version/kernel/fs/aufs/aufs.ko.gz \ 1.54 + $TMP_DIR/initfs/lib 1.55 + if [ -f /bin/cromfs-driver ]; then 1.56 + cp /bin/cromfs-driver $TMP_DIR/initfs/bin 1.57 + else 1.58 + [ ! -f /usr/sbin/mksquashfs ] && ! install_package squashfs && return 1 1.59 + while [ ! -f /lib/modules/$version/kernel/fs/squashfs/squashfs.ko.gz ]; do 1.60 + install_package linux-squashfs $version || return 1 1.61 + done 1.62 + cp /lib/modules/$version/kernel/fs/squashfs/squashfs.ko.gz \ 1.63 + $TMP_DIR/initfs/lib 1.64 + fi 1.65 + if [ "$1" == "cdrom" ]; then 1.66 + for i in $(ls /dev/[hs]d[a-f]); do 1.67 + cp -a $i $TMP_DIR/initfs/dev 1.68 + done 1.69 + fi 1.70 + if [ -x /usr/share/boot/busybox-static ]; then 1.71 + cp /usr/share/boot/busybox-static $TMP_DIR/initfs/bin/busybox 1.72 + else 1.73 + cp /bin/busybox $TMP_DIR/initfs/bin 1.74 + need_lib=true 1.75 + fi 1.76 + for i in $($TMP_DIR/initfs/bin/busybox | awk \ 1.77 + '{ if (s) printf "%s",$0 } /Currently/ { s=1 }' | sed 's/,//g'); do 1.78 + ln $TMP_DIR/initfs/bin/busybox $TMP_DIR/initfs/bin/$i 1.79 + done 1.80 + for i in /dev/console /dev/loop* /dev/null /dev/tty /dev/zero \ 1.81 + /dev/kmem /dev/mem /dev/random /dev/urandom; do 1.82 + cp -a $i $TMP_DIR/initfs/dev 1.83 + done 1.84 + $need_lib && for i in /lib/ld-* /lib/lib[cm].so* /lib/lib[cm]-* ; do 1.85 + cp -a $i $TMP_DIR/initfs/lib 1.86 + done 1.87 + cat > $TMP_DIR/initfs/init <<EOTEOT 1.88 +#!/bin/sh 1.89 + 1.90 +getarg() 1.91 +{ 1.92 + grep -q " \$1=" /proc/cmdline || return 1 1.93 + eval \$2=\$(sed 's/.* loram=\\([^ ]*\\).*/\\1/' < /proc/cmdline) 1.94 + return 0 1.95 +} 1.96 + 1.97 +copy_rootfs() 1.98 +{ 1.99 + total=\$(grep MemTotal /proc/meminfo | sed 's/[^0-9]//g') 1.100 + need=\$(du -c \${path}rootfs* | tail -n 1 | cut -f1) 1.101 + [ \$(( \$total / \$need )) -gt 1 ] || return 1 1.102 + if ! grep -q " keep-loram" /proc/cmdline && cp \${path}rootfs* /mnt; then 1.103 + path=/mnt/ 1.104 + return 0 1.105 + else 1.106 + rm -f /mnt/rootfs* 1.107 + return 1 1.108 + fi 1.109 +} 1.110 + 1.111 +echo "Switching / to tmpfs..." 1.112 +mount -t proc proc /proc 1.113 +size="\$(grep rootfssize= < /proc/cmdline | \\ 1.114 + sed 's/.*rootfssize=\\([0-9]*[kmg%]\\).*/-o size=\\1/')" 1.115 +[ -n "\$size" ] || size="-o size=90%" 1.116 + 1.117 +if [ -f \$(echo /rootfs*.gz | cut -f1 -d' ') ]; then # loram-ram 1.118 + 1.119 +total=\$(grep MemTotal /proc/meminfo | sed 's/[^0-9]//g') 1.120 +free=\$(grep MemFree /proc/meminfo | sed 's/[^0-9]//g') 1.121 +if [ \$(( \$total/\$free )) -gt 1 ] || ! mount -t tmpfs \$size tmpfs /mnt; then 1.122 + echo "No tmpfs for /mnt" 1.123 + mkdir -p /mnt/.rw 1.124 + mount -t tmpfs tmpfs /mnt/.rw 1.125 + mkdir -p /mnt/.rw/mnt/.rw 1.126 + path=/ 1.127 +else 1.128 + mkdir -p /mnt/.rw 1.129 + path=/mnt/. 1.130 + for i in rootfs* ; do 1.131 + mv /\$i \$path\$i 1.132 + done 1.133 +fi 1.134 +insmod /lib/squashfs.ko.gz 1.135 + 1.136 +else # loram-cdrom 1.137 + 1.138 +getarg cdrom DRIVE_NAME || 1.139 +DRIVE_NAME=\$(grep "drive name" < /proc/sys/dev/cdrom/info | cut -f 3) 1.140 +DEVICE=/dev/\$DRIVE_NAME 1.141 +DIR=fs 1.142 +if getarg loram DIR; then 1.143 + DEVICE=\${DIR%,*} 1.144 + DIR=/\${DIR#*,} 1.145 +fi 1.146 +mount -t tmpfs \$size tmpfs /mnt 1.147 +mkdir -p /mnt/.rw /mnt/.cdrom /mnt/mnt/.cdrom 1.148 +i=0 1.149 +while [ \$i -lt 5 ] && ! mount -r \$DEVICE /mnt/.cdrom; do 1.150 + case "\$DEVICE" in 1.151 + /dev/sd*|UUID=*|LABEL=*) 1.152 + mount -t sysfs sysfs /sys 1.153 + USBDELAY=\$(cat /sys/module/usb_storage/parameters/delay_use) 1.154 + umount /sys 1.155 + sleep \$((1+\$USBDELAY)) ;; 1.156 + esac 1.157 + i=\$((i+1)) 1.158 +done 1.159 +path=/mnt/.cdrom/ 1.160 +copy_rootfs && insmod /lib/squashfs.ko.gz && umount -d /mnt/.cdrom 1.161 + 1.162 +fi 1.163 + 1.164 +memfree=\$(grep MemFree /proc/meminfo | sed 's/[^0-9]//g') 1.165 +umount /proc 1.166 +branch=br=/mnt/.rw:/mnt/.cdrom/\$DIR 1.167 +if [ ! -d /mnt/.cdrom/fs/etc ]; then 1.168 +branch=br=/mnt/.rw 1.169 +for i in \${path}rootfs* ; do 1.170 + fs=\${i#*root} 1.171 + branch=\$branch:/mnt/.\$fs 1.172 + mkdir -p /mnt/.rw/mnt/.\$fs /mnt/.\$fs 1.173 + if [ -f /bin/cromfs-driver ]; then 1.174 + cromfs-driver \${path}root\$fs /mnt/.\$fs -o ro,dev,suid,allow_other 1.175 + else 1.176 + mount -o loop,ro -t squashfs \${path}root\$fs /mnt/.\$fs 1.177 + fi 1.178 +done 1.179 +fi 1.180 +insmod /lib/aufs.ko.gz 1.181 +mount -t aufs -o \$branch none /mnt 1.182 +[ \$memfree -lt 30000 ] && sed -i 's/ slim//' /mnt/etc/rcS.conf 1.183 +[ -x /mnt/sbin/init ] && exec /bin/switch_root mnt /sbin/init || sh 1.184 +EOTEOT 1.185 + chmod +x $TMP_DIR/initfs/init 1.186 + ( cd $TMP_DIR/initfs ; find | busybox cpio -o -H newc 2> /dev/null) | \ 1.187 + lzma e $TMP_DIR/initfs.gz -si 1.188 + rm -rf $TMP_DIR/initfs 1.189 + rem=$(( $(stat -c "%s" $TMP_DIR/initfs.gz) % 4 )) 1.190 + [ $rem -ne 0 ] && 1.191 + dd if=/dev/zero bs=1 count=$(( 4 - $rem )) >> $TMP_DIR/initfs.gz 2> /dev/null 1.192 + return 0 1.193 +} 1.194 + 1.195 +# Move each initramfs to squashfs (or cromfs) 1.196 +build_loram_rootfs() 1.197 +{ 1.198 + rootfs_sizes="" 1.199 + for i in $TMP_DIR/iso/boot/rootfs*.gz; do 1.200 + mkdir -p $TMP_DIR/fs 1.201 + cd $TMP_DIR/fs 1.202 + ( zcat $i 2> /dev/null || unlzma -c $i) | cpio -idm 1.203 + cd - > /dev/null 1.204 + rootfs=$TMP_DIR/$(basename $i) 1.205 + if [ -x /usr/bin/mkcromfs ]; then 1.206 + /usr/bin/mkcromfs -qq -f 262144 -b 16384 $TMP_DIR/fs $rootfs 1.207 + else 1.208 + /usr/sbin/mksquashfs $TMP_DIR/fs $rootfs -comp lzma 1.209 + fi 1.210 + cd $TMP_DIR 1.211 + rootfs_sizes="$rootfs_sizes $(( $(du -s $TMP_DIR/fs | cut -f1) - $(du -s $rootfs | cut -f1) ))" 1.212 + if [ "$1" != "cdrom" ]; then 1.213 + ( cd $(dirname $rootfs); echo $(basename $rootfs) | \ 1.214 + cpio -o -H newc ) > $rootfs.cpio 1.215 + rm -f $rootfs 1.216 + mv $rootfs.cpio $rootfs 1.217 + fi 1.218 + cd - > /dev/null 1.219 + rm -rf $TMP_DIR/fs 1.220 + done 1.221 +} 1.222 + 1.223 +# Move meta boot configuration files to basic configuration files 1.224 +# because meta loram flavor is useless when rootfs is not load in ram 1.225 +unmeta_boot() 1.226 +{ 1.227 + if [ -f $TMP_DIR/loramiso/boot/isolinux/noram.cfg ]; then 1.228 + # We keep enough information to do unloram... 1.229 + sed -i 's/label slitaz/label orgslitaz/' \ 1.230 + $TMP_DIR/loramiso/boot/isolinux/common.cfg 1.231 + sed -i -e 's|=/boot/rootfs\(.*\).gz |=/boot/rootfs.gz |' \ 1.232 + -e 's|label slitaz1|label slitaz|' \ 1.233 + -e '/label slitaz[1-9]/{NNNd}' \ 1.234 + $TMP_DIR/loramiso/boot/isolinux/*.cfg 1.235 + fi 1.236 +} 1.237 + 1.238 +# Move rootfs to squashfs filesystem(s) in the cdrom writeable with aufs. 1.239 +# These squashfs may be load in ram a boot time. 1.240 +# Rootfs are also copied to cdrom for tiny ramsize systems. 1.241 +# Meta flavors are converted to normal flavors. 1.242 +build_loram_cdrom() 1.243 +{ 1.244 + build_initfs cdrom || return 1 1.245 + build_loram_rootfs cdrom 1.246 + cp -a $TMP_DIR/iso $TMP_DIR/loramiso 1.247 + mkdir $TMP_DIR/loramiso/fs 1.248 + cd $TMP_DIR/loramiso/fs 1.249 + for i in $( ls ../boot/root* | sort -r ) ; do 1.250 + ( zcat $i 2> /dev/null || unlzma -c $i ) | cpio -idmu 1.251 + rm -f $i 1.252 + done 1.253 + cd - > /dev/null 1.254 + mv $TMP_DIR/initfs.gz $TMP_DIR/loramiso/boot/rootfs.gz 1.255 + mv $TMP_DIR/rootfs*.gz $TMP_DIR/loramiso 1.256 + mkdir -p $TMP_DIR/loramiso/fs/mnt/.cdrom 1.257 + unmeta_boot 1.258 + create_iso $OUTPUT $TMP_DIR/loramiso 1.259 +} 1.260 + 1.261 +# Update meta flavor selection sizes. 1.262 +# Reduce sizes with rootfs gains. 1.263 +update_metaiso_sizes() 1.264 +{ 1.265 + local append="$(grep append $TMP_DIR/loramiso/boot/isolinux/common.cfg)" 1.266 + local new 1.267 + [ -n "$append" ] || return 1.268 + set -- $append 1.269 + shift 1.270 + new="" 1.271 + while [ -n "$2" ]; do 1.272 + local s 1.273 + case "$1" in 1.274 + *G) s=$(( ${1%G} * 1024 * 1024 ));; 1.275 + *M) s=$(( ${1%M} * 1024 ));; 1.276 + *) s=${1%K};; 1.277 + esac 1.278 + rootfs_sizes=${rootfs_sizes#* } 1.279 + for i in $rootfs_sizes ; do 1.280 + s=$(( $s - $i )) 1.281 + done 1.282 + new="$new $s $2" 1.283 + shift 2 1.284 + done 1.285 + sed -i "s/append .*/append$new $1/" $TMP_DIR/loramiso/boot/isolinux/common.cfg 1.286 +} 1.287 + 1.288 +# Move rootfs to a squashfs filesystem into the initramfs writeable with aufs. 1.289 +# Meta flavor selection sizes are updated. 1.290 +build_loram_ram() 1.291 +{ 1.292 + build_initfs ram || return 1 1.293 + build_loram_rootfs 1.294 + cp -a $TMP_DIR/iso $TMP_DIR/loramiso 1.295 + rm -f $TMP_DIR/loramiso/boot/bzImage 1.296 + ln $TMP_DIR/loramiso/boot/vmlinuz* $TMP_DIR/loramiso/boot/bzImage 1.297 + rootfs=$(ls $TMP_DIR/rootfs* | sort | tail -n 1) 1.298 + cat $rootfs >> $TMP_DIR/initfs.gz 1.299 + mv $TMP_DIR/initfs.gz $rootfs 1.300 + cp $TMP_DIR/rootfs* $TMP_DIR/loramiso/boot 1.301 + update_metaiso_sizes 1.302 + create_iso $OUTPUT $TMP_DIR/loramiso 1.303 +} 1.304 + 1.305 #################### 1.306 # Tazlito commands # 1.307 #################### 1.308 @@ -1743,7 +2027,6 @@ 1.309 status 1.310 rm -f $TMP_DIR/iso/boot/rootfs.gz 1.311 update_bootconfig $TMP_DIR/iso/boot/isolinux "$append" 1.312 - echo "Generating $ISO" 1.313 create_iso $ISO $TMP_DIR/iso 1.314 rm -rf $TMP_DIR 1.315 ;; 1.316 @@ -1764,16 +2047,38 @@ 1.317 1.318 for i in $TMP_DIR/iso/boot/rootfs* ; do 1.319 echo -n "Repacking $(basename $i)" 1.320 - (zcat $i || unlzma -c $i || cat $i) \ 1.321 + (zcat $i 2> /dev/null || unlzma -c $i || cat $i) \ 1.322 2>/dev/null > $TMP_DIR/rootfs 1.323 lzma e $TMP_DIR/rootfs $i \ 1.324 $(lzma_switches $TMP_DIR/rootfs) 1.325 status 1.326 done 1.327 1.328 - echo "Generating $ISO" 1.329 create_iso $ISO $TMP_DIR/iso 1.330 rm -rf $TMP_DIR ;; 1.331 + 1.332 + build-loram) 1.333 + # Build a Live CD for low ram systems. 1.334 + # 1.335 + 1.336 + ISO=$2 1.337 + OUTPUT=$3 1.338 + mkdir -p $TMP_DIR/iso 1.339 + mount -o loop,ro -t iso9660 $ISO $TMP_DIR/iso 1.340 + if ! check_iso_for_loram ; then 1.341 + echo "$2 is not a valid SliTaz live CD. Abort." 1.342 + umount -d $TMP_DIR/iso 1.343 + rm -rf $TMP_DIR 1.344 + exit 1 1.345 + fi 1.346 + 1.347 + case "$4" in 1.348 + cdrom) build_loram_cdrom ;; 1.349 + *) build_loram_ram ;; 1.350 + esac 1.351 + umount -d $TMP_DIR/iso 1.352 + rm -rf $TMP_DIR ;; 1.353 + 1.354 1.355 frugal-install|-fi) 1.356 ISO_IMAGE="$2"
2.1 --- a/tazlitobox Wed Mar 24 20:57:25 2010 +0100 2.2 +++ b/tazlitobox Fri Mar 26 11:54:05 2010 +0100 2.3 @@ -111,6 +111,17 @@ 2.4 editor $DISTRO_SCRIPT 2.5 } 2.6 2.7 +loram_action() 2.8 +{ 2.9 + case "$LORAM_RAM$LORAM_CDROM" in 2.10 + falsetrue) type=cdrom ;; 2.11 + *) type=ram ;; 2.12 + esac 2.13 + xterm -geometry 80x16 \ 2.14 + -title "build loram iso image $LORAM_OUT" \ 2.15 + -e "tazlito build-loram $LORAM_IN $LORAM_OUT $type ; echo -e \"----\nENTER to continue...\" && read close" 2.16 +} 2.17 + 2.18 merge_input() 2.19 { 2.20 set -- $(cat /tmp/tazlito.mergelist 2> /dev/null) 2.21 @@ -265,7 +276,7 @@ 2.22 </pixmap> 2.23 </hbox> 2.24 2.25 - <notebook labels="Writeiso|Live flavor|Flavors list|Gen flavor|Meta|Configuration"> 2.26 + <notebook labels="Writeiso|Live flavor|Flavors list|Gen flavor|Meta|Low RAM|Configuration"> 2.27 2.28 <frame Filesystem to ISO> 2.29 2.30 @@ -496,6 +507,62 @@ 2.31 2.32 </frame> 2.33 2.34 + <frame Low RAM ISO image> 2.35 + 2.36 + <vbox> 2.37 + <hbox> 2.38 + <text wrap="true" width-chars="25" use-markup="true"> 2.39 + <label> 2.40 +" 2.41 +Build a low RAM version 2.42 +of a SliTaz ISO image. 2.43 +The root filesystem is 2.44 +compressed and slower. 2.45 +" 2.46 + </label> 2.47 + </text> 2.48 + 2.49 + <vbox> 2.50 + <radiobutton> 2.51 + <label>The filesystem is always in RAM.</label> 2.52 + <variable>LORAM_RAM</variable> 2.53 + </radiobutton> 2.54 + <radiobutton> 2.55 + <label>The filesystem may be on CDROM.</label> 2.56 + <variable>LORAM_CDROM</variable> 2.57 + </radiobutton> 2.58 + </vbox> 2.59 + </hbox> 2.60 + <hbox> 2.61 + <text use-markup="true"> 2.62 + <label>"<b>ISO input: </b>"</label> 2.63 + </text> 2.64 + <entry accept="filename"> 2.65 + <variable>LORAM_IN</variable> 2.66 + </entry> 2.67 + <button> 2.68 + <input file stock="gtk-open"></input> 2.69 + <action type="fileselect">LORAM_IN</action> 2.70 + </button> 2.71 + </hbox> 2.72 + <hbox> 2.73 + <text use-markup="true"> 2.74 + <label>"<b>ISO ouput:</b>"</label> 2.75 + </text> 2.76 + <entry accept="filename"> 2.77 + <default>loram.iso</default> 2.78 + <variable>LORAM_OUT</variable> 2.79 + </entry> 2.80 + <button> 2.81 + <input file icon="go-next"></input> 2.82 + <label>"Build ISO"</label> 2.83 + <action>$BIN loram_action</action> 2.84 + </button> 2.85 + </hbox> 2.86 + </vbox> 2.87 + 2.88 + </frame> 2.89 + 2.90 <frame Flavor config and packages list> 2.91 2.92 <text wrap="true" width-chars="60" use-markup="true">