Linux, Windows, Virtualization, OpenSource & Blogging

How to Mount External Directory Inside the Linux Container

3

This guide helps you to mount external directory inside the Linux container.If you are yet to setup Linux container in your environment, here are the guides you should take a look.

READ: Setup Linux Container with LXC on Ubuntu 16.04

READ: Setup Linux Container with LXC on CentOS 7 / RHEL 7

Step 1: Create a mounting directory on the host. Ex: raj, if you want to mount the device under the mount point “/raj” inside the Linux container.

sudo mkdir /var/lib/lxc/ubuntu_lxc/rootfs/raj

Step 2: Mount the device on the above directory.

sudo mount /dec/sda1 /var/lib/lxc/ubuntu_lxc/rootfs/raj

You should run the above commands on the Linux host, i.e., host operating system.

Where,

raj –  Mount point

/dev/sda1 –  Device you want to mount

ubuntu_lxc – Name of the Linux container

Step 3: Take a console or log in to Linux container and use df command to see the external directory.

sudo lxc-console -n ubuntu_lxc

The output of mounted external directory:

ubuntu@ubuntu_lxc:~$ df -h
Filesystem                   Size  Used Avail Use% Mounted on
/dev/mapper/server--vg-root   97G  2.8G   90G   3% /
none                         492K     0  492K   0% /dev
tmpfs                        488M     0  488M   0% /dev/shm
tmpfs                        488M  6.2M  482M   2% /run
tmpfs                        5.0M     0  5.0M   0% /run/lock
tmpfs                        488M     0  488M   0% /sys/fs/cgroup
/dev/sda1                    472M  148M  300M  33% /raj
ubuntu@ubuntu_lxc:~$

That’s All.

POSTS YOU MAY LIKE -:)

You might also like
  • jbombs16

    thanks for the guide. when trying to mount, I get this error: “mount: special device /mnt/USB/downloads does not exist”

    Am I doing something wrong?

    • Raj

      Can you share me the command you are using.

      • jbombs16

        I had an spelling error. This is the correct command I used:

        sudo mount /mnt/USB/downloads/transmission /var/lib/lxc/transmission/rootfs/downloads

        When do this command, i got the error that the mnt/USB “is not a block device”

        I found a solution online that is below:

        sudo mount –bind /mnt/USB/downloads/transmission /var/lib/lxc/transmission/rootfs/downloads

        you may want to add the –bind option to the guide if you get the “not a block device” error

How to Mount External Directory Inside the Linux Container

3