blob: b8cc10af34fd14a000e921a29d6bdf509ce0e48b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
#!/usr/bin/env bash
# -*- coding: utf-8 -*-
_parse_dracut_args() {
local verbose=false
local debug=false
while true; do
case "$1" in
--stdlog)
shift
local level="$1"
shift
[[ "$level" -ge 4 ]] && debug=true
;;
--verbose)
shift
verbose=true
;;
'')
break
;;
*)
shift
;;
esac
local level
$verbose && level=info
$debug && level=debug
done
$debug
return $?
}
# WTF does this actually do aside from taking space!
_debug=0
_parse_dracut_args ${dracut_args[*]} || _debug=$?
# endregion
clean() {
# Sourcing some helper functions
. "$(dirname "${BASH_SOURCE[0]}")/helper/build.inc"
clean_components
}
# region dracut plugin api
check() {
# Sourcing some helper functions
. "$(dirname "${BASH_SOURCE[0]}")/helper/build.inc"
if ! build_initialize_components; then
echo "Failed to initialize components."
return 1
fi
# NOTE: xmount must be compiled before qemu_xmount
local xmount_is_built=true
if [[ ! -f "$moddir/binaries/xmount/trunk/build/src/xmount" ]] ||
[[ ! -f "$moddir/binaries/qemu-xmount/libxmount_input_qemu.so" ]]; then
xmount_is_built=false
fi
# non-critical if failed
$xmount_is_built || echo "Compiling 'xmount'/'libxmount_input_qemu' failed."
if [[ ! -f "$moddir/binaries/dnbd3/build/src/kernel/dnbd3/dnbd3.ko" ]] || \
[[ ! -f "$moddir/binaries/dnbd3/build/src/client/dnbd3-client" ]]; then
CMAKE_FLAGS="-DKERNEL_BUILD_DIR=${kernel}" \
build_compile_dnbd3 "$moddir/binaries/dnbd3/"
[[ $? != 0 ]] && return 1
fi
# TODO xloop checks & remove them from installkernel
if [[ ! -f "$moddir/binaries/systemd-preserve-process-marker/systemd-preserve-process-marker" ]]; then
build_compile_systemd_preserve_process_marker \
"$moddir/binaries/systemd-preserve-process-marker/"
[[ $? != 0 ]] && return 1
fi
# TODO do we still need this ?
# NOTE: This are workarounds for:
# - distributions where "systemd-udevd" doesn't lives in "/usr/lib" but in
# "/lib".
local alternate_systemd_udevd_location='/lib/systemd/systemd-udevd'
if [[ ! -f "${systemdutildir}/systemd-udevd" ]] && \
[[ -f "$alternate_systemd_udevd_location" ]]; then
mkdir --parents "${initdir}${systemdutildir}"
ln --symbolic --force "$alternate_systemd_udevd_location" \
"${initdir}${systemdutildir}/systemd-udevd"
fi
# WTF?
# - "/usr/bin/sh" isn't available but "/bin/sh".
if [[ ! -f /usr/bin/sh ]] && [[ -f /bin/sh ]]; then
ln --symbolic --force /bin/sh /usr/bin/sh
fi
return 255
}
depends() {
echo base bash kernel-modules shutdown slx-dmsetup slx-network
}
installkernel() {
local extra_kmod_dir="/lib/modules/${kernel}/extra"
# dnbd3
mkdir -p "${initdir}/${extra_kmod_dir}"
inst "${moddir}/binaries/dnbd3/build/src/kernel/dnbd3/dnbd3.ko" "${extra_kmod_dir}/dnbd3.ko"
# kqcow2 kernel
local xloop_kmod_build_dir="${moddir}/binaries/xloop/build/src/kernel"
for mod in xloop xloop_file_fmt_raw xloop_file_fmt_qcow; do
if [ ! -e "${xloop_kmod_build_dir}/${mod}/${mod}.ko" ]; then
derror "Failed to find '$mod' in '$xloop_kmod_build_dir'."
continue
# TODO fatal fail once we move completely to xloop
fi
inst "${xloop_kmod_build_dir}/${mod}/${mod}.ko" "${extra_kmod_dir}/${mod}.ko"
done
}
install() {
# region binaries
inst "${moddir}/binaries/dnbd3/build/src/client/dnbd3-client" /usr/local/bin/dnbd3-client
inst "${moddir}/binaries/systemd-preserve-process-marker/systemd-preserve-process-marker" \
/usr/local/bin/systemd-preserve-process-marker
# xmount
local \
xmount_installation="${moddir}/binaries/xmount/trunk/build/release_build"
if [ -f "${xmount_installation}/usr/bin/xmount" ]; then
inst "${xmount_installation}/usr/bin/xmount" /usr/bin/xmount
for file in ${xmount_installation}/usr/lib/xmount/*; do
inst "$file" /usr/lib/xmount/"$(basename "$file")"
done
inst "$moddir/binaries/qemu-xmount/libxmount_input_qemu.so" \
/usr/lib/xmount/libxmount_input_qemu.so
# HACK fix missing libraries for some xmount input libs
# TODO copy the dependencies using dracut functions...
inst_libdir_file 'libafflib.so*'
inst_libdir_file 'libewf.so*'
fi
# xlosetup
local xlosetup_build_path="${moddir}/binaries/xloop/build/src/utils/sys-utils/xlosetup"
if [ -f "$xlosetup_build_path" ]; then
inst "$xlosetup_build_path" /usr/local/bin/xlosetup
fi
local xloop_udev_rule="${moddir}/binaries/xloop/src/kernel/udev/50-xloop.rules"
if [ -f "$xloop_udev_rule" ]; then
inst "$xloop_udev_rule" "/etc/udev/rules.d/${xloop_udev_rule##*/}"
fi
# endregion
# region hooks
#inst_hook cmdline 00 "$moddir/hooks/enable-sysrq.sh"
# NOTE: Can be used to support old style ip append syntax and have an
# exclusive interface name - required when using dracut's regular
# 'network' module
dracut_module_included "network" && inst_hook cmdline 10 \
"$moddir/hooks/prepare-kernel-command-line-parameter.sh"
inst_hook cmdline 90 "$moddir/hooks/set-dracut-environment-variables.sh"
# make the final blockdevice for the root system (dnbd3 -> xmount ->
# device-mapper)
slx_service "s3-dnbd3root" "Setup dnbd3-based block device of rootfs" \
--after "s3-fetch-config.service" \
--after "dracut-pre-mount.service" \
--wbefore "dracut-mount.service" \
--wbefore "initrd-root-device.target"
# Mount the root file system
slx_service "s3-mount-root" "Mount /sysroot" \
--after "initrd-root-device.target" \
--requires "initrd-root-device.target" \
--wbefore "initrd-root-fs.target"
slx_service "s3-write-fstab" "Write final fstab for stage4" \
--after "s3-mount-root.service"
# Copy systemd services to new root (so they don't get killed after
# switch_root)
inst_hook pre-pivot 90 \
"$moddir/hooks/copy-dracut-systemd-files-into-newroot.sh"
# endregion
# region configuration files
mkdir --parents \
"${initdir}/etc/systemd/system.conf.d"
# Make sure all services know about NEWROOT=/sysroot
inst "$moddir/configuration/systemd-newroot.conf" \
"/etc/systemd/system.conf.d/systemd-newroot.conf"
# Use terminal readline settings from the template system.
inst /etc/inputrc /etc/inputrc
# Set some aliases for the initramfs context.
if [[ "$_debug" == 0 ]]; then
inst "$moddir/configuration/bash" '/etc/bash.bashrc'
inst "$moddir/configuration/bash" '/etc/profile.d/aliases'
fi
# endregion
# check if busybox can offer a desired tool (and desired features)
# before adding anything here.
inst_multiple \
bash \
curl \
dmsetup \
grep \
insmod \
lsblk \
mount
}
|