[lxc-users] How to enable df inside a lxc container?

Craig Ruff cruff at ucar.edu
Thu Nov 13 18:17:16 UTC 2014


I do this by creating /etc/mtab inside the container at startup based on
the contents of the lxc.fstab file that was bind mounted inside the
container.  I add lines prefixed with "#df" for other file systems bind
mounted inside the container by means external to the lxc startup
mechanisms.

This is the contents of the /etc/lxc.init file that is run at container
start.

#!/bin/bash

lxctab=/etc/lxc.fstab
mtab=/etc/mtab

[ -e $tab ] || return 0;

first=1
cat <<EOF > $mtab
none   /        ext4   rw                  0 0
proc   /proc    proc   nodev,noexec,nosuid 0 0
devpts /dev/pts devpts defaults            0 0
sysfs  /sys     sysfs  defaults            0 0
EOF

while read src dst type opts x y; do
        if [ $first = 1 ]; then
                first=0
                prefix=${dst%/etc/lxc.fstab}
                continue
        fi

        case $src in
        \#df) src=none ;;
        esac

        dst=${dst#$prefix}
        case $dst in
        /tmp)
                src=none
                chmod 1777 /tmp
                ;;

        /var/tmp)
                src=none
                ;;
        esac

        echo "$src $dst $type $opts $x $y" >> $mtab
done < $lxctab

umount $lxctab
exit 0

Here is a sample lxc.fstab file:

/containers/data-access1/lxc.fstab
/containers/data-access1/rootfs/etc/lxc.fstab none bind,ro 0 0
#/containers/data-access1/tmpfs /containers/data-access1/rootfs/tmp ext4
defaults 0 0
/containers/data-access1/rootfs/tmp /containers/data-access1/rootfs/var/tmp
ext4 bind 0 0
/containers/glade /containers/data-access1/rootfs/glade none
rbind,create=dir 0 0
/containers/data /containers/data-access1/rootfs/data none rbind,create=dir
0 0
/nfs/home/dasg/authdb /containers/data-access1/rootfs/nfs/home/dasg/authdb
nfs bind 0 0
#df /glade/p gpfs bind 0 0
#df /glade/scratch gpfs bind 0 0
#df /glade/u gpfs bind 0 0
#df /data/share gpfs bind 0 0


Craig Ruff
NCAR/CISL
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linuxcontainers.org/pipermail/lxc-users/attachments/20141113/9e01270a/attachment.html>


More information about the lxc-users mailing list