Bug 1361043

Summary: pivot_root: failed to change root from `.' to `old-root': Invalid argument
Product: Red Hat Enterprise Linux 7 Reporter: Xibo Ning <xning>
Component: util-linuxAssignee: Karel Zak <kzak>
Status: CLOSED NOTABUG QA Contact: qe-baseos-daemons
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 7.2CC: fw.dmitrii, lpol
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-12-01 10:53:37 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description Xibo Ning 2016-07-28 08:58:38 UTC
Description of problem:
pivot_root: failed to change root from `.' to `old-root': Invalid argument

Version-Release number of selected component (if applicable):
[root@localhost new-root]# cat /etc/redhat-release 
CentOS Linux release 7.2.1511 (Core) 
[root@localhost new-root]# rpm -qa | grep util-linux
util-linux-debuginfo-2.23.2-26.el7_2.2.x86_64
util-linux-2.23.2-26.el7_2.2.x86_64
[root@localhost new-root]# 

How reproducible:


Steps to Reproduce:
1. mkdir /new-root
2. mount -n -t tmpfs -o size=500M none /new-root
3. cd /new-root
4. mkdir old-root
5. pivot_root . old-root

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

Expected results:
pivot_root should run successfully and quit.

Additional info:
The above steps works well on RHEL 6.

Comment 2 Dmitrii 2016-11-20 21:37:38 UTC
Hi,

You may have some mounts with MS_SHARED so this is probably not a bug:

Note 'shared' in the output:

grep -iP '/ /\s' /proc/$$/mountinfo
...
25 0 252:1 / / rw,relatime shared:1 - ext4 /dev/mapper/my--vg-root rw,errors=remount-ro,data=ordered
...

This will block you from using pivot_root, see linux/fs/namespace.c, pivot_root definition.

The relevant kernel code (checks for IS_MNT_SHARED and returns EINVAL on failure):
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/fs/namespace.c?h=v3.10#n2627

1da177e4c 1313 (Linus Torvalds      2005-04-16 15:20:36 -0700 3064) 	error = -EINVAL;
419148da6e 2627 (Al Viro             2011-11-24 19:41:16 -0500 3065) 	new_mnt = real_mount(new.mnt);
419148da6e 2628 (Al Viro             2011-11-24 19:41:16 -0500 3066) 	root_mnt = real_mount(root.mnt);
84d17192d2 2613 (Al Viro             2013-03-15 10:53:28 -0400 3067) 	old_mnt = real_mount(old.mnt);
84d17192d2 2614 (Al Viro             2013-03-15 10:53:28 -0400 3068) 	if (IS_MNT_SHARED(old_mnt) ||
fc7be130c7 2647 (Al Viro             2011-11-25 01:05:37 -0500 3069) 		IS_MNT_SHARED(new_mnt->mnt_parent) ||
fc7be130c7 2648 (Al Viro             2011-11-25 01:05:37 -0500 3070) 		IS_MNT_SHARED(root_mnt->mnt_parent))
b12cea9198 2603 (Al Viro             2011-03-18 08:55:38 -0400 3071) 		goto out4;


If you do `unshare -m` before step 5 it should work just fine.

-Dmitrii S.

Comment 3 Karel Zak 2016-12-01 10:53:37 UTC
Yes, due to migration to systemd we use "shared" as the default propagation for mount points.