Connect a USB drive to a LXC container in PVE

Connecting a USB drive to a LXC container expands the disk space for that container. In my case, I was able to expand a nextcloud with external space that did not need a backup.

Mount to PVE host

To connect, lets start with connecting the hardware and get the ID of it. Execute the following on your PVE host.

ls -ahlp /dev/disk/by-id
It will return something like this:
Mar 15 02:02 usb-Seagate_Basic_NT22RPD8-0:0 -> ../../sda
Mar 15 02:02 usb-Seagate_Basic_NT22RPD8-0:0-part1 -> ../../sda1
Now permanently mount the disk to a folder by creating a service and start and enabling it. Create a file:
# vim /etc/systemd/system/mnt-pve-YOURDIR.mount
[Install]
WantedBy=multi-user.target

[Mount]
Options=defaults
Type=ext4
What=/dev/disk/by-id/usb-Seagate_Basic_NT22RPD8-0:0-part1
Where=/mnt/pve/YOURDIR
[Unit]
Description=Mount storage 'YOURDIR' under /mnt/pve
Now reload the system daemon, start the service and if it succeeds, enable it to mount it at every system startup.
systemctl daemon-reload
systemctl start mnt-pve-YOURDIR.mount
systemctl enable mnt-pve-YOURDIR.mount
If everything worked, you can access your USB drive via ls /mnt/pve/YOURDIR from the PVE host.

Mount to LXC container

Access the configuration file of your LXC container and add line:

# vim /etc/pve/lxc/XXX.conf
# Add this line
lxc.mount.entry: /mnt/pve/YOURDIR path/in/container none bind,optional,create=dir
The optional enables the container to start even if the bind fails. Not the leading / in the path of the PVE folder, but the missing / in the path inside the container!

Limitation

This directly maps an external disk into a container. Note, that

  1. the container can only run on the PVE host, where the disk is connected to
  2. no backup via the PBS is possible that way

Previous Blog Entry


Last update: 2026-03-17