Skip to content

Commit 50a2da4

Browse files
ahesfordzdykstra
andcommitted
General fixes to support busybox in mkinitcpio images
Co-authored-by: Zach Dykstra <[email protected]> Co-authored-by: Andrew J. Hesford <[email protected]>
1 parent 1fe8c4c commit 50a2da4

File tree

3 files changed

+81
-42
lines changed

3 files changed

+81
-42
lines changed

90zfsbootmenu/bin/zfs-chroot

Lines changed: 69 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
11
#!/bin/bash
22
# vim: softtabstop=2 shiftwidth=2 expandtab
33

4+
_mnt=()
5+
6+
cleanup() {
7+
for _fs in "${_mnt[@]}"; do
8+
umount "${_fs}" || zerror "unable to unmount ${_fs}"
9+
done
10+
11+
_mnt=()
12+
trap - HUP INT QUIT ABRT EXIT
13+
}
14+
415
# shellcheck disable=SC1091
516
source /lib/profiling-lib.sh >/dev/null 2>&1
17+
# shellcheck disable=SC1091
618
source /etc/zfsbootmenu.conf 2>&1 || exit 1
19+
# shellcheck disable=SC1091
720
source /lib/kmsg-log-lib.sh >/dev/null 2>&1 || exit 1
21+
# shellcheck disable=SC1091
822
source /lib/zfsbootmenu-core.sh >/dev/null 2>&1 || exit 1
923

1024
selected="${1}"
@@ -13,45 +27,61 @@ zdebug "started with ${selected}"
1327

1428
[ -n "${selected}" ] || exit 0
1529

16-
if mountpoint="$( allow_rw=yes mount_zfs "${selected}" )"; then
17-
zdebug "mounted ${selected} to ${mountpoint}"
18-
mount -t proc proc "${mountpoint}/proc"
19-
mount -t sysfs sys "${mountpoint}/sys"
20-
mount -B /dev "${mountpoint}/dev"
21-
mount -B /tmp "${mountpoint}/tmp"
22-
mount -t devpts pts "${mountpoint}/dev/pts"
23-
24-
pool="${selected%%/*}"
25-
26-
# Snapshots and read-only pools always produce read-only mounts
27-
if is_snapshot "${selected}" || ! is_writable "${pool}"; then
28-
writemode="$( colorize green "read-only")"
29-
else
30-
writemode="$( colorize red "read/write")"
31-
fi
32-
33-
_SHELL=
34-
if [ -x "${mountpoint}/bin/bash" ] \
30+
if ! mountpoint="$( allow_rw=yes mount_zfs "${selected}" )"; then
31+
zerror "failed to mount ${selected}"
32+
exit 1
33+
fi
34+
35+
# Track submounts so we know how to clean up on exit
36+
trap cleanup HUP INT QUIT ABRT EXIT
37+
_mnt=( "${mountpoint}" )
38+
39+
zdebug "mounted ${selected} to ${mountpoint}"
40+
41+
mount -B /tmp "${mountpoint}/tmp" \
42+
&& _mnt=( "${mountpoint}/tmp" "${_mnt[@]}" )
43+
44+
mount -t proc proc "${mountpoint}/proc" \
45+
&& _mnt=( "${mountpoint}/proc" "${_mnt[@]}" )
46+
47+
mount -t sysfs sys "${mountpoint}/sys" \
48+
&& _mnt=( "${mountpoint}/sys" "${_mnt[@]}" )
49+
50+
mount -B /dev "${mountpoint}/dev" \
51+
&& _mnt=( "${mountpoint}/dev" "${_mnt[@]}" )
52+
53+
# Not all /dev filesystems have /dev/pts
54+
[ -d "${mountpoint}/dev/pts" ] \
55+
&& mount -t devpts pts "${mountpoint}/dev/pts" \
56+
&& _mnt=( "${mountpoint}/dev/pts" "${_mnt[@]}" )
57+
58+
pool="${selected%%/*}"
59+
60+
# Snapshots and read-only pools always produce read-only mounts
61+
if is_snapshot "${selected}" || ! is_writable "${pool}"; then
62+
writemode="$( colorize green "read-only")"
63+
else
64+
writemode="$( colorize red "read/write")"
65+
fi
66+
67+
_SHELL=
68+
if [ -x "${mountpoint}/bin/bash" ] \
3569
&& chroot "${mountpoint}" /bin/bash -c "exit 0" >/dev/null 2>&1 ; then
36-
_SHELL="/bin/bash"
37-
chroot_extra="--norc"
38-
elif [ -x "${mountpoint}/bin/sh" ] \
70+
_SHELL="/bin/bash"
71+
chroot_extra="--norc"
72+
elif [ -x "${mountpoint}/bin/sh" ] \
3973
&& chroot "${mountpoint}" /bin/sh -c "exit 0" >/dev/null 2>&1 ; then
40-
_SHELL="/bin/sh"
41-
else
42-
zerror "unable to test execute a shell in ${selected}"
43-
fi
44-
45-
if [ -n "${_SHELL}" ]; then
46-
echo -e "$( colorize orange "${selected}") is mounted ${writemode}, /tmp is shared and read/write\n"
47-
48-
# regardless of shell, set PS1
49-
if ! env "PS1=$( colorize orange "${selected}") \w > " chroot "${mountpoint}" "${_SHELL}" "${chroot_extra}" ; then
50-
zdebug "chroot ${selected}:${_SHELL} returned code $?"
51-
fi
52-
fi
53-
54-
if ! umount -R "${mountpoint}"; then
55-
zerror "unable to unmount ${mountpoint}"
56-
fi
74+
_SHELL="/bin/sh"
75+
fi
76+
77+
if [ -z "${_SHELL}" ]; then
78+
zerror "unable to test execute a shell in ${selected}"
79+
exit 1
80+
fi
81+
82+
echo -e "$( colorize orange "${selected}") is mounted ${writemode}, /tmp is shared and read/write\n"
83+
84+
# regardless of shell, set PS1
85+
if ! env "PS1=$( colorize orange "${selected}") \w > " chroot "${mountpoint}" "${_SHELL}" "${chroot_extra}" ; then
86+
zdebug "chroot ${selected}:${_SHELL} returned code $?"
5787
fi

90zfsbootmenu/bin/zlogtail

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,10 @@ fuzzy_default_options+=(
1010

1111
export FZF_DEFAULT_OPTS="${fuzzy_default_options[*]}"
1212

13-
# shellcheck disable=SC2086
14-
dmesg --notime -f user,daemon -l err,warn | ${FUZZYSEL}
13+
# Try to use feature flags found on dmesg from util-linux
14+
if output="$( dmesg --notime -f user -l err,warn 2>/dev/null )" ; then
15+
echo "${output}" | ${FUZZYSEL}
16+
else
17+
# fall back to manually parsing dmesg output; will show all ZBM generated logs up to zinfo level
18+
dmesg | awk '/ZFSBootMenu:/{ for (i=3; i<=NF; i++){ printf("%s ", $i)}; printf "\n" }' | ${FUZZYSEL}
19+
fi

90zfsbootmenu/bin/ztrace

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#!/bin/bash
2-
#shellcheck disable=SC2086
2+
3+
# Unusable for now with busybox-provided dmesg/less
4+
if ! dmesg -T --time-format reltime -f user -l 7 >/dev/null 2>&1 ; then
5+
exit 0
6+
fi
37

48
r="\033[0;31m"
59
g="\033[0;32m"

0 commit comments

Comments
 (0)