mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chris Wedgwood <cw@f00f.org>
To: robotti@godmail.com, linux-kernel@vger.kernel.org,
	Al Viro <viro@parcelfarce.linux.theplanet.co.uk>
Subject: Re: Initramfs and TMPFS!
Date: Wed, 24 Aug 2005 13:59:44 -0700	[thread overview]
Message-ID: <20050824205944.GA32599@taniwha.stupidest.org> (raw)
In-Reply-To: <20050824205237.GB14136@animx.eu.org>

On Wed, Aug 24, 2005 at 04:52:37PM -0400, Wakko Warner wrote:

> Care to send me the patch?

Heh.  Not really as I don't really know if people should be using it
in it's current state --- the shmem init is very very hacky and I have
other changes I've not had a chance to do.

Anyhow, here is an older version of it.  It's from some old internal
embedded tree but should be trivial to shoehorn into anything recent.

If people really do like or want this I would like to know and maybe
something more elegant can be worked out.



Index: linux/init/main.c
===================================================================
--- linux/init/main.c	(revision 51)
+++ linux/init/main.c	(working copy)
@@ -689,6 +689,49 @@
 #endif
 }
 
+/* If we want the rootfs on initramfs so we mount initramfs over the
+ * rootfs before we unpack it.  The little dance we do by creating a
+ * pivot point and moving the root to that is in fact necessary
+ * because lookups of "." don't resolve mountpoints.
+ */
+static inline void __init overmount_rootfs(void)
+{
+#ifdef CONFIG_EARLYUSERSPACE_ON_TMPFS
+	int init_tmpfs(void);
+	int (*initfunc)(void) = init_tmpfs;
+	mm_segment_t oldfs;
+	char pivot[] = "/pivot";
+
+	/* Explicitly go and init the overmount fs early (long-term
+	 * the need for this will probably go away. */
+
+	if (initfunc())
+		goto err;
+
+	oldfs = get_fs();
+	set_fs(KERNEL_DS);
+
+	if (sys_mkdir(pivot, 0700) < 0)
+		goto err;
+	if (sys_mount("tmpfs", pivot, "tmpfs", 0, NULL))
+		goto err;
+
+	/* Below here errors are unlikely and icky to deal with. */
+	sys_chdir(pivot);
+	sys_mount(".", "/", NULL, MS_MOVE, NULL);
+	sys_chdir(".");
+	sys_chroot(".");
+	printk(KERN_INFO "Overmounted tmpfs\n");
+	goto out;
+
+ err:
+	printk(KERN_ERR "Overmount error\n");
+
+ out:
+	set_fs(oldfs);
+#endif /* CONFIG_EARLYUSERSPACE_ON_TMPFS */
+}
+
 static int init(void * unused)
 {
 	lock_kernel();
@@ -715,6 +758,7 @@
 	 * Do this before initcalls, because some drivers want to access
 	 * firmware files.
 	 */
+	overmount_rootfs();
 	populate_rootfs();
 
 	do_basic_setup();
Index: linux/fs/Kconfig
===================================================================
--- linux/fs/Kconfig	(revision 51)
+++ linux/fs/Kconfig	(working copy)
@@ -951,6 +951,18 @@
 	  If you are not using a security module that requires using
 	  extended attributes for file security labels, say N.
 
+config EARLYUSERSPACE_ON_TMPFS
+	bool "Unpack the early userspace onto tmpfs"
+	depends TMPFS
+	default y
+	help
+	  Use this to have your early userspace placed (decompressed)
+	  onto tmpfs as opposed ramfs.  This will allow you to
+	  restrict the size of your root-filesystem and it will also
+	  be swappable.
+
+	  If unsure, say Y.
+
 config HUGETLBFS
 	bool "HugeTLB file system support"
 	depends X86 || IA64 || PPC64 || SPARC64 || SUPERH || X86_64 || BROKEN
Index: linux/mm/shmem.c
===================================================================
--- linux/mm/shmem.c	(revision 51)
+++ linux/mm/shmem.c	(working copy)
@@ -2206,7 +2206,7 @@
 };
 static struct vfsmount *shm_mnt;
 
