-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_rootfs
executable file
·57 lines (43 loc) · 1.72 KB
/
setup_rootfs
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
#!/bin/sh -ex
dest_img="$1"
[ ! -d "$ROOTFS_BUILD_DIR" ] || rm -rf "$ROOTFS_BUILD_DIR"
mkdir "$ROOTFS_BUILD_DIR"
# being on a tmpfs inside the mount namespace is really nice.
# it can limit size of the file system, cleanup is free, and - of course - it's super fast.
# but mke2fs has problems with it, so no: mount -t tmpfs none "$ROOTFS_BUILD_DIR".
# however, not using a tmpfs leads other problems
mount -t tmpfs -o noatime none "$ROOTFS_BUILD_DIR"
tar -C "$ROOTFS_BUILD_DIR" -xf "$BASE_ROOTFS_TAR"
mkdir -p "$ROOTFS_BUILD_DIR/boot"
run_mounted() {
# exporting in a loop is a hassle
{
grep -v '^#' .env.rootfs-customization
echo ./customize_rootfs
echo "$ROOTFS_BUILD_DIR"
} | xargs -d '\n' env
}
# this includes /proc/sys/fs/binfmt_misc, which allows running the binaries inside
mount --rbind /proc/ "$ROOTFS_BUILD_DIR/proc"
# /dev/shm, /dev/random, /dev/urandom and the likes are required for GPG and such
mount --rbind /dev "$ROOTFS_BUILD_DIR/dev"
mount --bind . "$ROOTFS_BUILD_DIR/mnt"
mount --bind "$PACMAN_CACHE_DIR" "$ROOTFS_BUILD_DIR/var/cache/pacman/pkg"
mount --bind /etc/resolv.conf "$ROOTFS_BUILD_DIR/etc/resolv.conf"
run_mounted
umount "$ROOTFS_BUILD_DIR/etc/resolv.conf"
umount "$ROOTFS_BUILD_DIR/var/cache/pacman/pkg"
umount "$ROOTFS_BUILD_DIR/mnt"
umount -l "$ROOTFS_BUILD_DIR/dev"
umount -l "$ROOTFS_BUILD_DIR/proc"
apparent_size="$(du -xsm "$ROOTFS_BUILD_DIR" | awk '{ print $1 }')"
# this can fail because of the host FS
#mke2fs -L "system" -U "$ROOTFS_UUID" -d "$ROOTFS_BUILD_DIR" \
mke2fs -F -L "system" -U "$ROOTFS_UUID" -d "$ROOTFS_BUILD_DIR" \
-O "^has_journal" \
-m 2 \
-t ext4 \
"$dest_img" \
$(( apparent_size * 105 / 100 + ROOTFS_WIGGLEROOM_MB ))M 2>&1
umount "$ROOTFS_BUILD_DIR"
rm -rf "$ROOTFS_BUILD_DIR"