0

I am trying to change the root of my process to new file system that I mounted at /tmp/mount_dir and i have created another directory inside it /tmp/mount_dir/inner_mount_dir, and according to the man page pivot_root(2) there is no glibc wrapper for this system call so I made my own

int pivot_root(const char *new_root, const char *put_old){

  return(syscall(SYS_pivot_root, new_root, put_old));

}

and I call it in this code after creating the two nested directories as specified by the man page

fprintf(stderr,"-->Changing the process's root...");
if(pivot_root(mount_dir, inner_mount_dir)){
  fprintf(stderr,"Failed..%m\n");
  return -1;
}else{
  fprintf(stderr,"Success\n");
}

The system call returns a success, but the issue is that the system goes into a crashing state, first all the icons from the gnome dash are gone, i cannot interact with the system at all (the system freezes i can only change windows at first then all terminates), and the screen turns into a blank black screen with a "-" at the upper left corner as if the system is shutting down, but freezes at that state until i force shutdown.

1 Answers1

3

pivot_root() acts on the namespace.

To affect only your process (and its children), first enter a new mount namespace. And you need to ensure the pivot_root operation does not propagate back to the original namespace, e.g. by using mount --make-rslave /.

How to perform chroot with Linux namespaces?

sourcejedi
  • 50,249
  • Though I did create a mount namespace before calling the pivot_root(), I think the problem was with the namespaces itself not with pivot_root() so thanks. – o.awajan May 05 '19 at 05:39