Fedora Diskless init patch

From MythTV Official Wiki
Jump to: navigation, search
--- initrd/disklessrc   2007-08-11 13:33:10.000000000 -0500
+++ initramfs/init      2007-09-05 22:37:33.000000000 -0500
@@ -89,7 +89,7 @@
 #  over the root directory.
 #
 mountfile () {
-    snapshotfile=/.snapshot/${2}${1}
+    snapshotfile=/mnt/.snapshot/${2}${1}
     dir=`dirname $snapshotfile`
 #
 #  Check if file already exists in snapshot directory.  If not attempt to copy
@@ -98,9 +98,9 @@
     if [ ! -e $snapshotfile ]; then
        mkdir -p $dir
        echo "${1} missing from client specific area."
-       if [ -e ${1} ] ; then
+       if [ -e /mnt/${1} ] ; then
            echo "Copying ${1}"
-           rsync -a ${1} $snapshotfile
+           rsync -a /mnt/${1} $snapshotfile
        else
            echo "Creating ${1}"
            touch $snapshotfile
@@ -111,13 +111,13 @@
 #   snapshot directory.
        if [ ${1} == "/dev" -a ${1} -nt ${dir}/dev ]; then
            echo "RSYNC-ing /dev";
-           rsync -a ${1} $snapshotfile
+           rsync -a /mnt/${1} $snapshotfile
        fi
     fi
 #
 #  Mount the snapshotfile over the root file so the client will have r/w access
 #
-    mount -n -o bind /.snapshot/${2}${1} ${1}
+    mount -n -o bind /mnt/.snapshot/${2}${1} /mnt/${1}
 }

 echo "==============================================================================="
@@ -308,7 +308,7 @@
 if [ -w /proc/progress ]; then echo 55 "Mounting root filesystem" >/proc/progress; fi
 echo "Mounting root filesystem: ${NFS_DIR}/root from: ${NFS_IP}"

-mount -n -o nolock,ro ${NFS_IP}:${NFS_DIR}/root /mnt
+mount -n -o nosharecache,nolock,ro,rsize=32768,async,intr ${NFS_IP}:${NFS_DIR}/root /mnt

 if [ $? -ne 0 ]; then
     if [ -w /proc/progress ]; then echo f >/proc/progress; fi
@@ -327,63 +327,50 @@

 if [ "${INITRD_DBG}" = "5" ]; then exec /bin/bash; fi

-#
-# Now that the NFS root partition has been mounted do a pivot_root to switch
-# the memory resident root with the NFS one.
-#
-if [ -w /proc/progress ]; then echo 60 "Pivoting root" >/proc/progress; fi
-
-umount /proc
-echo "Doing the pivot_root"
-
-cd /mnt
-/sbin/pivot_root . .oldroot
-
-cd /
-mount -n -t proc /proc /proc
+export LD_LIBRARY_PATH=/mnt/usr/lib64:/mnt/usr/lib:/mnt/lib64:/mnt/lib
+export PATH=/mnt/usr/sbin:/mnt/usr/bin:/mnt/sbin:/mnt/bin:$PATH

 #
 #  Mount the snapshot directory from the server and then mount files
 #  in the snapshot/files file over the the shared ones
 #

-if [ "${INITRD_DBG}" = "6" ]; then exec /bin/bash; fi
 echo Mounting Snapshot directories
