1

I want to test the pivot_root command line, which moves the root file system of the current process to the directory put_old and makes new_root the new root file system. http://man7.org/linux/man-pages/man8/pivot_root.8.html

But I always get

pivot_root: failed to change root from `.' to `old-root/': Invalid argument

I use fedora as base root, I have a Archlinux in my home folder

[root@localhost arch-root]# ls
bin  boot  dev  etc  home  lib  lib64  mnt  old-root  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

[root@localhost arch-root]# pivot_root . old-root/ 
pivot_root: failed to change root from `.' to `old-root/': Invalid argument

I also try to call linux function pivot_root("/chroot_test", "/chroot_test/old-root"); Got same error.

Any idea about this ?

Update 1:

I also try to test pivot_root in Docker.

I mount this arch-root in to Docker container.

But get the following error: Operation not permitted

root@00d871ce892b:/# cd test_root/
root@00d871ce892b:/test_root# ls
bin  boot  dev  etc  home  lib  lib64  mnt  old-root  opt  proc  root  run  sbin  srv     sys  test_pivot_root  test_pivot_root.c   tmp  usr  var
root@00d871ce892b:/test_root# pivot_root . tmp/
pivot_root: Operation not permitted

I have found the solution:

Run docker with --privileged=true

So we can test pivot_root in the docker container

migrated from stackoverflow.com Sep 16 '14 at 12:48

This question came from our site for professional and enthusiast programmers.

2

pivot_root is subject to a number of important limitations; one of them is that the new root must be on a different filesystem from the current one. In your case, unless you have a filesystem mounted at /home, chances are that your Arch system is installed on the same filesystem as the current root.

Chances are that you don't want pivot_root() anyway, though. It's primarily intended to be used during system startup, and will have some really strange effects when used on a running system. You probably want to use chroot instead, as that doesn't affect the rest of the system, and isn't subject to any of the odd limitations of pivot_root. Try, for instance:

chroot arch-root /bin/bash
  • Thanks for answering. Here is some other information. 1, I have tried chroot firstly. It works. So I move to pivot_root. 2 You are correct, my arch-root is in my current file system. But I also try like this : i mount from virtual box share folder to fedora. it still does not work – vvilp Sep 16 '14 at 1:12
  • Why would you want to move to pivot_root? pivot_root and chroot do almost completely different things. – tangrs Sep 16 '14 at 2:35
  • Hello man, because I am a geek!. Just kidding. Because I am doing some research about linux container. they seem change chroot to pivot_root. Btw chroot can be jailbreak. – vvilp Sep 16 '14 at 3:20
  • 1
    pivot_root is not used with containers. As I mentioned in my answer, it's really only useful during system startup. – duskwuff Sep 16 '14 at 3:34
  • Docker lxc have change the chroot to the pivot_root as default method long time ago....please never be so sure about something – vvilp Sep 16 '14 at 6:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.