blob: d03c3461327e90b1fba9fa027ba576cb5b6ea231 (
plain)
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
|
#!/bin/sh
umask 0022
# Defaults
keep="n"
CONFDIR="/etc/mkinitramfs"
verbose="n"
errors_to="2>/dev/null"
# BUSYBOXDIR="/usr/lib/initramfs-tools/bin/"
BUSYBOXDIR="/bin"
OPTIONS=`getopt -o d:ko:r: --long supported-host-version:,supported-target-version: -n "$0" -- "$@"`
# Check for non-GNU getopt
if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
eval set -- "$OPTIONS"
while true; do
case "$1" in
-d)
CONFDIR="$2"
shift 2
if [ ! d "${CONFDIR}" ]; then
echo "${0}: ${CONFDIR}: Not a directory" >&2
exit 1
fi
;;
-o)
touch $2
outfile="$(readlink -f "$2")"
shift 2
;;
-k)
keep="y"
shift
;;
-r)
# ignore (FIXME: manpage says differently?!?)
shift 2
;;
--supported-host-version)
supported_host_version="$2"
shift 2
;;
--supported-target-version)
supported_target_version="$2"
shift 2
;;
--)
shift
break
;;
*)
echo "Internal error!" >&2
exit 1
;;
esac
done
if [ -n "$supported_host_version" ] || [ -n "$supported_target_version" ]; then
if [ -n "$supported_host_version" ]; then
host_upstream_version="${supported_host_version%%-*}"
fi
if [ -n "$supported_target_version" ]; then
target_upstream_version="${supported_target_version%%-*}"
if dpkg --compare-versions "$target_upstream_version" lt "2.6.12"; then
exit 2
fi
fi
exit 0
fi
# For dependency ordered mkinitramfs hook scripts.
. /usr/share/initramfs-tools/scripts/functions
. /usr/share/initramfs-tools/hook-functions
. "${CONFDIR}/initramfs.conf"
if [ -z "${outfile}" ]; then
usage
fi
# And by "version" we really mean path to kernel modules
# This is braindead, and exists to preserve the interface with mkinitrd
if [ ${#} -ne 1 ]; then
version="$(uname -r)"
else
version="${1}"
fi
if dpkg --compare-versions "${version}" lt 2.6.12; then
echo "Kernel version too old. initramfs-tools requires at least 2.6.12."
exit 1
fi
case "${version}" in
/lib/modules/*/[!/]*)
;;
/lib/modules/[!/]*)
version="${version#/lib/modules/}"
version="${version%%/*}"
;;
esac
case "${version}" in
*/*)
echo "$PROG: ${version} is not a valid kernel version" >&2
exit 1
;;
esac
if [ -d "${outfile}" ]; then
echo "${outfile} is a directory"
exit 1
fi
MODULESDIR="/lib/modules/${version}"
if [ ! -e "${MODULESDIR}" ]; then
echo "Cannot find ${MODULESDIR}"
exit 1
fi
DESTDIR="$(mktemp -t -d mkinitramfs_XXXXXX)" || exit 1
__TMPCPIOGZ="$(mktemp -t mkinitramfs-OL_XXXXXX)" || exit 1
# Export environment for hook scripts.
#
export MODULESDIR
export version
export CONFDIR
export DESTDIR
# Private, used by 'catenate_cpiogz'.
export __TMPCPIOGZ
for d in bin conf etc lib modules sbin scripts; do
mkdir -p "${DESTDIR}/${d}"
done
# MODULES=list case. Always honour.
for x in "${CONFDIR}/modules" /usr/share/initramfs-tools/modules.d/*; do
if [ -f "${x}" ]; then
add_modules_from_file "${x}"
fi
done
if [ "${MODULES}" = "dep" ]; then
dep_add_modules
fi
if [ "${MODULES}" = "most" ]; then
auto_add_modules
fi
# Have to do each file, because cpio --dereference doesn't recurse down
# symlinks.
cp /usr/share/initramfs-tools/init "${DESTDIR}/init"
cp -a /usr/share/initramfs-tools/scripts/* "${DESTDIR}/scripts"
for f in $(cd /etc/mkinitramfs/scripts && \
find . \( -name '*.dpkg*' -prune -o -name '*~' -prune \) \
-o -type f -print); do
mkdir --parents "${DESTDIR}/scripts/$(dirname "${f}")"
cp -p "/etc/mkinitramfs/scripts/${f}" "${DESTDIR}/scripts/$(dirname "${f}")"
done
cp "${CONFDIR}/initramfs.conf" "${DESTDIR}/conf"
cp -a /etc/udev "${DESTDIR}/etc"
# udev
cp /sbin/udev "${DESTDIR}/sbin"
cp /sbin/udevd "${DESTDIR}/sbin"
cp /sbin/udevsynthesize "${DESTDIR}/sbin"
cp -a /lib/hotplug "${DESTDIR}/lib"
# Busybox
cp "${BUSYBOXDIR}/busybox" "${DESTDIR}/bin/busybox"
# Modutils
cp /sbin/modprobe "${DESTDIR}/sbin"
cp /sbin/depmod "${DESTDIR}/sbin"
cp /sbin/rmmod "${DESTDIR}/sbin"
mkdir -p "${DESTDIR}/etc/modprobe.d"
cp /etc/modprobe.d/aliases "${DESTDIR}/etc/modprobe.d"
# Raid
cp /sbin/mdadm "${DESTDIR}/sbin"
cp /sbin/mdrun "${DESTDIR}/sbin"
# LVM
cp /lib/lvm-200/vgchange "${DESTDIR}/sbin"
run_scripts /usr/share/initramfs-tools/hooks
run_scripts /etc/mkinitramfs/hooks
mklibs-copy -d "${DESTDIR}/lib" --root="${DESTDIR}" $(find "${DESTDIR}" -type f -perm +0111 -o -name '*.so')
ln -s /usr/lib/klibc/bin/* "${DESTDIR}/bin"
ln -s /usr/lib/klibc/lib/* "${DESTDIR}/lib"
rm "${DESTDIR}/bin/sh"
ln -s busybox "${DESTDIR}/bin/sh"
# Apply DSDT to initramfs
if [ -e "${CONFDIR}/DSDT.aml" ]; then
cp "${CONFDIR}/DSDT.aml" "${DESTDIR}"
fi
(cd "${DESTDIR}" && find . | cpio --quiet --dereference -o -H newc | gzip -9 >"${outfile}")
if [ -s "${__TMPCPIOGZ}" ]; then
cat "${__TMPCPIOGZ}" >>"${outfile}"
fi
if [ "${keep}" = "y" ]; then
echo "Working files in ${DESTDIR} and overlay in ${__TMPCPIOGZ}"
else
rm -rf "${DESTDIR}"
rm -rf "${__TMPCPIOGZ}"
fi
exit 0
|