大网数据广告活动
服务器运维问答

How do I unmount one of two devices mounted to the same mount point?

· 52CE 我爱测

I accidentally left two different devices mounted on /opt : /dev/xvdf on /opt type ext4 (rw,relatime,seclabel,data=ordered) /dev/md0 on /opt type ext4 (rw,relatime,seclabel,stripe=256,data=ordered) It would be a problem to umount…

问题原文

原帖链接 · Some Linux Nerd · CC BY-SA 3.0

I accidentally left two different devices mounted on /opt:

/dev/xvdf on /opt type ext4 (rw,relatime,seclabel,data=ordered)
/dev/md0 on /opt type ext4 (rw,relatime,seclabel,stripe=256,data=ordered)

It would be a problem to umount /dev/md0, and things are using /opt. /dev/md0 should be mounted on top of /dev/xvdf. Any suggestions how I can just unmount /dev/xvdf?

Tried:

[root@redacted ~]# umount /dev/xvdf
umount: /dev/xvdf: umount failed: Invalid argument

[root@redacted ~]# mount --move /dev/xvdf /temp
mount: bad option. Note that moving a mount residing under a shared
       mount is unsupported.

Also I've had AWS support for volumes yell at me about force detaching in-use volumes, so that's not an option.

社区高分解答

原帖链接 · kasperd · CC BY-SA 3.0

You cannot do it atomically. You can however do it with a sequence of mount --move commands. And you will need two other directories to use as mount points.

cp /etc/mtab /root/mtab-before
mkdir /mnt/shuffle-md0 /mnt/shuffle-xvdf
mount --move /opt /mnt/shuffle-md0
mount --move /opt /mnt/shuffle-xvdf
mount --move /mnt/shuffle-md0 /opt
umount /mnt/shuffle-xvdf
cp /etc/mtab /root/mtab-after

Notice that the /etc/mtab entry for /dev/xvdf may end up looking pretty weird in the end. So I recommend you create a copy of /etc/mtab before you start such that you can reconstruct that entry once you are done.

Anything opening paths through /opt while you are shuffling around the mount points may get unexpected results. But files and directories which were opened before you started will be unaffected by this maneuver.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-10-25)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。