I’ll show you how to automatically mount an SMB share on an LXC container.

1. Install required packages inside the LXC container

First, make sure you have the necessary packages installed in your LXC container:

apt update
apt install cifs-utils

2. Create a mount point

Create a directory where you want to mount the SMB share:

mkdir -p /mnt/plex_storage

3. Set up credentials file (for security)

Create a credentials file to store your SMB credentials securely:

nano /root/.smbcredentials

Add your credentials:

username=your_username
password=your_password
domain=your_domain  # If applicable

Set proper permissions:

chmod 600 /root/.smbcredentials

4. Configure auto-mounting in fstab

Edit the fstab file to set up automatic mounting:

nano /etc/fstab

Add the following line:

//server_ip/share_name /mnt/plex_storage cifs credentials=/root/.smbcredentials,uid=1000,gid=1000,file_mode=0644,dir_mode=0755,x-systemd.automount 0 0

Replace:

  • server_ip with your SMB server IP
  • share_name with your share name
  • uid and gid with appropriate user and group IDs

5. Test the mount

Test if the configuration works:

mount -a

6. Verify the share is mounted

Check if the share mounted successfully:

df -h

For LXC-specific considerations, make sure:

  1. The LXC container has the necessary privileges to mount filesystems
  2. Network connectivity between the container and SMB server is working

If your LXC container doesn’t retain mounts across reboots, you may need to add a startup script in the container that runs mount -a on boot.

Automount via systemd

To make your SMB share automatically mount at boot time in your LXC container, you need to ensure it’s properly configured in the /etc/fstab file and potentially add a systemd service or startup script.

Here’s how to set it up for automatic mounting at boot:

1. Update your fstab entry

Make sure your /etc/fstab entry is properly configured:

nano /etc/fstab

Add or modify the line for your SMB share:

//192.168.1.82/plex_storage /mnt/plex_storage cifs credentials=/root/.smbcredentials,uid=1000,gid=1000,file_mode=0644,dir_mode=0755,rw,vers=3.0,_netdev,auto 0 0

Key options explained:

  • _netdev - Tells the system this is a network device that requires network to be up before mounting
  • auto - Ensures the filesystem is mounted automatically at boot

2. Create a systemd mount unit (more reliable approach)

Systemd mount units provide better handling of network mounts. Create a file:

nano /etc/systemd/system/mnt-plex_storage.mount

Add the following:

[Unit]
Description=Mount SMB Share for Plex
After=network-online.target
Wants=network-online.target

[Mount]
What=//192.168.1.82/plex_storage
Where=/mnt/plex_storage
Type=cifs
Options=credentials=/root/.smbcredentials,uid=1000,gid=1000,file_mode=0644,dir_mode=0755,rw,vers=3.0

[Install]
WantedBy=multi-user.target

Enable the service:

systemctl enable mnt-plex_storage.mount

3. Add a backup startup script (optional)

For extra reliability, create a startup script:

nano /etc/rc.local

Add these lines:

#!/bin/bash
# Wait for network to be fully available
sleep 30
# Attempt to mount if not already mounted
if ! grep -qs '/mnt/plex_storage' /proc/mounts; then
    mount -t cifs //192.168.1.82/plex_storage /mnt/plex_storage -o credentials=/root/.smbcredentials,uid=1000,gid=1000,file_mode=0644,dir_mode=0755,rw,vers=3.0
fi
exit 0

Make it executable:

chmod +x /etc/rc.local

4. Test your configuration

Reboot your LXC container to test if the mount works automatically:

reboot

After reboot, verify the mount with:

df -h

The systemd mount unit is the most reliable approach for modern systems, but having both methods provides good redundancy in case one fails.