[PATCH 01/12] Various modifications for building vservers

Sam Vilain sam at vilain.net
Mon May 1 05:46:31 CEST 2006


Check in FAI script whether we are running inside a vserver or not,
the test being whether or not /proc/cmdline exists.  Use this variable
to disable various things in subroutines-linux and subroutines.

Allow mkrw and create_ramdisk to handle something external setting up
the system for it, and give them an alternate method to do mounts
should a tmpfs mount fail.  In general, inside a vserver, only bind
mounts are safe.

---

=== debian/changelog
==================================================================
--- debian/changelog	(revision 8121)
+++ debian/changelog	(revision 8122)
@@ -1,3 +1,9 @@
+fai (2.10.1-1) unstable; urgency=low
+
+  * get_fai_dir: check not already mounted
+
+ -- Sam Vilain <sam at vilain.net>  Thu, 27 Apr 2006 16:32:59 +1200
+
 fai (2.10.1) unstable; urgency=low
 
   * fai-chboot: fix division by zero error

Property changes on: debian
___________________________________________________________________
Name: svn:ignore
 +fai-client
 +fai-doc
 +fai-doc.*.debhelper
 +fai-nfsroot
 +fai-quickstart
 +fai-server
 +files
 +tmp
 +


Property changes on: doc
___________________________________________________________________
Name: svn:ignore
 +fai-guide.*

=== lib/subroutines-linux
==================================================================
--- lib/subroutines-linux	(revision 8121)
+++ lib/subroutines-linux	(revision 8122)
@@ -10,6 +10,8 @@
 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 set_disk_info() {
 
+    [ -n "$VIRTUAL" ] && return
+
     # the variable holds a space separated list of devices and their block size
     device_size=$(disk-info)
 
@@ -20,7 +22,7 @@
 jobsrunning() {
 
     # test if jobs are running
-    ps r | egrep -qv "ps r|TIME COMMAND"
+    ps r | egrep -v "ps r|TIME COMMAND|$0"
 }
 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 eval_cmdline() {
@@ -28,14 +30,20 @@
     # parse kernel parameters and define variables
     local word
 
-    echo -n "Kernel parameters: "; cat /proc/cmdline
-    for word in $(cat /proc/cmdline) ; do
-	case $word in
-	    [a-zA-Z]*=*)
-		eval $word
-		;;
-	esac
-    done
+    if [ -e /proc/cmdline ]
+    then
+        echo -n "Kernel parameters: "; cat /proc/cmdline
+        for word in $(cat /proc/cmdline) ; do
+	    case $word in
+	        [a-zA-Z]*=*)
+		    eval $word
+		    ;;
+	    esac
+        done
+    else
+        echo "No /proc/cmdline - must be virtual, assuming env. already set up"
+	export VIRTUAL=1
+    fi
 }
 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 task_confdir() {
@@ -44,14 +52,17 @@
         local bootlog
         eval_cmdline
 
-        bootlog=$LOGDIR/boot.log
-        get-boot-info
-        echo "Reading $bootlog"
-        . $bootlog
-        unset T170 T171 T172 ROOT_PATH BOOTFILE
+	if [ -z "$VIRTUAL" ]
+	then
+            bootlog=$LOGDIR/boot.log
+            get-boot-info
+            echo "Reading $bootlog"
+            . $bootlog
+            unset T170 T171 T172 ROOT_PATH BOOTFILE
+            echo 6 > /proc/sys/kernel/printk
+	    klogd -c7 -f $LOGDIR/kernel.log
+	fi
 
-        echo 6 > /proc/sys/kernel/printk
-	klogd -c7 -f $LOGDIR/kernel.log
 	syslogd -m 0
         create_resolv_conf
     fi
=== lib/mkrw
==================================================================
--- lib/mkrw	(revision 8121)
+++ lib/mkrw	(revision 8122)
@@ -20,9 +20,22 @@
 	return
     fi
 
+    # test for already writable
+    temp=`mktemp -q -p $2`
+    if [ $? -eq 0 ]
+    then
+	echo "mkrw: $2 is already writable."
+	rm $temp && return
+    fi
+
     local tmp1=$(mktemp) || exit 12
     tar -C $2 -cf $tmp1 .
-    mount -o size=$1 -t tmpfs tmpfs $2
+    mount -o size=$1 -t tmpfs tmpfs $2 2>/dev/null || (
+	dirname="`echo $2 | sed 's/\//_/g'`"
+	mkdir /tmp/$dirname
+	echo "Making $2 writable with a bind mount from /tmp/$dirname"
+	mount --bind /tmp/$dirname $2
+    )
     tar -C $2 -xf $tmp1
     rm -f $tmp1
 }
