-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.bash
86 lines (61 loc) · 2.4 KB
/
build.bash
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
#!/bin/bash
# Fail on error
set -exo pipefail
# Print each command
set -o xtrace
# Build the system image in Docker
docker buildx build --platform linux/arm64 --tag tradeberry --load --progress plain .
# EXTRACT IMAGE
# Make a temporary directory
sudo rm -rf .tmp || true
mkdir .tmp/
# save the image to result-rootfs.tar
docker save --output ./.tmp/result-rootfs.tar tradeberry
# Extract the image using docker-extract
docker run --rm --tty --volume $(pwd)/./.tmp:/root/./.tmp --workdir /root/./.tmp/.. faddat/toolbox /tools/docker-extract --root ./.tmp/result-rootfs ./.tmp/result-rootfs.tar
# ===================================================================================
# IMAGE: Make a .img file and compress it.
# Uses Techniques from Disconnected Systems:
# https://disconnected.systems/blog/raspberry-pi-archlinuxarm-setup/
# ===================================================================================
# Unmount anything on the loop device
sudo umount /dev/loop0p2 || true
sudo umount /dev/loop0p1 || true
# Detach from the loop device
sudo losetup -d /dev/loop0 || true
# Unmount anything on the loop device
sudo umount /dev/loop0p2 || true
sudo umount /dev/loop0p1 || true
# Create a folder for images
rm -rf images || true
mkdir -p images
# Make the image file
fallocate -l 4G "images/tradeberry.img"
# loop-mount the image file so it becomes a disk
export LOOP=$(sudo losetup --find --show images/tradeberry.img)
# partition the loop-mounted disk
sudo parted --script $LOOP mklabel msdos
sudo parted --script $LOOP mkpart primary fat32 0% 200M
sudo parted --script $LOOP mkpart primary ext4 200M 100%
# format the newly partitioned loop-mounted disk
sudo mkfs.vfat -F32 $(echo $LOOP)p1
sudo mkfs.ext4 -F $(echo $LOOP)p2
# Use the toolbox to copy the rootfs into the filesystem we formatted above.
# * mount the disk's /boot and / partitions
# * use rsync to copy files into the filesystem
# make a folder so we can mount the boot partition
# soon will not use toolbox
sudo mkdir -p mnt/boot mnt/rootfs
sudo mount $(echo $LOOP)p1 mnt/boot
sudo mount $(echo $LOOP)p2 mnt/rootfs
sudo rsync -a ./.tmp/result-rootfs/boot/* mnt/boot
sudo rsync -a ./.tmp/result-rootfs/* mnt/rootfs --exclude boot
sudo mkdir mnt/rootfs/boot
# chill for a moment before unmounting
sleep 20
sudo umount mnt/boot mnt/rootfs
sleep 20
sudo losetup -d $LOOP # drop the loop mount
# Delete .tmp and mnt
sudo rm -rf .tmp
sudo rm -rf mnt