Adding Storage to a Linux Machine

Introduction

I host a lot of media and services on my home server so when I built it put in a hard drive that, at the time, I thought was sufficient to get me by for a few years. Who would fill up 6 TB? It turns out I filled up 6 TB, and it only took me about 15 months. If I had done the math, then before ripping my wife’s substantial movie library, I would have realized that.

The good news is that it’s not terribly difficult to add more space. $250 later, I was in the possession of a 12 TB drive. This is the story of how I added it, so you can do the same thing if you need more space.

It’s not as hard as you might think.

What You’ll Need

Before you get started, you need to be sure you can add more disk space. If you don’t know how to tell, a simple way would be to pop open the case and see if you have any free SATA ports. They’ll look something like this (pardon the dust):

I have a grand total of one of my six connections left, since I have multiple drives and other input devices already. If you don’t have room but still want to upgrade, you’ll first want to get all of your data off a drive, but this tutorial assumes you know how to move files around.

Be sure you also have sufficient power for the drive. If you don’t have a free plug, you won’t be able to continue. You can always buy a bigger power supply if you need more power. These are pretty easy to swap out – just make note of all of the things attached to your current power supply and when your new one arrives, start with those.

In terms of parts, you’ll obviously need a drive. I like the Western Digital Red Plus drives for a nice balance of performance, reliability, and cost. I went with a 12 TB, but only because I didn’t want to wait longer to save for the 16 TB. Anything between 8 and 16 TB is great value for the money.

Less obviously, you’ll also want to buy cables. Drives seldom come with SATA cables anymore, and the things can and will go bad. Grab a three, six, or ten pack and you won’t have to worry about it for a while.

Installation

The installation is pretty simple, but it depends on your case. Every case has a different place to put drives, but most modern cases use tabs that you can add to the screw holes in the side of your drives to clip them into bays.

Just plug in the drive, and you’re good to go. One tip I have if you’ve never done this before is to use the angled side of the SATA connector on the drive, and the straight plug on the motherboard.

The Software Side

Honestly, the hardest part of this whole process is getting the drive formatted and ready to use. Hardest, but still not hard. In Windows, the process is made trivial by the disk management software, but the Linux terminal is a bit more intimidating. I’ll try to help make it less scary.

In Linux, every attached device has a path, like a file or folder. You need to figure out what name your computer assigned your new drive, and for that, we’re going to use the built-in command fdisk:

sudo fdisk -l

From this, you’ll get output showing every drive you have connected. You need to find the new drive, and if you just added a new one you should have an idea of what the serial number is, or at least the size. In my case, it’s a 12 TB Western Digital drive, and here’s what the output looks like:

The path to the device is /dev/sdc

We need to create a partition for the new drive. Since we want to use the entire thing, we’ll only have one partition, but you could split it if you wanted. For this, we need another tool, parted. Note that you should use the device path identified previously where I use /dev/sdc:

sudo parted /dev/sdc

The parted tool opens its own command line, and you can tell because (parted) will now appear at the start of the terminal input line.

Our first step is going to be to call mklabel:

mklabel gpt

gpt in this case is the type of partition table (guid partition table). You may have heard of the master boot record on your Windows machine and this is an alternative. It’s more flexible and powerful, and effectively the default at this point, so we’ll use it.

Now we need to actually create the partition:

mkpart primary ext4 0% 100%

There’s a bit going on here. primary is the name I’m giving the partition. It’s customary to name the main partition on a drive “primary”, and I see no reason to deviate here. I’m using the ext4 format because it’s the standard Linux format. As I said earlier, I want the partition to encompass the entire drive, so I’m having it go from 0% to 100% of the drive. You could use (tera|giga|mega|kilo)bytes instead, but this is easier.

After running, you can quit out of parted by hitting ctrl-c. We’re almost done.

We need to run fdisk again:

sudo fdisk -l

If you get back to the entry for your new drive, you’ll find that there’s a partition listed now, and we need the name of this partition. In my case, it’s my drive name with a “1” appended to the end (/dev/sdc1):

Your computer has a drive in it, it’s partitioned, and the partition is formatted, but you can’t access it. You need to mount it first. That’s easy enough to do. You can change how it’s mounted later if you decide to use a different naming scheme, but here’s a reasonable starting point:

sudo mount /dev/sdc1 /mnt/storage

In my case, I’m mounting the partition under the /mnt directory as storage. From now on, I can go to /mnt/storage to access the drive.

Conclusion

I hope this made the process of adding disk space a little less intimidating. It’s a common need, and you can save yourself money if you can do it yourself with a large internal HDD. There are other ways to do it, but I’ve found this to be the fastest and easiest.

Leave a Reply

Your email address will not be published. Required fields are marked *