SVN: geninitrd/branches/devel/geninitrd
czarny
czarny at pld-linux.org
Wed Dec 13 12:11:54 CET 2006
Author: czarny
Date: Wed Dec 13 12:11:53 2006
New Revision: 8097
Modified:
geninitrd/branches/devel/geninitrd
Log:
- alternativ *working* script
- 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
Modified: geninitrd/branches/devel/geninitrd
==============================================================================
--- geninitrd/branches/devel/geninitrd (original)
+++ geninitrd/branches/devel/geninitrd Wed Dec 13 12:11:53 2006
@@ -1476,27 +1476,51 @@
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
More information about the pld-cvs-commit
mailing list