Add Drive to Proxmox

How Can We Help?

Add Drive to Proxmox

You are here:
< Back to the Wiki

Do you have a Proxmox installation and do you want to expand your storage with an external or internal drive? This article will explain how to prepare and add your drive to Proxmox

Prerequisites

In this scenario we assume that Proxmox is already installed and running

Setup

First make sure that your drive is connected, validate this by running lsblk. Most likely the sda drive includes your Proxmox installation so try to find a drive named differently, in our scenario it is called sdb, because we identified the following line:

sdb 8:16 0 223G 0 disk

Now install parted, using apt install parted so we can setup the drive correctly.

Add a label to your drive using parted /dev/sdb mklabel gpt, acknowledge that the drive will be wiped if prompted.
Now we create a partition using parted -a opt /dev/sdb mkpart primary ext4 o% 100%.
Optionally, we can add a label so it is easier to identify the drive later, do this by using mkfs.ext4 -L data /dev/sdb1

Now the drive needs to be mounted, so first create a folder i.e. mkdir -p /mnt/data.
Next, open /ect/fstab and add the following line:

LABEL=data /mnt/data ext4 defaults 0 2

Inform systemd about the fstab change using systemctl daemon-reload.

Finally, run mount -a, this will mount the drive so it is available for usage. You can validate this by running lsblk again, this should now show the mountpoint of your drive, i.e.:

sdb                                  8:16   0   223G  0 disk 
└─sdb1                               8:17   0   223G  0 part /mnt/data

Add Drive to Container

To add this drive to one of your containers, open the correct config in /etc/pve/lxc and add the following lines:

# First location is the path on Proxmox, the second one is within the container
# More arguments can be found at https://pve.proxmox.com/wiki/Linux_Container#pct_settings
mp0: /mnt/data,mp=/mnt/data
# uid map: from uid 0 map 1005 uids (in the ct) to the range starting 100000 (on the host), so 0..1004 (ct) → 100000..101004 (host)
lxc.idmap = u 0 100000 1005
lxc.idmap = g 0 100000 1005
# we map 1 uid starting from uid 1005 onto 1005, so 1005 → 1005
lxc.idmap = u 1005 1005 1
lxc.idmap = g 1005 1005 1
# we map the rest of 65535 from 1006 upto 101006, so 1006..65535 → 101006..165535
lxc.idmap = u 1006 101006 64530
lxc.idmap = g 1006 101006 64530

Now we have to allow the root to use these IDs, so add the following to the both the /etc/subuid and the /etc/subgid file:

root:1005:1

Take note that the values are the same since we use 1005 as group id and as user id, in case you use different values you have to change them accordingly.

Now set the ownership of the mount path using chown -R 1005:1005 /mnt/data and start the container.

Sources

Tags:

2 Responses

  1. Ivelisse says:

    Your post is engaging. We love reading your posts. Thank you for posting.

  2. Hallie says:

    Reading your blog is always a delight; your writing captivates me every time.

Leave a Reply to Hallie Cancel reply

Your email address will not be published. Required fields are marked *

Table of Contents