Chasing Windmills: Configuring Hard Drives on Linux

Disk Bullshit

I accidentally deleted my data harddrive because the disks utility in Fedora (don’t ask me about my window manager, this is a user-hostile detail) makes that really freaking easy and I missed the visual differentiators, if there were any.

Why was I mucking around in the disks utility, you ask? It’s because my data harddrive wasn’t being mounted when the computer started and that was really quite annoying. This is my old archive of crap from the last 100 computers I’ve owned, and even though I rarely look at it, I am emotionally connected to the bits stored on this drive.

Fortunately I have a backup (thanks Backblaze!) so I was able to retrieve my data. Unfortunately Backblaze doesn’t have a Linux client, but as I understand it that’s because linux users are all pathological and unprofitable. Can’t argue with that.

So I bought a second hard drive (at around the cost of a new license for Windows…) in order to ensure that if I failed or my backup were corrupt that I could take my old one to a computer forensics lab (at around the cost of a new Microsoft Surface Pro) to have its data restored.

This thing doesn’t mount either! FFS.

A Brief Lesson

Time to build a little bit of understanding. Or at least a mental model for practical purposes that is true enough in 2023.

A physical hard drive (a device) can be mapped to logical hard drives. Think about having a C: drive and a D: drive and an F: drive, each for different types of data. This is achieved through partitions that are slices of physical storage space you could organize into logical chunks. A good reason to do this might be to have your disposable youtube-dl content on a different volume than your priceless archival footage of grandpa on the ‘ol Super8. A bad reason to use partitions is if you’re using raid to set up a redundant disk array but are using different sized disks. Finally, partitions have a filesystem that determines the way data is written to the drive and has implications for compatibility if you want to put this drive in an old Compaq or if you decide to throw in the towel on Linux.

Devices and partitions are set up using tools like fstab and parted, and you mount them in order to link them to a folder in your filesystem.

Image depicting the relationship between devices, partitions, and filesystems. Likely incorrect

creating the partition

https://www.thegeekstuff.com/2012/08/2tb-gtp-parted/

fstab is old and doesn’t support modern hardware, so you have to use parted. Note that getting these commands wrong will destroy everything, starting with your confidence.

This will take the device /dev/sdb and create numbered partitions /dev/sdb1 / /dev/sdb2

$ parted /dev/sdb (or whatever the device is)
% print                             # get your bearings. note any red text and consider researching the scary messages

% mklabel gpt                       # read about MBR and GPT if you want to know more

% mkpart primary 0GB 2995GB                               
% mkpart secondary 3000GB 5995GB    # if you make the partition the full size of the disk, 
                                    # and run out of space, and the disk is doing important stuff 
                                    # (like hosting a datasette describing Grandpa's Finest Moments), 
                                    # you might be in trouble! 
parted output

setting up a filesystem

This is pretty fast. Like every other command in this post, mistakes will switfly ruin your day. Don’t use a filesystem that hasn’t been in development for at least 10 years. Ext4 is a good choice, has been around a long time, and these commands exit really quickly. I’m optimizing for spending the least amount of time on this (clearly), so I have made a deliberate choice not to google “linux mkfs.ext4 performance tuning” or “ext4 vs zfs dev machine”.

mkfs.ext4 /dev/sdb1
mkfs.ext4 /dev/sdb2

mounting it

Everyone except for StackExchange question askers is mounting their additional disks in /mnt, and there is probably a good reason for it. Find a greybeard and get a horror story. Or just follow the pattern.

I’ll be mounting into /mnt/backups and /mnt/documents. Then I’ll create symlinks in directories I actually use. Editing fstab seems to be pretty safe. It spits out lots of errors if you make a mistake.

Create the directories:

$ mkdir /mnt/backups
$ mkdir /mnt/documents

# I also chown'd these directories to my user account instead of root

Get UUIDs:

$ lsblk -o NAME,FSTYPE,LABEL,SIZE,MOUNTPOINT,UUID

sdb                                        5.5T            
├─sdb1      ext4                           2.7T            5a45f582-3aee-41dc-b412-271293034365
└─sdb2      ext4                           2.7T            cffc8741-4542-473a-81b1-2015d5fc0656

Edit /etc/fstab:

$ sudo vi /etc/fstab

# Added these lines
# Got the UUID from above
# Directory structure chosen with love
# The filesystem was previously decided
# Just use the defaults, customizations elided
# A deprecated option '0' remains
# And FS check order of '2' i can't explain
UUID=5a45f582-3aee-41dc-b412-271293034365 /mnt/backup             ext4    defaults   0 2
UUID=cffc8741-4542-473a-81b1-2015d5fc0656 /mnt/documents          ext4    defaults   0 2

Mount it and tell your system about the drives, i guess:

$ mount -a
$ systemctl daemon-reload

Here’s the finished product. Very nice, such a distinctive partition table, impossible to accidentally delete.

mounted disks

using it?

Finally I’ll create a symlink in a directory I actually use regularly in order to access the drives.

ln -s /mnt/backup/ Backup
ln -s /mnt/documents/ Docs2

At some point I’ll take the decision to copy my docs folder over here too, but I have to decide whether there are any performance implications.