Skip to content

Commit 2fcecc0

Browse files
committed
ci: generate ext4 image after downloading artifacts
Signed-off-by: Pablo Barbáchano <[email protected]>
1 parent 1881187 commit 2fcecc0

File tree

2 files changed

+22
-30
lines changed

2 files changed

+22
-30
lines changed

resources/rebuild.sh

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,6 @@ function install_dependencies {
2020
apt install -y bc flex bison gcc make libelf-dev libssl-dev squashfs-tools busybox-static tree cpio curl patch docker.io
2121
}
2222

23-
function dir2ext4img {
24-
# ext4
25-
# https://unix.stackexchange.com/questions/503211/how-can-an-image-file-be-created-for-a-directory
26-
local DIR=$1
27-
local IMG=$2
28-
# Default size for the resulting rootfs image is 300M
29-
local SIZE=${3:-300M}
30-
local TMP_MNT=$(mktemp -d)
31-
truncate -s "$SIZE" "$IMG"
32-
mkfs.ext4 -F "$IMG"
33-
mount "$IMG" "$TMP_MNT"
34-
tar c -C $DIR . |tar x -C "$TMP_MNT"
35-
# cleanup
36-
# Use the -l flag for lazy unmounting since sometimes umount fails
37-
# with "device busy" and simply calling `sync` doesn't help
38-
umount -l "$TMP_MNT"
39-
rmdir $TMP_MNT
40-
}
41-
4223
function prepare_docker {
4324
nohup /usr/bin/dockerd --host=unix:///var/run/docker.sock --host=tcp://127.0.0.1:2375 &
4425

@@ -102,8 +83,6 @@ EOF
10283
rootfs_img="$OUTPUT_DIR/$ROOTFS_NAME.squashfs"
10384
mv $rootfs/root/manifest $OUTPUT_DIR/$ROOTFS_NAME.manifest
10485
mksquashfs $rootfs $rootfs_img -all-root -noappend
105-
rootfs_ext4=$OUTPUT_DIR/$ROOTFS_NAME.ext4
106-
dir2ext4img $rootfs $rootfs_ext4
10786
rm -rf $rootfs
10887
for bin in fast_page_fault_helper fillmem init readmem; do
10988
rm $PWD/overlay/usr/local/bin/$bin
@@ -235,7 +214,7 @@ function build_al_kernels {
235214
local KERNEL_VERSION="all"
236215
elif [[ $# -ne 1 ]]; then
237216
die "Too many arguments in '$(basename $0) kernels' command. Please use \`$0 help\` for help."
238-
else
217+
else
239218
KERNEL_VERSION=$1
240219
if [[ "$KERNEL_VERSION" != @(5.10|5.10-no-acpi|6.1) ]]; then
241220
die "Unsupported kernel version: '$KERNEL_VERSION'. Please use \`$0 help\` for help."
@@ -259,33 +238,33 @@ function build_al_kernels {
259238

260239
# Undo kernel patches on top of AL configuration
261240
git restore $PWD/guest_configs
262-
rm -rf $PWD/guest_configs/*.orig
241+
rm -rf $PWD/guest_configs/*.orig
263242
}
264243

265244
function print_help {
266245
cat <<EOF
267246
Firecracker CI artifacts build script
268247
269248
Usage: $(basename $0) [<command>] [<command args>]
270-
249+
271250
Available commands:
272-
251+
273252
all (default)
274253
Build CI rootfs and default guest kernels using configurations from
275254
resources/guest_configs.
276255
This will patch the guest configurations with all the patches under
277256
resources/guest_configs/patches.
278257
This is the default command, if no command is chosen.
279-
258+
280259
rootfs
281260
Builds only the CI rootfs.
282-
261+
283262
kernels [version]
284263
Builds our the currently supported CI kernels.
285-
264+
286265
version: Optionally choose a kernel version to build. Supported
287266
versions are: 5.10, 5.10-no-acpi or 6.1.
288-
267+
289268
help
290269
Displays the help message and exits.
291270
EOF
@@ -310,7 +289,7 @@ function main {
310289
fi
311290

312291
set -x
313-
292+
314293
install_dependencies
315294

316295
# Create the directory in which we will store the kernels and rootfs

tools/test.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ if [ -f $CGROUP/cgroup.controllers -a -e $CGROUP/cgroup.type ]; then
3131
> $CGROUP/cgroup.subtree_control
3232
fi
3333

34+
cd build/img/$(uname -m)
35+
for SQUASHFS in *.squashfs; do
36+
EXT4=$(basename $SQUASHFS .squashfs).ext4
37+
# Create rw ext4 image from ro squashfs
38+
[ -f $EXT4 ] && continue
39+
say "Converting $SQUASHFS to $EXT4"
40+
truncate -s 400M $EXT4
41+
unsquashfs $SQUASHFS
42+
mkfs.ext4 -F $EXT4 -d squashfs-root
43+
rm -rf squashfs-root
44+
done
45+
cd -
46+
3447
say "Copy CI artifacts to /srv, so hardlinks work"
3548
cp -ruvf build/img /srv
3649

0 commit comments

Comments
 (0)