Introduction
The Raspberry Pi is an awesome device with lots of potential. This is the first part in a series of articles to get the most out of the device. I’m currently using my Raspberry Pi to serve a slew a functionality. From being a network drive to store media to eliminating ads on the network. Before we begin, start off with using the proper power supply. To save yourself headache, just buy the official Pi Power Supply for your board.
To start we are going to add a powered 8TB external hard drive and have it remount to the same folder every time the Pi is restarted. This is important so that you can rely on referencing this drive later. The instructions assume you’re comfortable with a command line.
Steps
- Open a terminal (Mac) or cmd (Windows) and ssh into the device. This command assumes the Pi is running on a specific IP
- Enter: ssh pi@192.168.1.20
- default password is raspberry, you’ll likely want to change that after you login.
- Connect the external drive to the USB port and check that it’s connected successfully.
- Enter: sudo blkid
/dev/sda1: LABEL=”seagate” UUID=”f6bfecc7-8a48-45c1-a126-7c7630cffae6″ TYPE=”ext4″ PARTLABEL=”Linux filesystem” PARTUUID=”1f96b357-2793-482d-8e0b-77addd5ee34e”
- From here we are going to assume the drive is on /dev/sda1
- Enter: sudo blkid
- Partition the Drive – We assume here that you want to fresh empty disk. Enter the following commands. Skip to step 6 if you do not want to delete any files on the drive.
- Start by downloading gdisk, as it supports large disk formats and I’m using an 8TB drive in this example. sudo apt-get install gdisk
- sudo gdisk /dev/sda
- Enter p to list the current partitions on the drive
Enter d to delete the partitions (there may be more than one)
Enter n to create a new partition
Hit Enter on each prompt to accept the defaults. Note that the Hex code tells the OS what type of drive this is. The default is 8300 for a ‘Linux filesystem’
Enter w to write the changes
- Now the new partition will be visible on fdisk. Enter this command to view it.
- Enter: sudo fdisk -l /dev/sda
You will then see:
Disk /dev/sda: 7.3 TiB, 8001563221504 bytes, 15628053167 sectors
Disk model: Expansion Desk
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 8FCB3584-1929-43D6-90CF-0711129223F5
Device Start End Sectors Size Type
/dev/sda1 2048 15628053133 15628051086 7.3T Linux filesystem
- Enter: sudo fdisk -l /dev/sda
- We are going to create an ext4 partition that is most common for Raspberry Pi drives. Choosing others is possible (ex. vfat, ntfs, exfat).
When using this command with ext4 we can give it a label. In this case ‘myusbdrive’
- Enter: sudo mkfs.ext4 /dev/sda1 -L myusbdrive
- The drive cannot be used yet until its mounted.
- Create a folder to mount the drive to. You can choose any location.
sudo mkdir -m 1777 /media/myusbdriveshare - Now mount to that folder
sudo mount /dev/sda1 /media/myusbdriveshare
- To unmount
sudo umount /dev/sda1
- Create a folder to mount the drive to. You can choose any location.
- Set up the Automount upon next boot to keep the drive pinned to that new folder.Add drive by enter a line in the fstab file. You can reference the drive using UUID or LABEL. There are a few options to set here, the most important is nofail since it will allow the computer to boot even if there is trouble mounting the drive.
- Enter: sudo nano /etc/fstab
- Add one of the following lines:LABEL=myusbdrive /media/myusbdriveshare ext4 defaults,nofail,auto 0 2
Or
UUID=f6bfecc7-8a48-45c1-a126-7c7630cffae6 /media/myusbdriveshare ext4 defaults,nofail,auto 0 2
Note that the UUID is from step 2 by entering: sudo blkid /dev/sda1
- Reboot your pi and confirm the drive is still correctly mounted
- Enter: sudo reboot
- After reboot login and run
Enter: df -H
- You should see your drive in the list
So what now?
At this point we have set a newly connected external drive to automount on start up to a specific folder. We can now reference this folder later in subsequent parts of this Raspberry Pi series of articles.