Setting up a new hard drive in Linux
I recently added a second SSD to my Linux server and had to look up how to format it and set it up, having not taken notes for the first one. These are the notes I took the second time.
This is all done from the command line and the monospace text is to be typed directly – though change the identifiers if requried.
- sudo lshw -C disk to confirm disk is seen by the BIOS and work out it’s path. In this case, it’s /dev/sdb
- Partition the disk with a single partition:
- sudo parted /dev/sdb
- mklabel gpt
- unit TB
- mkpart
- Partition Name: primary
- File system type: ext4
- Start: 0%
- End: 100%
- print to check everything is correct
- quit to save and exit
- Format the disk:
- sudo mkfs -t ext4 /dev/sdb1
- (press the <return> key to create the journal)
- Create mount point:
- sudo mkdir /media/ssd2
- Update the filesystem table:
- sudo vim /etc/fstab
- Add this line: /dev/sdb1 /media/ssd2 ext4 defaults 0 2
- Alternatively, use ls -l /dev/disk/by-uuid to find the UUID and add to fstab with UUID="{uuid}" as the first parameter.
- Mount it now: sudo mount -a
- Set permissions:
- sudo chgrp plugdev /media/ssd2
- sudo chmod g+rws /media/ssd2
- sudo chmod +t /media/ssd2
All done and working. I then updated by backup scripts to back this drive up to an external hard drive too.