@@ -29,12 +29,15 @@ echo "output: ${output:?}"
2929bootable_url=" https://github.com/oomol/builded/releases/download/v1.5/alpine_uefi_bootable-x86_64.img.zst"
3030bootable_img_zst=" $output /$( basename " $bootable_url " ) "
3131bootable_img=" ${bootable_img_zst% .* } "
32+ sudo rm -rf " $bootable_img_zst " " $bootable_img "
33+
3234profile_name=" $( basename " ${target_profile:? } " ) "
3335proot_args=()
34- rootfs_dir=" $output /rootfs_amd64 "
36+ rootfs_dir=" $output /rootfs "
3537if [[ $BUILD_TYPE == cross ]]; then
3638 proot_args+=(" --qemu=$output /qemu_bins/static_qemu/bin/qemu-x86_64" )
3739fi
40+
3841proot_args+=(" -r" " $rootfs_dir " )
3942proot_args+=(" -b" " /dev:/dev" )
4043proot_args+=(" -b" " /sys:/sys" )
@@ -46,24 +49,36 @@ proot_args+=("-w" "/root")
4649rootfs_part_uuid=" 4f1bfa20-73e8-4885-ab4b-1f9e67332f79"
4750efi_part_uuid=" F41A-23A6"
4851
52+ run_cmd_in_rootfs () {
53+ echo " Run cmd $* "
54+ sudo -E proot " ${proot_args[@]} " \
55+ -0 /bin/su -c " $* "
56+ }
57+
58+ mount_image () {
59+ kpartx -av " $bootable_img "
60+ mount -m -U " $rootfs_part_uuid " " $rootfs_dir "
61+ mount -m -U " $efi_part_uuid " " $rootfs_dir /boot/efi"
62+ }
63+
4964bootstrap_alpine () {
5065 echo " bootstrap alpine"
5166 cd " $workspace "
52- sudo rm -rf " $bootable_img_zst " " $bootable_img "
5367
5468 mkdir -p " $output "
5569 wget -c " $bootable_url " --output-document=" ${bootable_img_zst} " --output-file=" $output /wget_alpine_image.log"
5670
5771 cd " $output "
5872 zstd -d -f " ${bootable_img_zst} "
5973 # Mapping the part into /dev/mapper/loopNpN
60- kpartx -av " $bootable_img "
61- mount -m -U $rootfs_part_uuid " $rootfs_dir "
62- mount -m -U $efi_part_uuid " $rootfs_dir /boot/efi"
74+ mount_image
6375
6476 # add community repo into alpine repositories
6577 echo http://dl-cdn.alpinelinux.org/alpine/v3.20/community | tee -a " $rootfs_dir /etc/apk/repositories"
6678
79+ # change to mirror
80+ sed -i ' s#https\?://dl-cdn.alpinelinux.org/alpine#https://mirrors.tuna.tsinghua.edu.cn/alpine#g' " $rootfs_dir /etc/apk/repositories"
81+
6782 # Install required package into rootfs
6883
6984 echo " install pkgs into rootfs"
@@ -74,8 +89,6 @@ bootstrap_alpine() {
7489 sudo -E proot " ${proot_args[@]} " -0 /bin/su -c ' rm -rf /root/.ssh/ovm_id && \
7590 ssh-keygen -f /root/.ssh/ovm_id -N "" && \
7691 cat /root/.ssh/ovm_id.pub >> /root/.ssh/authorized_keys'
77-
78- # tar -Jcvf "$output/macos_arm64_ssh.tar.xz" "$rootfs_dir/root/.ssh"
7992 sync
8093}
8194
@@ -89,15 +102,6 @@ install_target_profile_deps() {
89102 fi
90103}
91104
92- clean_mapping () {
93- echo " clean disk mapping"
94- findmnt " $rootfs_dir " && {
95- umount -R " $rootfs_dir "
96- } || {
97- echo " $rootfs_dir not mount, no need to unmount"
98- }
99- }
100-
101105copy_layer () {
102106 cd " $workspace "
103107 layer_dir=" $workspace /layers/$profile_name "
@@ -106,9 +110,9 @@ copy_layer() {
106110 # In MacOS the console device is hvc0
107111 # In Qemu the console device is ttyAMA0
108112 if [[ $VM_PROVIDER == " qemu" ]]; then
109- find ./ -type f -exec sed -i ' s/VM_CONSOLE_DEVICE/ttyAMA0/g' {} + # Replace VM_CONSOLE_DEVICE to ttyAMA0
113+ find " $layer_dir " -type f -exec sed -i ' s/VM_CONSOLE_DEVICE/ttyAMA0/g' {} + # Replace VM_CONSOLE_DEVICE to ttyAMA0
110114 else
111- find ./ -type f -exec sed -i ' s/VM_CONSOLE_DEVICE/hvc0/g' {} + # Replace VM_CONSOLE_DEVICE to hvc0
115+ find " $layer_dir " -type f -exec sed -i ' s/VM_CONSOLE_DEVICE/hvc0/g' {} + # Replace VM_CONSOLE_DEVICE to hvc0
112116 fi
113117
114118 echo " copy $layer_dir layers files"
@@ -124,33 +128,24 @@ copy_layer() {
124128 -0 /bin/su -c " echo rc_parallel=YES >> /etc/rc.conf"
125129
126130 sudo -E proot " ${proot_args[@]} " \
127- -0 /bin/su -c " touch /.first_boot"
131+ -0 /bin/su -c " echo first_boot > /.first_boot"
128132
129- sync # must do sync !
130- }
131-
132- umount_rootfs () {
133- echo " umount rootfs"
134- umount -R " $rootfs_dir "
133+ sync
135134}
136135
137136pack_rootfs () {
138137 echo " pack rootfs"
138+ losetup -a
139139 cd " $output "
140- zstd --stdout --force " $bootable_img " > " $bootable_img_zst "
140+ zstd --stdout --force " $bootable_img " > " $bootable_img_zst "
141141 sha256sum " $bootable_img_zst " | tee " $bootable_img_zst .sha256sum"
142142 cd " $workspace "
143143}
144144
145145echo " === $profile_name ==="
146-
147- clean_mapping
148146install_target_profile_deps
149147
150148bootstrap_alpine
151149copy_layer
152- umount_rootfs
153- clean_mapping
154150
155- # Final stage: boot raw disk and do update-grub
156151pack_rootfs
0 commit comments