forked from zededa/eve
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make-rootfs
executable file
·50 lines (38 loc) · 1.41 KB
/
make-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
#!/bin/sh
#
# mkrootfs -- Create an EVE rootfs
#
# Input is a tarball containing the rootfs partition.
# Output is a raw partition on stdout
#
# The following env variables change the behaviour of this script
# DEBUG - makes this script verbose
set -e
[ -n "$DEBUG" ] && set -x
IMGFILE=/rootfs.img
[ -f "$IMGFILE" ] || EXPORT_CMD="cat $IMGFILE"
# we want everything except the final result to stderr
( exec 1>&2;
mkdir -p /tmp/rootfs
cd /tmp/rootfs
[ -t 0 ] || bsdtar xzf -
# This _filesystem_ UUID will be later reused as the _partition_
# UUID when creating the final image. This will allow us to have
# a static grub configuration.
ROOTFS_UUID=$(cat /proc/sys/kernel/random/uuid)
# In what can only be described as a horrible thing, create grub.cfg
# here. The only place we have to unpack the cmdline given by the
# yml image is here.
#
CMDLINE="$(cat boot/cmdline)"
sed -i'' -e "/set *linuxkit_cmdline=/s#=.*\$#=$CMDLINE#" EFI/BOOT/grub.cfg
ROOTFS_BLOCKSZ=4096
ROOTFS_PART_HEADROOM_BLOCKS=16000
ROOTFS_FILE_SIZE_KB=$(du -sk . | awk '{print $1}')
ROOTFS_PART_BLOCKS=$(( $ROOTFS_FILE_SIZE_KB / 4 + $ROOTFS_PART_HEADROOM_BLOCKS ))
ROOTFS_PART_SIZE=$(( $ROOTFS_PART_BLOCKS * $ROOTFS_BLOCKSZ ))
ROOTFS_PART_SIZE_KB=$(( ( ($ROOTFS_PART_SIZE + 1024) / 1024 * 1024) / 1024 ))
ROOTFS_PART_SECTORS=$(( $ROOTFS_PART_SIZE_KB * 2 ))
mksquashfs /tmp/rootfs/ $IMGFILE -noappend
)
$EXPORT_CMD