Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 13 Sep 2014 17:58:34 +0000 (UTC)
From:      Nathan Whitehorn <nwhitehorn@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-user@freebsd.org
Subject:   svn commit: r271537 - in user/nwhitehorn/bsdinstall_zfspartedit: partedit scripts
Message-ID:  <201409131758.s8DHwYG9052010@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: nwhitehorn
Date: Sat Sep 13 17:58:34 2014
New Revision: 271537
URL: http://svnweb.freebsd.org/changeset/base/271537

Log:
  Set up boot blocks, ZFS caches, and loader.conf correctly for ZFS systems.
  This makes the code feature complete and able to set up both UFS and ZFS
  systems.

Modified:
  user/nwhitehorn/bsdinstall_zfspartedit/partedit/gpart_ops.c
  user/nwhitehorn/bsdinstall_zfspartedit/scripts/config
  user/nwhitehorn/bsdinstall_zfspartedit/scripts/zfsboot

Modified: user/nwhitehorn/bsdinstall_zfspartedit/partedit/gpart_ops.c
==============================================================================
--- user/nwhitehorn/bsdinstall_zfspartedit/partedit/gpart_ops.c	Sat Sep 13 17:48:44 2014	(r271536)
+++ user/nwhitehorn/bsdinstall_zfspartedit/partedit/gpart_ops.c	Sat Sep 13 17:58:34 2014	(r271537)
@@ -27,6 +27,7 @@
  */
 
 #include <sys/param.h>
+#include <sys/stat.h>
 #include <errno.h>
 #include <libutil.h>
 #include <inttypes.h>
@@ -144,8 +145,16 @@ newfs_command(const char *fstype, char *
 				return;
 		}
 
-		strcpy(command, "zpool create -f -o cachefile=none"
-			" -m none -R /mnt ");
+		strcpy(command, "zpool create -f -m none ");
+		if (getenv("BSDINSTALL_TMPBOOT") != NULL) {
+			char zfsboot_path[MAXPATHLEN];
+			sprintf(zfsboot_path, "%s/zfs",
+			    getenv("BSDINSTALL_TMPBOOT"));
+			mkdir(zfsboot_path, S_IRWXU | S_IRGRP | S_IXGRP |
+			    S_IROTH | S_IXOTH);
+			sprintf(command, "%s -o cachefile=%s/zpool.cache ",
+			    command, zfsboot_path);
+		}
 		for (i = 0; i < (int)(sizeof(items)/sizeof(items[0])); i++) {
 			if (items[i].state == 0)
 				continue;
@@ -618,9 +627,10 @@ set_default_part_metadata(const char *na
 
 		if (newfs != NULL && newfs[0] != '\0') {
 			md->newfs = malloc(strlen(newfs) + strlen(" /dev/") +
-			    strlen(mountpoint) + 1 + strlen(name) + 1);
+			    strlen(mountpoint) + 5 + strlen(name) + 1);
 			if (strcmp("freebsd-zfs", type) == 0) {
-				zpool_name = strdup(&mountpoint[1]);
+				zpool_name = strdup((strlen(mountpoint) == 1) ?
+				    "root" : &mountpoint[1]);
 				for (i = 0; zpool_name[i] != 0; i++)
 					if (!isalnum(zpool_name[i]))
 						zpool_name[i] = '_';
@@ -681,6 +691,10 @@ set_default_part_metadata(const char *na
 			md->fstab->fs_type = strdup(FSTAB_SW);
 			md->fstab->fs_freq = 0;
 			md->fstab->fs_passno = 0;
+		} else if (strcmp(type, "freebsd-zfs") == 0) {
+			md->fstab->fs_type = strdup(FSTAB_RW);
+			md->fstab->fs_freq = 0;
+			md->fstab->fs_passno = 0;
 		} else {
 			md->fstab->fs_type = strdup(FSTAB_RW);
 			if (strcmp(mountpoint, "/") == 0) {
@@ -1251,12 +1265,22 @@ gpart_commit(struct gmesh *mesh)
 	struct gctl_req *r;
 	const char *errstr;
 	const char *modified;
+	const char *rootfs;
 
 	LIST_FOREACH(classp, &mesh->lg_class, lg_class) {
 		if (strcmp(classp->lg_name, "PART") == 0)
 			break;
 	}
 
+	/* Figure out what filesystem / uses */
+	rootfs = "ufs"; /* Assume ufs if nothing else present */
+	TAILQ_FOREACH(md, &part_metadata, metadata) {
+		if (md->fstab != NULL && strcmp(md->fstab->fs_file, "/") == 0) {
+			rootfs = md->fstab->fs_vfstype;
+			break;
+		}
+	}
+
 	if (strcmp(classp->lg_name, "PART") != 0) {
 		dialog_msgbox("Error", "gpart not found!", 0, 0, TRUE);
 		return;
@@ -1296,7 +1320,7 @@ gpart_commit(struct gmesh *mesh)
 					break;
 
 			if (cp == NULL) /* No sub-partitions */
-				gpart_partcode(pp, md->fstab->fs_vfstype);
+				gpart_partcode(pp, rootfs);
 		}
 
 		r = gctl_get_handle();

Modified: user/nwhitehorn/bsdinstall_zfspartedit/scripts/config
==============================================================================
--- user/nwhitehorn/bsdinstall_zfspartedit/scripts/config	Sat Sep 13 17:48:44 2014	(r271536)
+++ user/nwhitehorn/bsdinstall_zfspartedit/scripts/config	Sat Sep 13 17:58:34 2014	(r271537)
@@ -36,6 +36,7 @@ cp $BSDINSTALL_TMPETC/* $BSDINSTALL_CHRO
 
 cat $BSDINSTALL_TMPBOOT/loader.conf.* >> $BSDINSTALL_TMPBOOT/loader.conf
 rm $BSDINSTALL_TMPBOOT/loader.conf.*
+df -t zfs $BSDINSTALL_CHROOT > /dev/null && echo "zfs_load=\"YES\"" >> $BSDINSTALL_TMPBOOT/loader.conf
 
 cp $BSDINSTALL_TMPBOOT/* $BSDINSTALL_CHROOT/boot
 

Modified: user/nwhitehorn/bsdinstall_zfspartedit/scripts/zfsboot
==============================================================================
--- user/nwhitehorn/bsdinstall_zfspartedit/scripts/zfsboot	Sat Sep 13 17:48:44 2014	(r271536)
+++ user/nwhitehorn/bsdinstall_zfspartedit/scripts/zfsboot	Sat Sep 13 17:58:34 2014	(r271537)
@@ -1272,8 +1272,6 @@ zfs_create_boot()
 	          "$funcname"
 	f_eval_catch $funcname echo "$ECHO_APPEND" 'zfs_enable=\"YES\"' \
 	             $BSDINSTALL_TMPETC/rc.conf.zfs || return $FAILURE
-	f_eval_catch $funcname echo "$ECHO_APPEND" 'zfs_load=\"YES\"' \
-	             $BSDINSTALL_TMPBOOT/loader.conf.zfs || return $FAILURE
 	f_eval_catch $funcname echo "$ECHO_APPEND" \
 	             'kern.geom.label.disk_ident.enable=\"0\"' \
 	             $BSDINSTALL_TMPBOOT/loader.conf.zfs || return $FAILURE



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201409131758.s8DHwYG9052010>