Subject: [alpine-devel] mkinitfs initramfs-init questions

From: Евгений 'Rush' Непомнящий <[email-masked]>
Date: Tue, 26 Feb 2013 12:51:29 +0400

There are some magic when parsing kernel command line (at the end of message):

1. Which reason for doing sed 's: :_:g' ? What command line will be
affected this for example?
2. Syslinux (5.x) pass kernel path as the first arg (twice in my
case). This code run with errors "/init: eval: line 1:
KOPT_/boot/datacom=yes: not found". This a bug or feature?
3. I've passed console=tty0 console=ttyS1,115200 for my Ubuntu kernels
on Dell servers with IPMI SOL to see kernel output both on IP KVM and
IPMI SOL (because not everywhere I have both). I think tty0 must not
be placed in inittab, because it is "current console". Seems like a
bug?
4. Code looks overcomplicated because there are
  a) not many options to be parsed by initramfs-init
  b) not all kernel options must be parsed by initramfs-init, unknown
options must be skipped (and errors as in #2 will not be raised in the
future)

8<------------------------------------------------------------------------------------------->8
# read the kernel options. We use eval set so we can handle things like
# acpi_osi="!Windows 2006"
eval set -- `cat /proc/cmdline`

while [ $# -gt 0 ]; do
        case "$1" in
                s|single|1)
                        SINGLEMODE=yes ;;
                console=*)
                        CONSOLE="$CONSOLE ${1#console=}";;
                *=*)    eval "KOPT_${1%%=*}='${1#*=}'" ;;
                no*)    eval "KOPT_$(echo ${1#no} | sed 's: :_:g')=no" ;;
                *)      eval "KOPT_$(echo $1 | sed 's: :_:g')=yes" ;;
        esac
        shift
done
8<------------------------------------------------------------------------------------------->8

/ # cat /proc/cmdline
/boot/datacom /boot/datacom initrd=/boot/datacom.gz
alpine_dev=usbdisk:vfat modules=loop,squashfs,sd-mod,usb-storage
nomodeset console=tty0 console=ttyS1,115200

--
Cogito ergo sum

---
Unsubscribe:  [email-masked]
Help:         [email-masked]
---

---

From: Natanael Copa <[email-masked]>
Date: Tue, 26 Feb 2013 21:45:49 +0100

On Tue, 26 Feb 2013 12:51:29 +0400

> affected this for example?

git blame pointed me to this commit:
http://git.alpinelinux.org/cgit/mkinitfs/commit/?id=bcc5a38b9849411a880d8b65771b30042aa7ce62

I had an issue with parsning acpi_osi="!Windows 2006". While there I
probably added the sed 's: :_:g' out of paranoia, in case kernel or
anything would have a param with spaces.

  somenewopt:"arg with space"

I doubt there are anything current that actually needs it. It was more
for future, unexpected things.

> KOPT_/boot/datacom=yes: not found". This a bug or feature?

Bug/regression due to new syslinux behaviour. I have similar issue on
my computer too. Just not had time to actually fix it.

> be placed in inittab, because it is "current console". Seems like a

Yeah. this sounds like bug.

> options must be skipped (and errors as in #2 will not be raised in the

Agree. We should only fish out the options we actually use and don't
bother about the rest. I have one more example where current code will
break things:

  cirrus.modeset=0

> # read the kernel options. We use eval set so we can handle things
> like # acpi_osi="!Windows 2006"
>                 no*)    eval "KOPT_$(echo ${1#no} | sed
> 's: :_:g')=no" ;; *)      eval "KOPT_$(echo $1 | sed
> 's: :_:g')=yes" ;; esac
>         shift
> done

Thanks for your feedback, and sorry for the breakages due to syslinux-5.

-nc

---

---

From: Natanael Copa <[email-masked]>
Date: Tue, 26 Feb 2013 22:20:40 +0100

On Tue, 26 Feb 2013 21:45:49 +0100
Natanael Copa <[email-masked]> wrote:
 
> >   b) not all kernel options must be parsed by initramfs-init,
> > unknown options must be skipped (and errors as in #2 will not be
> > raised in the future)
> 
> bother about the rest.

How about this:
diff --git a/initramfs-init.in b/initramfs-init.in
index 6e1ebc1..60a0255 100755
--- a/initramfs-init.in
+++ b/initramfs-init.in
@@ -283,22 +283,23 @@ echo "Alpine Init $VERSION"
 # acpi_osi="!Windows 2006"
 eval set -- `cat /proc/cmdline`
 
-while [ $# -gt 0 ]; do
-	case "$1" in
-		s|single|1)
-			SINGLEMODE=yes ;;
-		console=*)
-			CONSOLE="$CONSOLE ${1#console=}";;
-		*=*)    eval "KOPT_${1%%=*}='${1#*=}'" ;;
-		no*)    eval "KOPT_$(echo ${1#no} | sed 's: :_:g')=no" ;;
-		*)      eval "KOPT_$(echo $1 | sed 's: :_:g')=yes" ;;
+for opt in "$@"; do
+	case "$opt" in
+	s|single|1)
+		SINGLEMODE=yes ;;
+	console=*)
+		CONSOLE="$CONSOLE ${opt#console=}";;
+	debug_init)
+		set -x;;
+	alpine_dev|autodetect|autoraid|chart|cryptroot|debug_init|dma|init_args|keep_apk_new|modules|ovl_dev|pkgs|quiet|root_size|root|usbdelay)
+		case "$opt" in
+		*=*)    eval "KOPT_${opt%%=*}='${opt#*=}'";;
+		no*)    eval "KOPT_${opt#no}=no";;
+		*)      eval "KOPT_$opt=yes";;
+		esac
 	esac
-	shift
 done
 
-# enable debugging if requested
-[ -n "$KOPT_debug_init" ] && set -x
-
 # pick first keymap if found
 for map in /etc/keymap/*; do
 	if [ -f "$map" ]; then

-nc

---

---

From: Natanael Copa <[email-masked]>
Date: Wed, 27 Feb 2013 11:43:28 +0100

On Tue, 26 Feb 2013 22:20:40 +0100

> +		*)      eval "KOPT_$opt=yes";;

Will not work due to things like nochart noquiet. :-/

Anyone have better ideas?

-nc

---