-
Notifications
You must be signed in to change notification settings - Fork 180
Expand file tree
/
Copy pathmake-rootfs
More file actions
executable file
·49 lines (39 loc) · 1.44 KB
/
make-rootfs
File metadata and controls
executable file
·49 lines (39 loc) · 1.44 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
#!/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)
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 ))
# Increase fs size on 800MB. We need extra room for updating packages while
# building live image. See 'LIVE_UPDATE=1 live' in the Makefile.
ROOTFS_PART_EXTRA_SPACE=$((800<<20))
ROOTFS_PART_SIZE=$(((ROOTFS_PART_BLOCKS * ROOTFS_BLOCKSZ) + ROOTFS_PART_EXTRA_SPACE))
ROOTFS_PART_SIZE_KB=$(((ROOTFS_PART_SIZE + 1023) / 1024))
dd if=/dev/zero of=$IMGFILE bs=1024 seek="$ROOTFS_PART_SIZE_KB" count=0
mkfs.ext4 -b 4096 -L eve_rootfs -U "$ROOTFS_UUID" -v "$IMGFILE"
mkdir -p /mnt
mount -o loop $IMGFILE /mnt
cp -R /tmp/rootfs/* /mnt
umount /mnt
)
$EXPORT_CMD