-
Notifications
You must be signed in to change notification settings - Fork 3
/
ostree_prep_rootfs.sh
executable file
·175 lines (140 loc) · 4.93 KB
/
ostree_prep_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
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
#!/bin/bash
# Modified from
# https://salsa.debian.org/debian/ostree/-/blob/debian/master/debian/ostree-boot-examples/modified-deb-ostree-builder
if [ ! -n "${BUILDDIR}" ]; then
echo "\$BUILDDIR must be defined"
exit 1
fi
if [ ! -n "${KERNEL_VERSION}" ]; then
echo "\$KERNEL_VERSION must be defined"
exit 1
fi
if [ ! -n "${OSTREE_BRANCH}" ]; then
echo "\$OSTREE_BRANCH must be defined"
exit 1
fi
if [ ! -n "${OSTREE_SUBJECT}" ]; then
echo "\$OSTREE_SUBJECT must be defined"
exit 1
fi
if [ ! -n "${OSTREE_VERSION}" ]; then
echo "\$OSTREE_VERSION must be defined"
exit 1
fi
cd /tmp
#mkdir /tmp/original
#cp -r ${BUILDDIR}/* /tmp/original
cd ${BUILDDIR}
# This is run at boot in /opt/scripts/boot/am335x_evm.sh, but errors due to read-only filesystem, doing it now while we can
sed -i -e 's:connmand -n:connmand -n --nodnsproxy:g' lib/systemd/system/connman.service || true
# /opt/scripts/tools/grow_partition.sh writes to /resizerootfs which is now a readonly location, so let's write to /var/resizerootfs
# We submitted a pull request to change these paths: (https://github.com/RobertCNelson/boot-scripts/pull/125)
# We'll want to take these lines out when those are merged:
if [ -f opt/scripts/tools/grow_partition.sh ]; then
HAS_VAR=$(grep "/var/resizerootfs" opt/scripts/tools/grow_partition.sh)
if [ -n "${HAS_VAR}" ]; then
echo "Don't need to replace /resizerootfs with /var/resizerootfs in grow_partition.sh"
else
echo "Replacing /resizerootfs with /var/resizerootfs in grow_partition.sh"
sed -i 's:/resizerootfs:/var/resizerootfs:g' opt/scripts/tools/grow_partition.sh
fi
fi
if [ -f opt/scripts/boot/generic-startup.sh ]; then
HAS_VAR=$(grep "/var/resizerootfs" opt/scripts/boot/generic-startup.sh)
if [ -n "${HAS_VAR}" ]; then
echo "Don't need to replace /resizerootfs with /var/resizerootfs in generic-startup.sh"
else
echo "Replacing /resizerootfs with /var/resizerootfs in generic-startup.sh"
sed -i 's:/resizerootfs:/var/resizerootfs:g' opt/scripts/boot/generic-startup.sh
fi
fi
mv opt usr
ln -s usr/opt opt
mv bin/* usr/bin
rm -r bin
ln -s usr/bin bin
mv sbin/* usr/sbin/
rm -r sbin
ln -s usr/sbin sbin
mkdir -p usr/lib/arm-linux-gnueabihf
mkdir -p usr/lib/systemd
mv lib/arm-linux-gnueabihf/* usr/lib/arm-linux-gnueabihf/
mv lib/systemd/* usr/lib/systemd/
rm -r lib/arm-linux-gnueabihf
rm -r lib/systemd
mv lib/* usr/lib/
rm -r lib
ln -s usr/lib lib
rm -rf dev
mkdir dev
sed -i -e 's|DHOME=/home|DHOME=/sysroot/home|g' etc/adduser.conf
sed -i -e 's|DHOME=/home|DHOME=/sysroot/home|g' etc/default/useradd
touch etc/machine-id
mv etc usr
mkdir -p usr/share/dpkg
mv var/lib/dpkg usr/share/dpkg/database
ln -sr usr/share/dpkg/database var/lib/dpkg
cat > usr/lib/tmpfiles.d/ostree.conf <<EOF
L /var/home - - - - ../sysroot/home
d /sysroot/home 0755 root root -
d /sysroot/root 0700 root root -
d /run/media 0755 root root -
L /var/lib/dpkg - - - - ../../usr/share/dpkg/database
EOF
mkdir -p sysroot
mv home /tmp/home
mv var /tmp/var
mkdir var
rm -rf {root,media}
ln -s /sysroot/ostree ostree
ln -s /sysroot/home home
ln -s /sysroot/root root
ln -s /run/media media
ln -s ../lib boot/lib
ln -s $KERNEL_VERSION boot/dtbs/current
ln -s $KERNEL_VERSION lib/modules/current
ln -s vmlinuz-$KERNEL_VERSION boot/vmlinuz-current
ln -s initrd.img-$KERNEL_VERSION boot/initrd.img-current
ln -s System.map-$KERNEL_VERSION boot/System.map-current
ln -s config-$KERNEL_VERSION boot/config-current
cd /tmp
# This is in here so ostree doesn't complain about the kernel
# when doing "ostree admin deploy"
# TODO - develop a specialized Beaglebone ostree bootloader deployment
cd ${BUILDDIR}
cp boot/vmlinuz-$KERNEL_VERSION usr/lib/modules/$KERNEL_VERSION/vmlinuz
cp boot/initrd.img-$KERNEL_VERSION usr/lib/modules/$KERNEL_VERSION/initramfs.img
CHECKSUM=$(cat boot/vmlinuz-$KERNEL_VERSION boot/initrd.img-$KERNEL_VERSION | sha256sum | head -c 64)
sed -i 's/^uname_r=.*$/uname_r=current/' boot/uEnv.txt
mkdir -p usr/lib/ostree-boot
cat > usr/lib/ostree-boot/setup.sh <<-__EOF__
#!/bin/bash
SYSROOT=\$1
DEPLOY=\$2
LOADER=\$3
echo "PWD: \$PWD"
echo "SYSROOT: \$SYSROOT"
echo "DEPLOY: \$DEPLOY"
echo "LOADER: \$LOADER"
cd \${SYSROOT}\${LOADER}
cp \${SYSROOT}\${DEPLOY}/boot/uEnv.txt uEnv.txt
sed -i "/^cmdline=/ s,\$, ostree=\${DEPLOY}," uEnv.txt
ln -s \${DEPLOY}/boot/vmlinuz-current
ln -s \${DEPLOY}/boot/initrd.img-current
ln -s \${DEPLOY}/boot/dtbs
ln -s \${DEPLOY}/boot/System.map-current
ln -s \${DEPLOY}/boot/config-current
ln -s \${DEPLOY}/boot/SOC.sh
ln -s \${DEPLOY}/boot/uboot
ln -s \${DEPLOY}/boot/lib
__EOF__
chmod +x usr/lib/ostree-boot/setup.sh
cd /tmp
REPO=/host/repo
if [ ! -d "$REPO" ]; then
ostree --repo="$REPO" init --mode=archive-z2
fi
ostree commit --repo="$REPO" --branch="${OSTREE_BRANCH}" --subject="${OSTREE_SUBJECT}" --skip-if-unchanged --table-output --add-metadata-string="version=${OSTREE_VERSION}" "${BUILDDIR}"
ostree summary --repo="$REPO" --update
# Remove rootfs so ostree_client_setup.sh can replace them
rm -r ${BUILDDIR}/*