/
stage4-build-init.sh
executable file
·135 lines (106 loc) · 3.49 KB
/
stage4-build-init.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
#!/bin/bash -
# Init script installed in stage3 disk image.
# Set up the PATH.
PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin
export PATH
# Root filesystem is mounted as ro, remount it as rw.
mount -o remount,rw /
# Mount standard filesystems.
mount -t proc /proc /proc
mount -t sysfs /sys /sys
mount -t tmpfs -o "nosuid,size=20%,mode=0755" tmpfs /run
mkdir -p /run/lock
# XXX devtmpfs
# Initialize dynamic linker cache.
ldconfig /usr/lib64 /usr/lib /lib64 /lib
# Fix owner of umount binary.
chown root.root /usr/bin/umount
# There is no hardware clock, just ensure the date is not miles out.
date `date -r /init +%m%d%H%M%Y`
hostname stage4-builder
echo stage4-builder.fedoraproject.org > /etc/hostname
echo
echo "This is the stage4 disk image automatic builder"
echo
# 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
mount -o remount,ro / >&/dev/null
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 50G /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 bind /dev /var/tmp/mnt/dev
mount -o bind /proc /var/tmp/mnt/proc
mount -o bind /sys /var/tmp/mnt/sys
rpm --root /var/tmp/mnt --initdb
# Adding glibc-langpack-en avoids the huge glibc-all-langpacks
# being used.
#
# We need --releasever here because fedora-release isn't
# installed inside the chroot.
#
# strict=0 is like the old --skip-broken option in yum. We can
# remove it when all @core packages are available.
dnf -y --releasever=25 --installroot=/var/tmp/mnt --setopt=strict=0 \
install \
@core \
glibc-langpack-en
# 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 local.repo in.
cp /var/tmp/local.repo /var/tmp/mnt/etc/yum.repos.d
# Set up /init (in the chroot) as a symlink.
pushd /var/tmp/mnt
ln -s usr/lib/systemd/systemd init
popd
# Add the riscv-set-date systemd service.
cp /var/tmp/riscv-set-date.service /var/tmp/mnt/etc/systemd/system/
chroot /var/tmp/mnt \
systemctl enable riscv-set-date
# Add the root-shell systemd service.
cp /var/tmp/root-shell.service /var/tmp/mnt/etc/systemd/system/
chroot /var/tmp/mnt \
systemctl enable root-shell
# Disable public repos, they don't serve riscv64 packages anyway.
chroot /var/tmp/mnt \
dnf config-manager --set-disabled updates updates-testing fedora
# 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
# List all the packages which were installed in the chroot
# so they appear in the build.log.
chroot /var/tmp/mnt rpm -qa | sort
# Unmount the chroot. Unfortunately some processes are still running
# in the chroot, so we can't do that.
sync
# 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.