Author: glen
Date: Wed Nov 12 21:55:46 2008
New Revision: 9982

Modified:
   geninitrd/trunk/geninitrd
Log:
- move ramfs rootdev finding and mounting to initrd_gen_initramfs_switchroot 
function

Modified: geninitrd/trunk/geninitrd
==============================================================================
--- geninitrd/trunk/geninitrd   (original)
+++ geninitrd/trunk/geninitrd   Wed Nov 12 21:55:46 2008
@@ -1715,6 +1715,84 @@
        EOF
 }
 
+initrd_gen_initramfs_switchroot() {
+       inst_d /newroot
+       if [ "$rootdev" = "/dev/nfs" ]; then
+               echo "rootfs on NFS root=/dev/nfs"
+       else
+               [ ! -e "$DESTDIR/$rootdev" ] && inst $rootdev $rootdev
+       fi
+       # Parsing root parameter
+       # We support passing root as hda3 /dev/hda3 0303 0x0303 and 303
+       add_linuxrc <<-'EOF'
+               device=/dev/no_partition_found
+               eval "$(busybox awk -v c="$ROOT" '
+                       BEGIN {
+                               num_pattern_short = "[0-9a-f][0-9a-f][0-9a-f]";
+                               num_pattern = "[0-9a-f]" num_pattern_short;
+                               dev_pattern = "[hms][a-z][a-z]([0-9])+";
+                               partition = "no_partition_found";
+                               min = -1; maj = -1;
+
+                               sub("^0x", "", c);
+                               if (c ~ "^" num_pattern_short "$") sub("^", 
"0", c);
+                               if (c ~ "^" num_pattern  "$") {
+                                       maj = sprintf("%s",substr(c,1,2));
+                                       min = sprintf("%s",substr(c,3));
+                               }
+                               if (c ~ "^\/dev\/" dev_pattern "$") 
sub("^/dev/","", c);
+                               if (c ~ "^" dev_pattern "$") partition = c;
+                       }
+
+                       $4 ~ partition { maj = $1; min = $2; }
+                       $1 ~ maj && $2 ~ min { partition = $4; }
+
+                       END {
+                               print sprintf("device=/dev/%s\nmaj=%s\nmin=%s",
+                                       partition, maj, min);
+                       }
+                       ' /proc/partitions)"
+               if [ "$device" != '/dev/no_partition_found' -a ! -b $device ]; 
then
+                       mknod $device b $maj $min
+               fi
+       EOF
+
+       add_linuxrc <<-EOF
+               rootdev=$rootdev
+               rootfs=$rootFs
+       EOF
+
+       add_linuxrc <<-'EOF'
+               if [ "$device" = '/dev/no_partition_found' ]; then
+                       device=$rootdev
+               fi
+
+               mount -t $rootfs -r $device /newroot
+               init="$(echo "$CMDLINE" | busybox awk '/init=\// { 
gsub(/.*init=/,NIL,$0); gsub(/ .*/,NIL,$0); print }')"
+               if [ -z "$init" -o ! -x "/newroot$init" ]; then
+                       init=/sbin/init
+               fi
+       EOF
+
+       umount_all
+       busybox_applet switch_root
+       add_linuxrc <<-'EOF'
+               exec switch_root /newroot $init
+
+               echo "Error! initramfs should not reach this place."
+               echo "It probably means you've got old version of busybox, with 
broken"
+               echo "initramfs support. Trying to boot anyway, but won't 
promise anything."
+
+               exec chroot /newroot $init
+
+               echo "Failed to chroot!"
+       EOF
+       # we need /init being real file, not symlink, otherwise the initramfs 
will
+       # not be ran by pid 1 which is required for switch_root
+       mv $DESTDIR/linuxrc $DESTDIR/init
+       ln -s init $DESTDIR/linuxrc
+}
+
 # main()
 if [ "$(id -u)" != 0 ]; then
        die "You need to be root to generate initrd"
@@ -2214,83 +2292,8 @@
 [ ! -e "$DESTDIR/$rootdev_add" ] && inst $rootdev_add /dev
 
 if [ "$INITRDFS" = "initramfs" ]; then
-       inst_d /newroot
-       if [ "$rootdev" = "/dev/nfs" ]; then
-               echo "rootfs on NFS root=/dev/nfs"
-       else
-               [ ! -e "$DESTDIR/$rootdev" ] && inst $rootdev $rootdev
-       fi
-       # Parsing root parameter
-       # We support passing root as hda3 /dev/hda3 0303 0x0303 and 303
-       add_linuxrc <<-'EOF'
-               device=/dev/no_partition_found
-               eval "$(busybox awk -v c="$ROOT" '
-                       BEGIN {
-                               num_pattern_short = "[0-9a-f][0-9a-f][0-9a-f]";
-                               num_pattern = "[0-9a-f]" num_pattern_short;
-                               dev_pattern = "[hms][a-z][a-z]([0-9])+";
-                               partition = "no_partition_found";
-                               min = -1; maj = -1;
-
-                               sub("^0x", "", c);
-                               if (c ~ "^" num_pattern_short "$") sub("^", 
"0", c);
-                               if (c ~ "^" num_pattern  "$") {
-                                       maj = sprintf("%s",substr(c,1,2));
-                                       min = sprintf("%s",substr(c,3));
-                               }
-                               if (c ~ "^\/dev\/" dev_pattern "$") 
sub("^/dev/","", c);
-                               if (c ~ "^" dev_pattern "$") partition = c;
-                       }
-
-                       $4 ~ partition { maj = $1; min = $2; }
-                       $1 ~ maj && $2 ~ min { partition = $4; }
-
-                       END {
-                               print sprintf("device=/dev/%s\nmaj=%s\nmin=%s",
-                                       partition, maj, min);
-                       }
-                       ' /proc/partitions)"
-               if [ "$device" != '/dev/no_partition_found' -a ! -b $device ]; 
then
-                       mknod $device b $maj $min
-               fi
-       EOF
-
-       add_linuxrc <<-EOF
-               rootdev=$rootdev
-               rootfs=$rootFs
-       EOF
-
-       add_linuxrc <<-'EOF'
-               if [ "$device" = '/dev/no_partition_found' ]; then
-                       device=$rootdev
-               fi
-
-               mount -t $rootfs -r $device /newroot
-               init="$(echo "$CMDLINE" | busybox awk '/init=\// { 
gsub(/.*init=/,NIL,$0); gsub(/ .*/,NIL,$0); print }')"
-               if [ -z "$init" -o ! -x "/newroot$init" ]; then
-                       init=/sbin/init
-               fi
-       EOF
-
-       umount_all
-       busybox_applet switch_root
-       add_linuxrc <<-'EOF'
-               exec switch_root /newroot $init
-
-               echo "Error! initramfs should not reach this place."
-               echo "It probably means you've got old version of busybox, with 
broken"
-               echo "initramfs support. Trying to boot anyway, but won't 
promise anything."
-
-               exec chroot /newroot $init
-
-               echo "Failed to chroot!"
-       EOF
-       # we need /init being real file, not symlink, otherwise the initramfs 
will
-       # not be ran by pid 1 which is required for switch_root
-       mv $DESTDIR/linuxrc $DESTDIR/init
-       ln -s init $DESTDIR/linuxrc
+       initrd_gen_initramfs_switchroot
 else
-       # other than initramfs
        umount_all
 fi
 
_______________________________________________
pld-cvs-commit mailing list
[email protected]
http://lists.pld-linux.org/mailman/listinfo/pld-cvs-commit

Reply via email to