diff --git a/target/livecd/build_stage1.sh b/target/livecd/build_stage1.sh index b767fe0eb..709bae49b 100644 --- a/target/livecd/build_stage1.sh +++ b/target/livecd/build_stage1.sh @@ -1,27 +1,55 @@ echo_header "Creating initrd data:" rm -rf $disksdir/initrd -mkdir -p $disksdir/initrd/{dev,sys,proc,mnt/{cdrom,floppy,stick,}} +mkdir -p $disksdir/initrd/{dev,proc,sys,mnt/{cdrom,floppy,stick,}} mkdir -p $disksdir/initrd/mnt/{cowfs_ro/{etc,home,bin,sbin,opt,usr/{bin,sbin},tmp,var,lib},cowfs_rw} cd $disksdir/initrd + # echo_status "Creating read-only symlinks..." for d in etc home bin sbin opt usr tmp var lib ; do - ln -s /mnt/cowfs_rw/$d $d - ln -s /mnt/cowfs_ro/$d mnt/cowfs_rw/$d + ln -s mnt/cowfs_rw/$d $d + ln -s ../cowfs_ro/$d mnt/cowfs_rw/$d done # if [ -L $disksdir/2nd_stage/lib64 ] ; then - ln -s /mnt/cowfs_rw/lib64 lib64 - ln -s /mnt/cowfs_ro/lib64 mnt/cowfs_rw/lib64 + ln -s mnt/cowfs_rw/lib64 lib64 + ln -s ../cowfs_ro/lib64 mnt/cowfs_rw/lib64 +fi + +rock_targetdir="$base/target/$target/" +rock_target="$target" + +rootdir="$disksdir/2nd_stage" +targetdir="$disksdir/initrd" +cross_compile="" +if [ "$ROCKCFG_CROSSBUILD" = "1" ] ; then + cross_compile="`find ${base}/ROCK/tools.cross/ -name "*-readelf"`" + cross_compile="${cross_compile##*/}" + cross_compile="${cross_compile%%readelf}" fi +initrdfs="ext2fs" +block_size="" +ramdisk_size=12288 + +case ${initrdfs} in + ext2fs|ext3fs|cramfs) + initrd_img="${disksdir}/initrd.img" + ;; + ramfs) + initrd_img="${disksdir}/initrd.cpio" + ;; +esac echo_status "Creating some device nodes" -mknod dev/ram0 b 1 0 -mknod dev/null c 1 3 -mknod dev/zero c 1 5 -mknod dev/tty c 5 0 -mknod dev/console c 5 1 +mknod ${targetdir}/dev/ram0 b 1 0 +mknod ${targetdir}/dev/null c 1 3 +mknod ${targetdir}/dev/zero c 1 5 +mknod ${targetdir}/dev/tty c 5 0 +mknod ${targetdir}/dev/console c 5 1 + +# this copies a set of programs and the necessary libraries into a +# chroot environment echo_status "Create checkisomd5 binary" cp -r ${base}/misc/isomd5sum ${base}/build/${ROCKCFG_ID}/ @@ -36,28 +64,52 @@ chroot ${base}/build/${ROCKCFG_ID}/ /compile_isomd5sum.sh cp ${base}/build/${ROCKCFG_ID}/isomd5sum/checkisomd5 mnt/cowfs_ro/bin/ rm -rf ${base}/build/${ROCKCFG_ID}/compile_isomd5sum.sh ${base}/build/${ROCKCFG_ID}/isomd5sum -echo_status "Copying and adjusting linuxrc scipt" +echo_status "Copying and adjusting linuxrc script" cp ${base}/target/${target}/linuxrc.sh linuxrc chmod +x linuxrc -#sed -i -e "s,^STAGE_2_BIG_IMAGE=\"2nd_stage.tar.gz\"$,STAGE_2_BIG_IMAGE=\"${ROCKCFG_SHORTID}/2nd_stage.tar.gz\"," \ -# -e "s,^STAGE_2_SMALL_IMAGE=\"2nd_stage_small.tar.gz\"$,STAGE_2_SMALL_IMAGE=\"${ROCKCFG_SHORTID}/2nd_stage_small.tar.gz\"," \ sed -i -e "s,\(^STAGE_2_BIG_IMAGE=\"\)\(2nd_stage.img.z\"$\),\1${ROCKCFG_SHORTID}/\2," \ linuxrc -# -echo_status "Copy various helper applications." -cp ../2nd_stage/bin/{tar,gzip} mnt/cowfs_ro/bin/ -cp ../2nd_stage/sbin/hwscan mnt/cowfs_ro/sbin/ -cp ../2nd_stage/usr/bin/gawk mnt/cowfs_ro/bin/ - -for file in ../2nd_stage/bin/{tar,gzip,bash2,bash,sh,mount,umount,ls,cat,uname,rm,ln,mkdir,rmdir,gawk,awk,grep,sleep,dmesg} \ - ../2nd_stage/sbin/{ip,hwscan,pivot_root,swapon,swapoff,udev*,losetup} \ - ../2nd_stage/usr/bin/{wget,find,expand,readlink} \ - ../2nd_stage/usr/sbin/lspci ; do - programs="${programs} ${file#../2nd_stage}" - cp ${file} mnt/cowfs_ro/${file#../2nd_stage/} +libdirs="${rootdir}/lib `sed -e"s,^\(.*\),${rootdir}\1," ${rootdir}/etc/ld.so.conf | tr '\n' ' '`" + +needed_libs() { + local x="${1}" library + + ${cross_compile}readelf -d ${x} 2>/dev/null | grep "(NEEDED)" | + sed -e"s,.*Shared library: \[\(.*\)\],\1," | + while read library ; do + find ${libdirs} -name "${library}" 2>/dev/null | + sed -e "s,^${rootdir},,g" | tr '\n' ' ' + done +} + +libs="${libs} `needed_libs bin/checkisomd5`" + +echo_status "Copying other files ... " +for x in ${rock_targetdir}/initrd/initrd_* ; do + [ -f ${x} ] || continue + while read file target ; do + file="${rootdir}/${file}" + [ -e ${file} ] || continue + + while read f ; do + tfile=${targetdir}/${target}${f#${file}} + [ -e ${tfile} ] && continue + + if [ -d ${f} -a ! -L ${f} ] ; then + mkdir -p "${tfile}" + continue + else + mkdir -p "${tfile%/*}" + fi + + cp -a ${f} ${tfile} + + file -L ${f} | grep -q ELF || continue + libs="${libs} `needed_libs ${f}`" + done < <( find "${file}" ) + done < ${x} done -cp -a $build_root/etc/udev mnt/cowfs_ro/etc/ for x in modprobe.static modprobe.static.old \ insmod.static insmod.static.old @@ -89,42 +141,32 @@ done # rm -f mnt/cowfs_ro/lib/modules/[0-9]*/kernel/drivers/net/{dummy,ppp*}.{o,ko} -echo_status "Copying necessary libraries" - -libs="/lib/ld-linux.so.2 /lib/libdl.so.2 /lib/libc.so.6 /lib/librt.so.1 /lib/libpthread.so.0 /usr/lib/libpopt.so.0" -# libpopt from checkisomd5 which is not in build/* -for x in ${programs} ; do - [ -e ./$x ] || continue - file $x | grep -q ELF || continue - libs="$libs `chroot ${base}/build/${ROCKCFG_ID} ldd $x 2>/dev/null | grep -v 'not a dynamic executable' | sed -e 's,^[\t ]*,,g' | cut -f 3 -d' '`" -done - -while [ -n "$libs" ] ; do - oldlibs=$libs +echo_status "Copying required libraries ... " +while [ -n "${libs}" ] ; do + oldlibs=${libs} libs="" - for x in $oldlibs ; do - mkdir -p mnt/cowfs_ro/${x%/*} - if [ ! -e ./$x ] ; then - cp ${base}/build/${ROCKCFG_ID}/$x mnt/cowfs_ro/$x - echo_status "- ${x##*/}" - fi - file $x | grep -q ELF || continue - for y in `chroot ${base}/build/${ROCKCFG_ID} ldd $x 2>/dev/null | grep -v 'not a dynamic executable' | sed -e 's,^[\t ]*,,g' | cut -f 3 -d' '` ; do - [ ! -e "./$y" ] && libs="$libs $y" + for x in ${oldlibs} ; do + [ -e "${targetdir}/${x}" ] && continue + mkdir -p "${targetdir}/${x%/*}" + cp ${rootdir}/${x} ${targetdir}/${x} + file -L ${rootdir}/${x} | grep -q ELF || continue + for y in `needed_libs ${rootdir}/${x}` ; do + [ ! -e "${targetdir}/${y}" ] && libs="${libs} ${y}" done done done -echo_status "Creating links for identical files." +echo_status "Creating links for identical files ..." while read ck fn do - if [ "$oldck" = "$ck" ] ; then - echo_status "\`- Found $fn -> $oldfn." - rm $fn ; ln -s ${oldfn#.} $fn + # don't link empty files... + if [ "${oldck}" = "${ck}" -a -s "${fn}" ] ; then + echo_status "\`- Found ${fn#${targetdir}} -> ${oldfn#${targetdir}}." + rm ${fn} ; ln -s /${oldfn#${targetdir}} ${fn} else - oldck=$ck ; oldfn=$fn + oldck=${ck} ; oldfn=${fn} fi -done < <( find -type f | xargs md5sum | sort ) +done < <( find ${targetdir} -type f | xargs md5sum | sort ) cd .. @@ -132,32 +174,40 @@ echo_header "Creating initrd filesystem image: " ramdisk_size=8139 +[ "${block_size}" == "" ] && block_size=1024 +block_count=$(( ( 1024 * ${ramdisk_size} ) / ${block_size} )) + echo_status "Creating temporary files." -tmpdir=initrd_$$.dir; mkdir -p $disksdir/$tmpdir; cd $disksdir -dd if=/dev/zero of=initrd.img bs=1024 count=$ramdisk_size &> /dev/null -tmpdev="" -for x in /dev/loop/* ; do - if losetup $x initrd.img 2> /dev/null ; then - tmpdev=$x ; break - fi -done -if [ -z "$tmpdev" ] ; then - echo_error "No free loopback device found!" - rm -f $tmpfile ; rmdir $tmpdir; exit 1 +tmpdir=`mktemp -d` ; mkdir -p ${tmpdir} +dd if=/dev/zero of=${initrd_img} bs=${block_size} count=${block_count} &> /dev/null +tmpdev="`losetup -f 2>/dev/null`" +if [ -z "${tmpdev}" ] ; then + for x in /dev/loop* /dev/loop/* ; do + [ -b "${x}" ] || continue + losetup ${x} 2>&1 >/dev/null || tmpdev="${x}" + [ -n "${tmpdev}" ] && break + done + if [ -z "${tmpdev}" ] ; then + echo_status "No free loopback device found!" + rm -f ${tmpfile} ; rmdir ${tmpdir}; exit 1 + fi fi -echo_status "Using loopback device $tmpdev." -# +echo_status "Using loopback device ${tmpdev}." +losetup "${tmpdev}" ${initrd_img} + echo_status "Writing initrd image file." -mke2fs -m 0 -N 360 -q $tmpdev &> /dev/null -mount -t ext2 $tmpdev $tmpdir -rmdir $tmpdir/lost+found/ -cp -a initrd/* $tmpdir -umount $tmpdir +mkfs.${initrdfs:0:4} -b ${block_size} -m 0 -N 360 -q ${tmpdev} &> /dev/null +mount -t ${initrdfs:0:4} ${tmpdev} ${tmpdir} +rmdir ${tmpdir}/lost+found/ +cp -a ${targetdir}/* ${tmpdir} +umount ${tmpdir} + +echo_status "Removing temporary files." +losetup -d ${tmpdev} +rm -rf ${tmpdir} # echo_status "Compressing initrd image file." -gzip -9 initrd.img -mv initrd{.img,}.gz -# -echo_status "Removing temporary files." -losetup -d $tmpdev -rm -rf $tmpdir +gzip -9 -c ${initrd_img} > ${initrd_img}.gz +mv ${initrd_img%.img}{.img,}.gz + +target="$rock_target" diff --git a/target/livecd/build_stage2.sh b/target/livecd/build_stage2.sh index 557666722..5706645f7 100644 --- a/target/livecd/build_stage2.sh +++ b/target/livecd/build_stage2.sh @@ -40,12 +40,13 @@ mkdir home/{rocker,root} chown 1000:100 home/rocker sed -i -e 's,root:.*,root:x:0:0:root:/home/root:/bin/bash,' etc/passwd -sed -i -e 's,root:.*,root:$1$1YssESn0$Y9LvBGGXpsZhjNKZ0x8OM/:12548::::::,' etc/shadow -sed -i -e 's,sound:x:17:,sound:x:17:rocker,' etc/group +sed -i -e 's,root:.*,root:$1$9KtEb9vt$IDoD/c7IG5EpCwxvBudgA:13300::::::,' etc/shadow echo 'rocker:x:1000:100:ROCK Live CD User:/home/rocker:/bin/bash' >> etc/passwd -echo 'rocker:$1$//TuI8QD$kTxVesUbGLNKuxILuK2UN/:12548:0:99999:7:::' >> etc/shadow -echo 'wheel:x:440:rocker' >> etc/group -echo 'wheel:!::rocker' >> etc/gshadow +echo 'rocker:$1$b3mL1k/q$zneIjKcHqok1T80fp1cPI1:13300:0:99999:7:::' >> etc/shadow +sed -i -e 's,wheel:x:10:,wheel:x:10:rocker,' etc/group +sed -i -e 's,video:x:16:,video:x:16:rocker,' etc/group +sed -i -e 's,sound:x:17:,sound:x:17:rocker,' etc/group +sed -i -e 's,cdrom:x:29:,cdrom:x:29:rocker,' etc/group # echo_status "activating shadowfs through /etc/ld.so.preload" diff --git a/target/livecd/initrd/initrd_livecd b/target/livecd/initrd/initrd_livecd new file mode 100644 index 000000000..73367f68d --- /dev/null +++ b/target/livecd/initrd/initrd_livecd @@ -0,0 +1,38 @@ +bin/awk mnt/cowfs_ro/bin/awk +bin/bash2 mnt/cowfs_ro/bin/bash2 +bin/bash mnt/cowfs_ro/bin/bash +bin/cat mnt/cowfs_ro/bin/cat +bin/cp mnt/cowfs_ro/bin/cp +bin/dmesg mnt/cowfs_ro/bin/dmesg +bin/find mnt/cowfs_ro/bin/find +bin/gawk mnt/cowfs_ro/bin/gawk +bin/grep mnt/cowfs_ro/bin/grep +bin/gzip mnt/cowfs_ro/bin/gzip +bin/ln mnt/cowfs_ro/bin/ln +bin/ls mnt/cowfs_ro/bin/ls +bin/mkdir mnt/cowfs_ro/bin/mkdir +bin/mount mnt/cowfs_ro/bin/mount +bin/rmdir mnt/cowfs_ro/bin/rmdir +bin/rm mnt/cowfs_ro/bin/rm +bin/sh mnt/cowfs_ro/bin/sh +bin/sleep mnt/cowfs_ro/bin/sleep +bin/tar mnt/cowfs_ro/bin/tar +bin/umount mnt/cowfs_ro/bin/umount +bin/uname mnt/cowfs_ro/bin/uname +etc/udev mnt/cowfs_ro/etc/udev +lib/udev mnt/cowfs_ro/lib/udev +sbin/hwscan mnt/cowfs_ro/sbin/hwscan +sbin/ip mnt/cowfs_ro/sbin/ip +sbin/losetup mnt/cowfs_ro/sbin/losetup +sbin/pivot_root mnt/cowfs_ro/sbin/pivot_root +sbin/swapoff mnt/cowfs_ro/sbin/swapoff +sbin/swapon mnt/cowfs_ro/sbin/swapon +sbin/udevcontrol mnt/cowfs_ro/sbin/udevcontrol +sbin/udevd mnt/cowfs_ro/sbin/udevd +sbin/udevsettle mnt/cowfs_ro/sbin/udevsettle +sbin/udevtrigger mnt/cowfs_ro/sbin/udevtrigger +usr/bin/expand mnt/cowfs_ro/usr/bin/expand +usr/bin/find mnt/cowfs_ro/usr/bin/find +usr/bin/readlink mnt/cowfs_ro/usr/bin/readlink +usr/bin/wget mnt/cowfs_ro/usr/bin/wget +usr/sbin/lspci mnt/cowfs_ro/usr/sbin/lspci diff --git a/target/livecd/linuxrc.sh b/target/livecd/linuxrc.sh index cc102747a..21c6f3768 100644 --- a/target/livecd/linuxrc.sh +++ b/target/livecd/linuxrc.sh @@ -153,7 +153,7 @@ getcdromdevice () { # {{{ cdroms="${1}" floppies="${2}" autoboot="${3}" - devicelists="/dev/cdroms/* /dev/hd[a-d] /dev/floppy/*" + devicelists="/dev/cdroms/* /dev/floppy/*" [ "${cdroms}" == "0" -a "${floppies}" == "0" ] && return -1 @@ -178,14 +178,10 @@ getcdromdevice () { # {{{ echo " ${x}. CD-ROM #${cdrom} (IDE/ATAPI or SCSI)" cdrom=$((${cdrom}+1)) fi - if [[ ${device} = /dev/floppy* ]] ; then + if [[ ${device} = /dev/flopp* ]] ; then echo " ${x}. FDD (Floppy Disk Drive) #${floppy}" floppy=$((${floppy}+1)) fi - if [[ ${device} = /dev/hd[a-d] ]] ; then - echo " ${x}. IDE Drive #${x}" - floppy=$((${floppy}+1)) - fi x=$((${x}+1)) done @@ -236,6 +232,7 @@ prepare_root () { ln -svf /mnt/cowfs_ro/* /mnt/cowfs_rw-new/ rm -rf /mnt/cowfs_rw-new/{home,tmp} mkdir -p /mnt/cowfs_rw-new/{home,tmp} + chmod 1777 /mnt/cowfs_rw-new/tmp mkdir -p /mnt/cowfs_rw-new/home/{rocker,root} chmod 755 /mnt/cowfs_rw-new/home/rocker chmod 700 /mnt/cowfs_rw-new/home/root @@ -281,7 +278,7 @@ EOF fi exit_linuxrc=1 - echo "Using ${devicefile}://${filename}." + echo "Using ${devicefile}:${filename}." if ! mkdir -p /mnt/cdrom ; then echo "Can't create /mnt/cdrom" @@ -293,14 +290,15 @@ EOF exit_linuxrc=0 fi - if ! losetup /dev/loop/0 "/mnt/cdrom/${filename}" ; then + loopdev="dev/loop/0" ; [ ! -e "${loopdev}" ] && loopdev="/dev/loop0" + if ! losetup "${loopdev}" "/mnt/cdrom/${filename}" ; then echo "Can't losetup /mnt/cdrom/${filename}" exit_linuxrc=0 fi # mkdir -p /mnt/cowfs_r{o,w} - if ! mount -t squashfs /dev/loop/0 /mnt/cowfs_ro -o ro ; then + if ! mount -t squashfs "${loopdev}" /mnt/cowfs_ro -o ro ; then echo "Can't mount squashfs on /mnt/cowfs_ro" exit_linuxrc=0 fi @@ -386,32 +384,29 @@ checkisomd5() { # {{{ read } # }}} +emit_udev_events() { # {{{ + /sbin/udevtrigger + /sbin/udevsettle +} # }}} + input=1 exit_linuxrc=0 [ -z "${autoboot}" ] && autoboot=0 -mount -t tmpfs tmpfs /dev || echo "Can't mount a tmpfs on /dev" -mount -t sysfs sysfs /sys || echo "Can't mount sysfs on /sys" -mount -t proc proc /proc || echo "Can't mount /proc" -mount -t tmpfs -o ${TMPFS_OPTIONS} tmpfs /tmp || echo "Can't mount /tmpfs" -cd /dev -rm -rf fd -ln -s /proc/self/fd -cd - +mount -t tmpfs -o ${TMPFS_OPTIONS} tmpfs /tmp || echo "Can't mount /tmpfs" +mount -t proc proc /proc || echo "Can't mount /proc" +mount -t sysfs sysfs /sys || echo "Can't mount sysfs on /sys" +mount -t tmpfs tmpfs /dev || echo "Can't mount a tmpfs on /dev" export PATH="/sbin:/bin:/usr/sbin:/usr/bin:$PATH" +cp -r /lib/udev/devices/* /dev + echo "" > /proc/sys/kernel/hotplug /sbin/udevd --daemon + # create nodes for devices already in kernel -while read uevent; do - echo 1 > $uevent -done < <( find /sys -name uevent ) -udevwait=0 -while [ -d /dev/.udev/queue -a $udevwait -lt 300 ] ; do - sleep 1 - (( udevwait++ )) -done +emit_udev_events mod_load_info @@ -452,7 +447,7 @@ while [ ${exit_linuxrc} -eq 0 ] ; do 8. Validate a CD/DVD against its embedded checksum EOF - echo -n "What do you want to do [0-7] (default=0)? " + echo -n "What do you want to do [0-8] (default=0)? " read text [ -z "${text}" ] && text=0 input=${text//[^0-9]/} diff --git a/target/livecd/powerpc/yaboot.conf b/target/livecd/powerpc/yaboot.conf index 24d79bace..1a082e3f2 100644 --- a/target/livecd/powerpc/yaboot.conf +++ b/target/livecd/powerpc/yaboot.conf @@ -8,11 +8,11 @@ image=/boot/vmlinux label=livecd initrd=/boot/initrd.gz initrd-size=8192 - append="root=/dev/ram devfs=nocompat init=/linuxrc rw" + append="root=/dev/ram devfs=nocompat init=/linuxrc rw autoboot=1" image=/boot/vmlinux label=livecd-text initrd=/boot/initrd.gz initrd-size=8192 - append="root=/dev/ram devfs=nocompat init=/linuxrc rw video=ofonly" + append="root=/dev/ram devfs=nocompat init=/linuxrc rw video=ofonly autoboot=1" diff --git a/target/livecd/sparc/silo.conf b/target/livecd/sparc/silo.conf index 0d045e9ca..f10ea10eb 100644 --- a/target/livecd/sparc/silo.conf +++ b/target/livecd/sparc/silo.conf @@ -5,7 +5,7 @@ default=livecd root=/dev/ram initrd=/boot/initrd.gz read-write -append="devfs=nocompat init=/linuxrc" +append="devfs=nocompat init=/linuxrc autoboot=1" image[sun4u]=/boot/vmlinux64.gz label=livecd diff --git a/target/livecd/x86/isolinux.cfg b/target/livecd/x86/isolinux.cfg index 59bf309d1..9b81c01c8 100644 --- a/target/livecd/x86/isolinux.cfg +++ b/target/livecd/x86/isolinux.cfg @@ -9,21 +9,20 @@ F2 help1.txt LABEL livecd kernel vmlinuz - APPEND initrd=initrd.gz root=/dev/ram devfs=nocompat init=/linuxrc video=vesa:ywrap,mtrr vga=0x317 rw + APPEND initrd=initrd.gz root=/dev/ram devfs=nocompat init=/linuxrc video=vesa:ywrap,mtrr autoboot=1 vga=0x317 rw LABEL livecd-1280 kernel vmlinuz - APPEND initrd=initrd.gz root=/dev/ram devfs=nocompat init=/linuxrc video=vesa:ywrap,mtrr vga=0x31A rw + APPEND initrd=initrd.gz root=/dev/ram devfs=nocompat init=/linuxrc video=vesa:ywrap,mtrr autoboot=1 vga=0x31A rw LABEL livecd-800 kernel vmlinuz - APPEND initrd=initrd.gz root=/dev/ram devfs=nocompat init=/linuxrc video=vesa:ywrap,mtrr vga=0x314 rw + APPEND initrd=initrd.gz root=/dev/ram devfs=nocompat init=/linuxrc video=vesa:ywrap,mtrr autoboot=1 vga=0x314 rw LABEL livecd-640 kernel vmlinuz - APPEND initrd=initrd.gz root=/dev/ram devfs=nocompat init=/linuxrc video=vesa:ywrap,mtrr vga=0x311 rw + APPEND initrd=initrd.gz root=/dev/ram devfs=nocompat init=/linuxrc video=vesa:ywrap,mtrr autoboot=1 vga=0x311 rw LABEL livecd-text kernel vmlinuz - APPEND initrd=initrd.gz root=/dev/ram devfs=nocompat init=/linuxrc vga=0 rw - + APPEND initrd=initrd.gz root=/dev/ram devfs=nocompat init=/linuxrc autoboot=1 vga=0 rw