Add rocket's unionfs patch and linuxrc cleanup; fix Pegasos with regard to initramfs.
authorTim Yamin <plasmaroo@gentoo.org>
Wed, 15 Jun 2005 19:05:31 +0000 (19:05 +0000)
committerTim Yamin <plasmaroo@gentoo.org>
Wed, 15 Jun 2005 19:05:31 +0000 (19:05 +0000)
git-svn-id: svn+ssh://svn.gentoo.org/var/svnroot/genkernel/trunk@208 67a159dc-881f-0410-a524-ba9dfbe2cb84

12 files changed:
gen_cmdline.sh
gen_compile.sh
gen_determineargs.sh
gen_funcs.sh
gen_initramfs.sh
gen_initrd.sh
gen_package.sh
generic/initrd.defaults
generic/initrd.scripts
generic/linuxrc
genkernel
genkernel.conf

index d0bab9672dd2ace0c2adfd8bc109e97c3589c788..e6c43f636591c1dbf8734636d973ce94b278bdc7 100755 (executable)
@@ -64,6 +64,7 @@ longusage() {
   echo "       --evms2                 Include EVMS2 support"
   echo "                                --> 'emerge evms' in the host operating system first"
   echo "       --lvm2                  Include LVM2 support"
+  echo "       --unionfs               Include UNIONFS support"
   echo "       --dmraid                Include DMRAID support"
   echo "       --bootloader=grub       Add new kernel to GRUB configuration"
   echo "       --linuxrc=<file>        Specifies a user created linuxrc"
@@ -167,6 +168,10 @@ parse_cmdline() {
                      CMD_EVMS2=1
                      print_info 2 "CMD_EVMS2: $CMD_EVMS2"
              ;;
+             --unionfs)
+                     CMD_UNIONFS=1
+                     print_info 2 "CMD_UNIONFS: $CMD_UNIONFS"
+             ;;
              --lvm2)
                      CMD_LVM2=1
                      print_info 2 "CMD_LVM2: $CMD_LVM2"
index b50f6ea63bffb5928530d1fd87d50c28c9ba2515..00071db30e3008598f99c6a2b54e819ccad9e058 100644 (file)
@@ -164,7 +164,7 @@ compile_generic() {
 extract_dietlibc_bincache() {
        cd "${TEMP}"
        rm -rf "${TEMP}/diet" > /dev/null
-       tar -jxpf "${DIETLIBC_BINCACHE}" ||
+       /bin/tar -jxpf "${DIETLIBC_BINCACHE}" ||
                gen_die 'Could not extract dietlibc bincache!'
        [ ! -d "${TEMP}/diet" ] &&
                gen_die "${TEMP}/diet directory not found!"
@@ -240,6 +240,83 @@ compile_kernel() {
        fi
 }
 
+compile_unionfs_modules() {
+       if [ ! -f "${UNIONFS_MODULES_BINCACHE}" ]
+       then
+               [ -f "${UNIONFS_SRCTAR}" ] ||
+                       gen_die "Could not find unionfs source tarball: ${UNIONFS_SRCTAR}!"
+               cd "${TEMP}"
+               rm -rf ${UNIONFS_DIR} > /dev/null
+               rm -rf unionfs > /dev/null
+               mkdir -p unionfs
+               /bin/tar -zxpf ${UNIONFS_SRCTAR} ||
+                       gen_die 'Could not extract unionfs source tarball!'
+               [ -d "${UNIONFS_DIR}" ] ||
+                       gen_die 'Unionfs directory ${UNIONFS_DIR} is invalid!'
+               cd "${UNIONFS_DIR}"
+               print_info 1 'unionfs modules: >> Compiling...'
+               sed -i Makefile -e "s|LINUXSRC =.*|LINUXSRC =${KERNEL_DIR}|g"
+               if [ "${PAT}" -ge '6' ]
+               then
+                       compile_generic unionfs2.6 kernel
+               else
+                       compile_generic unionfs2.4 kernel
+               fi
+               print_info 1 'unionfs: >> Copying to cache...'
+
+               mkdir -p ${TEMP}/unionfs/lib/modules/${KV}/kernel/fs
+               
+               if [ -f unionfs.ko ]
+               then 
+                       cp unionfs.ko ${TEMP}/unionfs/lib/modules/${KV}/kernel/fs 
+               else 
+                       cp unionfs.o ${TEMP}/unionfs/lib/modules/${KV}/kernel/fs 
+               fi
+               
+               cd ${TEMP}/unionfs      
+               /bin/tar -cjf "${UNIONFS_MODULES_BINCACHE}" . ||
+                       gen_die 'Could not create unionfs modules binary cache'
+               
+               cd "${TEMP}"
+               rm -rf "${UNIONFS_DIR}" > /dev/null
+               rm -rf unionfs > /dev/null
+       fi
+}
+
+compile_unionfs_utils() {
+       if [ ! -f "${UNIONFS_BINCACHE}" ]
+       then
+               [ -f "${UNIONFS_SRCTAR}" ] ||
+                       gen_die "Could not find unionfs source tarball: ${UNIONFS_SRCTAR}!"
+               cd "${TEMP}"
+               rm -rf ${UNIONFS_DIR} > /dev/null
+               rm -rf unionfs > /dev/null
+               mkdir -p unionfs/sbin
+               /bin/tar -zxpf ${UNIONFS_SRCTAR} ||
+                       gen_die 'Could not extract unionfs source tarball!'
+               [ -d "${UNIONFS_DIR}" ] ||
+                       gen_die 'Unionfs directory ${UNIONFS_DIR} is invalid!'
+               cd "${UNIONFS_DIR}"
+               print_info 1 'unionfs tools: >> Compiling...'
+               sed -i Makefile -e 's|${CC} -o|${CC} -static -o|g'
+               compile_generic utils utils
+               
+               print_info 1 'unionfs: >> Copying to cache...'
+               strip uniondbg unionctl
+               cp uniondbg ${TEMP}/unionfs/sbin/ || 
+                       gen_die 'Could not copy the uniondbg binary to the tmp directory'
+               cp unionctl ${TEMP}/unionfs/sbin/ ||
+                       gen_die 'Could not copy the unionctl binary to the tmp directory'
+               cd ${TEMP}/unionfs      
+               /bin/tar -cjf "${UNIONFS_BINCACHE}" . ||
+                       gen_die 'Could not create unionfs tools binary cache'
+               
+               cd "${TEMP}"
+               rm -rf "${UNIONFS_DIR}" > /dev/null
+               rm -rf unionfs > /dev/null
+       fi
+}
+
 compile_busybox() {
        if [ ! -f "${BUSYBOX_BINCACHE}" ]
        then
@@ -249,7 +326,7 @@ compile_busybox() {
                        gen_die "Cound not find busybox config file: ${BUSYBOX_CONFIG}!"
                cd "${TEMP}"
                rm -rf ${BUSYBOX_DIR} > /dev/null
-               tar -jxpf ${BUSYBOX_SRCTAR} ||
+               /bin/tar -jxpf ${BUSYBOX_SRCTAR} ||
                        gen_die 'Could not extract busybox source tarball!'
                [ -d "${BUSYBOX_DIR}" ] ||
                        gen_die 'Busybox directory ${BUSYBOX_DIR} is invalid!'
@@ -283,12 +360,12 @@ compile_lvm2() {
                        gen_die "Could not find LVM2 source tarball: ${LVM2_SRCTAR}! Please place it there, or place another version, changing /etc/genkernel.conf as necessary!"
                cd "${TEMP}"
                rm -rf ${LVM2_DIR} > /dev/null
-               tar -zxpf ${LVM2_SRCTAR} ||
+               /bin/tar -zxpf ${LVM2_SRCTAR} ||
                        gen_die 'Could not extract LVM2 source tarball!'
                [ -d "${LVM2_DIR}" ] ||
                        gen_die 'LVM2 directory ${LVM2_DIR} is invalid!'
                rm -rf "${TEMP}/device-mapper" > /dev/null
-               tar -jxpf "${DEVICE_MAPPER_BINCACHE}" -C "${TEMP}" ||
+               /bin/tar -jxpf "${DEVICE_MAPPER_BINCACHE}" -C "${TEMP}" ||
                        gen_die "Could not extract device-mapper binary cache!";
                
                cd "${LVM2_DIR}"
@@ -306,7 +383,7 @@ compile_lvm2() {
                print_info 1 '      >> Copying to bincache...'
                strip "sbin/lvm.static" ||
                        gen_die 'Could not strip lvm.static!'
-               tar -cjf "${LVM2_BINCACHE}" sbin/lvm.static ||
+               /bin/tar -cjf "${LVM2_BINCACHE}" sbin/lvm.static ||
                        gen_die 'Could not create binary cache'
 
                cd "${TEMP}"
@@ -323,12 +400,12 @@ compile_dmraid() {
                        gen_die "Could not find DMRAID source tarball: ${DMRAID_SRCTAR}! Please place it there, or place another version, changing /etc/genkernel.conf as necessary!"
                cd "${TEMP}"
                rm -rf ${DMRAID_DIR} > /dev/null
-               tar -jxpf ${DMRAID_SRCTAR} ||
+               /bin/tar -jxpf ${DMRAID_SRCTAR} ||
                        gen_die 'Could not extract DMRAID source tarball!'
                [ -d "${DMRAID_DIR}" ] ||
                        gen_die 'DMRAID directory ${DMRAID_DIR} is invalid!'
                rm -rf "${TEMP}/device-mapper" > /dev/null
-               tar -jxpf "${DEVICE_MAPPER_BINCACHE}" -C "${TEMP}" ||
+               /bin/tar -jxpf "${DEVICE_MAPPER_BINCACHE}" -C "${TEMP}" ||
                        gen_die "Could not extract device-mapper binary cache!";
                
                cd "${DMRAID_DIR}"
@@ -347,7 +424,7 @@ compile_dmraid() {
                        install -m 0755 -s tools/dmraid "${TEMP}/dmraid/sbin/dmraid"
                print_info 1 '      >> Copying to bincache...'
                cd "${TEMP}/dmraid"
-               tar -cjf "${DMRAID_BINCACHE}" sbin/dmraid ||
+               /bin/tar -cjf "${DMRAID_BINCACHE}" sbin/dmraid ||
                        gen_die 'Could not create binary cache'
 
                cd "${TEMP}"
@@ -367,7 +444,7 @@ compile_modutils() {
                        gen_die "Could not find modutils source tarball: ${MODUTILS_SRCTAR}!"
                cd "${TEMP}"
                rm -rf "${MODUTILS_DIR}"
-               tar -jxpf "${MODUTILS_SRCTAR}"
+               /bin/tar -jxpf "${MODUTILS_SRCTAR}"
                [ ! -d "${MODUTILS_DIR}" ] &&
                        gen_die "Modutils directory ${MODUTILS_DIR} invalid!"
                cd "${MODUTILS_DIR}"
@@ -421,7 +498,7 @@ compile_module_init_tools() {
                        gen_die "Could not find module-init-tools source tarball: ${MODULE_INIT_TOOLS_SRCTAR}"
                cd "${TEMP}"
                rm -rf "${MODULE_INIT_TOOLS_DIR}"
-               tar -jxpf "${MODULE_INIT_TOOLS_SRCTAR}"
+               /bin/tar -jxpf "${MODULE_INIT_TOOLS_SRCTAR}"
                [ ! -d "${MODULE_INIT_TOOLS_DIR}" ] &&
                        gen_die "Module-init-tools directory ${MODULE_INIT_TOOLS_DIR} is invalid"
                cd "${MODULE_INIT_TOOLS_DIR}"
@@ -475,7 +552,7 @@ compile_devfsd() {
                        gen_die "Could not find devfsd source tarball: ${DEVFSD_SRCTAR}"
                cd "${TEMP}"
                rm -rf "${DEVFSD_DIR}"
-               tar -jxpf "${DEVFSD_SRCTAR}"
+               /bin/tar -jxpf "${DEVFSD_SRCTAR}"
                [ ! -d "${DEVFSD_DIR}" ] &&
                        gen_die "Devfsd directory ${DEVFSD_DIR} invalid"
                cd "${DEVFSD_DIR}"
@@ -524,7 +601,7 @@ compile_device_mapper() {
                        gen_die "Could not find device-mapper source tarball: ${DEVICE_MAPPER_SRCTAR}. Please place it there, or place another version, changing /etc/genkernel.conf as necessary!"
                cd "${TEMP}"
                rm -rf "${DEVICE_MAPPER_DIR}"
-               tar -zxpf "${DEVICE_MAPPER_SRCTAR}"
+               /bin/tar -zxpf "${DEVICE_MAPPER_SRCTAR}"
                [ ! -d "${DEVICE_MAPPER_DIR}" ] &&
                        gen_die "device-mapper directory ${DEVICE_MAPPER_DIR} invalid"
                cd "${DEVICE_MAPPER_DIR}"
@@ -539,7 +616,7 @@ compile_device_mapper() {
                        gen_die 'Could not remove manual pages!'
                strip "${TEMP}/device-mapper/sbin/dmsetup" ||
                        gen_die 'Could not strip dmsetup binary!'
-               tar -jcpf "${DEVICE_MAPPER_BINCACHE}" device-mapper ||
+               /bin/tar -jcpf "${DEVICE_MAPPER_BINCACHE}" device-mapper ||
                        gen_die 'Could not tar up the device-mapper binary!'
                [ -f "${DEVICE_MAPPER_BINCACHE}" ] ||
                        gen_die 'device-mapper cache not created!'
@@ -573,7 +650,7 @@ compile_dietlibc() {
                        gen_die "Could not find dietlibc source tarball: ${DIETLIBC_SRCTAR}"
                cd "${TEMP}"
                rm -rf "${DIETLIBC_DIR}" > /dev/null
-               tar -jxpf "${DIETLIBC_SRCTAR}" ||
+               /bin/tar -jxpf "${DIETLIBC_SRCTAR}" ||
                        gen_die 'Could not extract dietlibc source tarball'
                [ -d "${DIETLIBC_DIR}" ] ||
                        gen_die "Dietlibc directory ${DIETLIBC_DIR} is invalid!"
@@ -584,7 +661,7 @@ compile_dietlibc() {
                compile_generic "prefix=${TEMP}/diet install" utils
                print_info 1 "          >> Copying to bincache..."
                cd ${TEMP}
-               tar -jcpf "${DIETLIBC_BINCACHE}" diet ||
+               /bin/tar -jcpf "${DIETLIBC_BINCACHE}" diet ||
                        gen_die 'Could not tar up the dietlibc binary!'
                [ -f "${DIETLIBC_BINCACHE}" ] ||
                        gen_die 'Dietlibc cache not created!'
@@ -603,7 +680,7 @@ compile_udev() {
                rm -rf "${UDEV_DIR}" udev
                [ ! -f "${UDEV_SRCTAR}" ] &&
                        gen_die "Could not find udev tarball: ${UDEV_SRCTAR}"
-               tar -jxpf "${UDEV_SRCTAR}" ||
+               /bin/tar -jxpf "${UDEV_SRCTAR}" ||
                        gen_die 'Could not extract udev tarball'
                [ ! -d "${UDEV_DIR}" ] &&
                        gen_die "Udev tarball ${UDEV_SRCTAR} is invalid"
@@ -612,7 +689,7 @@ compile_udev() {
                print_info 1 'udev: >> Compiling...'
 
                ln -snf "${KERNEL_DIR}" klibc/linux || gen_die "Could not link to ${KERNEL_DIR}"
-               compile_generic "KERNEL_DIR=$KERNEL_DIR USE_KLIBC=true USE_LOG=false DEBUG=false udevdir=/dev all etc/udev/udev.conf" utils
+               compile_generic "ARCH=${ARCH} KERNEL_DIR=$KERNEL_DIR USE_KLIBC=true USE_LOG=false DEBUG=false udevdir=/dev all etc/udev/udev.conf" utils
 
                strip udev || gen_die 'Failed to strip the udev binary!'
 
@@ -632,7 +709,7 @@ compile_udev() {
 
                cd "${TEMP}/udev"
                print_info 1 '      >> Copying to bincache...'
-               tar -cjf "${UDEV_BINCACHE}" * ||
+               /bin/tar -cjf "${UDEV_BINCACHE}" * ||
                        gen_die 'Could not create binary cache'
 
                cd "${TEMP}"
index b019a0825eac23a74b4c1a901dd916be4b6922d2..2d79d54f9542e3f4210b02d1c43f159aa71910fd 100644 (file)
@@ -7,7 +7,7 @@ get_KV() {
                (umask 077 && mkdir ${tmp}) || {
                        gen_die "Could not create temporary directory! Exiting."
                }
-               tar -xj -C ${tmp} -f ${CMD_KERNCACHE} kerncache.config 
+               /bin/tar -xj -C ${tmp} -f ${CMD_KERNCACHE} kerncache.config 
                if [ -e ${tmp}/kerncache.config ]
                then
                        VER=`grep ^VERSION\ \= ${tmp}/kerncache.config | awk '{ print $3 };'`
@@ -137,6 +137,8 @@ determine_real_args() {
        DEVICE_MAPPER_BINCACHE=`cache_replace "${DEVICE_MAPPER_BINCACHE}"`
        LVM2_BINCACHE=`cache_replace "${LVM2_BINCACHE}"`
        DMRAID_BINCACHE=`cache_replace "${DMRAID_BINCACHE}"`
+       UNIONFS_BINCACHE=`cache_replace "${UNIONFS_BINCACHE}"`
+       UNIONFS_MODULES_BINCACHE=`cache_replace "${UNIONFS_MODULES_BINCACHE}"`
   
        DEFAULT_KERNEL_CONFIG=`arch_replace "${DEFAULT_KERNEL_CONFIG}"`
        BUSYBOX_CONFIG=`arch_replace "${BUSYBOX_CONFIG}"`
@@ -151,6 +153,10 @@ determine_real_args() {
        DEVICE_MAPPER_BINCACHE=`arch_replace "${DEVICE_MAPPER_BINCACHE}"`
        LVM2_BINCACHE=`arch_replace "${LVM2_BINCACHE}"`
        DMRAID_BINCACHE=`arch_replace "${DMRAID_BINCACHE}"`
+       UNIONFS_BINCACHE=`arch_replace "${UNIONFS_BINCACHE}"`
+       UNIONFS_MODULES_BINCACHE=`arch_replace "${UNIONFS_MODULES_BINCACHE}"`
+       
+       UNIONFS_MODULES_BINCACHE=`kv_replace "${UNIONFS_MODULES_BINCACHE}"`
        
        if [ "${CMD_BOOTSPLASH}" != '' ]
        then
@@ -284,6 +290,12 @@ determine_real_args() {
        then
                DEVFS=0
        fi
+       
+       if isTrue "${CMD_DEVFS}"
+       then
+               DEVFS=1
+               UDEV=0
+       fi
 
        if isTrue "${CMD_LVM2}"
        then
@@ -299,6 +311,13 @@ determine_real_args() {
                EVMS2=0
        fi
        
+       if isTrue "${CMD_UNIONFS}"
+       then
+               UNIONFS=1
+       else
+               UNIONFS=0
+       fi
+       
        if isTrue "${CMD_NO_BUSYBOX}"
        then
                BUSYBOX=0
index 17c7e828f63b16584ad47477c9221bfa8d54852e..3512551c41786f8419c544761f24eed3b9fad4b5 100755 (executable)
@@ -182,6 +182,10 @@ arch_replace() {
   var_replace "ARCH" "${ARCH}" "${1}"
 }
 
+kv_replace() {
+  var_replace "KV" "${KV}" "${1}"
+}
+
 cache_replace() {
   var_replace "CACHE" "${CACHE_DIR}" "${1}"
 }
index d602623af0c810a5c8f56efcb30ea1c4d28590f0..09525e24dfcf64673de5fcbacab4a232dc7fb922 100644 (file)
@@ -91,7 +91,7 @@ create_udev_cpio(){
        fi
        cd ${TEMP}
        mkdir -p "${TEMP}/initramfs-udev-temp/bin/"
-       [ "${UDEV}" -eq '1' ] && { tar -jxpf "${UDEV_BINCACHE}" -C "${TEMP}/initramfs-udev-temp" ||
+       [ "${UDEV}" -eq '1' ] && { /bin/tar -jxpf "${UDEV_BINCACHE}" -C "${TEMP}/initramfs-udev-temp" ||
                gen_die "Could not extract udev binary cache!"; }
        cd "${TEMP}/initramfs-udev-temp/"
        find . -print | cpio --quiet -o -H newc | gzip -9 > ${CACHE_DIR}/cpio/initramfs-udev-${UDEV_VER}.cpio.gz
@@ -115,6 +115,44 @@ create_devfs_cpio(){
        rm -rf "${TEMP}/initramfs-devfs-temp" > /dev/null
 }
 
+create_unionfs_modules_cpio(){
+       #UNIONFS Modules
+       if [ "${UNIONFS}" -eq '1' ]
+       then
+               if [ -d "${TEMP}/initramfs-unionfs-modules-temp" ]
+               then
+                       rm -r "${TEMP}/initramfs-unionfs-modules-temp/"
+               fi
+               print_info 1 'UNIONFS MODULES: Adding support (compiling)...'
+               compile_unionfs_modules
+               mkdir -p "${TEMP}/initramfs-unionfs-modules-temp/"
+               /bin/tar -jxpf "${UNIONFS_MODULES_BINCACHE}" -C "${TEMP}/initramfs-unionfs-modules-temp" ||
+                       gen_die "Could not extract unionfs modules binary cache!";
+       cd "${TEMP}/initramfs-unionfs-modules-temp/"
+       find . -print | cpio --quiet -o -H newc | gzip -9 > ${CACHE_DIR}/cpio/initramfs-unionfs-${UNIONFS_VER}-modules-${KV}.cpio.gz
+       rm -r "${TEMP}/initramfs-unionfs-modules-temp/"
+       fi
+}
+
+create_unionfs_tools_cpio(){
+       #UNIONFS Tools
+       if [ "${UNIONFS}" -eq '1' ]
+       then
+               if [ -d "${TEMP}/initramfs-unionfs-tools-temp" ]
+               then
+                       rm -r "${TEMP}/initramfs-unionfs-tools-temp/"
+               fi
+               print_info 1 'UNIONFS TOOLS: Adding support (compiling)...'
+               compile_unionfs_utils
+               mkdir -p "${TEMP}/initramfs-unionfs-tools-temp/bin/"
+               /bin/tar -jxpf "${UNIONFS_BINCACHE}" -C "${TEMP}/initramfs-unionfs-tools-temp" ||
+                       gen_die "Could not extract unionfs tools binary cache!";
+       cd "${TEMP}/initramfs-unionfs-tools-temp/"
+       find . -print | cpio --quiet -o -H newc | gzip -9 > ${CACHE_DIR}/cpio/initramfs-unionfs-${UNIONFS_VER}-tools.cpio.gz
+       rm -r "${TEMP}/initramfs-unionfs-tools-temp/"
+       fi                                                                                      
+}
+
 create_dmraid_cpio(){
        # DMRAID
        if [ "${DMRAID}" = '1' ]
@@ -126,7 +164,7 @@ create_dmraid_cpio(){
                print_info 1 'DMRAID: Adding support (compiling binaries)...'
                compile_dmraid
                mkdir -p "${TEMP}/initramfs-dmraid-temp/"
-               tar -jxpf "${DMRAID_BINCACHE}" -C "${TEMP}/initramfs-dmraid-temp" ||
+               /bin/tar -jxpf "${DMRAID_BINCACHE}" -C "${TEMP}/initramfs-dmraid-temp" ||
                        gen_die "Could not extract dmraid binary cache!";
        cd "${TEMP}/initramfs-dmraid-temp/"
        find . -print | cpio --quiet -o -H newc | gzip -9 > ${CACHE_DIR}/cpio/initramfs-dmraid-${DMRAID_VER}.cpio.gz
@@ -152,7 +190,7 @@ create_lvm2_cpio(){
                else
                        print_info 1 '          LVM2: Adding support (compiling binaries)...'
                        compile_lvm2
-                       tar -jxpf "${LVM2_BINCACHE}" -C "${TEMP}/initramfs-lvm2-temp" ||
+                       /bin/tar -jxpf "${LVM2_BINCACHE}" -C "${TEMP}/initramfs-lvm2-temp" ||
                                gen_die "Could not extract lvm2 binary cache!";
                        mv ${TEMP}/initramfs-lvm2-temp/sbin/lvm.static ${TEMP}/initramfs-lvm2-temp/bin/lvm ||
                                gen_die 'LVM2 error: Could not move lvm.static to lvm!'
@@ -327,7 +365,7 @@ create_initramfs_aux() {
                echo 'MY_HWOPTS="${MY_HWOPTS} keymap"' >> ${TEMP}/initramfs-aux-temp/etc/initrd.defaults
        fi
        mkdir -p "${TEMP}/initramfs-aux-temp/lib/keymaps"
-       tar -C "${TEMP}/initramfs-aux-temp/lib/keymaps" -zxf "${GK_SHARE}/generic/keymaps.tar.gz"
+       /bin/tar -C "${TEMP}/initramfs-aux-temp/lib/keymaps" -zxf "${GK_SHARE}/generic/keymaps.tar.gz"
 
        cd ${TEMP}/initramfs-aux-temp/sbin && ln -s ../init init
        cd ${TEMP}
@@ -366,6 +404,14 @@ merge_initramfs_cpio_archives(){
        then
                MERGE_LIST="${MERGE_LIST} initramfs-udev-${UDEV_VER}.cpio.gz"
        fi
+       if [ "${UNIONFS}" -eq '1' -a -e ${CACHE_DIR}/cpio/initramfs-unionfs-${UNIONFS_VER}-tools.cpio.gz ]
+       then
+               MERGE_LIST="${MERGE_LIST} initramfs-unionfs-${UNIONFS_VER}-tools.cpio.gz"
+       fi
+       if [ "${UNIONFS}" -eq '1' -a -e ${CACHE_DIR}/cpio/initramfs-unionfs-${UNIONFS_VER}-modules-${KV}.cpio.gz ]
+       then
+               MERGE_LIST="${MERGE_LIST} initramfs-unionfs-${UNIONFS_VER}-modules-${KV}.cpio.gz"
+       fi
        if [ "${EVMS2}" -eq '1' -a -e "${CACHE_DIR}/cpio/initramfs-evms2.cpio.gz" ]
        then
                MERGE_LIST="${MERGE_LIST} initramfs-evms2.cpio.gz"
@@ -404,6 +450,10 @@ merge_initramfs_cpio_archives(){
        done
 
        cat ${MERGE_LIST} > ${TEMP}/initramfs-${KV}
+
+       [ "${KERNEL_MAKE_DIRECTIVE}" == 'zImage.initrd' ] ||
+               [ "${KERNEL_MAKE_DIRECTIVE_2}" == 'zImage.initrd' ] &&
+                       cp ${TEMP}/initramfs-${KV} ${KERNEL_DIR}/arch/${ARCH}/boot/images/ramdisk.image.gz
 }
 
 clear_cpio_dir(){
@@ -443,6 +493,18 @@ create_initramfs() {
            create_udev_cpio
        fi
        
+       if [ "${UNIONFS}" -eq '1' ]
+       then
+           print_info 1 "        >> Creating unionfs modules cpio archive..."
+           create_unionfs_modules_cpio
+       fi
+       
+       if [ "${UNIONFS}" -eq '1' ]
+       then
+           print_info 1 "        >> Creating unionfs tools cpio archive..."
+           create_unionfs_tools_cpio
+       fi
+
        if [ "${LVM2}" -eq '1' ]
        then
            
index 07002448f32fe8a9309164abdb9dc98edd29365c..458212e4fb9a46bc0a67126b7233180980e2327a 100644 (file)
@@ -91,16 +91,35 @@ create_base_initrd_sys() {
        # udev
        if [ "${UDEV}" -eq '1' ]
        then
-               tar -jxpf "${UDEV_BINCACHE}" -C "${TEMP}/initrd-temp" || gen_die 'Could not extract udev binary cache!'
+               /bin/tar -jxpf "${UDEV_BINCACHE}" -C "${TEMP}/initrd-temp" || gen_die 'Could not extract udev binary cache!'
                ln -sf "./udev" "${TEMP}/initrd-temp/bin/udevstart" ||  gen_die 'Could not symlink udev -> udevstart!'
        fi
+       
+       #unionfs modules
+       if [ "${UNIONFS}" -eq '1' ]
+       then
+               print_info 1 'UNIONFS MODULES: Adding support (compiling)...'
+               compile_unionfs_modules
+               /bin/tar -jxpf "${UNIONFS_MODULES_BINCACHE}" -C "${TEMP}/initrd-temp" ||
+                       gen_die "Could not extract unionfs modules binary cache!";
+       fi
+       
+       #unionfs utils
+       if [ "${UNIONFS}" -eq '1' ]
+       then
+               print_info 1 'UNIONFS TOOLS: Adding support (compiling)...'
+               compile_unionfs_utils
+               /bin/tar -jxpf "${UNIONFS_BINCACHE}" -C "${TEMP}/initrd-temp" ||
+                       gen_die "Could not extract unionfs tools binary cache!";
+       fi
+
 
        # DMRAID 
        if [ "${DMRAID}" = '1' ]
        then
                print_info 1 'DMRAID: Adding support (compiling binaries)...'
                compile_dmraid
-               tar -jxpf "${DMRAID_BINCACHE}" -C "${TEMP}/initrd-temp" ||
+               /bin/tar -jxpf "${DMRAID_BINCACHE}" -C "${TEMP}/initrd-temp" ||
                        gen_die "Could not extract dmraid binary cache!";
        fi
 
@@ -120,7 +139,7 @@ create_base_initrd_sys() {
                        print_info 1 'LVM2: Adding support (compiling binaries)...'
                        compile_lvm2
 
-                       tar -jxpf "${LVM2_BINCACHE}" -C "${TEMP}/initrd-temp" ||
+                       /bin/tar -jxpf "${LVM2_BINCACHE}" -C "${TEMP}/initrd-temp" ||
                                gen_die "Could not extract lvm2 binary cache!";
                        mv ${TEMP}/initrd-temp/bin/lvm.static ${TEMP}/initrd-temp/bin/lvm ||
                                gen_die 'LVM2 error: Could not move lvm.static to lvm!'
@@ -263,7 +282,7 @@ create_initrd_aux() {
                echo 'MY_HWOPTS="${MY_HWOPTS} keymap"' >> ${TEMP}/initrd-temp/etc/initrd.defaults
        fi
        mkdir -p "${TEMP}/initrd-temp/lib/keymaps"
-       tar -C "${TEMP}/initrd-temp/lib/keymaps" -zxf "${GK_SHARE}/generic/keymaps.tar.gz"
+       /bin/tar -C "${TEMP}/initrd-temp/lib/keymaps" -zxf "${GK_SHARE}/generic/keymaps.tar.gz"
 
        cd ${TEMP}/initrd-temp/sbin && ln -s ../linuxrc init
        cd ${OLDPWD}
index 16054a001fbee0a54362983fe4924b4735725af3..1fcf528d8c8c48644820ace3b94938ef83b96cc1 100644 (file)
@@ -7,8 +7,8 @@ gen_minkernpackage()
        mkdir "${TEMP}/minkernpackage" || gen_die 'Could not make a directory for the kernel package!'
        if [ "${CMD_KERNCACHE}" != "" ]
        then
-           tar -xj -C ${TEMP}/minkernpackage -f ${CMD_KERNCACHE} kernel-${ARCH}-${KV}
-           tar -xj -C ${TEMP}/minkernpackage -f ${CMD_KERNCACHE} config-${ARCH}-${KV}
+           /bin/tar -xj -C ${TEMP}/minkernpackage -f ${CMD_KERNCACHE} kernel-${ARCH}-${KV}
+           /bin/tar -xj -C ${TEMP}/minkernpackage -f ${CMD_KERNCACHE} config-${ARCH}-${KV}
        else
            cd "${KERNEL_DIR}"
            cp "${KERNEL_BINARY}" "${TEMP}/minkernpackage/kernel-${KV}" || gen_die 'Could not the copy kernel for the min kernel package!'
@@ -21,7 +21,7 @@ gen_minkernpackage()
                [ "${BUILD_INITRD}" -ne 0 ] && { cp "${TEMP}/initrd-${KV}" "${TEMP}/minkernpackage/initrd-${ARCH}-${KV}" || gen_die 'Could not copy the initrd for the kernel package!'; }
        fi
        cd "${TEMP}/minkernpackage" 
-       tar -jcpf ${MINKERNPACKAGE} * || gen_die 'Could not compress the kernel package!'
+       /bin/tar -jcpf ${MINKERNPACKAGE} * || gen_die 'Could not compress the kernel package!'
        cd "${TEMP}" && rm -rf "${TEMP}/minkernpackage" > /dev/null 2>&1
 }
 gen_modulespackage()
@@ -35,7 +35,7 @@ gen_modulespackage()
            mkdir -p ${TEMP}/modulespackage/lib/modules
            cp -r "${INSTALL_MOD_PATH}/lib/modules/${KV}" "${TEMP}/modulespackage/lib/modules"
            cd "${TEMP}/modulespackage" 
-           tar -jcpf ${MODULESPACKAGE} * || gen_die 'Could not compress the modules package!'
+           /bin/tar -jcpf ${MODULESPACKAGE} * || gen_die 'Could not compress the modules package!'
        else
            print_info 1 "Could not create a modules package ${INSTALL_MOD_PATH}/lib/modules/${KV} was not found"
        fi
@@ -64,7 +64,7 @@ gen_kerncache()
        fi
        
        cd "${TEMP}/kerncache" 
-       tar -jcpf ${KERNCACHE} * || gen_die 'Could not compress the kernel package!'
+       /bin/tar -jcpf ${KERNCACHE} * || gen_die 'Could not compress the kernel package!'
        cd "${TEMP}" && rm -rf "${TEMP}/kerncache" > /dev/null 2>&1
 }
 
@@ -74,7 +74,7 @@ gen_kerncache_extract_kernel()
        (umask 077 && mkdir ${tmp}) || {
            gen_die "Could not create temporary directory! Exiting."
        }
-               tar -f ${KERNCACHE} -C ${tmp} -xj 
+               /bin/tar -f ${KERNCACHE} -C ${tmp} -xj 
        cp "${tmp}/kernel-${ARCH}-${KV}" "/boot/kernel-${KNAME}-${ARCH}-${KV}" || {
                rm -r ${tmp}
                gen_die 'Could not copy the kernel binary to /boot!'
@@ -93,9 +93,9 @@ gen_kerncache_extract_modules()
                print_info 1 'Extracting kerncache kernel modules'
                if [ "${INSTALL_MOD_PATH}" != '' ]
                then
-                       tar xjf ${KERNCACHE} -C ${INSTALL_MOD_PATH} lib
+                       /bin/tar -xjf ${KERNCACHE} -C ${INSTALL_MOD_PATH} lib
                else
-                       tar xjf ${KERNCACHE} -C / lib
+                       /bin/tar -xjf ${KERNCACHE} -C / lib
                fi
        fi
 }
@@ -113,7 +113,7 @@ gen_kerncache_is_valid()
                    gen_die "Could not create temporary directory! Exiting."
                }
                
-               tar -xj -f ${KERNCACHE} -C ${tmp}
+               /bin/tar -xj -f ${KERNCACHE} -C ${tmp}
                if [ -e ${tmp}/config-${ARCH}-${KV} -a -e ${tmp}/kernel-${ARCH}-${KV} ] 
                then    
                        print_info 1 'Valid kernel cache found; no sources will be used'
@@ -129,7 +129,7 @@ gen_kerncache_is_valid()
                            
                        }
                
-                       tar -xj -f ${KERNCACHE} -C ${tmp}
+                       /bin/tar -xj -f ${KERNCACHE} -C ${tmp}
                        if [ -e ${tmp}/config-${ARCH}-${KV} -a -e /${KERNEL_DIR}/.config ]
                        then
        
index 18f5ec6d808d80aa326cb7132e27ecaef9cb74f1..302053e4906a8f0b0900e9decb9c0b85422e5c20 100644 (file)
@@ -1,6 +1,13 @@
 #!/bin/ash
 
 PATH=/usr/sbin:/usr/bin:/sbin:/bin
+
+# Default to the udev device manager
+USE_UDEV_NORMAL=1
+
+# Insert ctrl character
+# ctrl-V then esc will print ^[
+# ctrl-V then ctrl-shift-m will print ^M
 BACK_UP="\033[1K\033[0G"
 NORMAL="\033[0m"
 WARN="\033[33;1m"
@@ -8,17 +15,49 @@ BAD="\033[31;1m"
 BOLD="\033[1m"
 GOOD="\033[32;1m"
 
+
+# From KNOPPIX LINUXRC
+# Reset fb color mode
+RESET="\e]R"
+# ANSI COLORS
+# Erase to end of line
+CRE="
+\e[K"
+# Clear and reset Screen
+CLEAR="\ec"
+# Normal color
+NORMAL="\e[0;39m"
+# RED: Failure or error message
+RED="\e[1;31m"
+# GREEN: Success message
+GREEN="\e[1;32m"
+# YELLOW: Descriptions
+YELLOW="\e[1;33m"
+# BLUE: System mesages
+BLUE="\e[1;34m"
+# MAGENTA: Found devices or drivers
+MAGENTA="\e[1;35m"
+# CYAN: Questions
+CYAN="\e[1;36m"
+# BOLD WHITE: Hint
+WHITE="\e[1;37m"
+
+# Clear screen with colormode reset
+# echo "$CLEAR$RESET"
+# echo "$CLEAR"
+# Just go to the top of the screen
+# echo -n "\e[H\e[J"
+
 KV="`uname -r`"
 KMAJOR=`echo $KV | cut -f1 -d.`
 KMINOR=`echo $KV | cut -f2 -d.`
 KVER="${KMAJOR}.${KMINOR}"
 MISCOPTS='idebug detect'
 
-# Only sections that are in by default or those that
-# are not module groups need to be defined here...
-
-HWOPTS='usb firewire keymap cache lvm2 evms2 dmraid sata'
-MY_HWOPTS='usb firewire dmraid sata'
+if [ "${KMAJOR}" -eq 2 -a "${KMINOR}" -ge '6' ]
+then
+       KV_2_6_OR_GREATER="yes"
+fi
 
 QUIET=1
 ROOT_LINKS='bin sbin lib lib64 boot usr opt'
@@ -34,3 +73,9 @@ fi
 REAL_ROOT=''
 CDROOT=0
 CDROOT_DEV=''
+NEW_ROOT="/newroot"
+
+# Only sections that are in by default or those that
+# are not module groups need to be defined here...
+HWOPTS='usb firewire keymap cache evms2 sata lvm2 dmraid'
+MY_HWOPTS='usb firewire sata'
index 8497629614ab3528f26f378b7509ad290613a341..7369ebf88a6320fcb9469e25dc17b7f706baa326 100644 (file)
@@ -41,31 +41,82 @@ findcdmount() {
        then
                for x in $*
                do
-                       echo -e "${GOOD}>>${NORMAL} Attempting to mount CD:- ${x}"
-                       mount -r ${x} /newroot/mnt/cdrom > /dev/null 2>&1
-
-                       if [ "$?" = '0' ]
+                       # Check for a block device to mount
+                       if [ -b "${x}" ]
                        then
-                               # Check for a LiveCD
-                               if [ -e /newroot/mnt/cdrom/livecd ]
+                               good_msg "Attempting to mount CD:- ${x}"
+                               mount -r ${x} ${NEW_ROOT}/mnt/cdrom > /dev/null 2>&1
+
+                               if [ "$?" = '0' ]
                                then
-                                       REAL_ROOT="${x}"
-                                       break
-                               else
-                                       umount /newroot/mnt/cdrom
+                                       # Check for a LiveCD
+                                       if [ -e ${NEW_ROOT}/mnt/cdrom/livecd ]
+                                       then
+                                               REAL_ROOT="${x}"
+                                               break
+                                       else
+                                               umount ${NEW_ROOT}/mnt/cdrom
+                                       fi
                                fi
                        fi
                done
-               if [ "${REAL_ROOT}" != "" ]
+               if [ "${REAL_ROOT}" != '' ]
+               then
+                       good_msg "CD medium found on ${x}"
+               fi
+       fi
+}
+cache_cd_contents() {
+       # Check loop file exists and cache to ramdisk if DO_cache is enabled
+       if [ "${LOOPTYPE}" != 'noloop' ]
+       then
+               check_loop
+               if [ "${DO_cache}" ]
                then
-                       echo -e "${GOOD}>>${NORMAL} CD medium found on ${x}"
+                       good_msg "Copying loop file for caching..."
+                       cp -a ${NEW_ROOT}/mnt/cdrom/${LOOP} ${NEW_ROOT}/mnt/${LOOP}
+                       if [ $? -ne 0 ]
+                       then
+                               bad_msg "Failed to cache the loop file! Lack of space?"
+                               rm -rf ${NEW_ROOT}/mnt/livecd.* 2>/dev/null
+                               rm -rf ${NEW_ROOT}/mnt/zisofs 2>/dev/null
+                       else
+                               LOOPEXT='../'
+                       fi
                fi
        fi
 }
 
+mount_sysfs(){
+    if [ "${KV_2_6_OR_GREATER}" ]
+    then
+       # Udev is semi-broken on non /sys sysfs mount points.
+       mount -t sysfs /sys /sys >/dev/null 2>&1
+       ret=$?
+       
+       # sysfs mount failed .. udev wont work fall back to devfs if available
+       [ "$ret" -eq '0' ] || USE_UDEV_NORMAL=0
+    fi
+}
+
+# Insert a directory tree $2 to an union specified by $1
+# Top-level read-write branch is specified by it's index 0
+# $1 = union absolute path (starting with /)
+# $2 = path to data directory
+#
+union_insert_dir()
+{
+   /sbin/unionctl $1 --add --after 0 --mode ro $2
+   if [ $? = '0' ]
+   then
+       good_msg "Addition of $2 to $1 successful"
+   fi
+}
+
 findnfsmount() {
        if [ "${IP}" != '' ]; then
                if [ "${NFSROOT}" = '' ]; then
+                       # Obtain NFSIP  
                        OPTIONS=`busybox dmesg | grep rootserver | sed -e "s/,/ /g"`
                        for OPTION in $OPTIONS
                        do
@@ -73,7 +124,8 @@ findnfsmount() {
                                        NFSIP=`echo $OPTION | sed -e "s/=/ /g" | cut -d " " -f 2`;
                                fi 
                        done
-       
+                       
+                       # Obtain NFSPATH
                        OPTIONS=`busybox dmesg | grep rootpath | sed -e "s/,/ /g"`      
                        for OPTION in $OPTIONS
                        do
@@ -81,30 +133,33 @@ findnfsmount() {
                                        NFSPATH=`echo $OPTION | sed -e "s/=/ /g" | cut -d " " -f 2`;
                                fi 
                        done
-                       if [ "${NFSIP}" != "" ] && [ "$NFSPATH" != "" ]
+               
+                       # Setup NFSROOT
+                       if [ "${NFSIP}" != '' ] && [ "$NFSPATH" != '' ]
                        then
                                NFSROOT="${NFSIP}:${NFSPATH}"
                        else
-                               echo -e "${BAD}>>${NORMAL} The DHCP Server did not send a valid root-path."
-                               echo -e "${BAD}>>${NORMAL} Please check your DHCP setup, or provide a nfsroot=<...> parameter."
+                               bad_msg "The DHCP Server did not send a valid root-path."
+                               bad_msg "Please check your DHCP setup, or provide a nfsroot=<...> parameter."
                        fi
                fi
-               if [ "${NFSROOT}" != "" ]; then
+
+               if [ "${NFSROOT}" != '' ]; then
                        if [ "${CDROOT}" != '' ]; then
-                               echo -e "${GOOD}>>${NORMAL} Attempting to mount NFS CD image on ${NFSPATH}"
-                               mount -t nfs -o ro,nolock,rsize=1024,wsize=1024 ${NFSROOT} /newroot/mnt/cdrom
+                               good_msg "Attempting to mount NFS CD image on ${NFSPATH}"
+                               mount -t nfs -o ro,nolock,rsize=1024,wsize=1024 ${NFSROOT} ${NEW_ROOT}/mnt/cdrom
                                if [ "$?" = '0' ]; then
                                        REAL_ROOT="/dev/nfs"
                                else
-                                       echo -e "${BAD}>>${NORMAL} NFS Mounting failed. Is the path corrent ?"
+                                       bad_msg "NFS Mounting failed. Is the path corrent ?"
                                fi
                        else    
-                               echo -e "${GOOD}>>${NORMAL} Attemping to mount NFS root on ${NFSPATH}"
-                               mount -t nfs -o ro,nolock,rsize=1024,wsize=1024 ${NFSROOT} /newroot
+                               good_msg "Attemping to mount NFS root on ${NFSPATH}"
+                               mount -t nfs -o ro,nolock,rsize=1024,wsize=1024 ${NFSROOT} ${NEW_ROOT}
                                 if [ "$?" = '0' ]; then
                                        REAL_ROOT="/dev/nfs"
                                else
-                                       echo -e "${BAD}>>${NORMAL} NFS Mounting failed. Is the path correct ?"
+                                       bad_msg "NFS Mounting failed. Is the path correct ?"
                                fi
                                # FIXME: Need to start portmap and the other rpc daemons in order to
                                # FIXME: remount rw.
@@ -118,6 +173,22 @@ kill_devfsd() {
        killall devfsd > /dev/null 2>&1
 }
 
+check_loop() {
+    if [ "${LOOP}" = '' -o ! -e "mnt/cdrom/${LOOP}" ]
+    then
+       
+       bad_msg "Invalid loop location: ${LOOP}"
+       bad_msg 'Please export LOOP with a valid location, or reboot and pass a proper loop=...'
+       bad_msg 'kernel command line!'
+       
+       run_shell
+    fi
+}
+
+run_shell() {
+       /bin/ash
+}
+
 runUdev() {
        mount -t tmpfs -o size=100k udev /dev
        mkdir /dev/pts
@@ -129,3 +200,330 @@ runUdev() {
        ln -snf /proc/self/fd/2 /dev/stderr
        ln -snf /proc/kcore /dev/core
 }
+
+test_success() {
+       error_string=$1
+       error_string="${error_string:-run command}"
+       # If last command failed send error message and fall back to a shell    
+       if [ "$?" != '0' ]
+       then
+               bad_msg 'Failed to $1; failing back to the shell...'
+               run_shell
+       fi
+}
+
+good_msg() {
+       msg_string=$1
+       msg_string="${msg_string:-...}"
+       echo -e "${GOOD}>>${NORMAL}${BOLD} ${msg_string} ${NORMAL}"
+}
+
+bad_msg() {
+       msg_string=$1
+       msg_string="${msg_string:-...}"
+       echo -e "${BAD}!! ${NORMAL}${BOLD} ${msg_string} ${NORMAL}"
+} 
+
+warn_msg() {
+       msg_string=$1
+       msg_string="${msg_string:-...}"
+       echo -e "${WARN}** ${NORMAL}${BOLD} ${msg_string} ${NORMAL}"
+} 
+
+bind_mount_dev() {
+       # bind-mount /dev/ so that loop devices can be found
+       mount -o bind ${NEW_ROOT}/dev /dev
+}
+
+start_dev_mgr(){
+    # Check udev is available...
+    if [ "${KV_2_6_OR_GREATER}" -a ! "${USE_UDEV_NORMAL}" -eq '0' -a -x /sbin/udev ]
+    then
+       USE_UDEV_NORMAL=1
+    else
+       USE_UDEV_NORMAL=0
+    fi
+
+    if [ "${USE_UDEV_NORMAL}" -eq '1' ]
+    then
+       cd /sys
+       kill_devfsd
+       good_msg 'Activating udev'
+       runUdev
+    else
+       if [ ! -e /dev/.devfsd ]
+       then
+           good_msg 'Activating devfs'
+           mount -t devfs devfs /dev
+           devfsd /dev -np
+       fi
+    fi
+}
+
+bootstrapCD() {
+    # Locate the cdrom device with our media on it.
+    [ -n "${CDROOT_DEV}" ] && DEVICES="$DEVICES ${CDROOT_DEV}" # Device specified on the command line
+    DEVICES="$DEVICES /dev/cdroms/*" # CDROM DEVICES
+    DEVICES="$DEVICES /dev/ide/cd/*" # CDROM DEVICES
+    DEVICES="$DEVICES /dev/sr*" # UML DEVICES
+    DEVICES="$DEVICES /dev/sd*" # USB Keychain
+    DEVICES="$DEVICES /dev/hd*" # IDE devices
+    DEVICES="$DEVICES /dev/ubd* /dev/ubd/*" # UML DEVICES
+       
+    findcdmount $DEVICES
+}
+
+cmdline_hwopts() {
+    # Scan CMDLINE for any "doscsi" or "noscsi"-type arguments
+    
+    local FOUND
+    local TMP_HWOPTS
+
+    for x in $HWOPTS
+    do
+       for y in $CMDLINE
+       do
+           if [ "${y}" = "do${x}" ]
+           then
+               MY_HWOPTS="${MY_HWOPTS} $x"
+           elif [ "${y}" = "no${x}" ]
+           then
+               MY_HWOPTS="`echo ${MY_HWOPTS} | sed -e \"s/${x}//g\" -`"
+           fi
+       done
+    done
+    
+    MY_HWOPTS=$(echo ${MY_HWOPTS} | sort)
+    
+    for x in ${MY_HWOPTS}
+    do
+       FOUND=0
+       for y in ${TMP_HWOPTS}
+       do
+               if [ "${y}" = "${x}" ]
+               then 
+                       FOUND=1
+               fi
+       done
+       if [ ! "${FOUND}" = '1' ]
+       then
+               TMP_HWOPTS="${TMP_HWOPTS} ${x}"
+       fi
+    done
+
+    MY_HWOPTS=${TMP_HWOPTS}
+}
+
+load_modules() {
+    # Load modules listed in MY_HWOPTS if /lib/modules exists
+    
+    if [ -d '/lib/modules' ]
+    then
+       good_msg 'Loading modules'
+       # Load appropriate kernel modules
+       for modules in $MY_HWOPTS
+       do
+           modules_scan $modules
+           eval DO_`echo $modules | sed 's/-//'`=1
+       done
+    else
+       good_msg 'Skipping module load; no modules in the initrd!'
+    fi
+}
+
+detect_sbp2_devices() {
+    # http://www.linux1394.org/sbp2.php
+    
+    # /proc
+    # /proc/scsi/sbp2/0, /proc/scsi/sbp2/1, etc.
+    #
+    # You may manually add/remove SBP-2 devices via the procfs with add-single-device <h> <b> <t> <l> or remove-single-device <h> <b> <t> <l>, where:
+    #
+    #
+    # <h> = host (starting at zero for first SCSI adapter)
+    # <b> = bus (normally zero)
+    # <t> = target (starting at zero for first SBP-2 device)
+    # <l> - lun (normally zero) 
+    # e.g. To manually add/detect a new SBP-2 device
+    #   echo "scsi add-single-device 0 0 0 0" > /proc/scsi/scsi
+    #   e.g. To manually remove a SBP-2 device after it's been unplugged
+    #     echo "scsi remove-single-device 0 0 0 0" > /proc/scsi/scsi
+    #     e.g. To check to see which SBP-2/SCSI devices are currently registered
+    #       cat /proc/scsi/scsi 
+    
+    [ -e /proc/scsi/scsi ] && echo 'scsi add-single-device 0 0 0 0' > /proc/scsi/scsi
+}
+
+setup_keymap() {
+       if [ "${DO_keymap}" ]
+       then
+               if [ ! -e /dev/vc/0 ]
+               then
+                       DEVBIND=1
+                       mount -o bind ${NEW_ROOT}/dev /dev
+               fi
+       
+               chooseKeymap
+
+               [ "${DEVBIND}" -eq '1' ] && umount /dev
+               
+               if [ -e /etc/sysconfig/keyboard -a "${CDROOT}" -eq '1' ]
+               then
+                       mkdir -p ${NEW_ROOT}/etc/sysconfig/
+                       cp /etc/sysconfig/keyboard ${NEW_ROOT}/etc/sysconfig/keyboard
+               fi
+       fi
+}
+chooseKeymap() {
+    good_msg "Loading keymaps"
+    cat /lib/keymaps/keymapList
+    read -t 10 -p '<< Load keymap (Enter for default): ' keymap
+    if [ -e /lib/keymaps/${keymap}.map ]
+    then
+       good_msg "Loading the ''${keymap}'' keymap"
+       loadkmap < /lib/keymaps/${keymap}.map
+       xkeymap=${keymap}
+       echo ${keymap} | egrep -e "[0-9]+" >/dev/null 2>&1
+       if [ "$?" -eq '0'  ]; then
+           xkeymap=`tail -n 7 /lib/keymaps/keymapList | grep ${keymap} | sed -r "s/.*\s+${keymap}\s+([a-z-]+).*/\1/g" | egrep -v 1`
+       fi
+       mkdir -p /etc/sysconfig
+       echo "XKEYBOARD=${xkeymap}" > /etc/sysconfig/keyboard
+    elif [ "$keymap" = '' ]
+    then
+       echo
+       good_msg "Keeping default keymap"
+    else
+       bad_msg "Sorry, but keymap ''${keymap}'' is invalid!"
+       chooseKeymap
+    fi
+}
+
+startVolumes() {
+    good_msg 'Checking if volumes need to be started...'
+    
+    if [ "${USE_DMRAID_NORMAL}" -eq '1' ]
+    then
+       if [ -e '/sbin/dmraid' ]
+       then
+       
+           good_msg "Activating Device-Mapper RAID(s)"
+           /sbin/dmraid -ay
+       fi
+    fi
+
+    if [ "${USE_LVM2_NORMAL}" -eq '1' ]
+    then
+       if [ -e '/bin/vgscan' -a -e '/bin/vgchange' ]
+       then
+           good_msg "Scanning for Volume Groups"
+           /bin/vgscan --ignorelockingfailure --mknodes
+           good_msg "Activating Volume Groups"
+           /bin/vgchange -ay --ignorelockingfailure
+
+           # Disable EVMS since lvm2 is activated and they dont work together.
+           if [ "${USE_EVMS_NORMAL}" -eq '1' ]
+           then
+              bad_msg "Disabling EVMS Support because LVM2 started"
+              bad_msg "Do not add dolvm2 to the cmdline if this is not what you want"
+              bad_msg "LVM2 and EVMS do not work well together"
+              USE_EVMS_NORMAL=0
+           fi
+       
+       else
+           bad_msg "vgscan or vgchange not found: skipping LVM2 volume group activation!"
+       fi
+
+    fi
+
+    if [ "${USE_EVMS_NORMAL}" -eq '1' ]
+    then
+       if [ -e '/sbin/evms_activate' ]
+       then
+           good_msg "Activating EVMS"
+           evms_activate
+       fi
+    fi
+}
+
+sdelay() {
+       # Sleep a specific number of seconds if SDELAY is set otherwise only 1 second
+       if [ -n "${SDELAY}" ]; then
+               sleep ${SDELAY}
+       else
+               sleep 1
+       fi
+}
+
+quiet_kmsg() {
+    # if QUIET is set make the kernel less chatty
+    [ -n "$QUIET" ] && echo '0' > /proc/sys/kernel/printk
+}
+
+verbose_kmsg() {
+    # if QUIET is set make the kernel less chatty
+    [ -n "$QUIET" ] && echo '6' > /proc/sys/kernel/printk
+}
+
+
+cdupdate() {
+    if [ -x /${NEW_ROOT}/mnt/cdrom/cdupdate.sh ]
+    then
+       ${NEW_ROOT}/mnt/cdrom/cdupdate.sh
+       if [ "$?" != '0' ]
+       then
+           bad_msg "FAILED TO EXECUTE cdupdate.sh"
+           run_shell
+       fi
+    fi
+}
+
+rundebugshell(){
+    if [ -n "$DEBUG" ]; then
+       good_msg 'Starting debug shell as requested by "debug" option.'
+       good_msg 'Type "exit" to continue with normal bootup.'
+       [ -x /bin/sh ] && /bin/sh || /bin/ash
+    fi
+}
+
+setup_unionfs(){
+       if [ "${USE_UNIONFS_NORMAL}" -eq '1' -a "${CDROOT}" -eq '1' ]
+       then
+               # Directory used for rw changes in union mount filesystem
+               UNION=/union
+               MEMORY=/memory
+               CHANGES=$MEMORY/changes
+               
+               mkdir -p ${MEMORY}
+               mkdir -p ${UNION}
+               good_msg "Loading unionfs module"
+               modprobe unionfs > /dev/null 2>&1
+               if [ -n "${UNIONFS}" ]
+               then
+                       CHANGESDEV=${UNIONFS}
+                       good_msg "mounting $CHANGESDEV to $MEMORY for unionfs support"
+                       mount -t auto $CHANGESDEV $MEMORY
+                       # mount tmpfs only in the case when changes= boot parameter was empty
+                       # or we were not able to mount the storage device
+                       ret=$?
+                       if [ "${ret}" -ne 0 ]
+                       then
+                               bad_msg "mount of $CHANGESDEV failed falling back to ramdisk based unionfs"
+                               mount -t tmpfs tmpfs $MEMORY
+                       fi
+               else 
+                       good_msg "Mounting ramdisk to $MEMORY for unionfs support..."
+                       mount -t tmpfs tmpfs $MEMORY 
+               fi 
+               
+               mkdir -p $CHANGES 
+               mount -t unionfs -o dirs=$CHANGES=rw unionfs ${UNION}
+               ret=$?
+               if [ "${ret}" -ne 0 ]
+               then 
+                       die "Can't setup union ${UNION} in  directory!"
+               fi
+       else
+               USE_UNIONFS_NORMAL=0
+       fi
+}
index 41bce6bfa2854a66893f6da5c6cd8c6814fc2a06..a31f058a214339d6d3c5778747d2961d50eb8f3e 100644 (file)
@@ -6,11 +6,8 @@
 . /etc/initrd.defaults
 . /etc/initrd.scripts
 
-USE_DEVFS_NORMAL=1
-USE_UDEV_NORMAL=2
-USE_EVMS_NORMAL=1
-USE_LVM2_NORMAL=1
-USE_DMRAID_NORMAL=1
+# Clean input/output
+exec >/dev/console </dev/console 2>&1
 
 if [ "$$" != '1' ]
 then
@@ -23,256 +20,186 @@ fi
 mount -o remount,rw /
 mount -t proc proc /proc
 
+# Set up symlinks
 if [ "$0" = '/init' ]
 then
-       /bin/busybox --install -s
-       rm /linuxrc
-       if [ -e /sbin/udev ]
-       then
-               ln -s /sbin/udev /sbin/udevstart
-       fi
-       
-       if [ -e /bin/lvm ]
-       then
-               ln -s /bin/lvm /bin/vgscan
-               ln -s /bin/lvm /bin/vgchange
-       fi
+    /bin/busybox --install -s
+
+    [ -e /linuxrc ] && rm /linuxrc
+    [ -e /sbin/udev ] && ln -s /sbin/udev /sbin/udevstart
+
+    if [ -e /bin/lvm ]
+    then
+       ln -s /bin/lvm /bin/vgscan
+       ln -s /bin/lvm /bin/vgchange
+    fi
 fi
-[ -n "$QUIET" ] && echo '0' > /proc/sys/kernel/printk
 
-CMDLINE=`cat /proc/cmdline`
+quiet_kmsg
+
+CMDLINE="$(cat /proc/cmdline)"
 # Scan CMDLINE for any specified real_root= or cdroot arguments
 for x in ${CMDLINE}
 do
-       case "${x}" in
-               real_root\=*)
-                       REAL_ROOT=`parse_opt "${x}"`
-               ;;
-               cdroot)
-                       CDROOT=1
-                       REAL_ROOT=''
-               ;;
-               cdroot\=*)
-                       CDROOT=1
-                       CDROOT_DEV=`parse_opt "${x}"`
-                       REAL_ROOT=''
-               ;;
-               devfs)
-                       USE_DEVFS_NORMAL=1
-                       USE_UDEV_NORMAL=0
-               ;;
-               nodevfs)
-                       USE_DEVFS_NORMAL=0
-               ;;
-               nolvm2)
-                       USE_LVM2_NORMAL=0
-               ;;
-               nodmraid)
-                       USE_DMRAID_NORMAL=0
-               ;;
-               noevms)
-                       USE_EVMS_NORMAL=0
-               ;;
-               udev)
-                       USE_UDEV_NORMAL=1
-                       USE_DEVFS_NORMAL=0
-               ;;
-               noudev)
-                       USE_UDEV_NORMAL=0
-               ;;
-               loop\=*)
-                       LOOP=`parse_opt "${x}"`
-               ;;
-               looptype\=*)
-                       LOOPTYPE=`parse_opt "${x}"`
-               ;;
-               real_init\=*)
-                       REAL_INIT=`parse_opt "${x}"`
-               ;;
-               scandelay=\*)
-                       SDELAY=`parse_opt "${x}"`
-               ;;
-               scandelay)
-                       SDELAY=10
-               ;;
-               noload\=*)
-                       MLIST=`parse_opt "${x}"`
-                       MLIST="`echo ${MLIST} | sed -e \"s/,/ /\"`"
-                       export MLIST
-               ;;       
-               ip\=*)
-                       IP=`parse_opt "${x}"`
-                       if [ "${REAL_ROOT}" = '' ]; then
-                               CDROOT=1
-                               NFSLIVECD=1
-                       fi
-               ;;
-               nfsroot\=*)
-                       NFSROOT=`parse_opt "${x}"`
-               ;;
-       esac
+  case "${x}" in
+      real_root\=*)
+         REAL_ROOT=`parse_opt "${x}"`
+         ;;
+      real_init\=*)
+         REAL_INIT=`parse_opt "${x}"`
+         ;;
+           
+      # Livecd options
+      cdroot)
+         CDROOT=1
+         REAL_ROOT=''
+         ;;
+      cdroot\=*)
+         CDROOT=1
+         CDROOT_DEV=`parse_opt "${x}"`
+         REAL_ROOT=''
+         ;;
+
+      # Start livecd loop and looptype options
+      loop\=*)
+         LOOP=`parse_opt "${x}"`
+         ;;
+      looptype\=*)
+         LOOPTYPE=`parse_opt "${x}"`
+         ;;
+
+      # Start Device Manager options 
+      devfs)
+         USE_DEVFS_NORMAL=1
+         USE_UDEV_NORMAL=0
+         ;;
+      udev)
+         USE_DEVFS_NORMAL=0
+         USE_UDEV_NORMAL=1
+         ;;
+      unionfs)
+         if [ ! -x /sbin/unionctl ]
+         then
+             USE_UNIONFS_NORMAL=0
+             bad_msg 'Unionctl not found: aborting use of unionfs!'
+         else
+             USE_UNIONFS_NORMAL=1
+         fi
+         ;;
+      unionfs\=*)
+         if [ ! -x /sbin/unionctl ]
+         then
+             USE_UNIONFS_NORMAL=0
+             bad_msg 'Unionctl not found: aborting use of unionfs!'
+         else
+             USE_UNIONFS_NORMAL=1
+             UNIONFS=`parse_opt "${x}"`
+         fi
+         ;;
+
+      # Start Volume manager options 
+      dolvm2)
+         USE_LVM2_NORMAL=1
+         ;;
+      dodmraid)
+         USE_DMRAID_NORMAL=1
+         ;;
+      doevms)
+         USE_EVMS_NORMAL=1
+         ;;
+           # Start Debug Option
+      debug)
+         DEBUG='yes'
+         ;;
+
+      # Scandelay options 
+      scandelay\=*)
+         SDELAY=`parse_opt "${x}"`
+         ;;
+      scandelay)
+         SDELAY=10
+         ;;
+
+      # Module no-loads
+      noload\=*)
+         MLIST=`parse_opt "${x}"`
+         MLIST="`echo ${MLIST} | sed -e \"s/,/ /\"`"
+         export MLIST
+         ;;
+  esac
 done
 
-[ -e /proc/scsi/scsi ] && echo 'scsi add-single-device 0 0 0 0' > /proc/scsi/scsi
-
-# Scan CMDLINE for any "doscsi" or "noscsi"-type arguments
-for x in $HWOPTS
-do
-       for y in $CMDLINE
-       do
-               if [ "${y}" = "do${x}" ]
-               then
-                       MY_HWOPTS="${MY_HWOPTS} $x"
-               elif [ "${y}" = "no${x}" ]
-               then
-                       MY_HWOPTS="`echo ${MY_HWOPTS} | sed -e \"s/${x}//g\" -`"
-               fi
-       done
-done
+detect_sbp2_devices
+cmdline_hwopts
 
+# Load modules listed in MY_HWOPTS if /lib/modules exists
+    
 if [ -d '/lib/modules' ]
 then
-       echo -e "${GOOD}>>${NORMAL}${BOLD} Loading modules...${NORMAL}"
-       # Load appropriate kernel modules
-       for modules in $MY_HWOPTS
-       do
-               modules_scan $modules
-               eval DO_`echo $modules | sed 's/-//'`=1
-       done
+    good_msg 'Loading modules'
+    # Load appropriate kernel modules
+    for modules in $MY_HWOPTS
+    do
+      modules_scan $modules
+      eval DO_`echo $modules | sed 's/-//'`=1
+    done
 else
-       echo -e "${GREEN}>>${NORMAL}${BOLD} Skipping module load; no modules in the initrd!${NORMAL}"
+    good_msg 'Skipping module load; no modules in the initrd!'
 fi
 
-chooseKeymap() {
-       echo -e "${GOOD}>>${NORMAL}${BOLD} Loading keymaps...${NORMAL}"
-       cat /lib/keymaps/keymapList
-       read -t 10 -p '<< Load keymap (Enter for default): ' keymap
-       if [ -e /lib/keymaps/${keymap}.map ]
-       then
-               echo -e "${GOOD}>>${NORMAL}${BOLD} Loading the ''${keymap}'' keymap...${NORMAL}"
-               loadkmap < /lib/keymaps/${keymap}.map
-               xkeymap=${keymap}
-               echo ${keymap} | egrep -e "[0-9]+" >/dev/null 2>&1
-               if [ "$?" -eq '0'  ]; then
-                       xkeymap=`tail -n 7 /lib/keymaps/keymapList | grep ${keymap} | sed -r "s/.*\s+${keymap}\s+([a-z-]+).*/\1/g" | egrep -v 1`
-               fi
-               mkdir -p /etc/sysconfig
-               echo "XKEYBOARD=${xkeymap}" > /etc/sysconfig/keyboard
-       elif [ "$keymap" = '' ]
-       then
-               echo -e "${GOOD}>>${NORMAL}${BOLD} Keeping default keymap...${NORMAL}"
-       else
-               echo -e "${BAD}!! ${NORMAL}${BOLD}Sorry, but keymap ''${keymap}'' is invalid!${NORMAL}"
-               chooseKeymap
-       fi
-}
+# Mount sysfs
+mount_sysfs
 
-startVolumes() {
-       if [ "${DO_dmraid}" -a "${USE_DMRAID_NORMAL}" -eq '1' ]
-       then
-               if [ -e '/sbin/dmraid' ]
-               then
-                       echo -e "${GOOD}>>${NORMAL}${BOLD} Activating Device-Mapper raid(s)...${NORMAL}"
-                       /sbin/dmraid -ay
-                       [ "${USE_UDEV_NORMAL}" -eq '1' ] && /sbin/dmsetup mknodes
-               fi
-       fi
+# Start udev/devfs
+start_dev_mgr
 
-       if [ "${DO_lvm2}" -a "${USE_LVM2_NORMAL}" -eq '1' ]
-       then
-               if [ -e '/bin/vgscan' -a -e '/bin/vgchange' ]
-               then
-                       echo -e "${GOOD}>>${NORMAL}${BOLD} Scanning for Volume Groups...${NORMAL}"
-                       /bin/vgscan --ignorelockingfailure --mknodes
-                       echo -e "${GOOD}>>${NORMAL}${BOLD} Activating Volume Groups...${NORMAL}"
-                       /bin/vgchange -ay --ignorelockingfailure
-               fi
-       fi
+# Start EVMS
+startVolumes
 
-       if [ "${DO_evms2}" -a "${USE_EVMS_NORMAL}" -eq '1' ]
-       then
-               if [ -e '/sbin/evms_activate' ]
-               then
-                       echo -e "${GOOD}>>${NORMAL}${BOLD} Activating EVMS...${NORMAL}"
-                       evms_activate
-               fi
-       fi
-}
-
-echo -e "${GOOD}>>${NORMAL}${BOLD} Mounting filesystems${NORMAL}"
+# Set up unionfs
+mkdir -p ${NEW_ROOT}
+setup_unionfs
 
-# Check udev is on...
-[ "${KMAJOR}" -eq 2 -a "${KMINOR}" -ge '6' -a ! "${USE_UDEV_NORMAL}" -eq '0' ] && USE_UDEV_NORMAL=1
-[ "${USE_UDEV_NORMAL}" -eq '1' -a ! -x /sbin/udev ] && USE_UDEV_NORMAL=0
-
-# If using 2.4 and udev; back off...
-[ "${KMAJOR}" -eq 2 -a "${KMINOR}" -lt '6' -a "${USE_UDEV_NORMAL}" -eq 1 ] &&
-       USE_UDEV_NORMAL=0
+if [ "${USE_UNIONFS_NORMAL}" -eq '1' ]
+then
+       CHROOT=${UNION}
+else
+       CHROOT=${NEW_ROOT}
+fi
 
-# Disable devfs if we want udev...
-[ -e /dev/.devfsd -a "${USE_UDEV_NORMAL}" -eq 1 ] && echo '>> Enabling devfsd in favour of udev; use "nodevfs" if this is not intended...' && USE_UDEV_NORMAL=0
+# Run debug shell if requested
+rundebugshell
 
-mkdir /newroot
 if [ "${CDROOT}" -eq '1' ]
 then
-       mount -t tmpfs tmpfs /newroot
-       mkdir /newroot/dev /newroot/mnt /newroot/mnt/cdrom /newroot/mnt/livecd /newroot/tmp /newroot/tmp/.initrd /newroot/mnt/gentoo /newroot/sys
-       if [ "${USE_UDEV_NORMAL}" -eq '1' ]
-       then
-               # Udev is semi-broken on non /sys sysfs mount points.
-               mount -t sysfs none /sys
-               [ "$?" -eq '0' ] || USE_UDEV_NORMAL=0
-       fi
-
-       if [ "${USE_UDEV_NORMAL}" -eq '1' ]
+       if [ ! "${USE_UNIONFS_NORMAL}" -eq '1' ]
        then
-               cd /sys
-               kill_devfsd
-               echo -e "${GOOD}>>${NORMAL}${BOLD} Activating udev...${NORMAL}"
-               runUdev
-               startVolumes
-               mv /dev/* /newroot/dev
-               cd /
-       else
-               if [ ! -e /newroot/dev/.devfsd ]
-               then
-                       mount -t devfs devfs /newroot/dev
-                       devfsd /newroot/dev -np
-               fi
+               good_msg "Making tmpfs for ${NEW_ROOT}"
+               mount -t tmpfs tmpfs ${NEW_ROOT}
        fi
        
-       if [ -n "${SDELAY}" ]; then
-               sleep ${SDELAY}
-       else
-               sleep 1
-       fi
-
-bootstrapCD() {
-       if [ "${CDROOT_DEV}" = '' ]
-       then
-               findcdmount /newroot/dev/cdroms/*
-
-               # Not in /dev/cdroms: try /dev/ide/cd
-               [ "${REAL_ROOT}" = '' ] && findcdmount /newroot/dev/ide/cd/*
-               [ "${REAL_ROOT}" = '' ] && findcdmount /newroot/dev/sr0
-               [ "${REAL_ROOT}" = '' ] && findcdmount /newroot/dev/sd* # USB Keychain
-               [ "${REAL_ROOT}" = '' ] && [ "{NFSLIVECD}" != '' ] && findnfsmount # NFS
-       else
-               # Device specified on command line
-               findcdmount /newroot/${CDROOT_DEV}
-       fi
-}
+       for i in dev mnt mnt/cdrom mnt/livecd tmp tmp/.initrd mnt/gentoo sys
+       do
+               mkdir  ${NEW_ROOT}/$i
+               chown 755  ${NEW_ROOT}/$i
+       done
+       cp /dev/null ${NEW_ROOT}/dev
+       cp /dev/console ${NEW_ROOT}/dev
+       sdelay
 
        bootstrapCD
+       
        if [ "${REAL_ROOT}" = '' ]
        then
                echo -n -e "${WARN}>>${NORMAL}${BOLD} No bootable medium found. Waiting for new devices"
-               sleep 3
-               echo -n '.'
-               sleep 3
-               echo -n '.'
-               sleep 3
-               echo -n '.'
+               
+               COUNTER=0
+               while [ $COUNTER -lt 3 ]; do
+                       sleep 3
+                       echo -n '.'
+                       let COUNTER=$COUNTER+1
+               done    
+               
                sleep 1
                echo -e "${NORMAL}"
                bootstrapCD
@@ -281,142 +208,106 @@ bootstrapCD() {
        if [ "${REAL_ROOT}" = '' ]
        then
                # Undo stuff
-               umount /newroot/dev 2>/dev/null
-               umount /newroot/sys 2>/dev/null
+               umount  ${NEW_ROOT}/dev 2>/dev/null
+               umount  ${NEW_ROOT}/sys 2>/dev/null
                umount /sys 2>/dev/null
 
-               umount /newroot
-               rm -rf /newroot/*
+               umount  ${NEW_ROOT}
+               rm -rf  ${NEW_ROOT}/*
 
-               echo 'Could not find CD to boot, something else needed!'
+               bad_msg 'Could not find CD to boot, something else needed!'
                CDROOT=0
        fi
 fi
 
-if [ "${DO_keymap}" ]
-then
-       if [ ! -e /dev/vc/0 ]
-       then
-               DEVBIND=1
-               mount -o bind /newroot/dev /dev
-       fi
-       chooseKeymap
-       [ "${DEVBIND}" -eq '1' ] && umount /dev
-       
-       if [ -e /etc/sysconfig/keyboard -a "${CDROOT}" -eq '1' ]
-       then
-           mkdir -p /newroot/etc/sysconfig/
-           cp /etc/sysconfig/keyboard /newroot/etc/sysconfig/keyboard
-       fi
-fi
-
-# FIX: indent me in one $CDROOT -eq '0'
-
-# Try to mount sysfs, and if it fails, do not use udev
-if [ "${USE_UDEV_NORMAL}" -eq '1' -a "${CDROOT}" -eq '0' ]
-then
-       mount -t sysfs none /sys
-       [ "$?" -eq '0' ] || USE_UDEV_NORMAL=0
-fi
-
-# Don't merge these two blocks; ^^ USE_UDEV_NORMAL=0...
-if [ "${USE_UDEV_NORMAL}" -eq '1' -a "${CDROOT}" -eq '0' ]
-then
-       USE_DEVFS_NORMAL=0
-       cd /sys
-       echo -e "${GOOD}>>${NORMAL}${BOLD} Activating udev...${NORMAL}"
-       runUdev
-       cd /
-elif [ "${CDROOT}" -eq '0' -a "${USE_DEVFS_NORMAL}" -eq '1' ]
-then
-       [ ! -e /dev/.devfsd ] && mount -t devfs devfs /dev
-       devfsd /dev -np
-fi
-
-[ "${CDROOT}" -eq '0' ] && startVolumes
-
-echo -e "${GOOD}>>${NORMAL}${BOLD} Determining root device...${NORMAL}"
+setup_keymap
 
+# Determine root device
+good_msg 'Determining root device...'
 while true
 do
        while [ "${got_good_root}" != '1' ]
        do
+               
                if [ "${REAL_ROOT}" = 'shell' ]
                then
-                       /bin/ash
+                       run_shell
 
                        REAL_ROOT=''
                        got_good_root=0
                        continue
+               
                elif [ "${REAL_ROOT}" = '' ]
                then
                        # No REAL_ROOT determined/specified. Prompt user for root block device.
-                       echo -e "${BAD}>>${NORMAL} The root block device is unspecified or not detected."
+                       bad_msg "The root block device is unspecified or not detected."
                        echo '   Please specify a device to boot, or "shell" for a shell...'
                        echo -n 'boot() :: '
                        read REAL_ROOT
                        got_good_root=0
+
+               # Check for a block device or /dev/nfs
                elif [ -b "${REAL_ROOT}" ] || [ "${REAL_ROOT}" = "/dev/nfs" ]
                then
                        got_good_root=1
                else
-                       echo -e "${BAD}>>${NORMAL} Block device ${REAL_ROOT} is not a valid root device..."
+                       bad_msg "Block device ${REAL_ROOT} is not a valid root device..."
                        REAL_ROOT=""
                        got_good_root=0
                fi
        done
 
+
        if [ "${CDROOT}" -eq '1' -a "${got_good_root}" = '1' ]
        then
+               # cdrom device already mounted no further checks necessary
                break
        else
-               echo -e "${GOOD}>>${NORMAL}${BOLD} Mounting root...${NORMAL}"
+               good_msg "Mounting root..."
+
+               # Try to mount the device as  ${NEW_ROOT}
                if [ "${REAL_ROOT}" = '/dev/nfs' ]; then
                        findnfsmount
                else
-                       mount -o rw ${REAL_ROOT} /newroot
+                       mount -o rw ${REAL_ROOT}  ${NEW_ROOT}
                fi
+               
+               # If mount is successful break out of the loop 
+               # else not a good root and start over.
 
                if [ "$?" = '0' ]
                then
                        break
                else
-                       echo -e "${BAD}>> ${NORMAL}Could not mount specified ROOT, try again"
+                       bad_msg "Could not mount specified ROOT, try again"
                        got_good_root=0
                        REAL_ROOT=''
                fi
        fi
 done
+# End determine root device
 
-[ -n "$QUIET" ] && echo '6' > /proc/sys/kernel/printk
-check_loop() {
-       if [ "${LOOP}" = '' -o ! -e "mnt/cdrom/${LOOP}" ]
-       then
-               echo "Invalid loop location: ${LOOP}"
-               echo 'Please export LOOP with a valid location, or reboot and pass a proper loop=...'
-               echo 'kernel command line!'
-               /bin/ash
-       fi
-}
+verbose_kmsg
 
+# If cdroot is set determine the looptype to boot
 if [ "${CDROOT}" = '1' ]
 then
-       echo -e "${GOOD}>>${NORMAL}${BOLD} Filling tmpfs...${NORMAL}"
-       cd /newroot
+       good_msg 'Determining looptype ...'
+       cd ${NEW_ROOT}
 
        # Find loop and looptype if we have NFS-mounted a livecd
-       if  [ "${LOOP}" = '' ] && [ "${REAL_ROOT}" = "/dev/nfs" ]
+       if  [ "${LOOP}" = '' ] && [ "${REAL_ROOT}" = '/dev/nfs' ]
        then
-               if [ -e '/newroot/mnt/cdrom/livecd.loop' ]; then
+               if [ -e "${NEW_ROOT}/mnt/cdrom/livecd.loop" ]; then
                        LOOP='/livecd.loop'
                        LOOPTYPE='normal'
-                elif [ -e '/newroot/mnt/cdrom/zisofs' ]; then
+                elif [ -e "${NEW_ROOT}/mnt/cdrom/zisofs" ]; then
                        LOOP='/zisofs'
                        LOOPTYPE='zisofs'
-                elif [ -e '/newroot/mnt/cdrom/livecd.squashfs' ]; then
+                elif [ -e "${NEW_ROOT}/mnt/cdrom/livecd.squashfs" ]; then
                        LOOP='/livecd.squashfs'
                        LOOPTYPE='squashfs'
-                elif [ -e '/newroot/mnt/cdrom/livecd.gcloop' ]; then
+                elif [ -e "${NEW_ROOT}/mnt/cdrom/livecd.gcloop" ]; then
                        LOOP='/livecd.gcloop'
                        LOOPTYPE='gcloop'
                 else
@@ -427,7 +318,7 @@ then
        # Failsafe the loop type wasn't set
        if [ "${LOOPTYPE}" = '' ]
        then
-               echo -e "${WARN}** ${NORMAL}${BOLD}Warning: loop type unspecified!${NORMAL}"
+               warn_msg 'Warning: loop type unspecified!'
                if [ "${LOOP}" = '/livecd.loop' ]
                then
                        LOOPTYPE='normal'
@@ -445,153 +336,160 @@ then
                fi
        fi
 
-       if [ "${LOOPTYPE}" != 'noloop' ]
-       then
-           check_loop
-           if [ "${DO_cache}" ]
-           then
-               echo -e "${GOOD}>>${NORMAL}${BOLD} Copying loop file for caching...${NORMAL}"
-               cp -a /newroot/mnt/cdrom/${LOOP} /newroot/mnt/${LOOP}
-               if [ $? -ne 0 ]
-               then
-                       echo -e "${BAD}!!${NORMAL}${BOLD} Failed to cache the loop file! Lack of space?"
-                       rm -rf /newroot/mnt/livecd.* 2>/dev/null
-                       rm -rf /newroot/mnt/zisofs 2>/dev/null
-               else
-                       LOOPEXT='../'
-               fi
-           fi
-       fi
+       cache_cd_contents
+       # Setup the loopback mounts
 
        if [ "${LOOPTYPE}" = 'normal' ]
        then
-               # bind-mount /dev/ so that loop devices can be found
-               mount -o bind /newroot/dev /dev
-
-               echo -e "${GOOD}>>${NORMAL}${BOLD} Mounting loop filesystem...${NORMAL}"
-               mount -t ext2 -o loop,ro /newroot/mnt/cdrom/${LOOPEXT}${LOOP} /newroot/mnt/livecd
-               if [ "$?" != '0' ]
-               then
-                       echo 'Failed to mount filesystem; failing back to the shell...'
-                       /bin/ash
-               fi
+               good_msg 'Mounting loop filesystem'
+               mount -t ext2 -o loop,ro ${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP} ${NEW_ROOT}/mnt/livecd
+               test_success 'Mount filesystem'
                FS_LOCATION='mnt/livecd'
-               umount /dev
+
+
        elif [ "${LOOPTYPE}" = 'squashfs' ]
        then
-               mount -o bind /newroot/dev /dev
-               echo -e "${GOOD}>>${NORMAL}${BOLD} Mounting squashfs filesystem...${NORMAL}"
-               mount -t squashfs -o loop,ro /newroot/mnt/cdrom/${LOOPEXT}${LOOP} /newroot/mnt/livecd
-               if [ "$?" != '0' ]
-               then
-                       echo 'Failed to mount filesystem; failing back to the shell...'
-                       /bin/ash
-               fi
+               good_msg 'Mounting squashfs filesystem'
+               mount -t squashfs -o loop,ro ${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP} ${NEW_ROOT}/mnt/livecd
+               
+               test_success 'Mount filesystem'
                FS_LOCATION='mnt/livecd'
-               umount /dev
+       
        elif [ "${LOOPTYPE}" = 'gcloop' ]
        then
-               echo -e "${GOOD}>>${NORMAL}${BOLD} Mounting gcloop filesystem...${NORMAL}"
-               mount -o bind /newroot/dev /dev
-               echo ' ' | losetup -E 19 -e ucl-0 -p0 /newroot/dev/loop0 /newroot/mnt/cdrom/${LOOPEXT}${LOOP}
-               if [ "$?" != '0' ]
-               then
-                       echo "FAILED TO losetup THE LOOP DEVICE"
-                       /bin/ash
-               fi
-               mount -t ext2 -o ro /newroot/dev/loop0 /newroot/mnt/livecd
+               good_msg 'Mounting gcloop filesystem'
+               echo ' ' | losetup -E 19 -e ucl-0 -p0 ${NEW_ROOT}/dev/loop0 ${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}
+               test_success 'losetup the loop device'
+
+               mount -t ext2 -o ro ${NEW_ROOT}/dev/loop0 ${NEW_ROOT}/mnt/livecd
+               test_success 'Mount the losetup loop device'
                FS_LOCATION='mnt/livecd'
-               umount /dev
+       
        elif [ "${LOOPTYPE}" = 'zisofs' ]
        then
                FS_LOCATION="mnt/cdrom/${LOOPEXT}${LOOP}"
+       
        elif [ "${LOOPTYPE}" = 'noloop' ]
        then
                FS_LOCATION='mnt/cdrom'
        fi
 
-       echo -e "${GOOD}>>${NORMAL}${BOLD} Filling filesystem...${NORMAL}"
+#
+# End cdrom looptype determination and mounting if necessary
+#
 
-       # Copy over stuff that should be writable
-       (cd /newroot/${FS_LOCATION}; cp -a ${ROOT_TREES} /newroot)
+       if [ "${USE_UNIONFS_NORMAL}" -eq '1' ]
+       then
+               union_insert_dir $UNION /${NEW_ROOT}/${FS_LOCATION}
+               
+               # Make sure fstab notes livecd is mounted ro.  Makes system skip remount which fails on unionfs dirs.
+               cat /${UNION}/etc/fstab | sed -e 's|\(.*\s/\s*tmpfs\s*\)defaults\(.*\)|\1defaults,ro\2|' > /${UNION}/etc/fstab
+       fi
 
        # Unpacking additional packages from NFS mount
        # This is useful for adding kernel modules to /lib
        # We do this now, so that additional packages can add whereever they want.
        if [ "${REAL_ROOT}" = '/dev/nfs' ]
        then
-               if [ -e '/newroot/mnt/cdrom/add' ]
+               if [ -e "${CHROOT}/mnt/cdrom/add" ]
                then
-                       for targz in `ls /newroot/mnt/cdrom/add/*.tar.gz`
-                       do      
-                               tarname=`basename ${targz}`
-                               echo -e "${GOOD}>>${NORMAL}${BOLD} Adding additional package ${tarname}${NORMAL}"
-                               (cd /newroot ; tar -xzf ${targz})
-                       done
+                               for targz in $(ls ${CHROOT}/mnt/cdrom/add/*.tar.gz)
+                               do      
+                                       tarname=`basename ${targz}`
+                                       good_msg "Adding additional package ${tarname}"
+                                       (cd ${CHROOT} ; /bin/tar -xzf ${targz})
+                               done
                fi
        fi
 
-       # Now we do the links.
-       for x in ${ROOT_LINKS}
-       do
-               # List all subdirectories of x
-               for directory in $(find "/newroot/${FS_LOCATION}/${x}" -type d 2>/dev/null)
+       
+       if [ ! "${USE_UNIONFS_NORMAL}" -eq '1' ]
+       then
+               good_msg "Copying read-write image contents to tmpfs"
+               # Copy over stuff that should be writable
+               (cd ${NEW_ROOT}/${FS_LOCATION}; cp -a ${ROOT_TREES} ${NEW_ROOT})
+
+               # Now we do the links.
+               for x in ${ROOT_LINKS}
                do
-                       ## Strip the prefix of the FS_LOCATION
-                       directory=${directory#/newroot/${FS_LOCATION}/}
-
-                       ## Skip this directory if we already linked a parent directory
-                       if [ "${current_parrent}" != '' ]; then
-                               var=`echo "${directory}" | grep "^${current_parrent}"`
-                               if [ "${var}" != '' ]; then
-                                       continue
-                               fi
-                       fi
-                       ## Test if the directory exists already
-                       if [ -e "/newroot/${directory}" ]
-                       then
-                               # It does exist, link all the individual files
-                               for file in `ls /newroot/${FS_LOCATION}/${directory}`
-                               do
-                               if [ ! -d "/newroot/${FS_LOCATION}/${directory}/${file}" ] && [ ! -e "/newroot/${directory}/${file}" ]; then
-                                               ln -s "/${FS_LOCATION}/${directory}/${file}" "${directory}/${file}" 2> /dev/null
+                       # List all subdirectories of x
+                       for directory in `find "${NEW_ROOT}/${FS_LOCATION}/${x}" -type d 2>/dev/null`
+                       do
+                               ## Strip the prefix of the FS_LOCATION
+                               directory=${directory#${NEW_ROOT}/${FS_LOCATION}/}
+
+                               ## Skip this directory if we already linked a parent directory
+                               if [ "${current_parrent}" != '' ]; then
+                                       var=`echo "${directory}" | grep "^${current_parrent}"`
+                                       if [ "${var}" != '' ]; then
+                                               continue
                                        fi
-                               done
-                       else
-                               # It does not exist, make a link to the livecd
-                               ln -s "/${FS_LOCATION}/${directory}" "${directory}" 2> /dev/null
-                               current_parrent=${directory}
-                       fi
+                               fi
+                               ## Test if the directory exists already
+                               if [ -e "/${NEW_ROOT}/${directory}" ]
+                               then
+                                       # It does exist, link all the individual files
+                                       for file in `ls /${NEW_ROOT}/${FS_LOCATION}/${directory}`
+                                       do
+                                       if [ ! -d "/${NEW_ROOT}/${FS_LOCATION}/${directory}/${file}" ] && [ ! -e "${NEW_ROOT}/${directory}/${file}" ]; then
+                                                       ln -s "/${FS_LOCATION}/${directory}/${file}" "${directory}/${file}" 2> /dev/null
+                                               fi
+                                       done
+                               else
+                                       # It does not exist, make a link to the livecd
+                                       ln -s "/${FS_LOCATION}/${directory}" "${directory}" 2> /dev/null
+                                       current_parrent=${directory}
+                               fi
+                       done
                done
-       done
 
-       mkdir initrd proc tmp sys
-       chmod 1777 tmp
+               mkdir initrd proc tmp sys
+               chmod 1777 tmp
+       fi
+       
+       UML=$(cat /proc/cpuinfo|grep UML|sed -e 's|model name.*: ||')
+       if [ "${UML}" = 'UML' ]
+       then
+               # UML Fixes
+               good_msg 'Updating for uml system'
+
+               VC=$(cat ${CHROOT}/etc/securetty|grep 'vc/0'|sort|uniq)
+               if [ "${VC}" = 'vc/0' ]
+               then
+                       echo 'vc/0 already exists, skipping'
+               else
+                       echo 'vc/0' >> ${CHROOT}/etc/securetty
+               fi
+               TTY=$(cat ${CHROOT}/etc/securetty|grep 'tty0'|sort|uniq)
+               if [ "${TTY}" = 'vc/0' ]
+               then
+                       echo 'tty0, already exists skipping'
+               else
+                       echo tty0 >> ${CHROOT}/etc/securetty
+               fi
+               
+               # Setup console on 0 for uml
+               if [ -w /${CHROOT}/sbin/livecd-functions.sh ]
+               then
+                       cat /${CHROOT}/sbin/livecd-functions.sh |sed -e 's|for x in 1 2 3 4 5 6|for x in 0 1 2 3 4 5 6|'> /${CHROOT}/sbin/livecd-functions.sh
+               fi
+
+       fi
 
        # Let Init scripts know that we booted from CD
        export CDBOOT
        CDBOOT=1
 else
-       mkdir -p /newroot/tmp/.initrd
-fi
-
-if [ -x /newroot/mnt/cdrom/cdupdate.sh ]
-then
-    /newroot/mnt/cdrom/cdupdate.sh
-    if [ "$?" != '0' ]
-    then
-       echo "FAILED TO EXECUTE cdupdate.sh"
-       /bin/ash
-    fi
+       mkdir -p ${NEW_ROOT}/tmp/.initrd
 fi
 
 if [ "$0" = '/linuxrc' ]
 then
-       [ ! -e /newroot/dev/console ] && mknod /newroot/dev/console c 5 1
+       [ ! -e ${CHROOT}/dev/console ] && mknod ${CHROOT}/dev/console c 5 1
        echo -ne "${GOOD}>>${NORMAL}${BOLD} Booting"
 
-       cd /newroot
-       mkdir /newroot/proc /newroot/sys 2>/dev/null
+       cd ${CHROOT}
+       mkdir ${CHROOT}/proc ${CHROOT}/sys 2>/dev/null
        pivot_root . tmp/.initrd
        echo -n '.'
 
@@ -622,8 +520,7 @@ then
        fi
        echo -n '.'
 
-       # /usr/src/linux/Documentation/initrd.txt 
-       # here's the line it says we should do:
+       # /usr/src/linux/Documentation/initrd.txt:
        #       exec chroot . /sbin/init </dev/console >/dev/console 2>&1
 
        exec <dev/console >dev/console 2>&1
@@ -635,29 +532,15 @@ then
 EOF
 elif [ "$0" = '/init' ]
 then
-       [ ! -e /newroot/dev/console ] && mknod /newroot/dev/console c 5 1
-       echo -ne "${GOOD}>>${NORMAL}${BOLD} Booting (initramfs method)"
+       [ ! -e /${CHROOT}/dev/console ] && mknod /${CHROOT}/dev/console c 5 1
+       echo -ne "${GOOD}>>${NORMAL}${BOLD} Booting (initramfs)..."
 
-       cd /newroot
-       mkdir /newroot/proc /newroot/sys 2>/dev/null
+       cd ${CHROOT}
+       mkdir /${CHROOT}/proc /${CHROOT}/sys 2>/dev/null
        echo -n '.'
-
-       if [ "${USE_DEVFS_NORMAL}" -eq '1' -a "${CDROOT}" -eq '0' ]
-       then
-               umount /dev || echo '*: Failed to unmount the initrd /dev!'
-               umount /sys || echo '*: Failed to unmount the initrd /sys!'
-               umount /proc || echo '*: Failed to unmount the initrd /proc!'
-       elif [ "${USE_UDEV_NORMAL}" -eq '1' ]
-       then
                umount /dev || echo '*: Failed to unmount the initrd /dev!'
                umount /sys || echo '*: Failed to unmount the initrd /sys!'
                umount /proc || echo '*: Failed to unmount the initrd /proc!'
-       elif [ "${CDROOT}" -eq '1' ]
-       then
-               umount /dev 2>/dev/null
-               umount /sys 2>/dev/null
-               umount /proc || echo "*: Failed to unmount the initrd /proc!"
-       fi
        echo -n '.'
 
        exec <dev/console >dev/console 2>&1
@@ -665,11 +548,28 @@ then
 
        # Cleanup initramfs in the background
        # to reclaim initramfs tmpfs memoryspace
-       INITRAMFS_FILES=`ls /|grep -v newroot`
+       
+       
+       INITRAMFS_FILES=`ls /`
+       INITRAMFS_FILES=$(echo ${INITRAMFS_FILES}|sed -e "s|${CHROOT#/}||g")
+       
+       if [ -n "${MEMORY}" ]
+       then
+               INITRAMFS_FILES=$(echo ${INITRAMFS_FILES}|sed -e "s|${MEMORY#/}||g")
+       fi
+       
+       if [ -n "${UNION}" ]
+       then
+       INITRAMFS_FILES=$(echo ${INITRAMFS_FILES}|sed -e "s|${UNION#/}||g")
+       fi
+       
+       INITRAMFS_FILES=$(echo ${INITRAMFS_FILES}|sed -e "s|newroot||g")
        (sleep 10; cd /; rm -rf ${INITRAMFS_FILES}) &
+       
        # End initramfs cleanup
 
        # Start the real root init
+       
        exec chroot . /bin/sh <<- EOF
        exec /sbin/init ${REAL_INIT}
 EOF
index 482487328131a21477e63226242945b498d1bd26..f1fb801b188ebd02ca2dbc27338e2b7ddb1da99c 100755 (executable)
--- a/genkernel
+++ b/genkernel
@@ -1,7 +1,7 @@
 #!/bin/bash
 # Genkernel v3
 
-GK_V='3.2.0_pre2'
+GK_V='3.2.0_pre5'
 TEMP='/var/tmp/genkernel'
 TODEBUGCACHE=1 # Until an error occurs or DEBUGFILE is fully qualified.
 
index a20dc900c0268477bb3c44cdd6aff2c043b23cf6..8955c4076eab9b0301b720b5a1e22e0a1b0ea041 100755 (executable)
@@ -109,3 +109,9 @@ DMRAID_VER="1.0.0.rc6"
 DMRAID_DIR="dmraid/${DMRAID_VER}"
 DMRAID_SRCTAR="${GK_SHARE}/pkg/dmraid-${DMRAID_VER}.tar.bz2"
 DMRAID_BINCACHE="%%CACHE%%/dmraid-${DMRAID_VER}-%%ARCH%%.tar.bz2"
+
+UNIONFS_VER="1.0.12a"
+UNIONFS_DIR="unionfs-${UNIONFS_VER}"
+UNIONFS_SRCTAR="${GK_SHARE}/pkg/unionfs-${UNIONFS_VER}.tar.gz"
+UNIONFS_BINCACHE="%%CACHE%%/unionfs-${UNIONFS_VER}-tools-%%ARCH%%.tar.bz2"
+UNIONFS_MODULES_BINCACHE="%%CACHE%%/unionfs-${UNIONFS_VER}-modules-%%KV%%-%%ARCH%%.tar.bz2"