Subject: Re: feature request: root file system change
To: Lubomir Sedlacik <>
From: Simon J. Gerraty <>
List: tech-kern
Date: 04/20/2005 09:54:46
Hi, I had a very similar requirment to yours...

>On Sat, Apr 16, 2005 at 08:46:06PM +0200, Hubert Feyrer wrote:
>> Looking at the pivot_root(2) manpage, I don't understand how it is
>> different from chroot(2):

That was my initial reaction too fwiw.

>> ``pivot_root moves the root file system of the current process to the
>> directory put_old and makes new_root the new root file system of the
>> current process.''

>moves, not changes.  it's roughly equivalent to:

>  umount /
>  mount what_was_/_fs_before /put_old
>  mount new_/_fs /

possibly cute, but not strictly necessary.

>there is no reason to run init(8) twice and i've never said i want to do
>that.  the /etc/rc in md(4) would simply source /etc/rc from the new / fs
>after the change.

Indeed.  The trick is to make init do the chroot itself.

>i know how chroot works.  it might be enough for sandboxes but it's a
>mess for my purpose.  e.g.,

>- you don't fool kernel with chroot(2), things like savecore or mount -a
>  don't work properly

savecore works fine as does mount -a.

the only thing which is truely ugly is the fsck of /, you cannot chroot
until you do this - without some psycotherapy on the kernel.

>- after /etc/rc finishes, the shell executed from chroot(8) exits

yes, and once rc finished init(8) chroots and the rest is joy.

All of which is not to say that this pivot thing won't work or is a bad idea,
but you don't necessarily need it.