aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCem Keylan <cem@ckyln.com>2020-05-20 13:01:16 +0300
committerCem Keylan <cem@ckyln.com>2020-05-20 13:01:16 +0300
commita64b09d741a61771bd08a944ac60419f0fb9d058 (patch)
tree04da513938543da0e9582fef63560153f9e97e2c
parent3c1b9add8d8dd305106cddec18f1175511aecbe7 (diff)
downloadinit-a64b09d741a61771bd08a944ac60419f0fb9d058.tar.gz
init: primitive parsing of the command line
-rwxr-xr-xrc.boot12
-rw-r--r--rc.lib22
2 files changed, 31 insertions, 3 deletions
diff --git a/rc.boot b/rc.boot
index e0d9951..7d12a78 100755
--- a/rc.boot
+++ b/rc.boot
@@ -38,6 +38,10 @@ out "Mounting pseudo filesystems..."; {
mnt /dev/shm -o mode=1777,nosuid,nodev -nt tmpfs shm
}
+out "Parsing kernel commandline..."; {
+ parse_cmdline
+}
+
[ "$dmesg_level" ] && {
out "Setting dmesg level..."
dmesg -n$dmesg_level
@@ -55,12 +59,14 @@ out "Remounting rootfs as read-only..."; {
mount -o remount,ro / || shell
}
-out "Checking filesystems..."; {
- fsck -ATat noopts=_netdev
+[ "$FASTBOOT" = 1 ] || {
+ out "Checking filesystems..."
+ fsck "-ATat${FORCEFSCK}" noopts=_netdev
[ $? -gt 1 ] && shell
}
-out "Mounting rootfs read-write..."; {
+[ "$RO" = "1" ] || {
+ out "Mounting rootfs read-write..."
mount -o remount,rw / || shell
}
diff --git a/rc.lib b/rc.lib
index e0ee61f..7d5068d 100644
--- a/rc.lib
+++ b/rc.lib
@@ -39,3 +39,25 @@ random() {
esac
}
+parse_cmdline() {
+ # This is a primitive way of parsing kernel command line
+ # options. Before now, carbs-init ignored these options
+ # set by the user. More will be added as needed. Init scripts
+ # don't need to handle most of the command line options
+ # as the kernel deals with most of them, but not things
+ # such as mount options.
+ [ -r /proc/cmdline ] || {
+ err "Kernel command line options cannot be parsed"
+ shell
+ }
+
+ # We want to read words instead of lines here.
+ # shellcheck disable=2013
+ for arg in $(cat /proc/cmdline); do
+ case "$arg" in
+ ro) RO=1 ;;
+ forcefsck) FORCEFSCK="-f" ;;
+ fastboot) FASTBOOT=1 ;;
+ esac
+ done
+}