Re: pivot_root(".", ".") and the fchdir() dance

From: Michael Kerrisk (man-pages)
Date: Tue Sep 10 2019 - 07:21:22 EST


Hello Christian,

>> All: I plan to add the following text to the manual page:
>>
>> new_root and put_old may be the same directory. In particular,
>> the following sequence allows a pivot-root operation without needâ
>> ing to create and remove a temporary directory:
>>
>> chdir(new_root);
>> pivot_root(".", ".");
>> umount2(".", MNT_DETACH);
>
> Hm, should we mention that MS_PRIVATE or MS_SLAVE is usually needed
> before the umount2()? Especially for the container case... I think we
> discussed this briefly yesterday in person.
Thanks for noticing. That detail (more precisely: not MS_SHARED) is
already covered in the numerous other changes that I have pending
for this page:

The following restrictions apply:
...
- The propagation type of new_root and its parent mount must not
be MS_SHARED; similarly, if put_old is an existing mount point,
its propagation type must not be MS_SHARED.

Thanks,

Michael


--
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/