]> git.pld-linux.org Git - projects/geninitrd.git/commitdiff
- alternativ *working* script
authorczarny <czarny@pld-linux.org>
Wed, 13 Dec 2006 11:11:53 +0000 (11:11 +0000)
committerczarny <czarny@pld-linux.org>
Wed, 13 Dec 2006 11:11:53 +0000 (11:11 +0000)
- this time more awk (as proposed by pluto)
- accepts root parameter at boot in form of 0302 0x0302 /dev/hda3 hda3
- makes a device node regadles of udev - checks if the node passed in root exists

svn-id: @8097

geninitrd

index 5b4f28e15bbf8dbcd38e71cf34f63d32949605ee..3f0ecf83a63b856a0079539c17221b3bc58d6a63 100755 (executable)
--- a/geninitrd
+++ b/geninitrd
@@ -1476,27 +1476,51 @@ fi
 if [ "$INITRDFS" = "initramfs" ]; then
        mkdir -p $MNTIMAGE/newroot
        cp -HR $org_rootdev $MNTIMAGE/dev
-       echo "mount -t proc none /proc" >> "$s"
-       # the worst part if we don't have udev
-       if [ "$USE_UDEV" != "yes" ]; then
-               # We either have root passed into kernel as /dev/something or as a maj-min number
-               # we parse acordingly
-               cat << 'EOF' >> "$s"
-root="$(busybox awk ' /root=/ { gsub(/.*root=/,NIL,$0); gsub(/ .*/,NIL,$0); print $0; } ' /proc/cmdline )"
-if [[ "$root" == +(/+([A-z0-9])) ]]; then
-       rootnr="$(busybox awk -v root="$root" ' { if ($4 == root) { print $1 $2; } } ' /proc/partitions)"
-else
-       rootnr="${root#??} ${root%??}"
-       root="$(busybox awk " \
-               BEGIN { maj=${root#??}; min=${root%??}; } \
-               { if ( (\$1 == maj) && (\$2 == min) ) { print \$4; } } " \
-       /proc/partitions )"
+       # Parsing root parameter
+       # We support passing root as hda3 /dev/hda3 0303 0x0303
+       cat << 'EOF' >> "$s"
+set +x
+mount -t proc none /proc
+root="$(busybox awk -v prefix="root=" ' \
+function separate_root ( txt ) \
+{ \
+    gsub(/.*root=/,NIL,txt); \
+    gsub(/ .*/,NIL,txt); \
+    return txt \
+} \
+BEGIN { \
+    num_pattern = "[0-9][0-9][0-9][0-9]"; \
+    dev_pattern = "[hms][a-z][a-z]([0-9])+"; \
+    partition = "Metallica rocks!"; \
+    min = -1; maj = -1; \
+} \
+$0 ~ prefix "0x" num_pattern { sub(/root=0x/,"root="); } \
+$0 ~ prefix num_pattern { \
+    gsub(/.*root=/,NIL,partition); \
+    gsub(/ .*/,NIL,partition); \
+    partition = separate_root( $0 ); \
+    maj = sprintf("%d",substr(partition,1,2)); \
+    min = sprintf("%d",substr(partition,3)); \
+} \
+$0 ~ prefix "\/dev\/" dev_pattern { sub(/root=\/dev\//,"root="); } \
+$0 ~ prefix dev_pattern { \
+    partition = separate_root( $0 ); \
+} \
+$4 ~ partition { maj = $1; min = $2; } \
+$1 ~ maj && $2 ~ min { partition = $4; } \
+END { print sprintf("/dev/%s %d %d", partition, maj, min); }
+' /proc/cmdline /proc/partitions)"
+device=${root% * *}
+maj=${root#* }
+maj=${maj% *}
+min=${root#* * }
+set -x
+if [ ! -b $device ]; then
+       mknod $device b $maj $min
 fi
-mknod $root b $rootnr
 EOF
-       fi
        cat << EOF >> "$s"
-mount -t $rootFs \$root /newroot 
+mount -t $rootFs \$device /newroot 
 init="\$(busybox awk ' /init=\// { gsub(/.*init=/,NIL,\$0); gsub(/ .*/,NIL,\$0); print \$0; }  ' /proc/cmdline )"
 if [ -z "\$init" -o ! -x "/newroot\$init" ]; then
        init=/sbin/init
This page took 0.051929 seconds and 4 git commands to generate.