1000 FAQs, 500 tutorials and explanatory videos. Here, there are only solutions!
Mounting a Linux Volume on VPS Cloud
This guide explains how to format and then mount the volume dedicated to storing your data on Linux/Unix Cloud VPS.
Names of Disks and Partitions
Cloud VPSs come 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 may 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 - read more 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 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, you can format the volume with another filesystem 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 on the next reboot (because SSH will look for the keys in the .ssh
folder in the home directory 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 retained beforehand. 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:
- create a temporary folder
- mount the volume to the temporary folder
- copy the contents of the original
/home
directory to the root of the volume while preserving permissions, owner, group, etc. (note that you may need to install thersync
package depending on the chosen Linux distribution) - unmount the volume from the temporary folder
- mount the volume to the
/home
directory - remove the temporary folder
This way, you should be able to mount the volume on /home
while retaining the initial configuration that will be installed. However, we always recommend setting a password for root
to avoid losing control in case of 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 users typically work and store their data in /home
. A user without special rights will normally be limited to their /home/user
directory. It is possible to specify a different 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 modification 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, find the UUID and add it to the fstab
.
Getting the UUID of a Partition
To get 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.
Adding 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 (e.g., nano or vi) and add a new line for your partition using the example above as a template. Replace [device]
, [UUID1]
, and [UUID2]
with the appropriate values for your configuration.