-
Notifications
You must be signed in to change notification settings - Fork 3
/
stage4-bootstrap.sh
executable file
·177 lines (147 loc) · 5.26 KB
/
stage4-bootstrap.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/bin/bash -
# Firstboot script to build the stage4.
hostname stage4-builder
echo stage4-builder.fedoraproject.org > /etc/hostname
echo
echo "This is the stage4 disk image automatic builder"
echo
exec >& /build.log
# Clean the dnf cache.
dnf clean all
# Cleanup function called on failure or exit.
cleanup ()
{
set +e
# Sync disks and shut down.
sync
sleep 5
sync
# systemd poweroff is buggy, force immediate poweroff instead:
poweroff -f
}
trap cleanup INT QUIT TERM EXIT ERR
set -e
set -x
rm -f /var/tmp/stage4-disk.img
rm -f /var/tmp/stage4-disk.img-t
rm -rf /var/tmp/mnt
# Create a template disk image.
truncate -s 4G /var/tmp/stage4-disk.img-t
mkfs -t ext4 /var/tmp/stage4-disk.img-t
# Create the installroot.
mkdir /var/tmp/mnt
mount -o loop /var/tmp/stage4-disk.img-t /var/tmp/mnt
mkdir /var/tmp/mnt/{dev,proc,sys}
mount -o rbind /dev /var/tmp/mnt/dev
mount -o rbind /proc /var/tmp/mnt/proc
mount -o rbind /sys /var/tmp/mnt/sys
rpm --root /var/tmp/mnt --initdb
# glibc-langpack-en avoids the huge glibc-all-langpacks being used.
#
# openrdate allows us to set the clock correctly on boot.
#
# systemd-udev is apparently needed for systemd-remount-fs
#
# strict=0 is like the old --skip-broken option in yum. We can
# remove it when all @core packages are available.
dnf -y --releasever=28 --installroot=/var/tmp/mnt --setopt=strict=0 \
install \
@core \
@buildsys-build \
/usr/bin/ssh-keygen \
/usr/sbin/sshd \
glibc-langpack-en \
lsof \
nano \
openrdate \
python3-dnf-plugin-versionlock \
systemd-udev \
vim-minimal
# Do some configuration within the chroot.
# Write an fstab for the chroot.
cat > /var/tmp/mnt/etc/fstab <<EOF
/dev/root / ext4 defaults 0 0
EOF
# Set the hostname.
echo stage4.fedoraproject.org > /var/tmp/mnt/etc/hostname
# Copy in the welcome message.
cp /var/tmp/issue /var/tmp/mnt/etc/issue
cp /var/tmp/issue /var/tmp/mnt/etc/issue.net
# Copy local.repo in.
cp /var/tmp/local.repo /var/tmp/mnt/etc/yum.repos.d
# Enable systemd-networkd.
cp /var/tmp/50-wired.network /var/tmp/mnt/etc/systemd/network/
# Use Google's nameservers for DNS resolution.
rm -f /var/tmp/mnt/etc/resolv.conf
echo 'nameserver 8.8.4.4' > /var/tmp/mnt/etc/resolv.conf
# Copy in the rdate.service file.
cp /var/tmp/rdate.service /var/tmp/mnt/etc/systemd/system/
# Enable some systemd services.
chroot /var/tmp/mnt \
systemctl enable rdate sshd systemd-networkd
# systemd starts serial consoles on /dev/ttyS0 and /dev/hvc0. The
# only problem is they are the same serial console. Mask one.
chroot /var/tmp/mnt \
systemctl mask [email protected]
# Disable public repos, they don't serve riscv64 packages anyway.
chroot /var/tmp/mnt \
dnf config-manager --set-disabled rawhide updates updates-testing fedora
# Lock GCC 7.3.1 in place so that later versions won't be installed
# automatically. Yes unfortunately we have to list every package
# here. We can remove this when we move to building only Fedora 28 +
# Rawhide.
chroot /var/tmp/mnt \
dnf versionlock add \
cpp-7.3.1-5.2.riscv64.fc28 \
gcc-7.3.1-5.2.riscv64.fc28 \
gcc-c++-7.3.1-5.2.riscv64.fc28 \
gcc-gdb-plugin-7.3.1-5.2.riscv64.fc28 \
gcc-gfortran-7.3.1-5.2.riscv64.fc28 \
gcc-objc-7.3.1-5.2.riscv64.fc28 \
gcc-objc++-7.3.1-5.2.riscv64.fc28 \
gcc-plugin-devel-7.3.1-5.2.riscv64.fc28 \
libatomic-7.3.1-5.2.riscv64.fc28 \
libatomic-static-7.3.1-5.2.riscv64.fc28 \
libgcc-7.3.1-5.2.riscv64.fc28 \
libgccjit-7.3.1-5.2.riscv64.fc28 \
libgccjit-devel-7.3.1-5.2.riscv64.fc28 \
libgfortran-7.3.1-5.2.riscv64.fc28 \
libgfortran-static-7.3.1-5.2.riscv64.fc28 \
libgomp-7.3.1-5.2.riscv64.fc28 \
libobjc-7.3.1-5.2.riscv64.fc28 \
libstdc++-7.3.1-5.2.riscv64.fc28 \
libstdc++-devel-7.3.1-5.2.riscv64.fc28 \
libstdc++-static-7.3.1-5.2.riscv64.fc28
# Clean DNF cache in the chroot. This forces the first run of DNF
# by the new machine to refresh the cache and not use the stale
# data from the build environment.
chroot /var/tmp/mnt \
dnf clean all
# Set a root password ('riscv').
echo riscv |
chroot /var/tmp/mnt \
passwd root --stdin --force
# List all the packages which were installed in the chroot
# so they appear in the build.log.
chroot /var/tmp/mnt rpm -qa | sort
# As a last resort, fail if certain commands or files are not
# installed in the chroot which are required to build the next stage4
# or for general basic operation. This is just a backup in case
# things have gone very wrong above.
test -f /var/tmp/mnt/lib64/libc.so.6
test -f /var/tmp/mnt/usr/bin/dbus-daemon
test -f /var/tmp/mnt/usr/bin/dnf
test -f /var/tmp/mnt/usr/bin/mount
test -f /var/tmp/mnt/usr/sbin/init
test -f /var/tmp/mnt/usr/sbin/ip
test -f /var/tmp/mnt/usr/sbin/sshd
# Unmount the chroot.
sync
sleep 5
kill -HUP `lsof -t /var/tmp/mnt` ||:
umount -lR /var/tmp/mnt
# Disk image is built, so move it to the final filename.
# guestfish downloads this, but if it doesn't exist, guestfish
# fails indicating the earlier error.
mv /var/tmp/stage4-disk.img-t /var/tmp/stage4-disk.img
# cleanup() is called automatically here.