Skip to content

Commit

Permalink
Initramfs scripts for ZoL.
Browse files Browse the repository at this point in the history
* Supports booting of a ZFS snapshot.
  Do this by cloning the snapshot into a dataset. If this, the resulting
  dataset, already exists, destroy it. Then mount it on root.
  * If snapshot does not exist, use base dataset (the part before '@')
    as boot filesystem instead.
  * Clone with 'mountpoint=none' and 'canmount=noauto' - we mount manually
    and explicitly.
  * Allow rollback of snapshots instead of clone it and boot from the clone.
  * If no snapshot is specified on the 'root=' kernel command line, but there
    is an '@', then get a list of snapshots below that filesystem and ask the
    user which to use.
* Allows mounting a rootfs with mountpoint=legacy set
* Support all currently used kernel command line arguments
  All the different distributions have their own standard on what to specify
  on the kernel command line to boot of a ZFS filesystem.
  * Extra options:
    * zfsdebug=(on,yes,1)	Show extra debugging information
    * zfsforce=(on,yes,1)	Force import the pool
    * rollback=(on,yes,1)	Rollback (instead of clone) the snapshot
* Don't auto import pools when loading module - keep better control of the imports.
* Only try to import pool if it haven't already been imported
  * This will negate the need to force import a pool that have not been exported cleanly.
  * Support exclusion of pools to import by setting ZFS_POOL_EXCEPTIONS in /etc/default/zfs.
* Support additional configuration variable ZFS_INITRD_ADDITIONAL_DATASETS
  to mount additional filesystems not located under your root dataset.
* Include /etc/modprobe.d/{zfs,spl}.conf in the initrd if it/they exist.
* Include the udev rule to use by-vdev for pool imports.
* Include the /etc/default/zfs file to the initrd.
* Only try /dev/disk/by-* in the initrd if USE_DISK_BY_ID is set.
  * Use /dev/disk/by-vdev before anything.
  * Add /dev as a last ditch attempt.
  * Fallback to using the cache file if that exist if nothing else worked.
* Use /sbin/modprobe instead of built-in (BusyBox) modprobe.
  This gets rid of the message "modprobe: can't load module zcommon".
  Thanx to pcoultha for finding this.
* Ignore filesystems with mountpoint=none. Might not be correct though...
  Needs more testing.

Signed-off-by: Turbo Fredriksson <[email protected]>
Closes: openzfs#2116, openzfs#2114
  • Loading branch information
FransUrbo committed Jun 25, 2015
1 parent 72540ea commit 9815562
Show file tree
Hide file tree
Showing 8 changed files with 1,093 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ include $(top_srcdir)/config/tgz.am

SUBDIRS = include rpm
if CONFIG_USER
SUBDIRS += dracut udev etc man scripts lib cmd contrib
SUBDIRS += dracut udev etc man scripts lib cmd contrib initramfs

This comment has been minimized.

Copy link
@behlendorf

behlendorf Jun 29, 2015

[style] I'd add initramfs after dracut since they provide the same kind of functionality.

endif
if CONFIG_KERNEL
SUBDIRS += module
Expand Down
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ AC_CONFIG_FILES([
include/sys/fs/Makefile
include/sys/fm/Makefile
include/sys/fm/fs/Makefile
initramfs/Makefile
scripts/Makefile
scripts/zpios-profile/Makefile
scripts/zpios-test/Makefile
Expand Down
23 changes: 23 additions & 0 deletions initramfs/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
initrddir = $(datarootdir)/initramfs-tools

initrd_SCRIPTS = conf-hooks.d/zfs hooks/zfs scripts/zfs

EXTRA_DIST = \
$(top_srcdir)/initramfs/conf-hooks.d/zfs \
$(top_srcdir)/initramfs/hooks/zfs \
$(top_srcdir)/initramfs/scripts/zfs

install-initrdSCRIPTS: $(EXTRA_DIST)
for d in conf-hooks.d hooks scripts; do \
$(MKDIR_P) $(DESTDIR)$(initrddir)/$$d; \
cp $(top_srcdir)/initramfs/$$d/zfs \
$(DESTDIR)$(initrddir)/$$d/; \
done
if [ -f etc/init.d/zfs ]; then \
$(MKDIR_P) $(DESTDIR)$(DEFAULT_INITCONF_DIR); \
cp $(top_srcdir)/etc/init.d/zfs \
$(DESTDIR)$(DEFAULT_INITCONF_DIR)/; \
fi

distclean-local::
-$(RM) $(top_srcdir)/initramfs/scripts/zfs
2 changes: 2 additions & 0 deletions initramfs/conf-hooks.d/zfs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Force the inclusion of Busybox in the initramfs.
BUSYBOX=y
112 changes: 112 additions & 0 deletions initramfs/hooks/zfs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#!/bin/sh
#
# Add ZoL filesystem capabilities to an initrd, usually for a native ZFS root.
#

# This hook installs udev rules for ZoL.
PREREQ="zdev"

# 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="/sbin/zdb /sbin/zpool /sbin/zfs /sbin/mount.zfs"

# These prerequisites are provided by the base system.
COPY_EXEC_LIST="$COPY_EXEC_LIST /bin/hostname /sbin/blkid"

# Explicitly specify all kernel modules because automatic dependency resolution
# is unreliable on many systems.
BASE_MODULES="zlib_deflate spl zavl zcommon znvpair zunicode zfs"
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

. /usr/share/initramfs-tools/hook-functions

mkdir -p "$DESTDIR/etc/"

# ZDB uses pthreads for some functions, but the library dependency is not
# automatically detected. The `find` utility and extended `cp` options are
# 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

for ii in $MANUAL_ADD_MODULES_LIST
do
manual_add_modules "$ii"
done

if [ -f "/etc/hostname" ]
then
cp -p "/etc/hostname" "$DESTDIR/etc/"
else
hostname >"$DESTDIR/etc/hostname"
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

# The spl-dkms package ensures that the /etc/hostid file exists.
# NB: Commentary in the spl-dkms.postinst script.
[ -f "/etc/hostid" ] && cp -p "/etc/hostid" "$DESTDIR/etc/hostid"

# Install the zpool.cache file.
[ -d /boot/zfs ] && cp -r /boot/zfs "$DESTDIR/boot"
[ ! -d "$DESTDIR/boot/zfs" ] && mkdir -p "$DESTDIR/boot/zfs"
[ -f /etc/zfs/zpool.cache ] && cp /etc/zfs/zpool.cache $DESTDIR/boot/zfs/

# 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

# Copy the udev vdev rule
if [ -f /etc/zfs/vdev_id.conf ]; then
[ ! -d "$DESTDIR/etc/zfs" ] && mkdir -p $DESTDIR/etc/zfs
cp /lib/udev/rules.d/69-vdev.rules $DESTDIR/lib/udev/rules.d
cp /etc/zfs/vdev_id.conf $DESTDIR/etc/zfs/vdev_id.conf
fi

# Copy the defaults file
[ ! -d "$DESTDIR/etc/default" ] && mkdir -p "$DESTDIR/etc/default"
cp /etc/default/zfs $DESTDIR/etc/default/

exit 0
1 change: 1 addition & 0 deletions initramfs/scripts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
zfs

This comment has been minimized.

Copy link
@behlendorf

behlendorf Jun 29, 2015

We shouldn't need a .gitignore file here since the script is tracked by git.

Loading

0 comments on commit 9815562

Please sign in to comment.