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') 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