-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepare_rootfs.sh
87 lines (64 loc) · 2.24 KB
/
prepare_rootfs.sh
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
debootstrap --include=${deb_extra_packages}nano,iproute2,initramfs-tools,openssh-server,locales,xz-utils,zstd,systemd-coredump --arch=$deb_arch $deb_suite rootfs $deb_mirror || { echo >&2 "debootstrap failed." ; cat rootfs/debootstrap/debootstrap.log ; close_rootfs ; exit 1; }
root_uuid=$(blkid -s UUID -o value ${newroot}${loopdev}p1)
swap_uuid=$(blkid -s UUID -o value ${newroot}${loopdev}p2)
cat > rootfs/etc/fstab <<EOF
UUID=$root_uuid / ext2 rw,relatime 0 1
UUID=$swap_uuid none swap defaults 0 0
EOF
echo "$hostname" > rootfs/etc/hostname
rm -f rootfs/etc/motd
#
# get home directory of current user, or the user that ran sudo
#
home_dir="$HOME"
if [ -n "$SUDO_USER" ]; then
home_dir=$(eval echo ~$SUDO_USER)
fi
#
# if ssh public key exists, mark it as authorized under guest
#
if [ -e ${home_dir}/.ssh/id_rsa.pub ] ; then
mkdir -p rootfs/root/.ssh
chmod 0755 rootfs/root/.ssh
cp ${home_dir}/.ssh/id_rsa.pub rootfs/root/.ssh/authorized_keys
chmod 0600 rootfs/root/.ssh/authorized_keys
fi
cat > rootfs/etc/hosts <<EOF
127.0.0.1 localhost
127.0.1.1 $hostname.mydomain.org $hostname
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
EOF
cat > rootfs/etc/systemd/network/enp.network <<EOF
[Match]
Name=enp*
[Network]
DHCP=yes
EOF
cat > rootfs/etc/systemd/network/eth.network <<EOF
[Match]
Name=eth*
[Network]
DHCP=yes
EOF
sed -Ei 's,^# (en_US\.UTF-8 .*)$,\1,' rootfs/etc/locale.gen
sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/g' rootfs/etc/ssh/sshd_config
cat > rootfs/root/prepare_rootfs.sh <<EOF
#!/bin/bash
export DEBIAN_FRONTEND=noninteractive
dpkg-reconfigure locales
rm -f /etc/resolv.conf && echo "nameserver 8.8.8.8" > /etc/resolv.conf
systemctl enable systemd-networkd
systemctl enable systemd-resolved
systemctl enable systemd-timesyncd.service
systemctl enable sshd
echo 'root:root' | chpasswd
EOF
arch-chroot rootfs /bin/bash --login /root/prepare_rootfs.sh
rm rootfs/root/prepare_rootfs.sh
. "${source_path}/arch/${architecture}/prepare_rootfs.sh"
arch-chroot rootfs /bin/bash --login /root/prepare_rootfs_arch.sh
rm rootfs/root/prepare_rootfs_arch.sh
# do this last
ln -sf ../run/systemd/resolve/stub-resolv.conf rootfs/etc/resolv.conf