aboutsummaryrefslogtreecommitdiff
path: root/sbin/mdmfs
diff options
context:
space:
mode:
authorKyle Evans <kevans@FreeBSD.org>2019-11-01 03:10:53 +0000
committerKyle Evans <kevans@FreeBSD.org>2019-11-01 03:10:53 +0000
commitf85261860233dfed5150d785845f3f525d11b6a6 (patch)
tree030688e6e9bf0be74518bb1aa06cd3e78411e74a /sbin/mdmfs
parent8b079fcca72eb48c237fbb705cf00689c3e1dcf4 (diff)
downloadsrc-f85261860233dfed5150d785845f3f525d11b6a6.tar.gz
src-f85261860233dfed5150d785845f3f525d11b6a6.zip
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
Notes
Notes: svn path=/head/; revision=354236
Diffstat (limited to 'sbin/mdmfs')
-rw-r--r--sbin/mdmfs/mdmfs.88
-rw-r--r--sbin/mdmfs/mdmfs.c32
2 files changed, 35 insertions, 5 deletions
diff --git a/sbin/mdmfs/mdmfs.8 b/sbin/mdmfs/mdmfs.8
index 7505ff214ca8..6e1f46f2dba1 100644
--- a/sbin/mdmfs/mdmfs.8
+++ b/sbin/mdmfs/mdmfs.8
@@ -25,7 +25,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd September 9, 2017
+.Dd October 31, 2019
.Dt MDMFS 8
.Os
.Sh NAME
@@ -48,6 +48,7 @@ filesystem
.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 O Ar optimization
.Op Fl o Ar mount-options
@@ -193,6 +194,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
diff --git a/sbin/mdmfs/mdmfs.c b/sbin/mdmfs/mdmfs.c
index 2dcf087079e5..2e6bb458def3 100644
--- a/sbin/mdmfs/mdmfs.c
+++ b/sbin/mdmfs/mdmfs.c
@@ -88,6 +88,7 @@ static void do_mount_md(const char *, const char *);
static void do_mount_tmpfs(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 const char *run_exitstr(int);
@@ -104,7 +105,7 @@ main(int argc, char **argv)
enum md_types mdtype; /* The type of our memory disk. */
bool have_mdtype, mlmac;
bool detach, softdep, autounit, newfs;
- const char *mtpoint, *size_arg, *unitstr;
+ const char *mtpoint, *size_arg, *skel, *unitstr;
char *p;
int ch, idx;
void *set;
@@ -118,6 +119,7 @@ main(int argc, char **argv)
mlmac = false;
newfs = true;
have_mdtype = false;
+ skel = NULL;
mdtype = MD_SWAP;
mdname = MD_NAME;
mdnamelen = strlen(mdname);
@@ -142,7 +144,7 @@ main(int argc, char **argv)
}
while ((ch = getopt(argc, argv,
- "a:b:Cc:Dd:E:e:F:f:hi:LlMm:NnO:o:Pp:Ss:tT:Uv:w:X")) != -1)
+ "a:b:Cc:Dd:E:e:F:f:hi:k:LlMm:NnO:o:Pp:Ss:tT:Uv:w:X")) != -1)
switch (ch) {
case 'a':
argappend(&newfs_arg, "-a %s", optarg);
@@ -184,6 +186,9 @@ main(int argc, char **argv)
case 'i':
argappend(&newfs_arg, "-i %s", optarg);
break;
+ case 'k':
+ skel = optarg;
+ break;
case 'L':
loudsubs = true;
break;
@@ -359,6 +364,8 @@ main(int argc, char **argv)
}
do_mtptsetup(mtpoint, &mi);
+ if (skel != NULL)
+ do_copy(mtpoint, skel);
return (0);
}
@@ -615,6 +622,23 @@ do_newfs(const char *args)
run_exitnumber(rv));
}
+
+/*
+ * Copy skel into the mountpoint.
+ */
+static void
+do_copy(const char *mtpoint, const char *skel)
+{
+ int rv;
+
+ rv = chdir(skel);
+ if (rv != 0)
+ err(1, "chdir to %s", skel);
+ rv = run(NULL, "/bin/pax -rw -pe . %s", mtpoint);
+ if (rv != 0)
+ 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
@@ -822,8 +846,8 @@ usage(void)
fprintf(stderr,
"usage: %s [-DLlMNnPStUX] [-a maxcontig] [-b block-size]\n"
"\t[-c blocks-per-cylinder-group][-d max-extent-size] [-E path-mdconfig]\n"
-"\t[-e maxbpg] [-F file] [-f frag-size] [-i bytes] [-m percent-free]\n"
-"\t[-O optimization] [-o mount-options]\n"
+"\t[-e maxbpg] [-F file] [-f frag-size] [-i bytes] [-k skel]\n"
+"\t[-m percent-free] [-O optimization] [-o mount-options]\n"
"\t[-p permissions] [-s size] [-v version] [-w user:group]\n"
"\tmd-device mount-point\n", getprogname());
exit(1);