Bug 146254 - [patch] mdmfs(8): Add -k option to specify a skeldir
Summary: [patch] mdmfs(8): Add -k option to specify a skeldir
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: Normal Affects Only Me
Assignee: Kyle Evans
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-02 22:20 UTC by Jeremie Le Hen
Modified: 2019-12-03 18:48 UTC (History)
1 user (show)

See Also:
kevans: mfc-stable12+
kevans: mfc-stable11+


Attachments
mdmfs-k.diff (3.82 KB, patch)
2010-05-05 17:09 UTC, Jeremie Le Hen
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jeremie Le Hen 2010-05-02 22:20:07 UTC
	mdmfs(8) lacks the ability to populate throwaway memory filesystems
	from an existing directory.
	This features permits an interesting setup where /var for instance
	lives on a device where wear-leveling is something you want to
	avoid as much as possible and nonetheless you don't want to lose
	your logs, ports metadata, etc.  Here are the steps:
	1) Copy /var to /var.bak;
	2) Mount an mfs into /var using -k /var.bak at startup;
	3) Synchronize /var to /var.bak weekly and on shutdown.

	Note that this more or less mimics OpenBSD's mount_mfs(8) -P flag.
	By the way I have got this neat idea on the following webpage which
	explains how to set up OpenBSD on a Soekris:
	http://techblagh.blogspot.com/2008/08/installing-openbsd-43-on-soekris-5501.html

--- mdmfs-k.diff begins here ---
Index: mdmfs.8
===================================================================
RCS file: /mnt/repos/freebsd-cvsroot/src/sbin/mdmfs/mdmfs.8,v
retrieving revision 1.22
diff -u -p -u -r1.22 mdmfs.8
--- mdmfs.8	16 Feb 2006 21:28:54 -0000	1.22
+++ mdmfs.8	2 May 2010 20:43:06 -0000
@@ -46,6 +46,7 @@ driver
 .Op Fl F Ar file
 .Op Fl f Ar frag-size
 .Op Fl i Ar bytes
+.Op Fl k Ar skel
 .Op Fl m Ar percent-free
 .Op Fl n Ar rotational-positions
 .Op Fl O Ar optimization
@@ -170,6 +171,11 @@ memory disk backed by
 The fragment size of the file system in bytes.
 .It Fl i Ar bytes
 Number of bytes per inode.
+.It Fl k Ar skel
+Copy the content of directory
+.Ar skel
+into
+.Ar mount-point .
 .It Fl l
 Enable multilabel MAC on the new file system.
 .It Fl L
Index: mdmfs.c
===================================================================
RCS file: /mnt/repos/freebsd-cvsroot/src/sbin/mdmfs/mdmfs.c,v
retrieving revision 1.27
diff -u -p -u -r1.27 mdmfs.c
--- mdmfs.c	16 Feb 2006 21:28:54 -0000	1.27
+++ mdmfs.c	2 May 2010 20:50:03 -0000
@@ -78,6 +78,7 @@ static void	 do_mdconfig_detach(void);
 static void	 do_mount(const char *, const char *);
 static void	 do_mtptsetup(const char *, struct mtpt_info *);
 static void	 do_newfs(const char *);
+static void	 do_copy(const char *, const char *);
 static void	 extract_ugid(const char *, struct mtpt_info *);
 static int	 run(int *, const char *, ...) __printflike(2, 3);
 static void	 usage(void);
@@ -91,7 +92,7 @@ main(int argc, char **argv)
 	enum md_types mdtype;		/* The type of our memory disk. */
 	bool have_mdtype;
 	bool detach, softdep, autounit, newfs;
-	char *mtpoint, *unitstr;
+	char *mtpoint, *unitstr, *skel;
 	char *p;
 	int ch;
 	void *set;
@@ -104,6 +105,7 @@ main(int argc, char **argv)
 	autounit = false;
 	newfs = true;
 	have_mdtype = false;
+	skel = NULL;
 	mdtype = MD_SWAP;
 	mdname = MD_NAME;
 	mdnamelen = strlen(mdname);
@@ -123,7 +125,7 @@ main(int argc, char **argv)
 		compat = true;
 
 	while ((ch = getopt(argc, argv,
-	    "a:b:Cc:Dd:E:e:F:f:hi:LlMm:Nn:O:o:Pp:Ss:t:Uv:w:X")) != -1)
+	    "a:b:Cc:Dd:E:e:F:f:hi:k:LlMm:Nn:O:o:Pp:Ss:t:Uv:w:X")) != -1)
 		switch (ch) {
 		case 'a':
 			argappend(&newfs_arg, "-a %s", optarg);
@@ -169,6 +171,9 @@ main(int argc, char **argv)
 		case 'i':
 			argappend(&newfs_arg, "-i %s", optarg);
 			break;
+		case 'k':
+			skel = optarg;
+			break;
 		case 'L':
 			if (compat)
 				usage();
@@ -287,6 +292,8 @@ main(int argc, char **argv)
 		do_newfs(newfs_arg);
 	do_mount(mount_arg, mtpoint);
 	do_mtptsetup(mtpoint, &mi);
+	if (skel)
+		do_copy(mtpoint, skel);
 
 	return (0);
 }
