-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathbuild-rootfs-img.sh
More file actions
executable file
·51 lines (42 loc) · 1.66 KB
/
build-rootfs-img.sh
File metadata and controls
executable file
·51 lines (42 loc) · 1.66 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
#!/bin/bash
: "${LINUX_OUT:=prebuilt/linux}"
: "${IMG_OUT:=out}"
: "${IMGSIZE:=6GiB}"
set -e
if [ -c /dev/kvm -a -w /dev/kvm ]; then
# Have virtualization support, can use fakemachine (default, fast, safe)
DEBOS="debos -c $(nproc) -m 6Gb"
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 6Gb"
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.gz -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 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