1000 FAQs, 500 tutorials and explanatory videos. Here, there are only solutions!
Mount a Linux Volume on a Cloud VPS
This guide explains how to format and then mount the volume dedicated to storing your data on VPS Cloud Linux/Unix.
Disk and partition names
VPS Clouds are offered with two volumes:
- 1 volume for the operating system of your choice
- 1 volume for storing your data
The volume for storing data must be formatted and then mounted by the client.
In Linux systems, disks and partitions are referenced by names, which vary depending on the Linux distribution, such as:
/dev/sda
,/dev/sdb
, β¦/dev/vda
,/dev/vdb
, β¦/dev/sda1
,/dev/sda2
, β¦
These names are not static and can change depending on various factors, such as the driver used (e.g., virtio-scsi or virtio-blk) or kernel and udev updates.
Therefore, it is recommended to use the UUID (Universal Unique Identifier - see below) of a partition rather than its name when referencing it in the filesystem configuration file (/etc/fstab
).
Formatting the storage volume
If you choose XFS, for example, it is necessary to install the appropriate tools (if they are not already present):
sudo apt install xfsprogs
Then format the volume with the following SSH commands:
sudo mkfs.xfs -f /dev/[device]
And if you choose EXT4:
sudo mkfs.ext4 /dev/[device]
If necessary, it is possible to format the volume with another file system supported by your distribution.
Mounting the storage volume
Attention: if you mount your data volume in /home
, you will no longer be able to connect to your server via your private key at the next reboot (because SSH looks for the keys in the .ssh
folder in the home (home folder) of the user and if the data volume is mounted on this folder, the keys are lost). Therefore, it is necessary to copy the data to be kept in advance. Help for SSH connection
For example as root:
mkdir /mnt/home
mount /dev/[device] /mnt/home
rsync -rlptgoDHAX /home/ /mnt/home/
umount /mnt/home
mount /dev/[device] /home
rmdir /mnt/home
What it does in order:
- a temporary folder is created
- the volume is mounted on the temporary folder
- the content of the original folder
/home
is copied to the root of the volume while preserving the rights, owner, group, etc. (note that you may need to install thersync
package depending on the chosen Linux distribution) - the volume is unmounted from the temporary folder
- the volume is mounted on the folder
/home
- the temporary folder is deleted
In this way, you should be able to mount the volume on /home
while preserving the initial configuration that will be installed. However, it is recommended to always set a password for root
to avoid losing control in case of an error. The password can be removed later.
Alternative solution: do not mount in /home...
This is a standard location for mounting the data volume because it is generally in /home
that users will work and especially store their data. A user without special rights will normally be limited to their directory /home/user
. It is possible to indicate another default directory for a user (but the configuration will no longer be "standard").
Another alternative solution: automatic mounting of the volume at startup...
A mount does not survive a reboot. If you want to make the change persistent, you can add your volume to the /etc/fstab
file (Debian documentation on this subject) for example:
/dev/md0 / ext4 errors=remount-ro 0 1
UUID=181A-4B53 /boot/efi vfat errors=remount-ro,nofail 0 0
UUID=181B-AED3 /boot/efi2 vfat errors=remount-ro,nofail 0 0
UUID=[UUID1] /srv/node/sda xfs noatime,nodiratime,nofail,logbufs=8 0 0
UUID=[UUID2] /srv/node/sdb xfs noatime,nodiratime,nofail,logbufs=8 0 0
After formatting the disk, locate the UUID and add it to the fstab
.
Obtain the UUID of a partition
To obtain the UUID of a partition after formatting it, use the blkid
command. This command displays the UUID as well as other information about all partitions detected by your system.
Add the UUID to fstab
Once you have obtained the UUID of the partition you want to mount automatically at startup, you can add it to your fstab
file. To do this, open the fstab
file with a command-line text editor (for example nano or vi) and add a new line for your partition using the example above as a model. Replace [device]
, [UUID1]
and [UUID2]
with the appropriate values for your configuration.