commit:     69d703093a5a6560988d077e57ddf69303d08906
Author:     Richard Yao <ryao <AT> gentoo <DOT> org>
AuthorDate: Sun Sep 20 13:41:35 2015 +0000
Commit:     Richard Yao <ryao <AT> gentoo <DOT> org>
CommitDate: Sun Sep 20 14:09:37 2015 +0000
URL:        https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=69d70309

Improve upon patch to read zpool.cache from the root pool at boot

Signed-off-by: Richard Yao <ryao <AT> gentoo.org>

 defaults/initrd.scripts | 30 +++++++++++++++++++++---------
 gen_initramfs.sh        | 12 +-----------
 2 files changed, 22 insertions(+), 20 deletions(-)

diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts
index 55b7f57..9c0c290 100644
--- a/defaults/initrd.scripts
+++ b/defaults/initrd.scripts
@@ -1034,21 +1034,33 @@ startVolumes() {
                elif [ -z "${ZFS_POOL}" ]
                then
                        bad_msg "Please boot with root=ZFS=\$DATASET"
-               else
+               elif /sbin/zpool import -f -N -o readonly=on "${ZFS_POOL}" 2>&1 
>/dev/null
+               then
                        mkdir -p /tmp/zfs
-                       /sbin/zpool import -f -N -o readonly=on "${ZFS_POOL}"
                        mount -o ro,zfsutil -t zfs "${REAL_ROOT#*=}" /tmp/zfs
-                       if [ -e /tmp/zfs/etc/zfs/zpool.cache ]
+
+                       # Copy important files to /etc/zfs
+                       for i in zpool.cache zdev.conf
+                       do
+                               if [ -f /tmp/zfs/etc/zfs/${i} ]
+                               then
+                                       good_msg "Reading ${i} from 
${REAL_ROOT#*=}."
+                                       cp "/tmp/zfs/etc/zfs/${i}" 
"/etc/zfs/${i}"
+                               fi
+                       done
+
+                       umount /tmp/zfs
+                       /sbin/zpool export -F "${ZFS_POOL}"
+
+                       if [ -f /etc/zfs/zpool.cache ]
                        then
-                               cp /tmp/zfs/etc/zfs/zpool.cache /tmp/zpool.cache
-                               umount /tmp/zfs
-                               /sbin/zpool export "${ZFS_POOL}"
-                               /sbin/zpool import -c /tmp/zpool.cache -aN
+                               /sbin/zpool import -c /etc/zfs/zpool.cache -aN
                        else
-                               umount /tmp/zfs
-                               /sbin/zpool export "${ZFS_POOL}"
                                bad_msg "No /etc/zfs/zpool.cache in 
${REAL_ROOT#*=}"
+
                        fi
+               else
+                       bad_msg "Failed to import ${ZFS_POOL}."
                fi
        fi
 }

diff --git a/gen_initramfs.sh b/gen_initramfs.sh
index 1b4afe6..bf1b495 100755
--- a/gen_initramfs.sh
+++ b/gen_initramfs.sh
@@ -442,19 +442,9 @@ append_zfs(){
                rm -r "${TEMP}/initramfs-zfs-temp"
        fi
 
+       # Populated during boot
        mkdir -p "${TEMP}/initramfs-zfs-temp/etc/zfs"
 
-       # Copy files to /etc/zfs
-       for i in zdev.conf
-       do
-               if [ -f /etc/zfs/${i} ]
-               then
-                       print_info 1 "        >> Including ${i}"
-                       cp -a "/etc/zfs/${i}" 
"${TEMP}/initramfs-zfs-temp/etc/zfs" 2> /dev/null \
-                               || gen_die "Could not copy file ${i} for ZFS"
-               fi
-       done
-
        # Copy binaries
        copy_binaries "${TEMP}/initramfs-zfs-temp" 
/sbin/{mount.zfs,zdb,zfs,zpool}
 

Reply via email to