Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm trying to create a Linux image with custom picked packages.
What I'm trying to do is to hand craft the packages I'm going to use on an XO laptop, because compiling packages takes really long time on the real XO hardware, if I can build all the packages I need and just flash the image to the XO, I can save time and space.

When I tried to install some packages, it failed to configure due to missing the proc, sys, dev directories. So, I learned from other places that I need to "mount" the host proc, ... directories to my chroot environment.

I saw two syntax and am not sure which one to use.

In host machine:

  mount --bind /proc <chroot dir>/proc 

and another syntax (in chroot environment):

  mount -t proc none /proc

Which one should I use, and what are the difference?

share|improve this question

migrated from stackoverflow.com Jul 19 '10 at 0:35

This question came from our site for professional and enthusiast programmers.

    
Beware: granting access to the disk devices means that you lose some of the benefits of 'chroot()'. In particular, the determined can read files outside of their section of the file system if you are not careful. –  Jonathan Leffler Jul 18 '10 at 19:18
    
@Jonathan Leffler: that doesn't sound like an issue for what he is doing. –  Zifre Jul 19 '10 at 1:02

4 Answers 4

up vote 15 down vote accepted

For /proc and /sys, I suppose you could use either method. They are both special file systems so they can be recreated any number of times (the bind mount method uses the exact same mount as the host system, whereas the other method uses a new mount). I've always seen the bind mount recommended in guides, so I'd use that. As far as I know, there is no real important difference.

However, /dev is usually a tmpfs mount that is managed by udev, so it has to be the actual same file system as on the host machine. That means that you would need to use the bind mount method.

If this chroot is going to be around for awhile, you can put these entries in /etc/fstab on the host system to simplify things.

share|improve this answer

The Arch Linux Wiki suggests the following commands:

cd /mnt/arch # or where you are preparing the chroot dir
mount -t proc proc proc/
mount -t sysfs sys sys/
mount -o bind /dev dev/

I can confirm they worked for me.

share|improve this answer
    
They also seemed to work for me in ubuntu. –  isaaclw Sep 28 '12 at 21:01

The Gentoo Handbook specifically calls out these two commands for re-mounting /proc and /dev. I've used them several times.

mount -t proc none /mnt/chroot/proc
mount -o bind /dev /mnt/chroot/dev

I suspect /sys is just a regular folder, so you should be able to make a hard link.

ln /sys /mnt/chroot/sys
share|improve this answer
9  
You can't hardlink a directory (usually) like you suggest for /sys, and if you use a symlink it'll break as soon as you chroot. –  Steven Schlansker Jul 19 '10 at 0:31

I've also wondered about these other pseudo filesystems and tmpfs locations. This is on debian

/dev/pts 
/run
/run/shm
/proc/sys/fs/binfmt_mist
/var/lib/nfs/rpc_pipefs
/proc/fs/nfsd
/proc/bus/usb

It should be okay to mount the usbfs, rpc_pipefs and devpts pseudo-filesystems from within the chroot. I reccomend not binding /proc to the chroot's /proc, since the kernel has the concept of namespaces, and can actually put different things in the chroot's proc. I assume it's the same for /sys, but I don't know.

It's probably a bad idea to mount the system's /var or /run onto the chroot.

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.