Unable to get new root in new namespace

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi All, 

       Here is the complete code attempting to work in the new root of the new namespace. This program is built and executed successfully.
       But within the child context, my root is still the original root directory. My intention is to make /opt/lxc/ as my new root.
       Required executables (bash and ls) along with the required libraries are placed in /opt/lxc. 
       ** New PID Namespace is working right.         
       # ls /proc is showing the processes that are executed only in the new namespace.
      Any help is appreciated.

-----------------------------------------------------------------------------------------------------------------------------------------
#define STACK_SIZE (8 * 1024)
unsigned char stack[STACK_SIZE];
char *args[] = { "/usr/bin/bash", NULL };

int child_function (void *arg)
{

    ret = mount("", "/", "", MS_REC|MS_PRIVATE, NULL);
    ret = mount("/opt/lxc/", "/", "", MS_BIND|MS_REC, NULL);
    ret = mount("proc", "/proc", "proc", 0, NULL);
    execv(args[0],args);
    return 0;
}
int main()
{
        unshare (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWPID | CLONE_NEWNET);

        clone(child_function, stack+STACK_SIZE, CLONE_PARENT | SIGCHLD, NULL);

         return 0;
}
-----------------------------------------------------------------------------------------------------------------------------------------------------

Regards,
Prabhu
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux