Skip to content

Commit

Permalink
fix(builder): fix boot failed in CI env
Browse files Browse the repository at this point in the history
  • Loading branch information
ihexon committed Dec 23, 2024
1 parent 2af753b commit 7801838
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 89 deletions.
2 changes: 1 addition & 1 deletion layers/macos_arm64/etc/default/grub
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ GRUB_TIMEOUT=0
GRUB_DISABLE_SUBMENU=y
GRUB_DISABLE_RECOVERY=true
GRUB_TERMINAL=console
GRUB_CMDLINE_LINUX_DEFAULT="console=VM_CONSOLE_DEVICE modules=sd-mod,usb-storage,ext4 quiet rootfstype=ext4"
GRUB_CMDLINE_LINUX_DEFAULT="console=ttyAMA0 modules=sd-mod,usb-storage,ext4 quiet rootfstype=ext4"
2 changes: 1 addition & 1 deletion layers/macos_arm64/etc/inittab
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ tty6::respawn:/sbin/getty 38400 tty6
::shutdown:/sbin/openrc shutdown

# enable login on alternative console
VM_CONSOLE_DEVICE::respawn:/sbin/getty -L 0 VM_CONSOLE_DEVICE vt100
ttyAMA0::respawn:/sbin/getty -L 0 ttyAMA0 vt100
2 changes: 1 addition & 1 deletion make
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ parse_profile() {
if [[ $SKIP_INSTALL_QEMU == "true" ]]; then
echo "SKIP_INSTALL_QEMU set true, skip install qemu"
else
bash +x ${workspace}/subfunc/install_qemu.sh || {
output=$output workspace=$workspace bash +x ${workspace}/subfunc/install_qemu.sh || {
echo "Error: Install qemu failed"
exit 100
}
Expand Down
25 changes: 20 additions & 5 deletions subfunc/boot_raw_disk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,44 @@ check_envs() {
boot_raw_arm64() {
check_envs
echo "INFO:Boot arm64 alpine disk"
set -x
"$output/qemu_bins/lib/$ld_loader" \
--library-path "$output/qemu_bins/lib" \
"$output/qemu_bins/bin/qemu-system-aarch64" -machine virt -cpu cortex-a72 -m 2048 \
-nographic \
-drive file="$raw_disk,format=raw,if=virtio" \
-bios "$output/qemu_bins/share/qemu/edk2-aarch64-code.fd" \
-netdev user,id=net0,restrict=n,hostfwd=tcp:127.0.0.1:10025-:22 \
-device e1000,netdev=net0 -device virtio-balloon-pci,id=balloon0
set +x
}

# Args1: bootable.img path
boot_raw_x86_64() {
check_envs
echo "INFO:Boot $raw_disk"
mycmd="./qemu_bins/lib/$ld_loader --library-path ./qemu_bins/lib \
./qemu_bins/bin/qemu-system-x86_64 \
set -x
"$output/qemu_bins/lib/$ld_loader" \
--library-path "$output/qemu_bins/lib" \
"$output/qemu_bins/bin/qemu-system-x86_64" \
-nographic -cpu max -smp 4 -m 2G \
-netdev user,id=net0,restrict=n,hostfwd=tcp:127.0.0.1:10025-:22 \
-device e1000,netdev=net0 \
-device virtio-balloon-pci,id=balloon0 \
-drive file=$raw_disk,format=raw,if=virtio
"
echo "Run: $mycmd"
-drive file="$raw_disk,format=raw,if=virtio"
set -x
}

boot_raw_disk() {
check_envs
if [[ "$target_arch" == arm64 ]] || [[ "$target_arch" == aarch64 ]]; then
set -x
boot_raw_arm64 "$raw_disk"
set +x
elif [[ "$target_arch" == x86_64 ]] || [[ "$target_arch" == amd64 ]]; then
set -x
boot_raw_x86_64 "$raw_disk"
set +x
fi
}

Expand Down
2 changes: 1 addition & 1 deletion subfunc/install_qemu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ download_qemu() {
}

test_qemu_bin() {
cd "$output"
set -xe
cd "$output"
./qemu_bins/lib/$ld_loader --library-path ./qemu_bins/lib ./qemu_bins/bin/qemu-system-x86_64 --version >/dev/null
./qemu_bins/lib/$ld_loader --library-path ./qemu_bins/lib ./qemu_bins/bin/qemu-system-aarch64 --version >/dev/null
./qemu_bins/static_qemu/bin/qemu-x86_64 --version >/dev/null
Expand Down
59 changes: 0 additions & 59 deletions subfunc/mkext4disk.sh

This file was deleted.

45 changes: 31 additions & 14 deletions target_builder/macos_amd64
Original file line number Diff line number Diff line change
Expand Up @@ -190,27 +190,33 @@ copy_layer() {
sync # must do sync !
}

pack_rootfs() {
bootable_file="${bootable_file_zst%.*}"
sha1sum_file="${bootable_file_zst}.sha1sum"
set -x

umount_rootfs() {
cd $output && {
umount -R ./target_rootfs
} || {
echo "Error: failed to umount $output/target_rootfs"
exit 100
} && cd $workspace
}
cd $workspace || {
echo "Change dir to workspace failed"
exit 100
}
}

pack_rootfs() {
cd $output && {
zstd --force $bootable_file && {
sha1sum "${bootable_file_zst}" >"${sha1sum_file}"
zstd --force alpine_uefi_bootable.img && {
sha1sum alpine_uefi_bootable.img.zst >alpine_uefi_bootable.img.zst.sha1sum
} || {
echo "Error: Compress alpine_uefi_bootable.img failed"
exit 100
}
} && cd $workspace
set +x
}

cd "$workspace" || {
echo "Change dir to workspace failed"
exit 100
}
}

bootimage() {
Expand All @@ -230,11 +236,22 @@ if [[ -z $workspace ]] && [[ -z $output ]]; then
exit 100
fi

echo workspace: $workspace
echo output: $output
echo "workspace: $workspace"
echo "output: $output"
clean_mapping
bootstrap_alpine
#copy_layer
pack_rootfs
umount_rootfs
clean_mapping
bootimage
bootimage >/tmp/vm_boot_log 2>&1 &
while true; do
ssh -o ConnectTimeout=1 -o StrictHostKeyChecking=no -i /tmp/ovm_ssh/ovm_id [email protected] -p10025 "update-grub && sync && halt" && {
echo Update-grub successful
break
} || {
echo "Try ssh into vm again..."
sleep 2
continue
}
done
pack_rootfs
46 changes: 39 additions & 7 deletions target_builder/macos_arm64
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,20 @@ copy_layer() {
sync # must do sync !
}

pack_rootfs() {
set -x
umount_rootfs() {
cd $output && {
umount -R ./target_rootfs
} || {
echo "Error: failed to umount $output/target_rootfs"
exit 100
}
cd $workspace || {
echo "Change dir to workspace failed"
exit 100
}
}

pack_rootfs() {
cd $output && {
zstd --force alpine_uefi_bootable.img && {
sha1sum alpine_uefi_bootable.img.zst >alpine_uefi_bootable.img.zst.sha1sum
Expand All @@ -179,23 +184,50 @@ pack_rootfs() {
exit 100
}
}
set +x
cd $workspace || {

cd "$workspace" || {
echo "Change dir to workspace failed"
exit 100
}
}

bootimage() {
cd "$workspace" || {
echo "Failed to change dir to workspace"
exit 100
}

bootable_file=alpine_uefi_bootable.img
output=$output workspace=$workspace bash +x ./subfunc/boot_raw_disk.sh "$output/$bootable_file" arm64 || {
echo "Error: boot $output/$bootable_file failed"
exit 100
}
}

echo "=== Bootstrap Alpine ==="
if [[ -z $workspace ]] && [[ -z $output ]]; then
echo 'Error: $workspace or $output empty'
exit 100
fi

echo workspace: $workspace
echo output: $output
echo "workspace: $workspace"
echo "output: $output"
clean_mapping
bootstrap_alpine
copy_layer
pack_rootfs
umount_rootfs
clean_mapping

# Final stage: boot raw disk and do update-grub
bootimage >/tmp/vm_boot_log 2>&1 &
while true; do
ssh -o ConnectTimeout=1 -o StrictHostKeyChecking=no -i /tmp/ovm_ssh/ovm_id [email protected] -p10025 "update-grub && sync && halt" && {
echo Update-grub successful
break
} || {
echo "Try ssh into vm again..."
sleep 2
continue
}
done
pack_rootfs

0 comments on commit 7801838

Please sign in to comment.