Add a USB Drive or Memory to an LXC and Share it Over the Network with Samba

Guides~20 min

Attach a USB hard drive or memory stick to a privileged LXC container on Proxmox VE, install Samba inside the container, and share the contents over the network.

Recommended

ProxMenux now exposes both halves of this workflow as guided menus:

  • Disk Manager → Format / Wipe Physical Disk for the format step.
  • Storage & Share Manager → LXC network sharing → Samba server in LXC for the privileged-CT install + Samba config.

The guided flows handle the unprivileged-CT permission quirks, share-mode presets (read-write / read-only / custom) and the sharedfiles group setup. This guide is the manual equivalent — useful if you want full visibility into each step or prefer to wire things by hand.

Sometimes it's useful to add a hard drive or USB memory stick to a Proxmox host, especially on a mini PC with limited internal expansion. This guide walks through:

What you'll do

  1. Attaching the USB disk to a privileged LXC.
  2. Installing Samba inside the container.
  3. Sharing the disk contents over the LAN.

Use cases

  • Hosting Torrent files and serving them on the network.
  • Backing a media server (Plex / Jellyfin / Emby).
  • Holding documents that get auto-scanned by Paperless.
  • Generic NAS-style storage for the home network.

Privileged container used in this recipe

This recipe uses a privileged LXC with a block device as mp0. For an unprivileged container, an alternative is to mount the filesystem on the host and bind-mount its directory, with appropriate ID mapping and permissions. See Storage & Share Manager → LXC Mount Points in ProxMenux.

1. Attach the USB disk to the LXC

1.1 Identify the device

Compare the disk list before and after plugging in the USB drive — the new device is your target.

Before:

Disk list before adding USB drive

After:

Disk list after adding USB drive

You can also use lsblk -o NAME,SIZE,MODEL,SERIAL to list every block device with model and serial.

Important — use a stable identifier

/dev/sdb1 can change between boots if you have multiple USB disks. Find the persistent identifier:

ls -l /dev/disk/by-id/

Use the /dev/disk/by-id/usb-... entry for the intended partition in the LXC config, instead of /dev/sdb1. Choose the partition entry, not the whole-disk entry; it identifies the same partition when device enumeration changes.

1.2 Format the disk

ext4 is a practical choice for Linux-backed shares: it is case-sensitive and supports POSIX ACLs and large files. Formatting destroys the existing filesystem’s contents. Run on the Proxmox host, after confirming the partition, not inside the container:

mkfs.ext4 /dev/sdb1

Replace /dev/sdb1 with the actual partition device — or with the persistent /dev/disk/by-id/usb-...-part1 path.

1.3 Create the mount point inside the LXC

Inside the LXC, create the directory where the disk will appear (any name works):

mkdir /mnt/lxc_USB

1.4 Wire the device into the LXC

On the Proxmox host (not inside the CT), edit the container's config. Replace <CTID> with the container ID:

nano /etc/pve/lxc/CTID.conf

Add this line:

mp0: /dev/disk/by-id/usb-VENDOR_MODEL_SERIAL-part1,mp=/mnt/lxc_USB,backup=0

(Or, if you accept the risk of the device path changing, the shorter form: mp0: /dev/sdb1,mp=/mnt/lxc_USB,backup=0.)

This example sets backup=0. Device and bind mount contents are not included in container vzdump backups. Arrange a separate backup for the external disk’s data.

1.5 Restart the LXC and set permissions

Restart the CT to apply the mount point:

pct reboot CTID

Inside the LXC, create the share account before assigning ownership, then set the directory permissions:

adduser --system --group --no-create-home --shell /usr/sbin/nologin proxmenux
mkdir -p /mnt/lxc_USB
chown -R proxmenux:proxmenux /mnt/lxc_USB
chmod 770 /mnt/lxc_USB

Note

Replace proxmenux with your chosen account name. The mode 770 allows the owner and group to access the directory, with no access for others; it is more restrictive than chmod -R 777. The account is created here and registered with Samba in step 2.2.

2. Install Samba

2.1 Install the package inside the LXC

apt-get update
apt-get install -y samba

Confirm the service is running:

systemctl status smbd.service

2.2 Verify the share user

The account proxmenux was created in step 1.5 as a system user without a login shell. Check it before setting its Samba password; substitute your chosen name throughout:

id proxmenux

Set the Samba password (separate from the system password — Samba maintains its own credential store):

smbpasswd -a proxmenux

2.3 Set ownership / ACLs

If the simple chown from step 1.5 is enough for your case, you're done with permissions. For finer-grained control (multiple users sharing the same path with different rights), use ACLs:

apt-get install -y acl
setfacl -R -m "u:proxmenux:rwx" /mnt/lxc_USB
setfacl -d -R -m "u:proxmenux:rwx" /mnt/lxc_USB    # default ACL — applies to new files

3. Configure the Samba share

3.1 Edit smb.conf

nano /etc/samba/smb.conf

Append a share definition at the end:

[lxc_usb]
    comment = Shared USB storage
    path = /mnt/lxc_USB
    read only = no
    writable = yes
    browseable = yes
    guest ok = no
    valid users = proxmenux
    create mask = 0660
    directory mask = 0770

Note

The valid users = proxmenux line restricts access to that single Samba user. For group-based access, use valid users = @samba_users after adding the user(s) to a group named samba_users.

3.2 Reload Samba

systemctl restart smbd

4. Verify access

From any LAN client, browse to \\<CT_IP> (Windows) or smb://<CT_IP> (macOS / Linux file managers). Authenticate with the Samba user (proxmenux) and the password you set with smbpasswd.

Samba server access from a clientSamba authentication prompt

You can use the share both inside the container and across the network:

Using the USB drive over the share

Troubleshooting

  • pct reboot fails with "device not found": the device path in mp0 doesn't exist on the host. Check with ls -l /dev/disk/by-id/ and update the path.
  • CT starts but /mnt/lxc_USB is empty: the disk may not be mounted, or its filesystem may be empty. Check from the host with pct exec <CTID> -- mount | grep lxc_USB. If the mount is absent, inspect its configuration, device path and startup errors.
  • Samba authenticates but writes fail with "Permission denied": check the directory’s Linux permissions and the share’s write settings. Review chown and setfacl in sections 1.5 and 2.3.
  • Share discovery fails but smb://<ip>/lxc_usb works: legacy NetBIOS discovery uses nmbd. Modern Windows discovery uses WS-Discovery instead; on Debian 12 install apt-get install -y wsdd; on Debian 13, where wsdd is not in the stable archive, use apt-get install -y wsdd2. Check the service and firewall. Enabling nmbd alone does not provide WS-Discovery.
  • To add a second user to the share: create the account with adduser, register it with smbpasswd -a and add it to the comma-separated valid users = list. Also grant the required filesystem permissions or ACLs.

Sponsor

If you would like to support the project.

Support me on Ko-fi

Connect

Join the community discussions on GitHub to get help, share ideas, and contribute to the project. Every idea is welcome!

Join the Discussion

ProxMenux, an open-source and collaborative project by MacRimi.