@@ -501,6 +508,23 @@ do_newfs(const char *args)
 		errx(1, "newfs exited with error code %d", rv);
 }
 
+
+/*
+ * Copy skel into the mountpoint.
+ */
+static void
+do_copy(const char *mtpoint, const char *skel)
+{
+	int rv;
+
+	rv = chdir(skel);
+	if (rv)
+		err(1, "chdir to %s", skel);
+	rv = run(NULL, "/bin/pax -rw -pe . %s", mtpoint);
+	if (rv)
+		errx(1, "skel copy failed");
+}
+
 /*
  * 'str' should be a user and group name similar to the last argument
  * to chown(1); i.e., a user, followed by a colon, followed by a
@@ -681,9 +705,9 @@ usage(void)
 		fprintf(stderr,
 "usage: %s [-DLlMNPSUX] [-a maxcontig] [-b block-size] [-c cylinders]\n"
 "\t[-d rotdelay] [-E path-mdconfig] [-e maxbpg] [-F file] [-f frag-size]\n"
-"\t[-i bytes] [-m percent-free] [-n rotational-positions] [-O optimization]\n"
-"\t[-o mount-options] [-p permissions] [-s size] [-v version]\n"
-"\t[-w user:group] md-device mount-point\n", name);
+"\t[-i bytes] [-k skel] [-m percent-free] [-n rotational-positions]\n"
+"\t[-O optimization] [-o mount-options] [-p permissions] [-s size]\n"
+"\t[-v version] [-w user:group] md-device mount-point\n", name);
 	fprintf(stderr,
 "usage: %s -C [-lNU] [-a maxcontig] [-b block-size] [-c cylinders]\n"
 "\t[-d rotdelay] [-E path-mdconfig] [-e maxbpg] [-F file] [-f frag-size]\n"
--- mdmfs-k.diff ends here ---
Comment 1 Jeremie Le Hen 2010-05-05 17:09:33 UTC
Patch properly attached.

-- 
Jeremie Le Hen
Comment 2 Eitan Adler freebsd_committer freebsd_triage 2017-12-31 07:59:38 UTC
For bugs matching the following criteria:

Status: In Progress Changed: (is less than) 2014-06-01

Reset to default assignee and clear in-progress tags.

Mail being skipped
Comment 3 Kyle Evans freebsd_committer freebsd_triage 2019-11-01 03:11:18 UTC
Take; committed; will MFC. Thanks!
Comment 4 commit-hook freebsd_committer freebsd_triage 2019-11-01 03:11:26 UTC
A commit references this bug:

Author: kevans
Date: Fri Nov  1 03:10:53 UTC 2019
New revision: 354236
URL: https://svnweb.freebsd.org/changeset/base/354236

Log:
  mdmfs(8): add -k skel option to populate fs from a skeleton

  mdmfs(8) lacks the ability to populate throwaway memory filesystems from an
  existing directory.

  This features permits an interesting setup where /var for instance lives on
  a device where wear-leveling is something you want to avoid as much as
  possible and nonetheless you don't want to lose your logs, ports metadata,
  etc. Here are the steps:

  1. Copy /var to /var.bak;
  2. Mount an mfs into /var using -k /var.bak at startup;
  3. Synchronize /var to /var.bak weekly and on shutdown.

  Note that this more or less mimics OpenBSD's mount_mfs(8) -P flag.

  PR:		146254
  Submitted by:	jlh (many moons ago)
  MFC after:	1 week

Changes:
  head/sbin/mdmfs/mdmfs.8
  head/sbin/mdmfs/mdmfs.c
Comment 5 commit-hook freebsd_committer freebsd_triage 2019-12-03 18:39:50 UTC
A commit references this bug:

Author: kevans
Date: Tue Dec  3 18:38:53 UTC 2019
New revision: 355348
URL: https://svnweb.freebsd.org/changeset/base/355348

Log:
  MFC r354236: mdmfs(8): add -k skel option to populate fs from a skeleton

  mdmfs(8) lacks the ability to populate throwaway memory filesystems from an
  existing directory.

  This features permits an interesting setup where /var for instance lives on
  a device where wear-leveling is something you want to avoid as much as
  possible and nonetheless you don't want to lose your logs, ports metadata,
  etc. Here are the steps:

  1. Copy /var to /var.bak;
  2. Mount an mfs into /var using -k /var.bak at startup;
  3. Synchronize /var to /var.bak weekly and on shutdown.

  Note that this more or less mimics OpenBSD's mount_mfs(8) -P flag.

  PR:		146254

Changes:
_U  stable/11/
  stable/11/sbin/mdmfs/mdmfs.8
  stable/11/sbin/mdmfs/mdmfs.c
_U  stable/12/
  stable/12/sbin/mdmfs/mdmfs.8
  stable/12/sbin/mdmfs/mdmfs.c