Adding an external storage device to your Raspberry Pi.

Partition’s are displayed by their device’s name such as, /dev/sda, /dev/sda1, /dev/sda2,etc.

This command will list all bulk storage devices on the Raspberry Pi:
$ lsblk
// returns the following: [ exact copy of mine]

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 1 29.8G 0 disk                     (This is the USB stick plugged into the USB port)
└─sda1 8:1 1 29.8G 0 part
mmcblk0 179:0 0 29.8G 0 disk    (This is your SD card!)
├─mmcblk0p1 179:1 0 43.9M 0 part /boot
└─mmcblk0p2 179:2 0 29.8G 0 part /

 

I removed the USB device from the RPi and repeat the same command:

$ lsblk

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
mmcblk0 179:0 0 29.8G 0 disk           (This again is your SD card!)
├─mmcblk0p1 179:1 0 43.9M 0 part /boot
└─mmcblk0p2 179:2 0 29.8G 0 part /

Look!  No ‘sda’.

Now the work begins.  (Be careful what you type in : double check!)

$ sudo fdisk  /dev/sda
// fdisk stands for “fixed disk or format disk”. It is a command line based, disk
// manipulation utility for Linux/Unix systems. The ‘fdisk’ allows you to create a
// maximum of 4 new primary partitions and a number of logical(extended) partitions.

To view ALL  disk partitions on the Raspberry Pi run the following  fsdisk command:
(That’s a lowercase ‘L’, not an integer value 1.)
$ sudo fdisk   -l

Disk /dev/ram0: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram1: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

 ( outputs sequentially numerical disks >  Disk /dev/ram3 [,… ram4 [, … ram5[ , … ram6 ] ) and so on!) until  Disk  /dev/ram15/)

Disk /dev/ram15: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Then you see a difference here below.

Disk /dev/mmcblk0: 29.8 GiB, 32010928128 bytes, 62521344 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xac396f91

Device Boot Start End Sectors Size Id Type
/dev/mmcblk0p1 8192 98045 89854 43.9M c W95 FAT32 (LBA)
/dev/mmcblk0p2 98304 62521343 62423040 29.8G 83 Linux
Disk /dev/sda: 29.8 GiB, 32015679488 bytes, 62530624 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x05034f09

Device Boot Start End Sectors Size Id Type
/dev/sda1 * 63 62530623 62530561 29.8G 7 HPFS/NTFS/exFAT

 

Now to wipe the existing partitions:
$ sudo   fdisk   /dev/sda       (The ‘sda’ is the USB mounted device location)

Returned output:
Welcome to fdisk (util-linux 2.29.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

I would recommend quickly taking a look at the fdisk ‘help’  first to get
a basic understanding of the choices your about to make.

 

The following opens:   Command( m for help):
Now you make selections.
Command (m for help): 0                 // Enter a lowercase ‘o’ .  Not a int, zero. It’s a letter.

(Returned output:)  Created a new DOS disklabel with disk identifier 0x7165773b.
Enter the following:
Enter a,  n
Enter a: p
Then select the default value by hitting the “ENTER” key on keyboard.
Then  the “ENTER” key for default once more.
Then ‘w‘ to write.

If you make a mistake, just start over.
$ sudo fdisk    /dev/sda

Now to format the DISK! But, let’s first make sure the partition was created.

The partition you just created is named, ‘sda1‘.  (You could also run: $ lsblk) or
($ df -h ) .  You can also use the fdisk command: $ fdisk  /dev/sda . Then, enter a ‘p‘ for print.  Commands will output similar but different metadata(info).
$ sudo  fdisk -l  /dev/sda  

 

FORMAT and attach a Label at the same time with the following:

( The ‘PILABELHERE’ must be capitalized here. You can name it with some other name!)
$ sudo mkfs.ext4 -L  PILABELHERE    /dev/sda1

Now to pick/choose a directory to mount the storage under. You have many choices.
For example, you could select: $ /home/pi
To make things simple and logical, I selected the directory,  ‘/mnt ‘.

Create/Make a directory for the USB device mount point. ‘mkdir‘ means make directory.
$ sudo mkdir  /mnt/pilabelhere

Test it!
$ sudo mount  -L  PILABELHERE  /mnt/pilabelhere

$ ls  /mnt/pilabelhere

 

Now to make the storage permanent.

Open the /etc/fstab file with an editor. I use nano on the Pi.
$ sudo nano  /etc/fstab

This will open the fstab file and you’ll notice other lines of code already in the file.
At the bottom of the file enter the following:
[ NOTE: no spaces in the LABEL=PILABELHERE.  That is a zero integer, not a character.
No spaces between the defaults,noactive]

LABEL=PILABELHERE   /mnt/pilabelhere   ext4     defaults,noactive   0     1

To save it:  First:  CTRL + O (key)    // That IS a ‘char’ character. Not a integer.
Second: ENTER(key)
Lastly: CTRL + X(key)

If you made a mistake, no worries… just repeat above.

Always try to use something like:
$ sudo shutdown  -h  now    (halts and shuts off)
$ sudo shutdown  -r  now     ( shuts down and reboots)
$ halt -h                                  (ummm….  halts  :)`

 

Repair by

$ sudo umount    /mnt/pilabelhere
$ sudo fsck    /dev/sda1