This guide covers how to add a new storage device (such as a platter or a solid state drive) to your Linux machine. All work is done from the command-line.

Selecting the right storage device

This guide does not cover selecting the right model or kind of storage device.

Plugging the device into the computer

This guide does not cover how to plug the device into the computer.

What’s the device name?

Now that the device is plugged into the computer we should figure out what name it got. It usually follows the pattern /dev/sdX where X is a letter (a, b, c, d…).

Step 1 is to find the names of all devices.

Is a somewhat crude method that is often used and often works.

/proc/partitions will list all the block devices and partitions that the system recognizes.

This will list the partition tables for the devices mentioned in /proc/partitions. I personally dislike fdisk since it can’t handle GPT partition tables. We will look into that subject later.

Step 2 is to figure out which of these devices is the new one.

A new storage-device almost never has a partition table setup. Perhaps you already know from the output of the previous two commands.

Those two commands will give you info on what devices are mounted where and if they are filled with anything yet. Your device is probably not mounted already.

A properly setup storage-device should have an entry in /etc/fstab. Your device is probably not in there.

You should now have figured out the device name and for the rest of the guide we will call the device /dev/sdb.

Partitioning and file system

You may skip this section if your storage device already has partitions and you want to keep them.

We use the application “parted” to setup a partition table.I personally prefer the partition table type “gpt” since it can handle disks larger than 2TB:

We now have a partition table but no partitions. You can view info on the storage-device at any time using parted “print” command:

Lets create one large partition only:

We now have a partition covering all of the device. Note how we used %-notation and parted will then align the partition for best performance. If you try entering detailed values manually you may get the message “Warning: The resulting partition is not properly aligned for best performance.”. Now lets place an ext4 file system on that partition:

And that is pretty much it. The partitions and file systems are set up. This would be all the commands in a batch:

Parted has interactive and non-interactive mode. So far we have been making use of the interactive mode. This is what the above would look like in non-interactive mode:

Creating a mount-point

A mount point is simply a directory. We should create one using the mkdir command, but where should we put it? I do not know the best practice here but the folders /media and /mnt both seem to be used for temporary mount points. As our storage device is a permanent one I suggest creating a brand new top-level folder for it. For example:

What file permissions should this new directory have? It does not matter. They will be changed as we mount something onto the directory.

Temporarily mounting the device partition

To temporarily mount the device partition we can run the command:

This will however only get it mounted once. We should create an entry in /etc/fstab to make it mount automatically on reboot.

Permanently mounting the device partition using fstab

Step 1 is to find the partition UUID. To add the filesystem by UUID is a good idea since you will be able to switch around with SATA hardware contacts and the system will still work. Find the UUID using any of these commands:

It may also be fun to know the model number of the storage device. You may get this info using:

Step 2 is to add the info to /etc/fstab. Please read up more on fstab elsewhere since my info here is not complete.

Are you running on an SSD? In such case you should add the “discard” option to /etc/fstab. Doing that will enable automatic TRIM and works well on ext4 filesystems. You can also stop writing last access time for files and folders by adding the option “noatime”.

What you add could look something like either of these two:

Make sure you leave a blank line at the end of the file. If you do not you will get a warning message in the next step:

Step 3 is to test that the fstab entry is correct. First unmount the /hdd using:

In case you get the warning message “umount: /hdd: device is busy.” you are probably standing in the device. Use “cd /” to get out of there and try again.

Now ensure everything in /etc/fstab is correct by mounting all of it: