Skip to content

Instantly share code, notes, and snippets.

@avagin
Created March 13, 2014 13:44
Show Gist options
  • Save avagin/9528751 to your computer and use it in GitHub Desktop.
Save avagin/9528751 to your computer and use it in GitHub Desktop.
chroot vs pivot_root
diff --git a/test/zdtm/lib/ns.c b/test/zdtm/lib/ns.c
index 29e9e9e..ac5751b 100644
--- a/test/zdtm/lib/ns.c
+++ b/test/zdtm/lib/ns.c
@@ -13,6 +13,7 @@
#include <fcntl.h>
#include <signal.h>
#include <sched.h>
+#include <libgen.h>
#include "ns.h"
@@ -34,7 +35,14 @@ static int prepare_mntns()
return -1;
}
- if (chdir(root)) {
+ if (mount("none", "/", "none", MS_REC|MS_PRIVATE, NULL)) {
+ fprintf(stderr, "Can't remount root with MS_PRIVATE: %m\n");
+ return -1;
+ }
+
+ chroot(dirname(strdupa(root)));
+ chdir("/");
+ if (chdir(basename(root))) {
fprintf(stderr, "chdir(%s) failed: %m\n", root);
return -1;
}
@@ -43,11 +51,6 @@ static int prepare_mntns()
return -1;
}
- if (mount("none", "/", "none", MS_REC|MS_PRIVATE, NULL)) {
- fprintf(stderr, "Can't remount root with MS_PRIVATE: %m\n");
- return -1;
- }
-
if (pivot_root(".", "./old")) {
fprintf(stderr, "pivot_root(., ./old) failed: %m\n");
return -1;
@avagin
Copy link
Author

avagin commented Mar 13, 2014

[root@avagin-fc19-cr crtools]# bash test/zdtm.sh ns/static/env00
================================= CRIU CHECK =================================
Looks good.
Execute zdtm/live/static/env00
./env00 --pidfile=env00.pid --outfile=env00.out --envname=ENV_00_TEST
PID TTY TIME CMD
30131 ? 00:00:00 env00
Dump 30131
WARNING: env00 returned 1 and left running for debug needs
Test: zdtm/live/static/env00, Result: FAIL
==================================== ERROR ====================================
Test: zdtm/live/static/env00, Namespace: 1
Dump log : /root/crtools/test/dump/env00/30131/1/dump.log
--------------------------------- grep Error ---------------------------------
(00.000461) Error (image.c:197): Unable to open irmap-cache: No such file or directory
(00.001490) Error (mount.c:1678): The root task has another root than mntns: /tmp
(00.001552) Error (cr-dump.c:1863): Dumping FAILED.
------------------------------------- END -------------------------------------
================================= ERROR OVER =================================

@avagin
Copy link
Author

avagin commented Mar 13, 2014

[root@avagin-fc19-cr crtools]# cat /proc/30131/mountinfo
71 45 8:3 /root/crtools/test / rw,relatime - ext4 /dev/sda3 rw,data=ordered
70 71 0:35 / /proc rw,relatime - proc proc rw
76 71 0:11 / /dev/pts rw,relatime - devpts pts rw,mode=600,ptmxmode=000
[root@avagin-fc19-cr crtools]# nsenter -t 30131 -m
[root@avagin-fc19-cr /]# cat /proc/self/mountinfo
45 44 8:3 / / rw,relatime - ext4 /dev/sda3 rw,data=ordered
46 45 0:5 / /dev rw,nosuid - devtmpfs devtmpfs rw,size=1468772k,nr_inodes=367193,mode=755
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment