]> git.proxmox.com Git - proxmox-backup-restore-image.git/blob - src/build_initramfs.sh
build initramfs: add busybox to base image as well
[proxmox-backup-restore-image.git] / src / build_initramfs.sh
1 #!/bin/sh
2
3 set -e
4
5 ROOT="root"
6 BUILDDIR="build/initramfs"
7 INIT="../../init-shim-rs/target/x86_64-unknown-linux-gnu/release/init-shim-rs"
8
9 echo "Using build dir: $BUILDDIR"
10 rm -rf "$BUILDDIR"
11 mkdir -p "$BUILDDIR"
12 if [ -d pkgs ]; then
13 echo "copying package cache into build-dir"
14 cp -a pkgs "$BUILDDIR/pkgs"
15 fi
16 cd "$BUILDDIR"
17 mkdir "$ROOT"
18
19 # adds necessary packages to initramfs build root folder
20 add_pkgs() {
21 debdir=$2
22
23 if [ -z "$NO_DOWNLOAD" ]; then
24 DEPS=""
25 for pkg in $1; do
26 printf " getting reverse dependencies for '%s'" "$pkg"
27 LOCAL_DEPS=$(apt-rdepends -f Depends -s Depends "$pkg" | grep -v '^ ')
28 DEPS="$DEPS $LOCAL_DEPS"
29 done
30 # debconf and gcc are unnecessary, libboost-regex doesn't install on bullseye
31 DEPS=$(echo "$DEPS" |\
32 sed -E 's/debconf(-2\.0)?//g' |\
33 sed -E 's/libboost-regex//g' |\
34 sed -E 's/gcc-.{1,2}-base//g')
35
36 if [ ! -d "pkgs/$debdir" ]; then
37 mkdir -p "pkgs/$debdir"
38 fi
39
40 if [ -n "$DEPS" ]; then
41 (cd "pkgs/$debdir"; apt-get download $DEPS)
42 fi
43 fi
44 if [ -z "$DOWNLOAD_ONLY" ]; then
45 for deb in pkgs/$debdir/*.deb; do
46 dpkg-deb -x "$deb" "$ROOT"
47 done
48 fi
49 }
50
51 make_cpio() {
52 echo "creating CPIO archive '$1'"
53 fakeroot -- sh -c "
54 cd '$ROOT';
55 find . -print0 | cpio --null -oV --format=newc -F ../$1
56 "
57 }
58
59 if [ -z "$DOWNLOAD_ONLY" ]; then
60 echo "copying init"
61 cp $INIT "$ROOT/init"
62 chmod a+x "$ROOT/init" # just to be sure
63
64 # tell daemon it's running in the correct environment
65 touch "$ROOT/restore-vm-marker"
66 fi
67
68 echo "getting base dependencies"
69
70 add_pkgs "
71 busybox:amd64 \
72 libstdc++6:amd64 \
73 libssl3:amd64 \
74 libacl1:amd64 \
75 libblkid1:amd64 \
76 libuuid1:amd64 \
77 zlib1g:amd64 \
78 libzstd1:amd64 \
79 liblz4-1:amd64 \
80 liblzma5:amd64 \
81 libgcrypt20:amd64 \
82 libtirpc3:amd64 \
83 lvm2:amd64 \
84 thin-provisioning-tools:amd64 \
85 " 'base'
86
87 if [ -z "$DOWNLOAD_ONLY" ]; then
88
89 echo "install ZFS tool"
90 # install custom ZFS tools (built without libudev)
91 mkdir -p "$ROOT/sbin"
92 cp -a ../zfstools/sbin/* "$ROOT/sbin/"
93 cp -a ../zfstools/etc/* "$ROOT/etc/"
94 cp -a ../zfstools/lib/* "$ROOT/lib/"
95 cp -a ../zfstools/usr/* "$ROOT/usr/"
96
97 echo "cleanup unused data from base dependencies"
98 rm -rf ${ROOT:?}/usr/share # contains only docs and debian stuff
99 rm -rf ${ROOT:?}/usr/local/include # header files
100 rm -rf ${ROOT:?}/usr/local/share # mostly ZFS tests
101 rm -f ${ROOT:?}/lib/x86_64-linux-gnu/*.a # static libraries
102
103 make_cpio "initramfs.img"
104 fi
105
106 echo "getting extra/debug dependencies"
107
108 # add debug helpers for debug initramfs, packages from above are included too
109 add_pkgs "
110 util-linux:amd64 \
111 gdb:amd64 \
112 strace:amd64 \
113 " 'debug'
114
115 if [ -z "$DOWNLOAD_ONLY" ]; then
116 # leave /usr/share here, it contains necessary stuff for gdb
117 make_cpio "initramfs-debug.img"
118 fi