Verified Commit 61854484 authored by nl6720's avatar nl6720
Browse files

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.
parent 0f3a83ab
......@@ -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"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment