Re: [PATCH] mkinitrd rescue mode

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 2005-06-02 at 17:04 -0400, Bill Rugolsky Jr. wrote:
>  
> One is expected to delete files before doing the switchroot.  Unlike a ramdisk,
> the ramfs pages are immediately reclaimed.

Ok, I've whipped up a new patch. This adds a simple "unlink" function to
nash. The mkinitrd script now does an "rm /bin/fsck*" (using busybox's
rm), and then a "unlink /bin/busybox" after the rescue mode and prior to
the switchroot. That should free up any significant extra memory we
consume by adding these tools to the initramfs.

The new patch is attached to the BZ ticket:

https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=159287

I've done some looking around at whether there is some way to get at the
initramfs after switchrooting (or whether there is some mechanism to
cause the kernel to just free it), but haven't found any way to do this
yet.

The early-userspace docs seem to state that you can only have a single
cpio archive, but that multiple 'images' are allowed. I'm not clear at
this point on what these images are and how they're stored, however.

-- Jeff

Index: mkinitrd-4.2.15/mkinitrd
===================================================================
--- mkinitrd-4.2.15/mkinitrd	(revision 166)
+++ mkinitrd-4.2.15/mkinitrd	(working copy)
@@ -42,6 +42,7 @@
 builtins=""
 pivot=1
 initramfs=""
+rescue=""
 modulefile=/etc/modules.conf
 rc=0
 
@@ -58,7 +59,7 @@
 fi
 
 usage () {
-    echo "usage: `basename $0` [--version] [-v] [-f] [--preload <module>]" >&2
+    echo "usage: `basename $0` [--version] [-v] [-f] [--preload <module>] [--rescue]" >&2
     echo "       [--omit-scsi-modules] [--omit-raid-modules] [--omit-lvm-modules]" >&2
     echo "       [--with=<module>] [--image-version] [--fstab=<fstab>] [--nocompress]" >&2
     echo "       [--builtin=<module>] [--nopivot] <initrd-image> <kernel-version>" >&2
@@ -270,6 +271,9 @@
 	--allow-missing)
 	    allowmissing=yes
 	    ;;
+	--rescue)
+	    rescue=yes
+	    ;;
 	*)
 	    if [ -z "$target" ]; then
 		target=$1
@@ -636,6 +640,23 @@
     fi
 fi
 
+if [ -n "$rescue" ]; then
+    if [ -f "/sbin/busybox" ]; then
+        cp /sbin/busybox $MNTIMAGE/sbin/busybox
+        BUSYBOXSYMLINKS=`busybox 2>&1| awk '/^Currently defined functions:$/ {i++;next} i'|tr ',\t\n' ' '`
+        for link in ${BUSYBOXSYMLINKS//@(linuxrc|init|busybox)}; do
+    	    if [ ! -e $MNTIMAGE/bin/$link ]; then
+                ln -s busybox $MNTIMAGE/bin/$link
+	    fi
+        done
+        cp /sbin/fsck.ext3 $MNTIMAGE/sbin/fsck.ext3
+        cp /sbin/fsck $MNTIMAGE/sbin/fsck
+    else
+        echo "No /sbin/busybox, so not setting up rescue mode"
+        rescue=""
+    fi
+fi
+
 echo "#!/bin/nash" >| $RCFILE
 echo "" >> $RCFILE
 
@@ -745,6 +766,12 @@
 echo "mkrootdev /dev/root" >> $RCFILE
 rootdev=/dev/root
 
+if [ -n "$rescue" ]; then
+    echo "rescue /bin/msh" >> $RCFILE
+    echo "rm /bin/fsck*" >> $RCFILE
+    echo "unlink /bin/busybox" >> $RCFILE
+fi
+
 if [ -n "$initramfs" ]; then
   echo "echo Mounting root filesystem" >> $RCFILE
   echo "mount -o $rootopts --ro -t $rootfs $rootdev /sysroot" >> $RCFILE
Index: mkinitrd-4.2.15/nash/nash.c
===================================================================
--- mkinitrd-4.2.15/nash/nash.c	(revision 166)
+++ mkinitrd-4.2.15/nash/nash.c	(working copy)
@@ -1560,6 +1560,51 @@
     return 0;
 }
 
+int doRescueMode(char * cmd, char * end) {
+    char * kcmdline;
+    char * rescuep;
+    char * bin;
+    int retcode;
+ 
+    kcmdline = getKernelCmdLine();
+    rescuep = strstr(kcmdline, " rescue");
+
+    if ( rescuep == NULL || ( *(rescuep+7) != '\0' && *(rescuep+7) != ' ' ) ) {
+        free(kcmdline);
+	return 0;
+    }
+
+    free(kcmdline);
+
+    if (!(cmd = getArg(cmd, end, &bin))) {
+	printf("rescue: argument expected\n");
+	return 1;
+    }
+
+    /* must open controlling tty as stdin and then close it afterward, since
+     * runStartup closes it before we get here */
+    printf("*** Entering rescue mode -- exit shell to continue booting ***\n");
+    dup2(1,0);
+    retcode = otherCommand(bin, cmd, end, 1);
+    close(0);
+    return retcode;
+}
+
+/* simple unlink function -- no wildcards allowed */
+int unlinkFile(char * cmd, char * end) {
+    char * file = NULL;
+    int retcode = 0;
+
+    cmd = getArg(cmd, end, &file);
+    retcode = unlink(file);
+    if (retcode != 0) {
+	printf("unlink: error removing %s (%d)\n",file,errno);
+	return errno;
+    } else {
+	return 0;
+    }
+}
+
 int runStartup(int fd) {
     char contents[32768];
     int i;
@@ -1647,6 +1692,10 @@
             rc = readlinkCommand(chptr, end);
         else if (!strncmp(start, "setquiet", MAX(8, chptr-start)))
             rc = setQuietCommand(chptr, end);
+        else if (!strncmp(start, "rescue", MAX(6, chptr-start)))
+            rc = doRescueMode(chptr, end);
+        else if (!strncmp(start, "unlink", MAX(6, chptr-start)))
+            rc = unlinkFile(chptr, end);
 #ifdef DEBUG
         else if (!strncmp(start, "cat", MAX(3, chptr-start)))
             rc = catCommand(chptr, end);
-- 
fedora-devel-list mailing list
fedora-devel-list@xxxxxxxxxx
http://www.redhat.com/mailman/listinfo/fedora-devel-list

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Fedora Announce]     [Fedora Kernel]     [Fedora Testing]     [Fedora Formulas]     [Fedora PHP Devel]     [Kernel Development]     [Fedora Legacy]     [Fedora Maintainers]     [Fedora Desktop]     [PAM]     [Red Hat Development]     [Gimp]     [Yosemite News]
  Powered by Linux