Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 10 down vote accepted

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.

share|improve this answer
    
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

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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