Re: pivot_root alternative

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Kyle Moffett
Date: Sunday, June 24, 2007 - 4:29 pm

On Jun 24, 2007, at 17:27:34, Salvatore De Paolis wrote:

One interesting fact about the mount() syscall is this: when  
overmounting a directory tree, a process whose current working  
directory is within said directory tree will see the old vfsmounts  
until it does an absolute chdir().  Shells tend not to be terribly  
useful for this because they use absolute paths more than necessary,  
but I think you can make it work.  For instance, if you run these  
commands after mounting the root filesystem:

mount -t proc proc /realroot/proc
cd /
mount --move /realroot /
find /proc/$$/cwd/ -mindepth 1 -maxdepth 1 -print0 \
		| xargs -0 rm -rf -- '{}' ';'
cd /

This will set up proc on the new root filesystem, move /realroot to  
the root directory, and delete the contents of the old initramfs  
using the old current-working-directory link of your shell.  The  
amusing thing is that you are using the "find" and "rm" commands from  
the newly mounted root filesystem to remove the contents of the  
completely hidden initramfs.  The only reason it's actually possible  
is because you have the tenuous thread of the working directory.

Cheers,
Kyle Moffett

-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
pivot_root alternative, Salvatore De Paolis, (Sun Jun 24, 2:27 pm)
Re: pivot_root alternative, Jan Engelhardt, (Sun Jun 24, 2:29 pm)
Re: pivot_root alternative, Arnd Hannemann, (Sun Jun 24, 2:39 pm)
Re: pivot_root alternative, Salvatore De Paolis, (Sun Jun 24, 3:08 pm)
Re: pivot_root alternative, Kyle Moffett, (Sun Jun 24, 4:29 pm)
Re: pivot_root alternative, H. Peter Anvin, (Sun Jun 24, 8:59 pm)
Re: pivot_root alternative, Salvatore De Paolis, (Sun Jun 24, 10:04 pm)
Re: pivot_root alternative, Michael Tokarev, (Mon Jun 25, 3:19 am)