Setup additional drive on Linux VPS (only for plans with extra HDD)
Default drive its already configured as the primary drive with selected operating system. The HDD will be a second drive, in order to use it, we need to set it.
Let's see what's currently mounted. Right now, it's just the primary drive mounted to /
[email protected]:~# 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 the second disk:
[email protected]:~# 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 it on /dev/vdb
We need to deciding where to mount the second drive. We are going to mount it at /drive2
We'll create the mount point now:
[email protected]:~# mkdir /drive2
We can proceed to partition it.
[email protected]:~# 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.
[email protected]:~#
The above steps represent: n (new partition), p (primary), enter, enter, enter and w (to write the changes)
Output of fdisk -l
[email protected]:~# 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
[email protected]:~#
We have the partition and we need to format it for use by using mkfs.ext4 command
[email protected]:~# 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
[email protected]:~#
Let's mount the partition and check with df -h
[email protected]:~# mount /dev/vdb1 /drive2
[email protected]:~# 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% /drive2
[email protected]:~#
It's mounted at /drive2.
We'll add it to the fstab to make it permanent.
[email protected]:~# nano /etc/fstab
We need to edit fstab file by adding the last line.
# /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).
#
#
# / was on /dev/xvda1 during installation
LABEL=root / ext4 errors=remount-ro 0 1
/dev/vda2 swap swap defaults 0 0
/dev/vdb1 /drive2 ext4
Let's reboot the server and check after.
[email protected]:~# reboot
[email protected]:~# 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% /drive2
tmpfs 200M 0 200M 0% /run/user/0
[email protected]:~#
New drive has been mounted at /drive2.