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 your VPS Cloud under Linux/Unix.
Names of disks and partitions
Our unmanaged Cloud Servers come 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 can 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 based 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 after the next reboot (because SSH looks for 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
mkdir /mnt/home
mount /dev/[device] /mnt/home
rsync -rlptgoDHAX /home/ /mnt/home/
umount /mnt/home
mount /dev/[device] /home
rmdir /mnt/home
What this does in order:
- create a temporary folder
- mount the volume on the temporary folder
- copy the contents of the original "/home" folder to the root of the volume while preserving rights, owner, group, etc. (note that you may need to install the "rsync" package depending on the chosen Linux distribution)
- unmount the volume from the temporary folder
- mount the volume on the "/home" folder
- delete 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 still recommend setting a password for "root" to avoid losing control in case of an error. The password can be removed afterward.
Alternative solution: do not mount in "/home"...
This is a standard location to mount the data volume because users generally 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 specify 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 modification persistent, you can add your volume to the "/etc/fstab" file (Debian documentation on this topic) 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 fstab.
Get the UUID of a partition
To get the UUID of a partition after formatting it, you can use the command
blkid
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 automatically mount at startup, you can add it to your fstab file. To do this, open the fstab file with a command-line text editor (such as 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.