summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Ball <nullspoon@iohq.net>2016-01-16 12:06:11 -0700
committerAaron Ball <nullspoon@iohq.net>2016-01-25 20:53:56 -0700
commitc62aa8b7e7b625ab7a4c318195c61edd2779a1dd (patch)
treef46a4d939991528c7910ecfe3bdb19cbbbded9d0
parentdc556a1f70f80b986b0d5f86afca527e06f97f7d (diff)
downloadmkinitramfs-c62aa8b7e7b625ab7a4c318195c61edd2779a1dd.tar.gz
mkinitramfs-c62aa8b7e7b625ab7a4c318195c61edd2779a1dd.tar.xz
More updates to init scriptv1.0
Now has logging function that supports initdebug cmdline option. Renamed get_root_dev to parse_cmdline, since this function is used to parse cmdline arguments now. Added initdebug argument support to new parse_cmdline function Fixed syntax error on writing failure log message Changed to global variables. Now we have DEBUG and ROOTDEV, in lieu of local rootdev. This allows the parse_cmdline function to update variables to be used by other functions without storing all the parsing code in main.
-rw-r--r--init69
1 files changed, 48 insertions, 21 deletions
diff --git a/init b/init
index 55394c7..4588b38 100644
--- a/init
+++ b/init
@@ -1,5 +1,8 @@
#!/bin/bash
+DEBUG=0
+ROOTDEV=''
+
#
# Mounts the fakeroot from the kernel "root" param
#
@@ -11,11 +14,21 @@ function mount_fakeroot {
}
+function log {
+ local msg="${1}"
+ echo -e "${msg}"
+ if [[ ${DEBUG} -ne 0 ]]; then
+ echo "Press enter to continue"
+ read
+ fi
+}
+
+
#
# Resolves the path to the root device from the cmdline root= syntax.
# Currently handles UUID syntax and /dev/sdx syntax
#
-function get_root_dev {
+function parse_cmdline {
local cmdline=${1}
dev=''
@@ -24,19 +37,23 @@ function get_root_dev {
root=*)
if [[ ${i:5:4} == 'UUID' ]]; then
#mount by uuid
- dev="/dev/disk/by-uuid/$(echo ${i} | cut -d '=' -f 3)"
+ ROOTDEV="/dev/disk/by-uuid/$(echo ${i} | cut -d '=' -f 3)"
else
# mount by dev
- dev="$(echo ${i} | cut -d '=' -f 2)"
+ ROOTDEV="$(echo ${i} | cut -d '=' -f 2)"
fi
;;
+ initdebug)
+ # Enable debug mode (this is gonna be slow
+ DEBUG=1
+ ;;
esac
done
# Return the path to the root device
- echo "${dev}"
+ #echo "${dev}"
}
-
-
+
+
#
# Returns type of partition. If part is LUKS encrypted, returns 'luks'. If
# anything else, returns 'fs'.
@@ -55,6 +72,7 @@ function get_part_type {
fi
}
+
#
# Takes an encrypted device path and executes cryptsetup luksOpen. Returns path
# to the new decrypted block device. This path takes the rough form of
@@ -69,8 +87,8 @@ function setup_encrypted {
# Notify user and wait for input on failure
if [[ $? -gt 0 ]]; then
- echo "An error was detected mounting the encrypted root." > &2
- echo "Pausing. Press enter to continue." > &2
+ echo "An error was detected mounting the encrypted root." >&2
+ echo "Pausing. Press enter to continue." >&2
read
fi
@@ -90,24 +108,33 @@ function main {
local fakeroot='/mnt/root'
- rootdev=$(get_root_dev "$(cat /proc/cmdline)")
+ if [[ ! -d ${fakeroot} ]]; then
+ log "Fake root location ${fakeroot} does not exist. Creating."
+ mkdir ${fakeroot}
+ fi
+
+ log "Parsing cmdline arguments"
- echo -e "\nRootdevice: ${rootdev}\n"
+ parse_cmdline "$(cat /proc/cmdline)"
- if [[ $(get_part_type ${rootdev}) == 'luks' ]]; then
+ log "Root device: ${ROOTDEV}"
+
+ if [[ $(get_part_type ${ROOTDEV}) == 'luks' ]]; then
# Set new rootdev location (/dev/mapper/something). This will update it to
- # the deccrypted block device path.
- echo -e "\n${rootdev} is encrypted.\n"
- rootdev=$(setup_encrypted ${rootdev})
- echo -e "\nNew rootdev: ${rootdev}\n"
+ # the decrypted block device path.
+ log "Root device ${ROOTDEV} is encrypted."
+ ROOTDEV=$(setup_encrypted ${ROOTDEV})
+ log "New rootdev: ${ROOTDEV}"
fi
-
+
# Mount the fakeroot.
- mount_fakeroot ${rootdev} ${fakeroot}
-
- # Clean up.
- umount /proc
- umount /sys
+ log "Mounting fakeroot"
+ mount_fakeroot ${ROOTDEV} ${fakeroot}
+
+ # # Clean up.
+ # # We actually don't do this because switch_root does this for us
+ # #umount /proc
+ # #umount /sys
# Boot the real McCoy
exec switch_root ${fakeroot} /sbin/init

Generated by cgit