Linux Hard Drive Guide
Hard drives allow us to store large amounts of data in a predictable, uniform way. No matter which manufacturer produces the hard drive, Linux abstracts this away from the computer’s user so they can easily use the available space.
Storage is reaching amazing low prices and you can get a great 1TB hard drive for $46.88 and an even better deal for a 4TB Hard Drive for $99
File System Disk Usage/ Availability
If you’re curious about your file systems and the amount of space available, the df command is a good place to start:
sudo df
Filesystem 1K-blocks Used Available Use% Mounted on udev 1953036 0 1953036 0% /dev tmpfs 392704 40080 352624 11% /run /dev/sda2 5810266888 1563655440 3953768032 29% / tmpfs 1963504 0 1963504 0% /dev/shm tmpfs 5120 0 5120 0% /run/lock tmpfs 1963504 0 1963504 0% /sys/fs/cgroup /dev/sdc1 5328643256 1292087684 3767984540 26% /media/Disk2 /dev/sdd1 5724911000 1298579372 4137789884 24% /media/Disk3 tmpfs 392704 0 392704 0% /run/user/1000
Determine Available Disk
The lsblk command is a useful way to list all of the connected media:
sudo lsblk
sda 8:0 0 5.5T 0 disk ├─sda1 8:1 0 1M 0 part ├─sda2 8:2 0 5.5T 0 part / └─sda3 8:3 0 3.8G 0 part [SWAP] sdb 8:16 0 5.5T 0 disk └─sdb1 8:17 0 5.4T 0 part sdc 8:32 0 5.5T 0 disk └─sdc1 8:33 0 5T 0 part /media/Disk2 sdd 8:48 0 5.5T 0 disk └─sdd1 8:49 0 5.4T 0 part /media/Disk3 sde 8:64 0 5.5T 0 disk └─sde1 8:65 0 5.4T 0 part
Let’s mount the last disk called dev/sde1 onto /media/backups. First, create the mount point directory using the mkdir command with the -p parameter to tell the server to create any missing parent directories:
sudo mkdir /media/backups -p
The /etc/fstab File Defines Where Disks Are Mounted
It’s always good to start by copying the /etc/fstab file (cp is the linux command for copy)
sudo cp /etc/fstab fstab.backup
Viewing and Editing /etc/fstab File
Now that we’ve backed up our fstab file, let’s open it up to see the contents:
sudo nano /etc/fstab
# /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). # ## / was on /dev/sda2 during installation UUID=0f5fec53-4435-418a-bd53-2c11be1b295b / ext4 errors=remount-ro 0 1 # swap was on /dev/sda3 during installation UUID=fb3db8ac-0b9a-4823-b526-8cf92daadd7e none swap sw 0 0 UUID=9a8c92ff-1043-4ff1-8ad5-9ddbd12ea060 /media/Disk2 ext4 defaults,rw 0 UUID=a4e917c7-42be-43f2-b07b-57895952cbea /media/Disk3 ext4 defaults,rw 0
Notice what the comments in this file say, they are very helpful. Also note how Disk2 and Disk3 are mounted explicitly by disk UUID and the mountpoint path. Let’s exit out of the nano text editor by pressing ctrl+x (is prompted to save, say n for no)
Let’s use the blkid command to list out all of our Disk UUIDs:
sudo blkid
/dev/sda1: PARTUUID="9e7a3681-2c37-4b29-9838-5009a361ac05" /dev/sda2: UUID="0f5fec53-4435-418a-bd53-2c11be1b295b" TYPE="ext4" PARTUUID="01a3b250-de8a-4113-b1e2-9f1c35e1009a" /dev/sda3: UUID="fb3db8ac-0b9a-4823-b526-8cf92daadd7e" TYPE="swap" PARTUUID="4288ecbd-d6d2-4c7e-bfa9-cc262c310ead" /dev/sdb1: UUID="e49f4827-dead-46ee-b8aa-a00c10a39401" TYPE="ext4" PARTLABEL="primary" PARTUUID="354e01c2-ae30-4d08-8b0b-22875f69c26d" /dev/sdc1: UUID="9a8c92ff-1043-4ff1-8ad5-9ddbd12ea060" TYPE="ext4" PARTLABEL="primary" PARTUUID="aed464e3-01d3-448a-acf8-ef09c1f0a56a" /dev/sdd1: UUID="a4e917c7-42be-43f2-b07b-57895952cbea" TYPE="ext4" PARTLABEL="primary" PARTUUID="d2d84ec2-ca40-41c4-a6df-2174f04a0946" /dev/sde1: UUID="5c74fcc1-f217-4875-b326-e8f9c4cda3e5" TYPE="ext4" PARTLABEL="primary" PARTUUID="6e21bfc5-395f-4256-ab5a-f58304aa2f4e"
Note the UUID for the last line in the file for the /dev/sde1/, this is what we will add to the /etc/stab file (this is just an example, your disk’s UUID will be different)
Mounting a Disk by Modifying /etc/fstab
Make sure you have your UUID copied and let’s use the nano text editor to view & modify our fstab file
sudo nano /etc/fstab
Add a new line to /etc/fstab:
UUID=5c74fcc1-f217-4875-b326-e8f9c4cda3e5 /media/backups ext4 defaults,rw 0
After you modify /etc/fstab, always mount all reight away so you can test the configuration.
sudo mount -a
How to Get The Serial Number of Your DIsks
Sometimes we might forget which disk is disk. In these cases it is helpful to print the manufacturer’s serial number since this is usually listed on the disk’s label:
sudo hdparm -I /dev/sda | grep 'Serial\ Number'
Serial Number: WD-WX31BA45T9V1