51 lines
1.3 KiB
Bash
51 lines
1.3 KiB
Bash
set -ex -p pipefail
|
|
echo "Building initram disk"
|
|
mkdir -p $out/root
|
|
pushd $out/root
|
|
|
|
### copy rootfs
|
|
cp -prP $rootfs/* .
|
|
find . -type d -exec chmod 755 {} \;
|
|
mkdir sysroot
|
|
|
|
### create directories
|
|
ln -sf ../usr/lib/systemd/systemd init
|
|
|
|
### Create needed files
|
|
echo patos > ./etc/hostname
|
|
|
|
ln -sf /etc/os-release ./etc/initrd-release
|
|
|
|
# set default target to initrd inside initrd
|
|
ln -sf initrd.target ./usr/lib/systemd/system/default.target
|
|
|
|
# generate crypttab and fstab under /run
|
|
mkdir ./usr/lib/systemd/system/systemd-repart.service.d
|
|
cat <<EOF > ./usr/lib/systemd/system/systemd-repart.service.d/override.conf
|
|
[Unit]
|
|
After=sysroot-run.mount
|
|
Requires=sysroot-run.mount
|
|
|
|
[Service]
|
|
ExecStart=systemd-repart --dry-run=no --generate-crypttab=/run/crypttab --generate-fstab=/run/fstab
|
|
EOF
|
|
|
|
# bind mount /run to /sysroot/run
|
|
cat <<EOF > ./usr/lib/systemd/system/sysroot-run.mount
|
|
[Unit]
|
|
Before=initrd-fs.target
|
|
DefaultDependencies=false
|
|
|
|
[Mount]
|
|
Options=bind
|
|
What=/run
|
|
Where=/sysroot/run
|
|
EOF
|
|
mkdir ./usr/lib/systemd/system/initrd-fs.target.requires/
|
|
ln -sf ../sysroot-run.mount ./usr/lib/systemd/system/initrd-fs.target.requires/sysroot-run.mount
|
|
|
|
# gen initrd
|
|
find . -print0 | cpio --null --owner=root:root -o --format=newc | xz -9 --check=crc32 > ../initrd.xz
|
|
|
|
popd
|
|
rm -rf $out/root
|