>Number:         146254
>Category:       bin
>Synopsis:       [PATCH][mdmfs] Add -k option to specify a skeldir
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun May 02 21:20:07 UTC 2010
>Closed-Date:
>Last-Modified:
>Originator:     Jeremie Le Hen
>Release:        FreeBSD 9.0-CURRENT
>Organization:
None
>Environment:
System: FreeBSD felucia.tataz.chchile.org 9.0-CURRENT

>Description:
        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 ---


>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-bugs
To unsubscribe, send any mail to "[email protected]"

Reply via email to