Mounting External Storage to LXCs - slunat/Proxmox-Guides GitHub Wiki
This guide will cover the scenario where you want to add an external drive to your Proxmox host. For instance, you may want to mount a storage drive to be used as a media drive you can mount to Plex. There is different setup required depending on the state of your drive and the LXCs.
Mounting a Disk Without Existing Data
Only use these instructions if your disk is either blank or is safe to be wiped. Do NOT use these steps is you have existing data on the drive.
Mounting to Proxmox
- Connect your drive up to your Proxmox host.
- Head to the PVE > Disks section in Proxmox. Make note of the device path. For example, in my case the device path is
/dev/sdb
- Select the disk and click on the "Wipe Disk" button. This will delete any data stored on the disk.
- Go to PVE > Shell and enter the command
mkfs.ext4 /dev/sdb
. Make sure the path you use is the same one you found in step 2. This will set up the drive as an ext4 - Create the folder path you want to create. In this example we will create a folder in /mnt called media so the folder path will be /mt/media. Enter the command
mkdir /mnt/media
- Enter the command
mount /dev/sdb /mnt/media
to create the mountpoint. This command in particular will mount the/dev/sdb
drive (make sure this is the same path for your drive you got in step 2) to the mountpoint/mnt/media
(make sure this is the same folder path you created in step 5). You can change the mountpoint name to something else. it doesn't need to bemedia
. You can also unmount it again later if you need by enteringumount /mnt/media
Mounting to a Container (Privileged)
The drive is now configured to be used in Proxmox and you can access it via its mountpoint. However, you still need to pass through the drive to your LXCs. Please be aware that the following instructions are for mounting to a privileged container. The setup is different if providing access to an unprivileged container.
- Identify the container ID for the container you wish to mount the drive to. For the purpose of this setup, we will be mounting to container 101.
- Enter PVE > Shell
- Enter the command
nano /etc/pve/lxc/101.conf
, substitute101
in the command for your container id you found in step 1. - Add the following to the bottom of the file. This will mount the mountpoint from the host (on the left), to the location (on the right) in the container
mp0: /mnt/media,mp=/media
- Save your changes to the file and boot up your container. Browse to the folder you selected to mount, in this case /media, and you should be able to see all your files
Mounting to a Container (Unprivileged)
The drive is now configured to be used in Proxmox and you can access it via its mountpoint. However, you still need to pass through the drive to your LXCs. Please be aware that the following instructions are for mounting to a unprivileged container. The setup is different if providing access to an privileged container and is simpler. Mounting to unprivileged containers is a little more involved, but is recommended for security purposes, as it prevents access to the host files if a container is breached. The main difference will be having to create write permissions manually for your user as it will only have read access if configuring the same as above.
Read-only Access
If you only require read-only access to your data, for example if you are running something like Plex where files just tend to be read but you don't require the ability for files to be deleted or amended from this container, you can proceed with these instructions.
- Identify the container ID for the container you wish to mount the drive to. For the purpose of this setup, we will be mounting to container 101.
- Enter PVE > Shell
- Enter the command
nano /etc/pve/lxc/101.conf
, substitute101
in the command for your container id you found in step 1. - Add the following to the bottom of the file. This will mount the mountpoint from the host (on the left), to the location (on the right) in the container
mp0: /mnt/media,mp=/media
- Save your changes to the file. At this stage you can boot up your container. Browse to the folder you selected to mount, in this case /media, and you should be able to see all your files. If you require write access, proceed from step 6 in the next section.
Read and Write Access
If you also require the ability to write to the location form your container, proceed with the below.
- Identify the container ID for the container you wish to mount the drive to. For the purpose of this setup, we will be mounting to container 101.
- Enter PVE > Shell
- Enter the command
nano /etc/pve/lxc/101.conf
, substitute101
in the command for your container id you found in step 1. - Add the following to the bottom of the file. This will mount the mountpoint from the host (on the left), to the location (on the right) in the container
mp0: /mnt/media,mp=/media
- Save your changes to the file.
- You will now need to configure the permission for your containers user to access. First, you will need to figure out the User ID/Group ID to provide permissions to. You can find the IDs of existing users by running
cat /etc/passwd
or you can enter an ID of a user when creating them likeuseradd -u 1000 -m -s /usr/bin/bash service-account
. The user ID/Group ID value of the host users maps to the same UID/GID value of your container + 100000. For example if you are using a user with the ID of 1000, the id of that user in the container will be 101000. If you are using the default root user for your container, the host id for root user is 0, so the id will be 100000 in the container. - Now you need to apply the permissions, which can be done by setting ownership of the folder with the UID/GID you wish to map it to. If you are using the root user, the command would be
chown 100000:100000 /mnt/media -R
. This will set ownership of the folder /mnt/media (change this to the host mountpoint path on the left from step 4) to the user with id 100000, i.e. the root user. The-R
flag sets it recursively, so the permission are inherited by all files and folders contained in this folder. - You can now boot your container and you should have write access to the folder you mounted.