diff options
author | Ying-Chun Liu (PaulLiu) <liupa@google.com> | 2022-12-19 14:08:45 +0800 |
---|---|---|
committer | Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org> | 2022-12-20 18:09:12 +0800 |
commit | c256503a049a536a75885ed701e07a695c1afadd (patch) | |
tree | 3620759003a8a452211ef395844a5201d5fcf046 | |
parent | 48ea91e05b5e355bd5ad6c76fd16ab611c22b18f (diff) |
build_rootfs.sh: use e2tools instead of loop mount
loop mount is unfriendly in un-priviledge docker.
We use e2tools to replace the loop mount.
Change-Id: I20ce38d8164a8280cea88156ac65c702bfb3822e
Signed-off-by: Ying-Chun Liu (PaulLiu) <liupa@google.com>
-rwxr-xr-x | net/test/build_rootfs.sh | 45 |
1 files changed, 34 insertions, 11 deletions
diff --git a/net/test/build_rootfs.sh b/net/test/build_rootfs.sh index a86496b..8adfb69 100755 --- a/net/test/build_rootfs.sh +++ b/net/test/build_rootfs.sh @@ -421,33 +421,56 @@ cat "${ramdisk}" "${initramfs}" >"${initrd}" # Leave workdir to boot-test combined initrd cd - +rootfs_partition_tempfile=$(mktemp) # Mount the new filesystem locally if [[ ${rootfs_partition} = "raw" ]]; then sudo mount -o loop -t ext3 "${disk}" "${mount}" else rootfs_partition_start=$(partx -g -o START -s -n "${rootfs_partition}" "${disk}" | xargs) rootfs_partition_offset=$((${rootfs_partition_start} * 512)) - sudo mount -o loop,offset=${rootfs_partition_offset} -t ext3 "${disk}" "${mount}" + rootfs_partition_end=$(partx -g -o END -s -n "${rootfs_partition}" "${disk}" | xargs) + rootfs_partition_num_sectors=$((${rootfs_partition_end} - ${rootfs_partition_start} + 1)) + dd if="${disk}" of="${rootfs_partition_tempfile}" bs=512 skip=${rootfs_partition_start} count=${rootfs_partition_num_sectors} fi image_unmount2() { sudo umount "${mount}" raw_initrd_remove } -trap image_unmount2 EXIT +if [[ ${rootfs_partition} = "raw" ]]; then + trap image_unmount2 EXIT +fi # Embed the kernel and dtb images now, if requested -if [[ "${embed_kernel_initrd_dtb}" = "1" ]]; then - if [ -n "${dtb}" ]; then - sudo mkdir -p "${mount}/boot/dtb/${dtb_subdir}" - sudo cp -a "${dtb}" "${mount}/boot/dtb/${dtb_subdir}" - sudo chown -R root:root "${mount}/boot/dtb/${dtb_subdir}" - fi - sudo cp -a "${kernel}" "${mount}/boot/vmlinuz-${kernel_version}" - sudo chown root:root "${mount}/boot/vmlinuz-${kernel_version}" +if [[ ${rootfs_partition} = "raw" ]]; then + if [[ "${embed_kernel_initrd_dtb}" = "1" ]]; then + if [ -n "${dtb}" ]; then + sudo mkdir -p "${mount}/boot/dtb/${dtb_subdir}" + sudo cp -a "${dtb}" "${mount}/boot/dtb/${dtb_subdir}" + sudo chown -R root:root "${mount}/boot/dtb/${dtb_subdir}" + fi + sudo cp -a "${kernel}" "${mount}/boot/vmlinuz-${kernel_version}" + sudo chown root:root "${mount}/boot/vmlinuz-${kernel_version}" + fi +else + if [[ "${embed_kernel_initrd_dtb}" = "1" ]]; then + if [ -n "${dtb}" ]; then + e2mkdir -G 0 -O 0 "${rootfs_partition_tempfile}":"/boot/dtb/${dtb_subdir}" + e2cp -G 0 -O 0 "${dtb}" "${rootfs_partition_tempfile}":"/boot/dtb/${dtb_subdir}" + fi + e2cp -G 0 -O 0 "${kernel}" "${rootfs_partition_tempfile}":"/boot/vmlinuz-${kernel_version}" + fi fi # Unmount the initial ramdisk -sudo umount "${mount}" +if [[ ${rootfs_partition} = "raw" ]]; then + sudo umount "${mount}" +else + rootfs_partition_start=$(partx -g -o START -s -n "${rootfs_partition}" "${disk}" | xargs) + rootfs_partition_end=$(partx -g -o END -s -n "${rootfs_partition}" "${disk}" | xargs) + rootfs_partition_num_sectors=$((${rootfs_partition_end} - ${rootfs_partition_start} + 1)) + dd if="${rootfs_partition_tempfile}" of="${disk}" bs=512 seek=${rootfs_partition_start} count=${rootfs_partition_num_sectors} conv=fsync,notrunc +fi +rm -f "${rootfs_partition_tempfile}" trap raw_initrd_remove EXIT # Boot test the new system and run stage 3 |