About Linux FAQ

Browse More FAQs:

FreeBSD: Mount /usr/ports Inside Jail

Posted by Vivek Gite [Last updated: October 6, 2008]

Q. I'd like to save disk space for my FreeBSD 7 ISP server. We run webserver, nameserver from various jails under powerful HP RAID 10 server. How do I export /usr/ports from host to each jail hosted on /jail/ volume such as /jail/www, /jail/ns, /jail/sql etc?

A. You need to use the mount_nullfs command. It creates a null layer, duplicating a sub-tree of the file system name space under another part of the global file system namespace. This allows existing files and directories to be accessed using a different pathname. You need to run this command outside jail.

Option #1: Mount ports in read write mode

Login as root and type the following command:
# D=/jail/www
# mkdir -p $D/usr/ports
# mount_nullfs /usr/ports $D/usr/ports
# mount | sort

Now login to jail called www (jail id # 10):
# jls
# jexec 10 sh

Try to install apache22:
# cd /usr/ports
# cd www/apache22
# make install clean

Option #2: Mount ports in read only mode

As suggested by reader Mel, you can mount ports tree in read only mode. This may result into ports tree integrity in a long run.
D=/jail/www
mkdir -p $D/usr/ports
mount_nullfs -o ro /usr/ports $D/usr/ports

Mount /var/distfiles in read-write mode:
# mkdir $D/var/distfiles
# mount_nullfs -o rw /usr/ports/distfiles $D/var/distfiles

Now install port called php5:
# cd /usr/ports/lang/php5
# make install clean WRKDIRPREFIX=/tmp

You need to set WRKDIRPREFIX as ports installed in read only mode. WRKDIRPREFIX specifies where to create any temporary files.

Further readings

  • man page ports, make

Acer Aspire One 8.9-inch Mini Laptop (1.6 GHz Intel Atom N270 Processor, 1 GB RAM, 160 GB Hard Drive, XP Home, 6 Cell Battery) Sapphire Blue

E-mail    Print    Can't find an answer to your question? Contact us

Related Other Helpful FAQs:

Discussion on This FAQ

  1. Mel Says:

    It’s better to mount read-only, so you don’t make changes to the ports in either, both or neither. Secondly, you don’t get to deal with the port’s cookies (${WRKDIR}/.*_done) when you build port foo in either.

    Setting:
    DISTDIR
    WRKDIRPREFIX

    to a jail writeable directory is required.

    I myself use:
    mkdir $D/var/distfiles
    mount -t nullfs -o rw /usr/ports/distfiles $D/var/distfiles

  2. vivek Says:

    Nice tips. Thanks for sharing with us. The FAQ has been updated to incorporate your view.

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Tags: , , , , , , , , , , , ,

Copyright © 2006-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Powered by Open source software.