-mount -t nfs $NFS_IP:${NFS_DIR}/snapshot /.snapshot -o rw,nolock &&
+mount -n -t nfs $NFS_IP:${NFS_DIR}/snapshot /mnt/.snapshot -o nosharecache,rw,nolock,rsize=32768,wsize=32768,async,intr &&
 {
-    for i in `grep -v "^#" /.snapshot/files`; do
-       if [ -e $i ]; then
+    for i in `grep -v "^#" /mnt/.snapshot/files`; do
+       if [ -e /mnt/$i ]; then
            mountfile $i ${SNAPSHOT}
        fi;
     done
-    if [ -e /.snapshot/files.custom ]; then
-       for i in `grep -v "^#" /.snapshot/files.custom`; do
-           if [ -e $i ]; then
+    if [ -e /mnt/.snapshot/files.custom ]; then
+       for i in `grep -v "^#" /mnt/.snapshot/files.custom`; do
+           if [ -e /mnt/$i ]; then
                mountfile $i ${SNAPSHOT}
            fi;
        done
     fi
     RELEASE=`uname -r`
-    for i in `ls /lib/modules/$RELEASE/modules.*`; do
-       if [ -e $i ]; then
+    for i in `ls /mnt/lib/modules/$RELEASE/modules.*`; do
+       if [ -e /mnt/$i ]; then
            mountfile $i ${SNAPSHOT}
        fi;
     done
-    /sbin/ifup lo
+    /mnt/sbin/ifup lo
 }
+if [ "${INITRD_DBG}" = "6" ]; then exec /bin/bash; fi

 #
 # Copy the files written by dhclient to new root:
 #
-[ -e /.oldroot/etc/resolv.conf ] &&  cp -fp /.oldroot/etc/resolv.conf /etc/resolv.conf 2>/dev/null
-[ -e /.oldroot/etc/yp.conf ] && cp -fp /.oldroot/etc/yp.conf /etc/yp.conf 2>/dev/null
-[ -e /.oldroot/etc/ntp.conf ] && cp -fp /.oldroot/etc/ntp.conf /etc/ntp.conf 2>/dev/null
-[ -e /.oldroot/etc/ntp/step-kickers ] && cp -fp /.oldroot/etc/ntp/step-tickers /etc/ntp/step-tickers 2>/dev/null
+[ -e /etc/resolv.conf ] &&  cp -fp /etc/resolv.conf /mnt/etc/resolv.conf 2>/dev/null
+[ -e /etc/yp.conf ] && cp -fp /etc/yp.conf /mnt/etc/yp.conf 2>/dev/null
+[ -e /etc/ntp.conf ] && cp -fp /etc/ntp.conf /mnt/etc/ntp.conf 2>/dev/null
+[ -e /etc/ntp/step-kickers ] && cp -fp /etc/ntp/step-tickers /mnt/etc/ntp/step-tickers 2>/dev/null

 # This will allow dhclient to be re-run for nfs interface by initscripts (keep_old_ip=yes):
-cp -fp .oldroot/tmp/dhclient.leases /var/lib/dhcp/dhclient-eth0.leases 2>/dev/null
-cp -fp .oldroot/tmp/dhclient.leases /var/lib/dhclient/dhclient-eth0.leases 2>/dev/null
+cp -fp /tmp/dhclient.leases /mnt/var/lib/dhcp/dhclient-eth0.leases 2>/dev/null
+cp -fp /tmp/dhclient.leases /mnt/var/lib/dhclient/dhclient-eth0.leases 2>/dev/null

 if [ "${INITRD_DBG}" = "7" ]; then exec /bin/bash; fi

@@ -396,15 +383,13 @@
 #
 if [ "${INITRD_DBG}" = "8" ]; then exec /bin/bash; fi

-/bin/kill -TERM `cat /.oldroot/tmp/dhclient.pid`
+/bin/kill -TERM `cat /tmp/dhclient.pid`

 echo "Running /sbin/init"

-umount /.oldroot/tmp
-
-echo 0x100 > /proc/sys/kernel/real-root-dev
+umount /tmp

-umount /proc
+echo 0x100 > /mnt/proc/sys/kernel/real-root-dev

 # Some useful environment variables to stop initscripts / dhclient-script
 # doing silly things:
@@ -412,4 +397,4 @@
 export fastboot=yes
 export READONLY=yes

-exec /sbin/init
+exec /sbin/switch_root -c /dev/console /mnt /sbin/init