From owner-freebsd-bugs@FreeBSD.ORG Sun May 2 21:20:07 2010 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id F260C106564A for ; Sun, 2 May 2010 21:20:07 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [69.147.83.40]) by mx1.freebsd.org (Postfix) with ESMTP id AF8C28FC1D for ; Sun, 2 May 2010 21:20:07 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id o42LK7H7087703 for ; Sun, 2 May 2010 21:20:07 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id o42LK7iv087702; Sun, 2 May 2010 21:20:07 GMT (envelope-from gnats) Resent-Date: Sun, 2 May 2010 21:20:07 GMT Resent-Message-Id: <201005022120.o42LK7iv087702@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Jeremie Le Hen Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 046D7106566B for ; Sun, 2 May 2010 21:11:22 +0000 (UTC) (envelope-from jlh@felucia.tataz.chchile.org) Received: from smtp5-g21.free.fr (smtp5-g21.free.fr [212.27.42.5]) by mx1.freebsd.org (Postfix) with ESMTP id B1A438FC1B for ; Sun, 2 May 2010 21:11:18 +0000 (UTC) Received: from smtp5-g21.free.fr (localhost [127.0.0.1]) by smtp5-g21.free.fr (Postfix) with ESMTP id 0836CD4808C for ; Sun, 2 May 2010 23:11:15 +0200 (CEST) Received: from endor.tataz.chchile.org (tataz.chchile.org [82.233.239.98]) by smtp5-g21.free.fr (Postfix) with ESMTP id 231A9D4808A for ; Sun, 2 May 2010 23:11:13 +0200 (CEST) Received: from felucia.tataz.chchile.org (felucia.tataz.chchile.org [192.168.1.9]) by endor.tataz.chchile.org (Postfix) with ESMTP id 42E8F33D2B for ; Sun, 2 May 2010 21:11:12 +0000 (UTC) Received: by felucia.tataz.chchile.org (Postfix, from userid 1000) id 39691A14E0; Sun, 2 May 2010 21:11:12 +0000 (UTC) Message-Id: <20100502211112.39691A14E0@felucia.tataz.chchile.org> Date: Sun, 2 May 2010 21:11:12 +0000 (UTC) From: Jeremie Le Hen To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Cc: Subject: bin/146254: [PATCH][mdmfs] Add -k option to specify a skeldir X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Jeremie Le Hen List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 02 May 2010 21:20:08 -0000 >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: