From 6185448477313e304a8ab662e5857b50a515d1fa Mon Sep 17 00:00:00 2001 From: nl6720 Date: Tue, 3 Aug 2021 11:56:08 +0300 Subject: mkarchiso: copy files to ext4 image using mkfs.ext4's -d option instead of mounting the file system mkfs.ext4 with its -d option can "copy the contents of the given directory into the root directory of the filesystem". This allows to get rid of the last directly used mount and umount commands in mkarchiso. Additionally try to make the ext4 image somewhat reproducible by setting E2FSPROGS_FAKE_TIME to SOURCE_DATE_EPOCH, clearing the UUID and using a reproducible hash seed. See https://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git/commit/?id=e1f7100643a46456be107b33098f6034b0835e6d . Place mkfs.ext4 options in an array to avoid duplicating the command. Related to #40. --- archiso/mkarchiso | 44 ++++++++++++++++---------------------------- 1 file changed, 16 insertions(+), 28 deletions(-) (limited to 'archiso/mkarchiso') diff --git a/archiso/mkarchiso b/archiso/mkarchiso index 3f8c67e..8b43f75 100755 --- a/archiso/mkarchiso +++ b/archiso/mkarchiso @@ -67,22 +67,6 @@ _msg_error() { fi } -_mount_airootfs() { - trap "_umount_airootfs" EXIT HUP INT TERM - install -d -m 0755 -- "${work_dir}/mnt/airootfs" - _msg_info "Mounting '${pacstrap_dir}.img' on '${work_dir}/mnt/airootfs'..." - mount -- "${pacstrap_dir}.img" "${work_dir}/mnt/airootfs" - _msg_info "Done!" -} - -_umount_airootfs() { - _msg_info "Unmounting '${work_dir}/mnt/airootfs'..." - umount -d -- "${work_dir}/mnt/airootfs" - _msg_info "Done!" - rmdir -- "${work_dir}/mnt/airootfs" - trap - EXIT HUP INT TERM -} - # Show help usage, with an exit status. # $1: exit status number. _usage() { @@ -186,22 +170,26 @@ _run_mksquashfs() { # Create an ext4 image containing the root file system and pack it inside a squashfs image. # Save the squashfs image on the ISO 9660 file system. _mkairootfs_ext4+squashfs() { + local ext4_hash_seed mkfs_ext4_options=() [[ -e "${pacstrap_dir}" ]] || _msg_error "The path '${pacstrap_dir}' does not exist" 1 - _msg_info "Creating ext4 image of 32 GiB..." - if [[ "${quiet}" == "y" ]]; then - mkfs.ext4 -q -O '^has_journal,^resize_inode' -E 'lazy_itable_init=0' -m 0 -F -- "${pacstrap_dir}.img" 32G - else - mkfs.ext4 -O '^has_journal,^resize_inode' -E 'lazy_itable_init=0' -m 0 -F -- "${pacstrap_dir}.img" 32G - fi + _msg_info "Creating ext4 image of 32 GiB and copying '${pacstrap_dir}/' to it..." + + ext4_hash_seed="$(uuidgen --sha1 --namespace 93a870ff-8565-4cf3-a67b-f47299271a96 \ + --name "${SOURCE_DATE_EPOCH} ext4 hash seed")" + mkfs_ext4_options=( + '-d' "${pacstrap_dir}" + '-O' '^has_journal,^resize_inode' + '-E' "lazy_itable_init=0,root_owner=0:0,hash_seed=${ext4_hash_seed}" + '-m' '0' + '-F' + '-U' 'clear' + ) + [[ ! "${quiet}" == "y" ]] || mkfs_ext4_options+=('-q') + E2FSPROGS_FAKE_TIME="${SOURCE_DATE_EPOCH}" mkfs.ext4 "${mkfs_ext4_options[@]}" -- "${pacstrap_dir}.img" 32G tune2fs -c 0 -i 0 -- "${pacstrap_dir}.img" > /dev/null _msg_info "Done!" - _mount_airootfs - _msg_info "Copying '${pacstrap_dir}/' to '${work_dir}/mnt/airootfs/'..." - cp -aT -- "${pacstrap_dir}/" "${work_dir}/mnt/airootfs/" - chown -- 0:0 "${work_dir}/mnt/airootfs/" - _msg_info "Done!" - _umount_airootfs + install -d -m 0755 -- "${isofs_dir}/${install_dir}/${arch}" _msg_info "Creating SquashFS image, this may take some time..." _run_mksquashfs "${pacstrap_dir}.img" -- cgit v1.2.3-70-g09d2 From b040ef1774ed3f3755128b18fdd5ba4eb2598794 Mon Sep 17 00:00:00 2001 From: nl6720 Date: Tue, 3 Aug 2021 12:04:11 +0300 Subject: mkarchiso: ensure there are no existing image files before trying to create them This could prevent a few issues when creating an image file when re-running mkarchiso after a failure. Remove useless test before running rm -f. The command will always succeed. --- archiso/mkarchiso | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'archiso/mkarchiso') diff --git a/archiso/mkarchiso b/archiso/mkarchiso index 8b43f75..e726e0e 100755 --- a/archiso/mkarchiso +++ b/archiso/mkarchiso @@ -160,6 +160,7 @@ _cleanup_pacstrap_dir() { # $@: options to pass to mksquashfs _run_mksquashfs() { local image_path="${isofs_dir}/${install_dir}/${arch}/airootfs.sfs" + rm -f -- "${image_path}" if [[ "${quiet}" == "y" ]]; then mksquashfs "$@" "${image_path}" -noappend "${airootfs_image_tool_options[@]}" -no-progress > /dev/null else @@ -186,6 +187,7 @@ _mkairootfs_ext4+squashfs() { '-U' 'clear' ) [[ ! "${quiet}" == "y" ]] || mkfs_ext4_options+=('-q') + rm -f -- "${pacstrap_dir}.img" E2FSPROGS_FAKE_TIME="${SOURCE_DATE_EPOCH}" mkfs.ext4 "${mkfs_ext4_options[@]}" -- "${pacstrap_dir}.img" 32G tune2fs -c 0 -i 0 -- "${pacstrap_dir}.img" > /dev/null _msg_info "Done!" @@ -213,6 +215,7 @@ _mkairootfs_erofs() { install -d -m 0755 -- "${isofs_dir}/${install_dir}/${arch}" local image_path="${isofs_dir}/${install_dir}/${arch}/airootfs.erofs" + rm -f -- "${image_path}" # Generate reproducible file system UUID from SOURCE_DATE_EPOCH fsuuid="$(uuidgen --sha1 --namespace 93a870ff-8565-4cf3-a67b-f47299271a96 --name "${SOURCE_DATE_EPOCH}")" _msg_info "Creating EROFS image, this may take some time..." @@ -490,7 +493,7 @@ _make_efibootimg() { )" # The FAT image must be created with mkfs.fat not mformat, as some systems have issues with mformat made images: # https://lists.gnu.org/archive/html/grub-devel/2019-04/msg00099.html - [[ -e "${work_dir}/efiboot.img" ]] && rm -f -- "${work_dir}/efiboot.img" + rm -f -- "${work_dir}/efiboot.img" _msg_info "Creating FAT image of size: ${imgsize} KiB..." mkfs.fat -C -n ARCHISO_EFI "${work_dir}/efiboot.img" "${imgsize}" @@ -903,6 +906,7 @@ _build_iso_image() { typeset -f "_add_xorrisofs_options_${bootmode}" &> /dev/null && "_add_xorrisofs_options_${bootmode}" done + rm -f -- "${out_dir}/${image_name}" _msg_info "Creating ISO image..." xorriso -as mkisofs \ -iso-level 3 \ -- cgit v1.2.3-70-g09d2