Skip to content

Commit 4504f66

Browse files
pb8ozulinx86
authored andcommitted
test: add a way to build initramfs
Use busybox instead of a full Alpine image. This results in a much smaller image. In addition, we leverage `busybox devmem` command to write the magic boot value into MMIO, removing the need for `init.c`. Signed-off-by: Pablo Barbáchano <pablob@amazon.com>
1 parent 7900e9f commit 4504f66

File tree

4 files changed

+52
-17
lines changed

4 files changed

+52
-17
lines changed

resources/rebuild.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,45 @@ EOF
9494
}
9595

9696

97+
# https://wiki.gentoo.org/wiki/Custom_Initramfs#Busybox
98+
function build_initramfs {
99+
INITRAMFS_BUILD=initramfs
100+
mkdir -p $INITRAMFS_BUILD
101+
pushd $INITRAMFS_BUILD
102+
mkdir bin dev proc sys
103+
cp /bin/busybox bin/sh
104+
ln bin/sh bin/mount
105+
106+
# Report guest boot time back to Firecracker via MMIO
107+
# See arch/src/lib.rs and the BootTimer device
108+
MAGIC_BOOT_ADDRESS=0xd0000000
109+
if [ $ARCH = "aarch64" ]; then
110+
MAGIC_BOOT_ADDRESS=0x40000000
111+
fi
112+
MAGIC_BOOT_VALUE=123
113+
cat > init <<EOF
114+
#!/bin/sh
115+
mount -t devtmpfs devtmpfs /dev
116+
mount -t proc none /proc
117+
devmem $MAGIC_BOOT_ADDRESS 8 $MAGIC_BOOT_VALUE
118+
mount -t sysfs none /sys
119+
exec 0</dev/console
120+
exec 1>/dev/console
121+
exec 2>/dev/console
122+
123+
echo Boot took $(cut -d' ' -f1 /proc/uptime) seconds
124+
echo ">>> Welcome to fcinitrd <<<"
125+
126+
exec /bin/sh
127+
EOF
128+
chmod +x init
129+
130+
find . -print0 |cpio --null -ov --format=newc -R 0:0 > $OUTPUT_DIR/initramfs.cpio
131+
popd
132+
rm -rf $INITRAMFS_BUILD
133+
}
134+
135+
97136
function get_linux_git {
98137
# git clone -s -b v$KV ../../linux
99138
# --depth 1
@@ -175,6 +214,8 @@ fi
175214
# build_rootfs ubuntu-20.04 focal
176215
build_rootfs ubuntu-22.04 jammy
177216

217+
build_initramfs
218+
178219
build_linux $PWD/guest_configs/microvm-kernel-ci-$ARCH-4.14.config
179220
build_linux $PWD/guest_configs/microvm-kernel-ci-$ARCH-5.10.config
180221

tests/conftest.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -440,13 +440,15 @@ def artifact_dir():
440440

441441

442442
@pytest.fixture
443-
def uvm_with_initrd(microvm_factory, guest_kernel_linux_4_14, record_property):
443+
def uvm_with_initrd(
444+
microvm_factory, guest_kernel_linux_5_10, record_property, artifact_dir
445+
):
444446
"""
445447
See file:../docs/initrd.md
446448
"""
447-
fs = defs.ARTIFACT_DIR / "minimal_with_initrd/initrd.img"
449+
fs = artifact_dir / "initramfs.cpio"
448450
record_property("rootfs", fs.name)
449-
uvm = microvm_factory.build(guest_kernel_linux_4_14)
451+
uvm = microvm_factory.build(guest_kernel_linux_5_10)
450452
uvm.initrd_file = fs
451453
yield uvm
452454

@@ -463,4 +465,3 @@ def uvm_legacy(microvm_factory, record_property, artifact_dir):
463465

464466
# backwards compatibility
465467
test_microvm_with_api = uvm_plain
466-
test_microvm_with_initrd = uvm_with_initrd

tests/integration_tests/functional/test_initrd.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
INITRD_FILESYSTEM = "rootfs"
88

99

10-
def test_microvm_initrd_with_serial(test_microvm_with_initrd):
10+
def test_microvm_initrd_with_serial(uvm_with_initrd):
1111
"""
1212
Test that a boot using initrd successfully loads the root filesystem.
1313
"""
14-
vm = test_microvm_with_initrd
14+
vm = uvm_with_initrd
1515
vm.jailer.daemonize = False
1616
vm.spawn()
1717
vm.memory_monitor = None
@@ -26,13 +26,6 @@ def test_microvm_initrd_with_serial(test_microvm_with_initrd):
2626
vm.start()
2727
serial = Serial(vm)
2828
serial.open()
29-
serial.rx(token="login: ")
30-
serial.tx("root")
31-
32-
serial.rx(token="Password: ")
33-
serial.tx("root")
34-
3529
serial.rx(token="# ")
36-
37-
serial.tx("findmnt /")
38-
serial.rx(token=f"/ {INITRD_FILESYSTEM} {INITRD_FILESYSTEM}")
30+
serial.tx("mount |grep rootfs")
31+
serial.rx(token=f"rootfs on / type {INITRD_FILESYSTEM}")

tests/integration_tests/performance/test_boottime.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,11 @@ def test_boottime_with_network(fast_microvm, record_property, metrics):
100100
), f"boot time {boottime_us} cannot be greater than: {MAX_BOOT_TIME_US} us"
101101

102102

103-
def test_initrd_boottime(test_microvm_with_initrd, record_property, metrics):
103+
def test_initrd_boottime(uvm_with_initrd, record_property, metrics):
104104
"""
105105
Check boot time of microVM when using an initrd.
106106
"""
107-
vm = test_microvm_with_initrd
107+
vm = uvm_with_initrd
108108
vm.jailer.extra_args.update({"boot-timer": None})
109109
_configure_and_run_vm(vm, initrd=True)
110110
boottime_us = _get_microvm_boottime(vm)

0 commit comments

Comments
 (0)