External USB drives

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

  1. Get the drive’s path using $ sudo fdisk -l
  2. Enter fdisk to edit the disk’s partition table: $ sudo fdisk /dev/sda1*
    1. d, n, p, 1, <enter>, <enter>, w
  3. Format the partition: $ sudo mkfs -t ext4 /dev/sda1*
  4. Create a directory (e.g. /ssd) and mount the partition: $ sudo mount /dev/sda1 /ssd
  5. (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 sda1. It could be something else, depending on your system’s configuration/hardware.