-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathbuild-rootfs-img.sh
More file actions
executable file
·54 lines (45 loc) · 1.89 KB
/
Copy pathbuild-rootfs-img.sh
File metadata and controls
executable file
·54 lines (45 loc) · 1.89 KB
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
#!/bin/bash
: "${LINUX_OUT:=prebuilt/linux}"
: "${IMG_OUT:=out}"
: "${IMGSIZE:=6GiB}"
: "${BUILD_ID:=$(date -u '+%Y%m%d-%H%M')}"
set -e
# 6Gb was not enough once zstd -T0 over the send streams started sizing its buffers
# to a 128-core builder: 2.9GB with 128 workers on zstd:9, against 1.1GB on zstd:3.
if [ -c /dev/kvm -a -w /dev/kvm ]; then
# Have virtualization support, can use fakemachine (default, fast, safe)
DEBOS="debos -c $(nproc) -m 10Gb"
elif [ -f /.dockerenv ]; then
# Running in a container without access to virtualization, fall back to the slow method
DEBOS="debos -b qemu -c $(nproc) -m 10Gb"
elif [ `id -u` -eq 0 ]; then
# Running as root, can use the host mode without fakemachine (fast, less safe)
DEBOS="debos"
else
DEBOS="sudo debos --disable-fakemachine"
fi
mkdir -p "$IMG_OUT"
if [ ! -f "$IMG_OUT"/debian-ospack.tar.zst -o "$UPDATE_OSPACK" ]; then
./build-ospack.sh
fi
rm -rf "$IMG_OUT"/linux_tmp
mkdir -p "$IMG_OUT"/linux_tmp
cp -r "$LINUX_OUT"/* "$IMG_OUT"/linux_tmp
echo "Creating the root FS image"
$DEBOS --artifactdir="$IMG_OUT" -t imagesize:"$IMGSIZE" -t kerneldir:linux_tmp -t buildid:"$BUILD_ID" debian-rk3576-img.yaml
sync "$IMG_OUT"/debian-nobootloader.img
owner=$(stat -c %u "$IMG_OUT"/debian-nobootloader.img)
whoami=$(id -u)
if [ "$owner" -ne "$whoami" ]; then
sudo chown "$whoami" "$IMG_OUT"/debian-nobootloader.img
fi
read START COUNT < <(
sfdisk -d "$IMG_OUT"/debian-nobootloader.img \
| awk -F'[, =:]+' '/name="root"/ { print $3, $5 }'
)
start_bytes=$((START * 512))
count_bytes=$((COUNT * 512))
bmaptool subrange --start $start_bytes --length $count_bytes "$IMG_OUT"/debian-nobootloader.img "$IMG_OUT"/debian-rootfs.img
bmaptool create -o "$IMG_OUT"/debian-rootfs.img.bmap "$IMG_OUT"/debian-rootfs.img
zeekstd -f -o "$IMG_OUT"/debian-rootfs.img.zst "$IMG_OUT"/debian-rootfs.img
rm -rf "$IMG_OUT"/linux_tmp "$IMG_OUT"/debian-nobootloader.img "$IMG_OUT"/debian-rootfs.img