10

Yesterday I had to install a Windows with its Grub override.

Well, it's not the first time I had to fix Grub, so I used LiveCD, mounted the root partition (I don't have boot, just / and home) and ran grub-install --root-directory=/mnt/ /dev/sda. However, it didn't work.

After Googling a while I found a tutorial in which instead of just mounting the Linux partition, he also did mount --bind /mnt/dev /dev and mount --bind /mnt/proc /proc/. After that chroot to /mnt and then installed Grub, and using this method, it worked.

What are the mount --bind commands for? I'm familiar with the usage of --bind used (man page) but I do not know why it was used on this example.

10

proc and sys filesystems are provided by the running kernel -- when the kernel is not running, they cease to exist. This means that when you chroot into another operating system, these filesystems are not present. Many programs expect them to exist so that they can function, for example, they may require information about the running system, or want to modify the way the kernel handles something. It is often enough simply to provide /proc and /sys from the current kernel for these programs to work as expected.

A symlink would not suffice, as the act of chrooting would invalidate the file paths used. In Linux, you also cannot hard link directories (other than . and .., as provided by mkdir). This means that a third option has to be used to mirror these filesystems to the chrooted environment -- bind mounting. A bind mount is provided by the kernel directly, and works as expected within a chroot.

  • proc and sys can be mounted in multiple places so --bind is not needed (only mount them twice). However /dev/ is managed by udev not insider kernel. – Maciej Piechotka May 7 '13 at 14:31
  • @MaciejPiechotka I never mentioned /dev, because it's not in the question, but that doesn't have to be managed by udev necessarily. – Chris Down May 8 '13 at 5:22
  • I was more referring to proc and sys as filesystems which can be double-mounted (mount -t proc none /mnt/proc) so you don't necessary need to mount --bind them. dev is usually managed by userspace (be it udev, busybox or anything else) so you need to do it. Minor point anyway. – Maciej Piechotka May 8 '13 at 7:21
0

The --bind option will allow the mount point to show up in a chroot-ed enviroment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.