Linux: Add a new drive
I’m adding a new 2TB SSD to my existing Linux system. This will be a nice upgrade because I’m currently running on a 120Gb SSD, which very quickly fills up, since this is my arch-gaming system and games these days are mind-blowingly huge.
(So these commands are being run on Arch, by the way, but nothing here differs from, say, Slackware.)
I’m very used to formatting and installing Linux on whole new systems, but adding a single drive to an existing system is something I do way, way less often.
After physically installing it in the case and connecting the SATA data and power cables, I boot back up.
The drive now shows up as a block device:
# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS sda 8:0 0 1.8T 0 disk sdb 8:16 0 111.8G 0 disk ├─sdb1 8:17 0 4G 0 part /boot ├─sdb2 8:18 0 16G 0 part [SWAP] └─sdb3 8:19 0 91.8G 0 part /
My existing SSD has now been bumped to sdb
, apparently. The new
one is now sda
and has a usable size of 1.8Tb.
Partition the drive
I can use fdisk
if I have to, but I much prefer the hand-holding of
a good TUI like cfdisk
. So that’s what I’m gonna use to make one big
partition on this drive:
# cfdisk /dev/sda
(It asks what type of label system to use, and I answer gpt
in the
menu.)
cfdisk shows me the UUID for the drive and lists it as unpartitioned ("Free space").
I hit the enter key to select New
from the bottom menu and choose
the default partition size of 1.8T (the whole drive).
By default, it picks "Linux filesystem" as the partition type, which is what I want.
That’s all I need from this tool, so I choose Write
, answer in the
affirmative that I wish to do this potentially destructive action,
and then Quit out.
I can now see the new partition, /dev/sda1
:
# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS sda 8:0 0 1.8T 0 disk └─sda1 8:1 0 1.8T 0 part sdb 8:16 0 111.8G 0 disk ├─sdb1 8:17 0 4G 0 part /boot ├─sdb2 8:18 0 16G 0 part [SWAP] └─sdb3 8:19 0 91.8G 0 part /
Format the partition with a file system
I’m gonna use tried-and-true ext4 on this drive.
The manual page for the mke2fs
tools (i.e. man mkfs.ext4
) lists
a huge number of options, but the only required parameter is the
device to format:
# mkfs.ext4 /dev/sda1 mke2fs 1.47.1 (20-May-2024) Discarding device blocks: done Creating filesystem with 488378368 4k blocks and 122101760 inodes Filesystem UUID: dc1fe6ce-2e92-4943-b696-2011524da74e Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 102400000, 214990848 Allocating group tables: done Writing inode tables: done Creating journal (262144 blocks): done Writing superblocks and filesystem accounting information: done
This runs for a while with a nice progress update on the number of blocks being "discarded".
Add to fstab
Now I want this drive to be mounted every time I boot, so I need to
add it to the file system table, /etc/fstab
.
The advantage of using UUIDs rather than device letters has become apparent when I installed this new drive. Here’s what my fstab previously looked like:
# cat /etc/fstab # Static information about the filesystems. # See fstab(5) for details. # <file system> <dir> <type> <options> <dump> <pass> # /dev/sda3 UUID=346e5623-a993-415c-b1eb-d2bf2e7811a6 / ext4 rw,relatime 0 1 # /dev/sda1 UUID=33A8-4066 /boot vfat rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro 0 2 # /dev/sda2 UUID=8e1a2de8-edbe-4c56-9031-f234b5d69c09 none swap defaults 0 0
Note that the comments are no longer correct. My 120Gb drive was
/dev/sda
until I installed this new drive. But the table entries
are still correct because the UUIDs haven’t changed.
Okay, so to add my new drive, I need its UUID:
# # blkid /dev/sdb2: UUID="8e1a2de8-edbe-4c56-9031-f234b5d69c09" TYPE="swap" ... /dev/sdb3: UUID="346e5623-a993-415c-b1eb-d2bf2e7811a6" TYPE="ext4" ... /dev/sdb1: UUID="33A8-4066" TYPE="vfat" ... /dev/sda1: UUID="dc1fe6ce-2e92-4943-b696-2011524da74e" TYPE="ext4" ...
I’ve trimmed the output for clarity. The UUIDs match up with the fstab entries. Now I just need to add a new entry for my new drive. I’ll also remove the installer-generated comments, which are now incorrect.
My new entry:
UUID=dc1fe6ce-2e92-4943-b696-2011524da74e /media ext4 rw,relatime 0 1
And I need to make that new mount point:
# mkdir /media
I’ll just reboot to see if the new setup works.
$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS sda 8:0 0 1.8T 0 disk └─sda1 8:1 0 1.8T 0 part /media sdb 8:16 0 111.8G 0 disk ├─sdb1 8:17 0 4G 0 part /boot ├─sdb2 8:18 0 16G 0 part [SWAP] └─sdb3 8:19 0 91.8G 0 part /
Yay!
Oh, and I need to give write access to this directory:
$ sudo chmod a+w /media
(This drive is going to mostly house installed game files. I don’t need fine-grained permissions.)
That’s it!
As for installing some of those big games I mentioned… I see that there’s an option
in Steam’s Settings: Storage to setup a "new drive". It saw my /media
mount point and
I selected it. Now I can install games to that drive. Woo!