Skip to content

How to Move Rootfs to External USB Storage

Introduction

The Raspberry Pi typically boots and runs its operating system from a microSD card. While convenient, microSD cards have limitations in terms of read/write speeds, longevity, and storage capacity. Moving the root filesystem (rootfs) to an external USB storage device, such as an SSD or USB flash drive, offers several significant advantages:

  • Improved Performance: SSD can provide read/write speeds many times faster than microSD cards
  • Enhanced Reliability: External storage often has better wear-leveling algorithms and longer lifespans
  • Increased Storage Capacity: External drives typically offer more space at a lower cost per gigabyte
  • Reduced Wear on SD Card: The SD card is only used for booting, minimizing write operations that can cause degradation

This guide explains how to move the root filesystem of a Raspberry Pi running Bookworm to an external USB storage device while keeping the boot partition on the SD card.

Prerequisites

Before beginning this procedure, ensure you have:

  • A Raspberry Pi with Raspberry Pi OS Bookworm installed
  • An external USB storage device (SSD, HDD, or USB flash drive)
  • A stable power supply for your Raspberry Pi and external drive
  • A backup of your important data
  • Access to terminal/SSH

Detailed Procedure

1. Prepare Your External USB Storage

First, identify your external storage device and prepare it for use:

1
2
3
sudo fdisk /dev/sdX
# Create a new partition (type Linux) and format it
sudo mkfs.ext4 /dev/sdX1

2. Mount the USB Storage

Create a mount point and mount the newly formatted partition:

sudo mkdir /mnt/usb
sudo mount /dev/sdX1 /mnt/usb

3. Copy RootFS to USB

Use rsync to create an exact copy of your root filesystem on the external storage:

sudo rsync -aAXv / --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} /mnt/usb

4. Modify Boot Configuration

Update the boot parameters to tell the Raspberry Pi to use the external storage for the root filesystem:

sudo nano /boot/firmware/cmdline.txt
Change the root= parameter to point to your USB device, e.g., root=/dev/sdX1.

5. Reboot the Raspberry Pi

Flush the filesystem buffers and restart your Raspberry Pi to apply the changes:

sudo sync
sudo reboot

After rebooting, your Raspberry Pi should boot from the SD card but mount the root filesystem from the external USB storage.

Verification

To verify the change was successful, check the current mount points:

df -h

You should see your external USB device mounted as / (root filesystem).

Troubleshooting

If your Raspberry Pi fails to boot:

  1. Remove the SD card and connect it to another computer
  2. Edit /boot/firmware/cmdline.txt to revert the root parameter to the original SD card partition
  3. Reinsert the SD card and boot the Raspberry Pi to try again

Conclusion

Moving the root filesystem to external USB storage offers significant performance improvements and extends the life of your SD card. This configuration provides the reliability of USB storage for day-to-day operations while maintaining the simple bootloader on the SD card.

For optimal performance with SSDs, consider enabling TRIM support for your external drive and implementing regular maintenance practices such as periodic file system checks. This hybrid approach allows you to leverage the advantages of both storage mediums while minimizing their individual limitations.

Remember that different Raspberry Pi models have different USB capabilities—Raspberry Pi 4 and newer models with USB 3.0 ports will see the most substantial performance improvements when using high-speed external storage devices.