Adding a new drive to a Linux server
What does every homelab server need? Storage! And this time I was lazy, connecting the drive and packing up before actually setting up the drive. Doing so took a little bit of digging, so I'm making a note of the steps for the next time I need to do this.
This is based on a wonderfully detailed post on the GNU Parted warning: "The resulting partition is not properly aligned for best performance", found here.
This assumes the newly mounted drive is at /dev/sda, check your path or you might overwrite your boot drive!
- Zero out the start of the drive
sudo dd if=/dev/zero of=/dev/sda bs=512 count=10000
- Initialise the partition table
sudo parted /dev/sda mktable gpt
- Create a new partition that uses the full drive, while being aligned for optimal performance
sudo parted /dev/sda mkpart name ext4 0% 100%- Where
namewill be the name for the new partition (whatever you want),ext4will be the filesystem (this is the most common for simple Linux setups) and0% 100%indicates that the partition should span the full drive, while allowingpartedto find the optimal starting and ending points
- Initialise the new partition
sudo mkfs.ext4 -L name /dev/sda1- Where
namewill be the name for the volume
- Create a mount point for the partition, I use
/dbut a folder like/mnt/dataworks fine toosudo mkdir /dsudo chown $USER:$USER /d
- Get the partition UUID
sudo blkid- Find your partition, in this case
/dev/sda1, look forUUID=... - I'll use
UUID=01234567-89ab-cdef-0123-456789abcdef
- Add the new partition to the filesystem table
nano /etc/fstab- Add a row to the end like:
UUID=01234567-89ab-cdef-0123-456789abcdef /d ext4 defaults 0 2 - Where the UUID is from
blkid,/dis the path created above,ext4is the filesystem you picked above,defaultssets the mount as read/write and some other options,0turns off an old/unused backup method and2tellsfsckto check this partition but only after the root partition (which will have1here)
- Update mount points
mount --all
- Profit 🚀