firecracker-netns/rootf-kernel/rootfs.sh
RouxAntoine 507d7025c7
Updated
Signed-off-by: RouxAntoine <antoinroux@hotmail.fr>
2024-01-05 14:55:09 +01:00

48 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# inspired by https://github.com/oraoto/archlinux-firecracker/blob/master/scripts/build-arch-rootfs.sh
set -x
DISK_SIZE=10G
DISK_FILE=../out/arch-rootfs.ext4
DISK_ROOT=../out/mount
# Allocate rootfs disk
dd if=/dev/zero of="$DISK_FILE" bs=1M count="$DISK_SIZE"
mkfs.ext4 $DISK_FILE
# Mount rootfs to mount
mkdir -p $DISK_ROOT
sudo mount $DISK_FILE $DISK_ROOT
yes y | sudo pacstrap -i -c $DISK_ROOT bash filesystem systemd-sysvcompat pacman iproute2 git
echo "nameserver 1.1.1.1" | sudo tee $DISK_ROOT/etc/resolv.conf
sudo tee $DISK_ROOT/etc/systemd/system/internal-network.service <<-'EOF'
[Unit]
Description=Internal Network
[Service]
Type=oneshot
ExecStart=ip link set eth0 up
ExecStart=ip addr add 172.16.0.2/24 dev eth0
ExecStart=ip route add default via 172.16.0.1 dev eth0
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
EOF
sudo ln -s /etc/systemd/system/internal-network.service $DISK_ROOT/etc/systemd/system/multi-user.target.wants/
# Remove default (locked) root password
# See https://github.com/archlinux/svntogit-packages/commit/0320c909f3867d47576083e853543bab1705185b
sudo sed 's/^root:.*/root::14871::::::/' -i $DISK_ROOT/etc/shadow
sudo umount $DISK_ROOT
rmdir $DISK_ROOT