Skip to content

Commit

Permalink
some additions with initram and pysh
Browse files Browse the repository at this point in the history
  • Loading branch information
xxcosita3czxx committed Jun 12, 2024
1 parent 2f9e4c9 commit 56ae132
Show file tree
Hide file tree
Showing 294 changed files with 1,333 additions and 2 deletions.
1 change: 1 addition & 0 deletions INITRAM/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
39.2
1 change: 1 addition & 0 deletions INITRAM/bin
4 changes: 4 additions & 0 deletions INITRAM/buildconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
MODULES=(btrfs)
BINARIES=(/usr/bin/btrfs)
FILES=()
HOOKS=(base udev autodetect keyboard keymap modconf block filesystems fsck)
6 changes: 6 additions & 0 deletions INITRAM/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
MODULES="btrfs"
EARLYHOOKS="udev"
HOOKS="udev keymap"
LATEHOOKS=""
CLEANUPHOOKS="udev"
EMERGENCYHOOKS=""
Empty file added INITRAM/dev/.ignore
Empty file.
1 change: 1 addition & 0 deletions INITRAM/early_cpio
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
Empty file added INITRAM/etc/fstab
Empty file.
1 change: 1 addition & 0 deletions INITRAM/etc/initrd-release
Binary file added INITRAM/etc/ld.so.cache
Binary file not shown.
Empty file added INITRAM/etc/ld.so.conf
Empty file.
1 change: 1 addition & 0 deletions INITRAM/etc/mtab
1 change: 1 addition & 0 deletions INITRAM/etc/os-release
23 changes: 23 additions & 0 deletions INITRAM/hooks/keymap
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/ash
# SPDX-License-Identifier: GPL-2.0-only

run_hook() {
local mode ctrl

if [ -e /keymap.bin ]; then
msg -n ':: Loading keymap...'
if [ -f /keymap.utf8 ]; then
mode='-u'
ctrl='G'
else
mode='-a'
ctrl='@'
fi
kbd_mode "$mode" -C /dev/console
printf "\033%%$ctrl" >>/dev/console
loadkmap </keymap.bin
msg 'done.'
fi
}

# vim: set ft=sh ts=4 sw=4 et:
30 changes: 30 additions & 0 deletions INITRAM/hooks/udev
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/ash

run_earlyhook() {
local quiet
kmod static-nodes --format=tmpfiles --output=/run/tmpfiles.d/kmod.conf
systemd-tmpfiles --prefix=/dev --create --boot
quiet="$(getarg quiet)"
if [ "${quiet}" = "y" ]; then
/usr/lib/systemd/systemd-udevd --daemon --resolve-names=never >/dev/null 2>&1
else
/usr/lib/systemd/systemd-udevd --daemon --resolve-names=never
fi
# used externally by poll_device()
# shellcheck disable=SC2034
udevd_running=1
}

run_hook() {
msg ":: Triggering uevents..."
udevadm trigger --action=add --type=subsystems
udevadm trigger --action=add --type=devices
udevadm settle
}

run_cleanuphook() {
udevadm control --exit
udevadm info --cleanup-db
}

# vim: set ft=sh ts=4 sw=4 et:
112 changes: 112 additions & 0 deletions INITRAM/init
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#!/usr/bin/ash
# SPDX-License-Identifier: GPL-2.0-only

export PATH='/usr/local/sbin:/usr/local/bin:/usr/bin'

udevd_running=0
mount_handler=default_mount_handler
init=/boot/init
rd_logmask=0

. /init_functions

mount_setup

# parse the kernel command line
parse_cmdline </proc/cmdline

# setup logging as early as possible
rdlogger_start

disablehooks="$(getarg disablehooks)"
# busybox ash supports string replacements
# shellcheck disable=SC3060
for d in ${disablehooks//,/ }; do
[ -e "/hooks/$d" ] && chmod 644 "/hooks/$d"
done

# shellcheck disable=SC1091
. /config

# We rely on word splitting
# shellcheck disable=SC2086
run_hookfunctions 'run_earlyhook' 'early hook' $EARLYHOOKS

if [ -n "$earlymodules$MODULES" ]; then
# busybox ash supports string replacements
# shellcheck disable=SC3060,SC2086
modprobe -qab ${earlymodules//,/ } $MODULES
fi

# We rely on word splitting
# shellcheck disable=SC2086
run_hookfunctions 'run_hook' 'hook' $HOOKS

# honor the old behavior of break=y as a synonym for break=premount
break="$(getarg break)"
if [ "${break}" = "y" ] || [ "${break}" = "premount" ]; then
# shellcheck disable=SC2086
run_hookfunctions 'run_emergencyhook' 'emergency hook' $EMERGENCYHOOKS
echo ":: Pre-mount break requested, type 'exit' to resume operation"
launch_interactive_shell
fi

if rootdev="$(resolve_device "$root")"; then
# If the tag is supported by util-linux mount, pass it as is.
# Otherwise, use the resolved device path.
case "$root" in
'UUID='* | 'LABEL='* | 'PARTUUID='* | 'PARTLABEL='*) : ;;
*) root="$rootdev" ;;
esac
fi
unset rootdev

fsck_root

# Mount root at /new_root
"$mount_handler" /new_root

# We rely on word splitting
# shellcheck disable=SC2086
run_hookfunctions 'run_latehook' 'late hook' $LATEHOOKS

# We rely on word splitting
# shellcheck disable=SC2086
run_hookfunctions 'run_cleanuphook' 'cleanup hook' $CLEANUPHOOKS

if [ "$(stat -c %D /)" = "$(stat -c %D /new_root)" ]; then
# Nothing got mounted on /new_root. This is the end, we don't know what to do anymore
# We fall back into a shell, but the shell has now PID 1
# This way, manual recovery is still possible.
# shellcheck disable=SC2086
run_hookfunctions 'run_emergencyhook' 'emergency hook' $EMERGENCYHOOKS
err "Failed to mount the real root device."
echo "Bailing out, you are on your own. Good luck."
echo
launch_interactive_shell --exec
elif [ ! -x "/new_root${init}" ]; then
# Successfully mounted /new_root, but ${init} is missing
# The same logic as above applies
# shellcheck disable=SC2086
run_hookfunctions 'run_emergencyhook' 'emergency hook' $EMERGENCYHOOKS
err "Root device mounted successfully, but ${init} does not exist."
echo "Bailing out, you are on your own. Good luck."
echo
launch_interactive_shell --exec
fi

if [ "${break}" = "postmount" ]; then
# shellcheck disable=SC2086
run_hookfunctions 'run_emergencyhook' 'emergency hook' $EMERGENCYHOOKS
echo ":: Post-mount break requested, type 'exit' to resume operation"
launch_interactive_shell
fi

# this should always be the last thing we do before the switch_root.
rdlogger_stop

exec env -i \
"TERM=$TERM" \
/usr/bin/switch_root /new_root "$init" "$@"

# vim: set ft=sh ts=4 sw=4 et:
Loading

0 comments on commit 56ae132

Please sign in to comment.