-static int __init init_tmpfs(void)
+int __init init_tmpfs(void)
 {
 	int error;
 
@@ -2239,7 +2239,12 @@
 	shm_mnt = ERR_PTR(error);
 	return error;
 }
+/* Don't do this if we are calling it early explicity */
+#ifndef CONFIG_EARLYUSERSPACE_ON_TMPFS
+/* Iff CONFIG_EARLYUSERSPACE_ON_TMPFS is set then we will interpose
+ * ramfs so this will get called explicitly and early */
 module_init(init_tmpfs)
+#endif /* !CONFIG_EARLYUSERSPACE_ON_TMPFS */
 
 /*
  * shmem_file_setup - get an unlinked file living in tmpfs

  reply	other threads:[~2005-08-24 21:00 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-23 22:05 robotti
2005-08-24  2:57 ` Chris Wedgwood
2005-08-24 20:52   ` Wakko Warner
2005-08-24 20:59     ` Chris Wedgwood [this message]
  -- strict thread matches above, loose matches on Subject: below --
2005-09-03  8:29 Chuck Ebbert
2005-08-27  8:19 Kent Robotti
2005-08-27 21:28 ` Chris Wedgwood
2005-08-27 21:42   ` Lee Revell
2005-08-27 22:45   ` Kent Robotti
2005-08-27 22:42     ` David Weinehall
2005-08-27 22:57     ` Patrick McFarland
2005-08-27 23:38     ` Chris Wedgwood
2005-08-27 23:41   ` Alistair John Strachan
2005-08-28  0:21     ` Patrick McFarland
2005-08-28  5:36     ` Willy Tarreau
     [not found] <4Fuuy-6df-11@gated-at.bofh.it>
     [not found] ` <4FJMZ-1YX-17@gated-at.bofh.it>
2005-08-26 15:49   ` Bodo Eggert
2005-08-26  6:09 Kent Robotti
2005-08-26  1:39 dwilson24
2005-08-26 19:06 ` Chris Wedgwood
2005-08-26 20:08   ` Kent Robotti
2005-08-26 20:22     ` Chris Wedgwood
2005-08-26 21:34       ` Kent Robotti
     [not found]       ` <20050826211231.GA957@Linux.nyc.rr.com>
     [not found]         ` <20050827004045.GA17686@taniwha.stupidest.org>
2005-08-27  3:21           ` Kent Robotti
2005-08-27  4:11             ` Chris Wedgwood
2005-08-25 19:32 dwilson24
2005-08-25 19:05 Alan Jenkins
2005-08-26 10:37 ` Erik Mouw
2005-08-26 19:08 ` Chris Wedgwood
2005-08-25 18:23 robotti
2005-08-25 18:15 robotti
2005-08-25 19:10 ` Ian Campbell
2005-08-26 10:29 ` Erik Mouw
2005-08-25 15:38 robotti
2005-08-25 16:00 ` Erik Mouw
2005-08-26 19:10 ` Chris Wedgwood
2005-08-25 15:34 robotti
2005-08-25 15:54 ` Erik Mouw
2005-08-26 15:03 ` Horst von Brand
2005-08-25  4:35 robotti
2005-08-25 13:49 ` Chris Wedgwood
2005-08-25  4:32 robotti
2005-08-25 13:47 ` Chris Wedgwood
2005-08-24 22:41 robotti
2005-08-25  3:12 ` Chris Wedgwood
2005-08-24  3:15 robotti
2005-08-23 21:16 robotti
2005-08-23 21:24 ` Olivier Galibert
2005-08-25  3:14 ` Chris Wedgwood

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050824205944.GA32599@taniwha.stupidest.org \
    --to=cw@f00f.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robotti@godmail.com \
    --cc=viro@parcelfarce.linux.theplanet.co.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®