@@ -16,8 +16,8 @@ source "$GIT_ROOT_DIR/tools/functions"
1616
1717# Make sure we have all the needed tools
1818function install_dependencies {
19- sudo apt update
20- sudo apt install -y bc flex bison gcc make libelf-dev libssl-dev squashfs-tools busybox-static tree cpio curl
19+ apt update
20+ apt install -y bc flex bison gcc make libelf-dev libssl-dev squashfs-tools busybox-static tree cpio curl patch docker.io
2121}
2222
2323function dir2ext4img {
@@ -30,13 +30,21 @@ function dir2ext4img {
3030 local TMP_MNT=$( mktemp -d)
3131 truncate -s " $SIZE " " $IMG "
3232 mkfs.ext4 -F " $IMG "
33- sudo mount " $IMG " " $TMP_MNT "
34- sudo tar c -C $DIR . | sudo tar x -C " $TMP_MNT "
33+ mount " $IMG " " $TMP_MNT "
34+ tar c -C $DIR . | tar x -C " $TMP_MNT "
3535 # cleanup
36- sudo umount " $TMP_MNT "
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 "
3739 rmdir $TMP_MNT
3840}
3941
42+ function prepare_docker {
43+ nohup /usr/bin/dockerd --host=unix:///var/run/docker.sock --host=tcp://127.0.0.1:2375 &
44+
45+ # Wait for Docker socket to be created
46+ timeout 15 sh -c " until docker info; do echo .; sleep 1; done"
47+ }
4048
4149function compile_and_install {
4250 local C_FILE=$1
@@ -54,6 +62,9 @@ function build_rootfs {
5462 local rootfs=" tmp_rootfs"
5563 mkdir -pv " $rootfs "
5664
65+ # Launch Docker
66+ prepare_docker
67+
5768 cp -rvf overlay/* $rootfs
5869
5970 # curl -O https://cloud-images.ubuntu.com/minimal/releases/jammy/release/ubuntu-22.04-minimal-cloudimg-amd64-root.tar.xz
@@ -76,25 +87,29 @@ mkdir -pv $rootfs/var/lib/dpkg/
7687EOF
7788
7889 # TBD what abt /etc/hosts?
79- echo | sudo tee $rootfs /etc/resolv.conf
90+ echo | tee $rootfs /etc/resolv.conf
8091
8192 # Generate key for ssh access from host
8293 if [ ! -s id_rsa ]; then
8394 ssh-keygen -f id_rsa -N " "
8495 fi
85- sudo install -d -m 0600 " $rootfs /root/.ssh/"
86- sudo cp id_rsa.pub " $rootfs /root/.ssh/authorized_keys"
96+ install -d -m 0600 " $rootfs /root/.ssh/"
97+ cp id_rsa.pub " $rootfs /root/.ssh/authorized_keys"
8798 id_rsa=$OUTPUT_DIR /$ROOTFS_NAME .id_rsa
88- sudo cp id_rsa $id_rsa
99+ cp id_rsa $id_rsa
89100
90101 # -comp zstd but guest kernel does not support
91102 rootfs_img=" $OUTPUT_DIR /$ROOTFS_NAME .squashfs"
92- sudo mv $rootfs /root/manifest $OUTPUT_DIR /$ROOTFS_NAME .manifest
93- sudo mksquashfs $rootfs $rootfs_img -all-root -noappend
103+ mv $rootfs /root/manifest $OUTPUT_DIR /$ROOTFS_NAME .manifest
104+ mksquashfs $rootfs $rootfs_img -all-root -noappend
94105 rootfs_ext4=$OUTPUT_DIR /$ROOTFS_NAME .ext4
95106 dir2ext4img $rootfs $rootfs_ext4
96- sudo rm -rf $rootfs
97- sudo chown -Rc $USER . $OUTPUT_DIR
107+ rm -rf $rootfs
108+ for bin in fast_page_fault_helper fillmem init readmem; do
109+ rm $PWD /overlay/usr/local/bin/$bin
110+ done
111+ rm -f id_rsa{,.pub}
112+ rm -f nohup.out
98113}
99114
100115
@@ -241,6 +256,10 @@ function build_al_kernels {
241256 if [[ " $KERNEL_VERSION " == @ (all| 6.1) ]]; then
242257 build_al_kernel $PWD /guest_configs/microvm-kernel-ci-$ARCH -6.1.config 5.10
243258 fi
259+
260+ # Undo kernel patches on top of AL configuration
261+ git restore $PWD /guest_configs
262+ rm -rf $PWD /guest_configs/* .orig
244263}
245264
246265function print_help {
0 commit comments