Re: Is initramfs freed after kernel is booted?

From: Hannes Reinecke
Date: Wed Nov 19 2003 - 10:16:38 EST


viro@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx wrote:
On Mon, Nov 17, 2003 at 09:33:59PM +0300, Andrey Borzenkov wrote:

On Monday 17 November 2003 21:03, viro@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx wrote:

On Mon, Nov 17, 2003 at 12:50:34PM -0500, Chris Friesen wrote:

viro@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx wrote:

On Mon, Nov 17, 2003 at 11:06:48AM -0500, Chris Friesen wrote:

Anyone know why it overmounts rather than pivots?

Because amount of extra code you lose that way takes more memory than
empty roots takes.

Remove whatever files you don't need and be done with that.

How do you remove files from the old rootfs after the new one has been
mounted on top of it?

You do that before ;-)

would the following work?

pivot_root . /initramfs
cd /initramfs && rm -rf *


No. pivot_root() will not move the absolute root of tree elsewhere.


?? doing it before is rather hard ... you apparently still need something to execute your mounts :)


You do, but you can trivially call unlink() on the executable itself. It
will be freed after it does exec() of final /sbin/init...

Alternatively, you could
mkdir /root
mount final root on /root

chdir("/root");
mount("/", "initramfs", NULL, MS_BIND, NULL);
mount(".", "/", NULL, MS_MOVE, NULL);
chroot(".");
execve("/sbin/init", ...)

Nope. initramfs shares the superblock with 'rootfs', which has the MS_NOUSER flags set. Hence graft_tree() (which is the worker function for MS_BIND) refuses to work.
Can't we just remove the MS_NOUSER flags if initramfs is active?
Probably not the correct way, but certainly the quickest :-)
The correct way would probably be to clone the superblock of initramfs, set the filesystem-type of initramfs to 'ramfs' so that initramfs appears to be a chroot()ed filesystem like initrd. Then we could do a pivot_root and we have the contents of initramfs still available.
But needs someone with deeper fs-knowledge than myself to do it.

Cheers,

Hannes
--
Dr. Hannes Reinecke hare@xxxxxxx
SuSE Linux AG S390 & zSeries
Deutschherrnstr. 15-19 +49 911 74053 688
90429 Nürnberg http://www.suse.de

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/