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 the VPS Cloud Linux/Unix.
Disk and Partition Names
The VPS Cloud comes with two volumes:
- 1 volume for the operating system of your choice
- 1 volume for storing your data
The volume for data storage must be formatted and then mounted by the client.
In Linux systems, disks and partitions are referenced by names, which may 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 due to 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 file system configuration file (/etc/fstab
).
Formatting the Storage Volume
If you choose XFS, for example, you need 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
Warning: if you mount your data volume to /home
, you will not be able to reconnect to your server via your private key on the next reboot (because SSH will look for keys in the .ssh
folder in the user's home directory, and if the data volume is mounted on this folder, the keys are lost). Therefore, it is necessary to copy the data to keep beforehand. SSH connection help
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
This is what it does in order:
- we create a temporary folder
- we mount the volume on the temporary folder
- we copy the content of the original
/home
folder to the root of the volume, keeping the rights, owner, group, etc. (note that you may need to install thersync
package depending on your chosen Linux distribution) - we unmount the volume from the temporary folder
- we mount the volume on the
/home
folder - we delete the temporary folder
In this way, you should be able to mount the volume to /home
while keeping the initial configuration installed. However, it is recommended to always set a password for root
to avoid losing control in case of error. The password can be removed later.
Alternative Solution: Don't mount in /home...
This is a standard location to mount the data volume because users usually work and especially store their data in /home
. A user without special rights will normally be limited to their /home/user
directory. It is possible to set another default directory for a user (but the configuration will no longer be "standard").
Another Alternative Solution: Automatic mounting at startup...
A mount does not persist across a reboot. If you want to make the change persistent, you can add your volume to the /etc/fstab
file (Debian documentation on this), 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
.
Get the UUID of a Partition
To obtain the UUID of a partition after formatting, 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.