Using an external USB drive (whether a traditional spinning-disk drive, an SSD, or a small flash drive) can help—or hinder—the performance of your Raspberry Pi.
Storing databases or large file shares onto an external drive instead of the internal microSD card can extend the life and performance of the internal card, since most microSD cards are not made to endure the frequent random access and rewriting required by general computing tasks.
Helpful hints for finding large files and folders
-
Find large files (10MB+):
sudo find / -type f -size +10000k -exec ls -lh {} \; | awk '{ print $NF ": " $5 }'
-
Find the largest folders (in current working directory):
sudo du -hsx * | sort -rh | head -10
Format a USB-connected drive on the Raspberry Pi in Raspbian
This guide assumes you just plugged in a new drive (e.g. SSD or USB flash drive) which has never been used before. Some of the partitioning commands may be slightly different if you are reformatting an existing drive with one or more partitions.
- Get the drive’s path using
$ sudo fdisk -l
- Enter
fdisk
to edit the disk’s partition table:$ sudo fdisk /dev/sda
*- Enter the following options when prompted:
n
,p
,1
,<enter>
,<enter>
,w
- Enter the following options when prompted:
- Format the partition:
$ sudo mkfs -t ext4 /dev/sda1
* - Create a directory to use as the filesystem mount: (e.g.
sudo mkdir /ssd
) - Mount the partition:
$ sudo mount /dev/sda1
*/ssd
- (If you want the disk mounted on boot) Edit fstab and add the drive:
$ sudo nano /etc/fstab
See this post for more tips.
*We’re assuming the device is sda
. It could be something else, depending on your system’s configuration/hardware.