From: Stephen Powell on
On Sun, 21 Mar 2010 09:38:12 -0400 (EDT), Katharina Haselhorst wrote:
> Since I'm doing a pivot_root before trying to umount the old root there
> are still several processes keeping some files open inside the old root
> subdirs. Init is still running, als well as rc and one shutdown script
> (atm I'm doing the pivot_root just before shutdown, because most
> processes are terminted by the time). If I kill one of these processes,
> the systems gets shut down.
> I don't understand why there is still that shutdown script running,
> because I'm doing a exec chroot. The pivot_root's manual says: "Note
> that exec chroot changes the running executable, which is necessary if
> the old root directory should be unmounted afterwards."
> And the init process is always running, so how does pivot_root handle
> the open files of init?
> I did move the /proc and /dev mountpoints from old-root to the new root
> - might that cause some problems? If I don't do that - lsof or fuser of
> course don't show any open files for old-root, but I'm not able to
> unmount to old-root either.

Maybe it's time to step back and ask a more basic question.
What is it that you are trying to accomplish? I know that you are trying
to do a pivot_root. But *why* are you trying to do a pivot_root?
Why do you think you need to do it? What is the real-world problem
that you are trying to solve?

--
.''`. Stephen Powell <zlinuxman(a)wowway.com>
: :' :
`. `'`
`-


--
To UNSUBSCRIBE, email to debian-user-REQUEST(a)lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster(a)lists.debian.org
Archive: http://lists.debian.org/1519384701.20787971269265796204.JavaMail.root(a)md01.wow.synacor.com
From: Katharina Haselhorst on
Hello,

> Maybe it's time to step back and ask a more basic question.
> What is it that you are trying to accomplish? I know that you are trying
> to do a pivot_root. But *why* are you trying to do a pivot_root?
> Why do you think you need to do it? What is the real-world problem
> that you are trying to solve?

I want to go back into an initramfs setting so that only the running
kernel and one specific process remains. Goal is to be able to boot a
new system from there with a new hard drive (for example mounted via nfs
or some other way) withouth the need to reboot the entire kernel. The
whole thing is running within a xen domU atm. So the new hard disk could
be passed through via xend or mounted via nfs. And for cleanly
terminating the first system I need to unmount the root filesystem and
somehow replace the old init process with my specific process running in
that initramfs setting.
According to the pivot_root manpage, it should be possible to clear all
dependencies to the old root fs so that it can be unmounted after the
pivot_root command. And that's what not working for me.

K. Haselhorst


--
To UNSUBSCRIBE, email to debian-user-REQUEST(a)lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster(a)lists.debian.org
Archive: http://lists.debian.org/4BA7BF1E.1020901(a)mathematik.uni-marburg.de
From: Stephen Powell on
On Mon, 22 Mar 2010 15:03:58 -0400 (EDT), Katharina Haselhorst wrote:
> Stephen Powell wrote:
>> Maybe it's time to step back and ask a more basic question.
>> What is it that you are trying to accomplish? I know that you are trying
>> to do a pivot_root. But *why* are you trying to do a pivot_root?
>> Why do you think you need to do it? What is the real-world problem
>> that you are trying to solve?
>
> I want to go back into an initramfs setting so that only the running
> kernel and one specific process remains. Goal is to be able to boot a
> new system from there with a new hard drive (for example mounted via nfs
> or some other way) withouth the need to reboot the entire kernel. The
> whole thing is running within a xen domU atm. So the new hard disk could
> be passed through via xend or mounted via nfs. And for cleanly
> terminating the first system I need to unmount the root filesystem and
> somehow replace the old init process with my specific process running in
> that initramfs setting.
> According to the pivot_root manpage, it should be possible to clear all
> dependencies to the old root fs so that it can be unmounted after the
> pivot_root command. And that's what not working for me.

You would probably want to run all the executable files in /etc/rc6.d
in alphabetical order, supplying the "stop" parameter, with the
exception of the last one, which on my system is S90reboot.
Then run something like this:

----------

#!/bin/sh
# Example: mount the new root file system over NFS from 10.0.0.1:/my_root
# and run init.
ifconfig lo 127.0.0.1 up # for portmap
# configure Ethernet or such
portmap # for lockd (implicitly started by mount)
mount -o ro 10.0.0.1:/my_root /mnt
killall portmap # portmap keeps old root busy
cd /mnt
pivot_root . old_root
exec chroot . sh -c 'umount /old_root; exec /sbin/init \
<dev/console >dev/console 2>&1

----------

The "# configure Ethernet or such" line is what is most likely
to give you trouble. Exactly what goes there is dependent on
your environment.

Another trick: "telinit -u" can sometimes be used to effectively
restart init, which may cause it to close the old files.
Debian uses this when applying maintenance
to the init program itself without rebooting.

HTH

--
.''`. Stephen Powell <zlinuxman(a)wowway.com>
: :' :
`. `'`
`-


--
To UNSUBSCRIBE, email to debian-user-REQUEST(a)lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster(a)lists.debian.org
Archive: http://lists.debian.org/1055911490.20899381269288098225.JavaMail.root(a)md01.wow.synacor.com
From: Katharina Haselhorst on
> You would probably want to run all the executable files in /etc/rc6.d
> in alphabetical order, supplying the "stop" parameter, with the
> exception of the last one, which on my system is S90reboot.

that's what I was doing - only with runlevel 0 without doing the actual
halt at the end.

> Then run something like this:
>
> ----------
>
> #!/bin/sh
> # Example: mount the new root file system over NFS from 10.0.0.1:/my_root
> # and run init.
> ifconfig lo 127.0.0.1 up # for portmap
> # configure Ethernet or such
> portmap # for lockd (implicitly started by mount)
> mount -o ro 10.0.0.1:/my_root /mnt
> killall portmap # portmap keeps old root busy
> cd /mnt
> pivot_root . old_root
> exec chroot . sh -c 'umount /old_root; exec /sbin/init \
> <dev/console>dev/console 2>&1
>
> ----------

I only see 2 places (without patching init itself) to put these commands:
1. into a new shutdown script in place of S90{halt,reboot}
2. into the rc script

But no matter which of these I choose there remains at least init and
perhaps the process executing rc running and keeping the old root busy.
So I cannot unmount it. At least on my system init has opened some
shared libraries in old-root/lib/... and rc as well (if it is still running)

The same would happen if I restarted init with telinit -u runlevel...

Your script above is from the manpage of pivot_root, isn't it? I really
wonder in which context this example (and also the other one given in
the manpage) could work? Have you sucessfully tried it on your system?

K. Haselhorst


--
To UNSUBSCRIBE, email to debian-user-REQUEST(a)lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster(a)lists.debian.org
Archive: http://lists.debian.org/4BA7ECFC.3020808(a)mathematik.uni-marburg.de
From: Stephen Powell on
On Mon, 22 Mar 2010 18:19:40 -0400 (EDT), Katharina Haselhorst wrote:
> Stephen Powell wrote:
>> You would probably want to run all the executable files in /etc/rc6.d
>> in alphabetical order, supplying the "stop" parameter, with the
>> exception of the last one, which on my system is S90reboot.
>
> that's what I was doing - only with runlevel 0 without doing the actual
> halt at the end.
>

Good.

>> Then run something like this:
>>
>> ----------
>>
>> #!/bin/sh
>> # Example: mount the new root file system over NFS from 10.0.0.1:/my_root
>> # and run init.
>> ifconfig lo 127.0.0.1 up # for portmap
>> # configure Ethernet or such
>> portmap # for lockd (implicitly started by mount)
>> mount -o ro 10.0.0.1:/my_root /mnt
>> killall portmap # portmap keeps old root busy
>> cd /mnt
>> pivot_root . old_root
>> exec chroot . sh -c 'umount /old_root; exec /sbin/init \
>> <dev/console>dev/console 2>&1
>>
>> ----------
>
> I only see 2 places (without patching init itself) to put these commands:
> 1. into a new shutdown script in place of S90{halt,reboot}
> 2. into the rc script
>
> But no matter which of these I choose there remains at least init and
> perhaps the process executing rc running and keeping the old root busy.
> So I cannot unmount it. At least on my system init has opened some
> shared libraries in old-root/lib/... and rc as well (if it is still running)
>
> The same would happen if I restarted init with telinit -u runlevel...
>
> Your script above is from the manpage of pivot_root, isn't it?

Yes.

> I really wonder in which context this example (and also the other one given
> in the manpage) could work? Have you sucessfully tried it on your system?

No, I've never had occasion to.
But where exactly is the failure occuring?
Does the mount command fail?
Does the pivot_root command fail? Does exec chroot fail?

Kill should be able to kill any process *except* init itself.
And "telinit -u" should be able to refresh init.

Something like this occurs during boot with the transition from the initial
RAM filesystem to the permanent root filesystem. Perhaps you should
study the scripts in /etc/rcS.d to find how the root file system is
changed there. Maybe that will give you some clues.

--
.''`. Stephen Powell <zlinuxman(a)wowway.com>
: :' :
`. `'`
`-


--
To UNSUBSCRIBE, email to debian-user-REQUEST(a)lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster(a)lists.debian.org
Archive: http://lists.debian.org/1037565534.20929511269295023681.JavaMail.root(a)md01.wow.synacor.com