-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
udm-mkinitramfs
executable file
·81 lines (66 loc) · 1.63 KB
/
udm-mkinitramfs
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
#!/bin/bash
# Bash script for building an initial ram disk for custom kernels.
#
# Copyright (C) 2021 Fabian Mastenbroek.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
set -e
## Command line interface
usage()
{
cat << EOF
Usage: $0 -o outfile [version]
Options:
-o outfile Write to outfile.
See udm-mkinitramfs(8) for further details.
EOF
}
OUT_FILE=
[ $# -eq 0 ] && usage && exit 1
while getopts ":ho:" arg; do
case $arg in
o)
OUT_FILE=$OPTARG
;;
h | *) # Display help.
usage
exit 0
;;
esac
done
shift $((OPTIND - 1))
if [ ${#} -ne 1 ]; then
KERNEL_VERSION="$(uname -r)"
else
KERNEL_VERSION="$1"
fi
if [ -z "$OUT_FILE" ]; then
OUT_FILE=/boot/initramfs-"$KERNEL_VERSION".gz
fi
BUILD_DIR=$(mktemp -d -t initramfs-XXXX)
BUSYBOX_PATH=/bin/busybox
KMOD_PATH=/bin/kmod
TOOLS_PATH=/usr/lib/udm-kernel-tools
mkdir -p "$BUILD_DIR"/initramfs
cd "$BUILD_DIR"/initramfs
mkdir -p bin sbin etc proc sys usr/bin usr/sbin overlay root
touch etc/mdev.conf
# Copy over kernel modules
mkdir -p lib/modules
if [ -d /lib/modules/"$KERNEL_VERSION" ]; then
cp -r /lib/modules/"$KERNEL_VERSION" lib/modules
else
echo "No modules found for kernel $KERNEL_VERSION"
fi
cp $KMOD_PATH bin/kmod
cp $BUSYBOX_PATH bin/busybox
ln -s busybox bin/sh
cp $TOOLS_PATH/udm-init init
chmod +x init
# Build the compressed initramfs
find . | cpio -H newc -o > ../initramfs.cpio
cd ..
gzip -c initramfs.cpio > "$OUT_FILE"