Subject: Re: feature request: root file system change
To: Lubomir Sedlacik <salo@Xtrmntr.org>
From: Hubert Feyrer <hubert@feyrer.de>
List: tech-kern
Date: 04/16/2005 20:46:06
On Sat, 16 Apr 2005, Lubomir Sedlacik wrote:
> what do you think about adding similar syscall to NetBSD?

Looking at the pivot_root(2) manpage, I don't understand how it is 
different from chroot(2):

``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.''

What will happen with other processes already running at that point?

Seeing that init(8) tries to be smart about getting started twice, the 
whole cgd-procedure needs to be started from there, somehow (I haven't 
looked what init(8) checks exactly to determine it's already running):

 	miyu# chroot /usr/sandbox /sbin/init
 	init: already running


I've wondered about how (but never tried!) to do what you propose a few 
times, but always thought that doing something like a "chroot -c /newroot 
/bin/sh /etc/rc" or similar would be enough, esp. as NetBSD hides the old 
root, and new processes will see "/" as their root filesystem:

 	miyu# df
 	Filesystem  512-blocks     Used     Avail Capacity  Mounted on
 	/dev/wd0a      6696396  5349538   1012040    84%    /
 	/dev/wd1e    475212206 190232774 261218822    42%    /home
 	mfs:339         387726     6728    361612     1%    /tmp
 	kernfs               2        2         0   100%    /kern
 	procfs               8        8         0   100%    /proc
 	procfs               8        8         0   100%    /usr/pkg/emul/linux/proc

 	miyu# chroot /usr/sandbox/
 	# df
 	Filesystem  512-blocks      Used     Avail Capacity  Mounted on
 	/dev/wd0a      6696396   5349538   1012040    84%    /
 	#


  - Hubert

-- 
NetBSD - Free AND Open!      (And of course secure, portable, yadda yadda)