mirror of
				https://git.proxmox.com/git/mirror_zfs.git
				synced 2025-10-26 18:05:04 +03:00 
			
		
		
		
	i-t: rewrite hooks
This produces a leaner image, doesn't fail if zdb doesn't exist, properly handles hostnameless systems, doesn't mention crypto modules for no reason, doesn't add useless empty executable in hopes an eight-year-old PR is merged, uses i-t builtins for all copies Also optimize the checkbashisms filter to spawn one (or a few) awks instead of one per regular file and remove initramfs/hooks therefrom due to a command -v false positive Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz> Closes #12017
This commit is contained in:
		
							parent
							
								
									019739b6e9
								
							
						
					
					
						commit
						d53a6969c1
					
				| @ -159,9 +159,10 @@ checkbashisms: | |||||||
| 				-o -name 'paxcheck.sh' -prune \
 | 				-o -name 'paxcheck.sh' -prune \
 | ||||||
| 				-o -name 'make_gitrev.sh' -prune \
 | 				-o -name 'make_gitrev.sh' -prune \
 | ||||||
| 				-o -name '90zfs' -prune \
 | 				-o -name '90zfs' -prune \
 | ||||||
|  | 				-o -path '*initramfs/hooks' -prune \
 | ||||||
| 				-o -type f ! -name 'config*' \
 | 				-o -type f ! -name 'config*' \
 | ||||||
| 				! -name 'libtool' \
 | 				! -name 'libtool' \
 | ||||||
| 			-exec sh -c 'awk "NR==1 && /#!.*bin\/sh.*/ {print FILENAME;}" "{}"' \;); \
 | 			-exec awk 'FNR==1 && /^#!.*bin\/sh/ {print FILENAME}' {} \+); \
 | ||||||
| 	else \
 | 	else \
 | ||||||
| 		echo "skipping checkbashisms because checkbashisms is not installed"; \
 | 		echo "skipping checkbashisms because checkbashisms is not installed"; \
 | ||||||
| 	fi | 	fi | ||||||
|  | |||||||
| @ -3,107 +3,48 @@ | |||||||
| # Add OpenZFS filesystem capabilities to an initrd, usually for a native ZFS root. | # Add OpenZFS filesystem capabilities to an initrd, usually for a native ZFS root. | ||||||
| # | # | ||||||
| 
 | 
 | ||||||
| # This hook installs udev rules for OpenZFS. | if [ "$1" = "prereqs" ]; then | ||||||
| PREREQ="udev" | 	echo "udev" | ||||||
| 
 | 	exit | ||||||
| # These prerequisites are provided by the zfsutils package. The zdb utility is |  | ||||||
| # not strictly required, but it can be useful at the initramfs recovery prompt. |  | ||||||
| COPY_EXEC_LIST="@sbindir@/zdb @sbindir@/zpool @sbindir@/zfs" |  | ||||||
| COPY_EXEC_LIST="$COPY_EXEC_LIST @mounthelperdir@/mount.zfs @udevdir@/vdev_id" |  | ||||||
| COPY_EXEC_LIST="$COPY_EXEC_LIST @udevdir@/zvol_id" |  | ||||||
| COPY_FILE_LIST="/etc/hostid @sysconfdir@/zfs/zpool.cache" |  | ||||||
| COPY_FILE_LIST="$COPY_FILE_LIST @initconfdir@/zfs" |  | ||||||
| COPY_FILE_LIST="$COPY_FILE_LIST @sysconfdir@/zfs/zfs-functions" |  | ||||||
| COPY_FILE_LIST="$COPY_FILE_LIST @sysconfdir@/zfs/vdev_id.conf" |  | ||||||
| COPY_FILE_LIST="$COPY_FILE_LIST @udevruledir@/60-zvol.rules" |  | ||||||
| COPY_FILE_LIST="$COPY_FILE_LIST @udevruledir@/69-vdev.rules" |  | ||||||
| 
 |  | ||||||
| # These prerequisites are provided by the base system. |  | ||||||
| COPY_EXEC_LIST="$COPY_EXEC_LIST /usr/bin/dirname /bin/hostname /sbin/blkid" |  | ||||||
| COPY_EXEC_LIST="$COPY_EXEC_LIST /usr/bin/env" |  | ||||||
| COPY_EXEC_LIST="$COPY_EXEC_LIST $(which systemd-ask-password)" |  | ||||||
| 
 |  | ||||||
| # Explicitly specify all kernel modules because automatic dependency resolution |  | ||||||
| # is unreliable on many systems. |  | ||||||
| BASE_MODULES="zlib_deflate spl zavl zcommon znvpair zunicode zlua zfs icp" |  | ||||||
| CRPT_MODULES="sun-ccm sun-gcm sun-ctr" |  | ||||||
| MANUAL_ADD_MODULES_LIST="$BASE_MODULES" |  | ||||||
| 
 |  | ||||||
| # Generic result code. |  | ||||||
| RC=0 |  | ||||||
| 
 |  | ||||||
| case $1 in |  | ||||||
| prereqs) |  | ||||||
| 	echo "$PREREQ" |  | ||||||
| 	exit 0 |  | ||||||
| 	;; |  | ||||||
| esac |  | ||||||
| 
 |  | ||||||
| for ii in $COPY_EXEC_LIST |  | ||||||
| do |  | ||||||
| 	if [ ! -x "$ii" ] |  | ||||||
| 	then |  | ||||||
| 		echo "Error: $ii is not executable." |  | ||||||
| 		RC=2 |  | ||||||
| 	fi |  | ||||||
| done |  | ||||||
| 
 |  | ||||||
| if [ "$RC" -ne 0 ] |  | ||||||
| then |  | ||||||
| 	exit "$RC" |  | ||||||
| fi | fi | ||||||
| 
 | 
 | ||||||