=== lib/subroutines
==================================================================
--- lib/subroutines	(revision 8121)
+++ lib/subroutines	(revision 8122)
@@ -157,8 +157,13 @@
 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 get_fai_dir() {
 
+    # maybe /fai has already been put magically where we want it
+    if [ -d "$FAI/class" ]
+    then
+        return
+    fi
+
     # get /fai directory; mount it or get it from a cvs repository
-
     [ -f /boot/RUNNING_FROM_FAICD ] && mkrw $FAI
     if [ -z "$FAI_LOCATION" ]; then
        get_fai_cvs
@@ -384,6 +389,7 @@
 task_faiend() {
 
     [ $DO_INIT_TASKS -eq 0 ] && exit 0
+    [ -n "$VIRTUAL" ] && exit 0
     wait_for_jobs
     echo "Press <RETURN> to reboot or ctrl-c to execute a shell"
     # reboot without prompting if FAI_FLAG reboot is set
=== lib/create_ramdisk
==================================================================
--- lib/create_ramdisk	(revision 8121)
+++ lib/create_ramdisk	(revision 8122)
@@ -4,18 +4,31 @@
 
 # create a writeable area on the install client
 
-mount -n -t proc proc /proc
+if [ ! -e /proc/self ]
+then
+    mount -n -t proc proc /proc
+fi
+
 # start devfsd if needed
 if [ -c /dev/.devfsd ]; then
     /sbin/devfsd /dev
 fi
 
-# if we have shm use it as ramdisk
-mount -t tmpfs tmpfs /tmp || {
-    ramdevice=/dev/ram0
-    mke2fs -q -m 0 $ramdevice && echo "ramdisk $ramdevice created"
-    mount -n $ramdevice /tmp
-}
-mkdir -p /tmp/etc /tmp/target
+# perhaps we already have a ramdisk set up
+temp=`mktemp -q -p /tmp`
+if [ $? -eq 0 ]
+then
+   echo "create_ramdisk: /tmp is already writable, magic!"
+   rm $temp
+   mkdir /tmp/etc
+else
+    # if we have shm use it as ramdisk
+    mount -t tmpfs tmpfs /tmp || {
+        ramdevice=/dev/ram0
+        mke2fs -q -m 0 $ramdevice && echo "ramdisk $ramdevice created"
+        mount -n $ramdevice /tmp
+    }
+    mkdir -p /tmp/etc /tmp/target
+fi
 
 mkrw /dev /var/run /var/log /var/lock /var/lib/discover /etc/sysconfig
=== bin/fai
==================================================================
--- bin/fai	(revision 8121)
+++ bin/fai	(revision 8122)
@@ -35,6 +35,7 @@
 stamp=$rundir/FAI_INSTALLATION_IN_PROGRESS
 romountopt="-o async,noatime,nolock,ro,actimeo=1800"
 fstab=fstab  # Solaris uses vfstab
+debug=1
 
 # the type of operating system (linux, sunos)
 oclass=$(uname -s | tr a-z A-Z)
@@ -112,14 +113,16 @@
 
     if [ X$oclass = XLINUX ]; then
 	if [ $DO_INIT_TASKS -eq 1 ]; then
-	    grep -q '[[:space:]]sysfs' /proc/filesystems && mount -t sysfs sysfs /sys
-	    ifup lo
-	    [ -x /etc/init.d/udev ] && /etc/init.d/udev start
-	    [ -x /sbin/portmap ] && /sbin/portmap
-	    mount -t devpts devpts /dev/pts
-	    # add other options for nfs mount of /dev/root to root-path in dhcpd.conf
-	    mount -o remount,noatime,ro /dev/root /
-	    cat /proc/kmsg >/dev/tty4 &
+	    if [ -z "$VIRTUAL" ]; then
+	        grep -q '[[:space:]]sysfs' /proc/filesystems && mount -t sysfs sysfs /sys
+	        ifup lo
+	        [ -x /etc/init.d/udev ] && /etc/init.d/udev start
+	        [ -x /sbin/portmap ] && /sbin/portmap
+	        mount -t devpts devpts /dev/pts
+	        # add other options for nfs mount of /dev/root to root-path in dhcpd.conf
+	        mount -o remount,noatime,ro /dev/root /
+	        cat /proc/kmsg >/dev/tty4 &
+            fi
 	fi
     fi
 
@@ -201,6 +204,8 @@
     # HG: are we called as an init substitute ?
     export DO_INIT_TASKS=0
     [ "$0" = "/etc/init.d/rcS" ] && DO_INIT_TASKS=1
+    echo GOT HERE
+    [ -d /proc/self -a ! -e /proc/cmdline ] && export VIRTUAL=1
     [ $DO_INIT_TASKS -eq 1 ] && renewclass=1 # always renew class list when installing
 
     # Solaris has already a writable /tmp directory

Property changes on: 
___________________________________________________________________
Name: svn:ignore
 +build-stamp



More information about the linux-fai mailing list