LoginSignup
8

More than 5 years have passed since last update.

--rbindでマウントしたディレクトリをアンマウント

Posted at

chroot環境に入る前におなじみの

# export CHROOT=/mnt/chroot
# mount -t proc none ${CHROOT}/proc
# mount --rbind /dev ${CHROOT}/dev
# mount --rbind /sys ${CHROOT}/sys
# chroot ${CHROOT} /bin/bash

ですが,chroot環境から出て

# umount ${CHROOT}/sys
umount: /mnt/chroot/sys: target is busy.
    (In some cases useful info about processes that use
     the device is found by lsof(8) or fuser(1))

となる原因と解決案がようやくわかった.

rbindはrecursive bind,なのでディレクトリを再帰的にマウントしてるんですね.
/proc/mountsを見るとわかるとおり,
/sysの下の/sys/kernelや/sys/fsもマウントしてるのでアンマウントできない.
なので

# awk '{print $2}' /proc/mounts | grep ${CHROOT} |  sort -r | xargs umount

すれば階層の深い順にアンマウントされる.

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8