Current section

Files

Jump to
alcove edoc pivot_root-4.edoc
Raw

edoc/pivot_root-4.edoc

@doc pivot_root(2): change the root mount
Use pivot_root(2) in a Linux mount namespace to change the root
filesystem.
Warning: using pivot_root(2) in the global namespace may have unexpected
effects.
To use an arbitrary directory as a mount point:
* mark the mount namespace as private
* create a mount point by bind mounting the new root directory over
itself
* change the current working directory to the new root directory
* call pivot_root(2) with new and old root set to the current working
directory
* unmount the current working directory
== Support ==
* Linux
== Examples ==
```
1> {ok, Drv} = alcove_drv:start([{exec, "sudo -n"}]).
{ok,<0.198.0>}
2> alcove:mkdir(Drv, [], "/tmp/alcove-root", 8#755).
ok
3> {ok, Pid} = alcove:clone(Drv, [], [clone_newns]).
{ok,29739}
4> alcove:mount(Drv, [Pid], "none", "/", [], [ms_rec, ms_private], [], []).
ok
5> alcove:mount(Drv, [Pid], "/tmp/alcove-root", "/tmp/alcove-root", [], [ms_bind], [], []).
ok
6> alcove:chdir(Drv, [Pid], "/tmp/alcove-root").
ok
7> alcove:pivot_root(Drv, [Pid], ".", ".").
ok
8> alcove:umount2(Drv, [Pid], ".", [mnt_detach]).
ok
'''