Locating the disk

In this tutorial we will show you how to create a partition and a filesystem. After we will mount the disk and make sure the changes are kept when a reboot occurs.

Before we start mounting a disk, we will make sure we have the correct disk. In the example below we used the command lsblk to see which disks are in the system and where they are used.

root@worldstream:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 119.2G 0 disk
|-sda1 8:1 0 953M 0 part /boot
|-sda2 8:2 0 110.6G 0 part /
|-sda3 8:3 0 1K 0 part
|-sda5 8:5 0 1M 0 part
|-sda6 8:6 0 243M 0 part /boot/efi
`-sda7 8:7 0 7.5G 0 part [SWAP]
sdb 8:16 0 10.9T 0 disk

If we look at the output, we see that /dev/sda contains several partitions, most notably the root partition. Because of the root partition we know this is where the operating system is installed. The disk at /dev/sdb has no mountpoint or partitions, so we can partition and mount this.

Note: If you see that there already is a partition available on the disk and no mountpoint you can skip to: ‘Creating a folder and mounting the disk’.

Creating a filesystem and partition

There are several programs to create a partition, but we will use the program parted to create a filesystem that spans over the entire disk. In our previous paragraph we found that /dev/sdb was unpartitioned. We will start the program with the disk we want to partition.

parted /dev/sdb

Then we’ll create a gpt filesystem with this command:

mklabel gpt
Do you want to continue: Yes

Next we will create one partition so we can assign the full size of the disk to a folder.

mkpart 1 ext4 0% 100%

Once this is created we will have to perform one last step, creating a filesystem. In the below example we use ext4, but you can substitute this part with xfs or ext3 if preferred:

mkfs.ext4 /dev/sdb1

In the above example we created /dev/sdb1, since this is the partition we created in the above example. If you have created a partition on another device path, adjust /dev/sdb1 to the partition where you want to create a filesystem on. Below is a summary that explains what we have done so far:

root@worldstream:~# parted /dev/sdb
GNU Parted 3.2
Using /dev/sdb
Welcome to GNU Parted! Type ‘help’ to view a list of commands.
(parted) mklabel gpt
(parted) mkpart 1 ext4 0% 100%
(parted) quit
Information: You may need to update /etc/fstab.
mkfs.ext4 /dev/sdb1

Creating a folder and mounting the disk

When you mount a filesystem, make sure this folder does not exist already! You can make the system inoperable or temporarily lose access to files. We will create a folder called /home2.

mkdir /home2

When this is created we can mount the created filesystem there.

mount /dev/sdb1 /home2

To summarize we have included the output:

root@worldstream:~# mkdir /home2
root@worldstream:~# mount /dev/sdb1 /home2
root@worldstream:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 119.2G 0 disk
|-sda1 8:1 0 953M 0 part /boot
|-sda2 8:2 0 110.6G 0 part /
|-sda3 8:3 0 1K 0 part
|-sda5 8:5 0 1M 0 part
|-sda6 8:6 0 243M 0 part /boot/efi
`-sda7 8:7 0 7.5G 0 part [SWAP]
sdb 8:16 0 10.9T 0 disk
`-sdb1 8:17 0 10.9T 0 part /home2

Reviewing and filesystem configuration file

When you have mounted the disk, you are able to review by running df -h at the terminal.

In order to make sure the filesystem will be kept after a reboot we will add the new filesystem at /etc/fstab. This file tells your machine what filesystem to mount and where on startup. We will need the UUID of the filesystem in order to proceed. If you type ‘blkid’ in the terminal you will get the following output:

root@worldstream:~# blkid
/dev/sda1: UUID=”4a18d6e5-54d3-4005-9a86-a01954f863c4″ TYPE=”ext4″ PARTUUID=”a3122a02-01″
/dev/sda2: UUID=”66933e94-5f5a-48c8-9fd8-5c1684792e5a” TYPE=”ext4″ PARTUUID=”a3122a02-02″
/dev/sda6: UUID=”9EB6-2422″ TYPE=”vfat” PARTUUID=”a3122a02-06″
/dev/sda7: UUID=”41c56b66-49f5-48e0-8a26-2578262a3a96″ TYPE=”swap” PARTUUID=”a3122a02-07″
/dev/sdd: PTUUID=”49dc9ef9-ac7b-4add-8f51-718a3f6620a7″ PTTYPE=”gpt”
/dev/sdc: PTUUID=”0fa77077-d52a-40fe-86b4-858699b26a07″ PTTYPE=”gpt”
/dev/sda5: PARTUUID=”a3122a02-05″
/dev/sdb1: UUID=”cef3dd7c-5ba6-4ad6-ac38-b496413e33c5″ TYPE=”ext4″ PARTLABEL=”1″ PARTUUID=”b747fe1e-48ce-4217-bc33-d4301dd66270″

As you can see the filesystem from our example (/dev/sdb1 starts with UUID=”cef3dd7c-5ba6-4ad6-ac38-b496413e33c5″. This is the UUID. Now do the following:

nano /etc/fstab

You can follow the logic of the other mounted filesystems as below. Note that we have used the UUID from our last paragraph and removed the double quotation marks.

# /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/sda2 during installation
UUID=66933e94-5f5a-48c8-9fd8-5c1684792e5a / ext4 errors=remount-ro 0 1
# /boot was on /dev/sda1 during installation
UUID=4a18d6e5-54d3-4005-9a86-a01954f863c4 /boot ext4 defaults 0 2
# /boot/efi was on /dev/sda6 during installation
UUID=9EB6-2422 /boot/efi vfat umask=0077 0 1
# swap was on /dev/sda7 during installation
UUID=41c56b66-49f5-48e0-8a26-2578262a3a96 none swap sw 0 0
UUID=cef3dd7c-5ba6-4ad6-ac38-b496413e33c5 /home2 ext4 defaults 0 0

When you exit this editor you have succesfully mounted the disk.

Note that this is an example set-up, but many formats are possible. If you require any assistance feel free to send us an email here.