misc/153666: [rc.d][patch] mount filesystems from fstab over zfs datasets (early)

Anonymous swell.k at gmail.com
Tue Jan 4 00:00:24 UTC 2011


>Number:         153666
>Category:       misc
>Synopsis:       [rc.d][patch] mount filesystems from fstab over zfs datasets (early)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-rc
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue Jan 04 00:00:23 UTC 2011
>Closed-Date:
>Last-Modified:
>Originator:     Anonymous
>Release:        FreeBSD 9.0-CURRENT amd64
>Organization:
>Environment:
zfsroot
>Description:
Provide a way to mount zfs datasets before fstab(5) but...

- unlike rc.d/mountlate do it more early before starting daemons or
  anything that may use them

- unlike rc.d/mountcritlocal allows to mount /boot dataset more early
  and not fail if filesystem module cannot be loaded

- unlike mounting datasets from fstab use zfs properties like noatime,
  noexec, mountpoint, etc

So, the workaround in conf/122036 may not be suitable for all cases.
And my solution tries to solve remaining integration issues of

  zfs mount -a vs. fstab

because even if one considers zfs mount superior and ditches fstab there
are still filesystems not managed by zfs(8).

Another way to solve it and which is easier to understand is smth like

  zfs_root=YES

that runs rc.d/zfs before rc.d/mountcritlocal. This way all datatesets
not marked by canmount=(off|noauto) should be mounted before fstab.
>How-To-Repeat:
1. create a zfsroot system

     $ zpool create \
         -O mountpoint=/ \
         -O atime=off \
         -O compression=on \
         tank gptid/A-B-C-D-E

     # create uncompressed dataset containing /boot,
     # e.g. for multiboot using grub2
     $ zfs create -o compression=off tank/boot
     $ zpool set bootfs=tank/boot

     $ zfs create -o atime=on tank/var
     [...]
     $ zfs list -o name,mountpoint
     NAME               MOUNTPOINT
     tank               /
     tank/var           /var

     $ echo 'zfs_enable=YES' >>/etc/rc.conf

2. add fstab entries that depends on a zfs dataset

     # needs tmpfs.ko from tank/boot
     # needs /var/run from tank/var
     $ echo 'nil /var/run tmpfs rw' >>/etc/fstab

3. try to boot

     Copyright (c) 1992-2010 The FreeBSD Project.
     Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994
             The Regents of the University of California. All rights reserved.
     FreeBSD is a registered trademark of The FreeBSD Foundation.
     FreeBSD 9.0-CURRENT-201012 #0: Tue Dec  7 20:28:03 UTC 2010
         root at farrell.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC amd64
     [...]
     Trying to mount root from zfs:tank []...
     Setting hostuuid: 76445d7f-1786-11e0-aa8f-525400123456.
     Setting hostid: 0xe5f49767.
     No suitable dump device was found.
     Entropy harvesting: interrupts ethernet point_to_point kickstart.
     Starting file system checks:
     Mounting local file systems:mount: /var/run: No such file or directory
     .
     Mounting /etc/fstab filesystems failed,  startup aborted
     ERROR: ABORTING BOOT (sending SIGTERM to parent)!
     Jan  3 22:11:53 init: /bin/sh on /etc/rc terminated abnormally, going to single user mode
     Enter full pathname of shell or RETURN for /bin/sh:

but if /var/run exists boot fails with another error

     Mounting local file systems:mount: nil : Operation not supported by device
     .
     Mounting /etc/fstab filesystems failed,  startup aborted
     ERROR: ABORTING BOOT (sending SIGTERM to parent)!
     Jan  3 22:16:46 init: /bin/sh on /etc/rc terminated abnormally, going to single user mode
     Enter full pathname of shell or RETURN for /bin/sh:

4. apply the patch or just install mountzfsbeforelocal script
5. configure and try again

     $ echo 'zfs_mount_before_fstab="tank/boot tank/var"' >>/etc/rc.conf

     Copyright (c) 1992-2010 The FreeBSD Project.
     Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994
             The Regents of the University of California. All rights reserved.
     FreeBSD is a registered trademark of The FreeBSD Foundation.
     FreeBSD 9.0-CURRENT-201012 #0: Tue Dec  7 20:28:03 UTC 2010
         root at farrell.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC amd64
     [...]
     Trying to mount root from zfs:tank []...
     Setting hostuuid: 94a90edd-1784-11e0-8702-525400123456.
     Setting hostid: 0xb22ca790.
     No suitable dump device was found.
     Entropy harvesting: interrupts ethernet point_to_point kickstart.
     Starting file system checks:
     Mounting local file systems:WARNING: TMPFS is considered to be a highly experimental feature in FreeBSD.
     .
     [...]
     Mon Jan  3 21:59:08 UTC 2011

     FreeBSD/amd64 (qemu.local) (ttyu0)

     login:

>Fix:
Note, rc.d/root allows us to create directories if they do not exist.

--- a.diff begins here ---
Index: etc/defaults/rc.conf
===================================================================
--- etc/defaults/rc.conf	(revision 216917)
+++ etc/defaults/rc.conf	(working copy)
@@ -57,6 +57,7 @@
 
 # ZFS support
 zfs_enable="NO"		# Set to YES to automatically mount ZFS file systems
+zfs_mount_before_fstab="" # List of ZFS datasets to mount before fstab(5)
 
 gptboot_enable="YES"	# GPT boot success/failure reporting.
 
Index: etc/rc.d/mountzfsbeforelocal
===================================================================
--- etc/rc.d/mountzfsbeforelocal	(revision 0)
+++ etc/rc.d/mountzfsbeforelocal	(revision 0)
@@ -0,0 +1,33 @@
+#!/bin/sh
+#
+# $FreeBSD$
+#
+
+# PROVIDE: mountzfsbeforelocal
+# REQUIRE: root
+# BEFORE:  mountcritlocal
+
+. /etc/rc.subr
+
+name="mountzfsbeforelocal"
+rcvar="zfs_enable"
+start_cmd="mountzfsbeforelocal_start"
+stop_cmd="mountzfsbeforelocal_stop"
+required_modules="zfs"
+
+mountzfsbeforelocal_start()
+{
+	for fs in $zfs_mount_before_fstab; do
+		zfs mount $fs
+	done
+}
+
+mountzfsbeforelocal_stop()
+{
+	for fs in $zfs_mount_before_fstab; do
+		zfs umount $fs
+	done
+}
+
+load_rc_config $name
+run_rc_command "$1"
Index: etc/rc.d/Makefile
===================================================================
--- etc/rc.d/Makefile	(revision 216917)
+++ etc/rc.d/Makefile	(working copy)
@@ -20,7 +20,7 @@
 	jail \
 	kadmind kerberos keyserv kldxref kpasswdd \
 	ldconfig local localpkg lockd lpd \
-	mixer motd mountcritlocal mountcritremote mountlate \
+	mixer motd mountcritlocal mountcritremote mountlate mountzfsbeforelocal \
 	mdconfig mdconfig2 mountd moused mroute6d mrouted msgs \
 	named natd netif netoptions \
 	newsyslog nfsclient nfscbd nfsd \
--- a.diff ends here ---
>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-rc mailing list