| . /usr/share/initramfs-tools/hook-functions | . /usr/share/initramfs-tools/hook-functions | ||||||
| 
 | 
 | ||||||
| mkdir -p "$DESTDIR/etc/" | for req in "@sbindir@/zpool" "@sbindir@/zfs" "@mounthelperdir@/mount.zfs"; do | ||||||
| 
 | 	copy_exec "$req" || { | ||||||
| # ZDB uses pthreads for some functions, but the library dependency is not | 		echo "$req not available!" >&2 | ||||||
| # automatically detected. The `find` utility and extended `cp` options are | 		exit 2 | ||||||
| # used here because libgcc_s.so could be in a subdirectory of /lib for | 	} | ||||||
| # multi-arch installations. |  | ||||||
| cp --target-directory="$DESTDIR" --parents $(find /lib/ -type f -name libgcc_s.so.1) |  | ||||||
| 
 |  | ||||||
| for ii in $COPY_EXEC_LIST |  | ||||||
| do |  | ||||||
| 	copy_exec "$ii" |  | ||||||
| done | done | ||||||
| 
 | 
 | ||||||
| for ii in $COPY_FILE_LIST | copy_exec "@sbindir@/zdb" | ||||||
| do | copy_exec "@udevdir@/vdev_id" | ||||||
| 	dir=$(dirname "$ii") | copy_exec "@udevdir@/zvol_id" | ||||||
| 	[ -d "$dir" ] && mkdir -p "$DESTDIR/$dir" | if command -v systemd-ask-password > /dev/null; then | ||||||
| 	[ -f "$ii" ] && cp -p "$ii" "$DESTDIR/$ii" | 	copy_exec "$(command -v systemd-ask-password)" | ||||||
|  | fi | ||||||
|  | 
 | ||||||
|  | # We use pthreads, but i-t from buster doesn't automatically | ||||||
|  | # copy this indirect dependency: this can be removed when buster finally dies. | ||||||
|  | for libgcc in $(find /lib/ -type f -name libgcc_s.so.[1-9]); do | ||||||
|  | 	copy_exec "$libgcc" | ||||||
| done | done | ||||||
| 
 | 
 | ||||||
| for ii in $MANUAL_ADD_MODULES_LIST | copy_file config "/etc/hostid" | ||||||
| do | copy_file cache  "@sysconfdir@/zfs/zpool.cache" | ||||||
| 	manual_add_modules "$ii" | copy_file config "@initconfdir@/zfs" | ||||||
| done | copy_file config "@sysconfdir@/zfs/zfs-functions" | ||||||
|  | copy_file config "@sysconfdir@/zfs/vdev_id.conf" | ||||||
|  | copy_file rule   "@udevruledir@/60-zvol.rules" | ||||||
|  | copy_file rule   "@udevruledir@/69-vdev.rules" | ||||||
| 
 | 
 | ||||||
| if [ -f "/etc/hostname" ] | manual_add_modules zfs | ||||||
| then | 
 | ||||||
| 	cp -p "/etc/hostname" "$DESTDIR/etc/" | if [ -f "/etc/hostname" ]; then | ||||||
|  | 	copy_file config "/etc/hostname" | ||||||
| else | else | ||||||
| 	hostname >"$DESTDIR/etc/hostname" | 	hostname="$(mktemp -t hostname.XXXXXXXXXX)" | ||||||
|  | 	hostname > "$hostname" | ||||||
|  | 	copy_file config "$hostname" "/etc/hostname" | ||||||
|  | 	rm -f "$hostname" | ||||||
| fi | fi | ||||||
| 
 |  | ||||||
| for ii in zfs zfs.conf spl spl.conf |  | ||||||
| do |  | ||||||
| 	if [ -f "/etc/modprobe.d/$ii" ]; then |  | ||||||
| 		if [ ! -d "$DESTDIR/etc/modprobe.d" ]; then |  | ||||||
| 			mkdir -p $DESTDIR/etc/modprobe.d |  | ||||||
| 		fi |  | ||||||
| 		cp -p "/etc/modprobe.d/$ii" $DESTDIR/etc/modprobe.d/ |  | ||||||
| 	fi |  | ||||||
| done |  | ||||||
| 
 |  | ||||||
| # With pull request #1476 (not yet merged) comes a verbose warning |  | ||||||
| # if /usr/bin/net doesn't exist or isn't executable. Just create |  | ||||||
| # a dummy... |  | ||||||
| [ ! -d "$DESTDIR/usr/bin" ] && mkdir -p "$DESTDIR/usr/bin" |  | ||||||
| if [ ! -x "$DESTDIR/usr/bin/net" ]; then |  | ||||||
|     touch "$DESTDIR/usr/bin/net" |  | ||||||
|     chmod +x "$DESTDIR/usr/bin/net" |  | ||||||
| fi |  | ||||||
| 
 |  | ||||||
| exit 0 |  | ||||||
|  | |||||||
| @ -1,17 +1,9 @@ | |||||||
| #!/bin/sh | #!/bin/sh | ||||||
| 
 | 
 | ||||||
| PREREQ="dropbear" | if [ "$1" = "prereqs" ]; then | ||||||
| 
 | 	echo "dropbear" | ||||||
| prereqs() { | 	exit | ||||||
|     echo "$PREREQ" | fi | ||||||
| } |  | ||||||
| 
 |  | ||||||
| case "$1" in |  | ||||||
|     prereqs) |  | ||||||
|         prereqs |  | ||||||
|         exit 0 |  | ||||||
|     ;; |  | ||||||
| esac |  | ||||||
| 
 | 
 | ||||||
| . /usr/share/initramfs-tools/hook-functions | . /usr/share/initramfs-tools/hook-functions | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 наб
						наб