Add back (modified) unionfs code in linuxrc
authoragaffney <agaffney@kagome.(none)>
Wed, 12 Nov 2008 22:16:21 +0000 (16:16 -0600)
committeragaffney <agaffney@kagome.(none)>
Wed, 12 Nov 2008 22:16:21 +0000 (16:16 -0600)
ChangeLog
defaults/initrd.scripts
defaults/linuxrc

index 6b611200f4e8e4042dd36d0e52f11601b416a190..0b3b691920e3fad1e641dc2c8682576e1e97321b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,10 @@
 # Copyright 1999-2008 Gentoo Foundation; 2008 Chris Gianelloni, Andrew Gaffney
 # Distributed under the GPL v2
 
+  12 Nov 2008; Andrew Gaffney <agaffney@gentoo.org> defaults/initrd.scripts,
+  defaults/linuxrc:
+  Add back (modified) unionfs code in linuxrc
+
   12 Nov 2008; Andrew Gaffney <agaffney@gentoo.org> gen_initramfs.sh:
   Add append_fuse() and append_unionfs_fuse() functions
 
index f58e1a453ea736ffa64469934e04c13ab12608d5..c69218dab1618ae5fb3d7dfbda88ae0184d337e4 100644 (file)
@@ -961,3 +961,62 @@ find_looptype() {
 getdvhoff() {
        echo $(( $(hexdump -n 4 -s $((316 + 12 * $2)) -e '"%i"' $1) * 512))
 }
+
+setup_unionfs() {
+       local rw_dir=$1
+       local ro_dir=$2
+       if [ "${USE_UNIONFS_NORMAL}" = '1' ]
+       then
+               # Directory used for rw changes in union mount filesystem
+               UNION=/union
+               MEMORY=/memory
+               if [ -z "$UID" ]
+               then
+                       CHANGES=$MEMORY/unionfs_changes/default
+               else
+                       CHANGES=$MEMORY/unionfs_changes/$UID
+               fi
+
+               mkdir -p ${MEMORY}
+               mkdir -p ${UNION}
+               good_msg "Loading fuse module"
+               modprobe fuse > /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    
+#                         if [ "${CDROOT}" -eq '1' -a ! -f ${MEMORY}/livecd.unionfs  ]          
+#                         then          
+#                                 umount $MEMORY        
+#                                 bad_msg "failed to find livecd.unionfs file on $CHANGESDEV"   
+#                                 bad_msg "create a livecd.unionfs file on this device if you wish to use it for unionfs"       
+#                                 bad_msg "falling back to ramdisk based unionfs for safety"    
+#                                 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}
+               unionfs -o allow_others,allow_root,cow,noinitgroups ${rw_dir}=RW:${ro_dir} ${UNION}
+               ret=$?
+               if [ "${ret}" -ne 0 ]
+               then
+                       bad_msg "Can't setup union ${UNION} in directory!"
+                       USE_UNIONFS_NORMAL=0
+               fi
+       else
+               USE_UNIONFS_NORMAL=0
+       fi
+}
index 925d619273c012661b8b0be92d938ad3c3581b86..f5e6ef1735654b3ededdc6653c6d7c5c53b16247 100644 (file)
@@ -183,6 +183,33 @@ do
                keymap\=*)
                        keymap=`parse_opt "${x}"`
                ;;
+               unionfs)
+                       if [ ! -x /sbin/unionfs ]
+                       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          
+#                                 CMD_UNIONFS=`parse_opt "${x}"`        
+#                                 echo ${CMD_UNIONFS}|grep , >/dev/null 2>&1    
+#                                 if [ "$?" -eq '0' ]   
+#                                 then          
+#                                         UID=`echo ${CMD_UNIONFS#*,}`          
+#                                         UNIONFS=`echo ${CMD_UNIONFS%,*}`      
+#                                 else          
+#                                         UNIONFS=${CMD_UNIONFS}        
+#                                 fi    
+#                         fi    
+#                 ;;
        esac
 done
 
@@ -436,7 +463,7 @@ then
        cache_cd_contents
 
        # If encrypted, find key and mount, otherwise mount as usual
-       if [ -n "${CRYPT_ROOT}" ] 
+       if [ -n "${CRYPT_ROOT}" ]
        then
                CRYPT_ROOT_KEY="$(head -n 1 ${NEW_ROOT}/mnt/cdrom/livecd)"
                CRYPT_ROOT='/dev/loop0'
@@ -512,22 +539,30 @@ then
                fi
        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 "${CHROOT}/mnt/cdrom/add" ]
+               if [ -e "${NEW_ROOT}/mnt/cdrom/add" ]
                then
-                               for targz in `ls ${CHROOT}/mnt/cdrom/add/*.tar.gz`
+                               for targz in `ls ${NEW_ROOT}/mnt/cdrom/add/*.tar.gz`
                                do      
                                        tarname=`basename ${targz}`
                                        good_msg "Adding additional package ${tarname}"
-                                       (cd ${CHROOT} ; /bin/tar -xzf ${targz})
+                                       (cd ${NEW_ROOT} ; /bin/tar -xzf ${targz})
                                done
                fi
        fi
 
+
+       if [ "${USE_UNIONFS_NORMAL}" = '1' ]
+       then
+               setup_unionfs ${NEW_ROOT} ${NEW_ROOT}/${FS_LOCATION}
+               CHROOT=/union
+       else
        
        good_msg "Copying read-write image contents to tmpfs"
        # Copy over stuff that should be writable
@@ -579,6 +614,8 @@ then
        mkdir initramfs proc tmp sys 2>/dev/null
        chmod 1777 tmp
 
+       fi
+
        #UML=`cat /proc/cpuinfo|grep UML|sed -e 's|model name.*: ||'`
        #if [ "${UML}" = 'UML' ]
        #then
@@ -594,6 +631,14 @@ then
        then
                sleep 10
        fi
+else
+       if [ "${USE_UNIONFS_NORMAL}" = '1' ]
+       then
+               mkdir /union_changes
+               mount -t tmpfs tmpfs /union_changes
+               setup_unionfs /union_changes ${NEW_ROOT}
+               mkdir -p ${UNION}/tmp/.initrd
+       fi
 fi
 
 # Execute script on the cdrom just before boot to update things if necessary