Setting up a dual drive VPS in Linux

This how-to is about getting your dual drive HostDoc KVM set up.

By default, when you have a dual drive setup (for example NVMe/HDD) the NVMe drive will be already configured as the primary drive with your operating system of choice installed. The HDD will be a second drive and will need to be set up first before we can use it.

First thing, we’ll have a look to see what’s currently mounted. Right now, it’s just the primary NVMe drive mounted to /

root@dualSTORE:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            970M     0  970M   0% /dev
tmpfs           200M  2.8M  197M   2% /run
/dev/vda1        78G  1.5G   73G   2% /
tmpfs           997M     0  997M   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           997M     0  997M   0% /sys/fs/cgroup
tmpfs           200M     0  200M   0% /run/user/0

Let’s see if the second disk is present:

root@dualSTORE:~# fdisk -l
Disk /dev/vda: 80 GiB, 85899345920 bytes, 167772160 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x941390d7

Device     Boot     Start       End   Sectors  Size Id Type
/dev/vda1  *         2048 165677055 165675008   79G 83 Linux
/dev/vda2       165677056 167772159   2095104 1023M 82 Linux swap / Solaris


Disk /dev/vdb: 80 GiB, 85899345920 bytes, 167772160 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

We can see that it’s sitting on /dev/vdb

The next thing is deciding where to mount the second drive. In this case, it’s a HDD so I’m going to mount it at /hdd
You can mount it to anywhere you like, but if you’re unsure, just leave it as the default /hdd so you can just copy/paste.

We’ll create the mount point now:

root@dualSTORE:~# mkdir /hdd

Now that we have the mount point, and we know the drive is located at /dev/vdb, we can proceed to partition it.

root@dualSTORE:~# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.31.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x6b36d253.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-167772159, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-167772159, default 167772159): 

Created a new partition 1 of type 'Linux' and of size 80 GiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

root@dualSTORE:~# 

The steps above are: n (new partition), p (primary), enter, enter, enter (for defaults) and finally w (to write out, or save the changes)

Let’s have another look at the output of fdisk -l

root@dualSTORE:~# fdisk -l
Disk /dev/vda: 80 GiB, 85899345920 bytes, 167772160 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x941390d7

Device     Boot     Start       End   Sectors  Size Id Type
/dev/vda1  *         2048 165677055 165675008   79G 83 Linux
/dev/vda2       165677056 167772159   2095104 1023M 82 Linux swap / Solaris


Disk /dev/vdb: 80 GiB, 85899345920 bytes, 167772160 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x6b36d253

Device     Boot Start       End   Sectors Size Id Type
/dev/vdb1        2048 167772159 167770112  80G 83 Linux
root@dualSTORE:~# 

We now have the partition, but we need to format it for use. Using the mkfs.ext4 command we can create a Linux formatted partition.

root@dualSTORE:~# mkfs.ext4 /dev/vdb1
mke2fs 1.44.1 (24-Mar-2018)
Creating filesystem with 20971264 4k blocks and 5242880 inodes
Filesystem UUID: 13ed1c87-3195-407b-b2ff-b6f73df93969
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000, 7962624, 11239424, 20480000

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (131072 blocks): done
Writing superblocks and filesystem accounting information: done   

root@dualSTORE:~# 

With that done, it’s time to mount the partition and see if it shows up in df -h

root@dualSTORE:~# mount /dev/vdb1 /hdd
root@dualSTORE:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            970M     0  970M   0% /dev
tmpfs           200M  2.8M  197M   2% /run
/dev/vda1        78G  1.5G   73G   2% /
tmpfs           997M     0  997M   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           997M     0  997M   0% /sys/fs/cgroup
tmpfs           200M     0  200M   0% /run/user/0
/dev/vdb1        79G   57M   75G   1% /hdd
root@dualSTORE:~# 

There it is, mounted at /hdd.

This will not be mounted anymore if you reboot, so we’ll add it to the fstab to make it permanent:

root@dualSTORE:~# nano /etc/fstab 

Edit your fstab file by adding the last line. This will tell Linux to mount that partition to /hdd upon boot.

# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/xvda1 during installation
LABEL=root /               ext4    errors=remount-ro 0       1
/dev/vda2        swap       swap       defaults        0 0
/dev/vdb1       /hdd    ext4

It’s a good idea to verify that those steps were performed correctly, so we’ll reboot now and see what the output of df -h looks like. See you after the reboot!

root@dualSTORE:~# reboot

Welcome back! Let’s check it out:

root@dualSTORE:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            970M     0  970M   0% /dev
tmpfs           200M  2.8M  197M   2% /run
/dev/vda1        78G  1.5G   73G   2% /
tmpfs           997M     0  997M   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           997M     0  997M   0% /sys/fs/cgroup
/dev/vdb1        79G   57M   75G   1% /hdd
tmpfs           200M     0  200M   0% /run/user/0
root@dualSTORE:~# 

Nice. We can see that the new drive has been mounted at /hdd automatically. We’re good to go!

I hope this how-to was easy to follow, please provide feedback if you think there is something that could be improved, I’d like to make this as user-friendly as possible.

would there be any issues / concerns mounting at /home ?

cybertech wrote:

would there be any issues / concerns mounting at /home ?

That’s a good idea! All you would need to do is make sure it is in the fstab so it mounts automatically on boot.