Move an existing Raspbian installation from memory SD card to USB flash drive (USB stick)

We all love the Raspberry Pi. It is fascinating to observe, what kind of different uses this low cost device motivates. I am using it in a rather conventional way as web server and backup file server, running the Debian-based Raspbian Linux distribution optimized for the Raspberry Pi.


The one thing that really bothered me with the Raspberry PI was the bad I/O performance to the memory SD card. My Kingston 16 GB class 4 card actually gives poor performance only, as a quick

dd if=/dev/zero of=/tmp/out bs=1M count=400

benchmark reveals

419430400 bytes (419 MB) copied, 94.3303 s, 4.4 MB/s

The more I was excited to learn that

  • performance with USB flash drives is as on standard PCs
  • and only Raspbian’s boot partition must reside on the SD memory card.

I decided to give it a try and move the root partition of my existing Raspbian installation to an USB stick and see, if things improve. In my case, writing performance improved by a factor of roughly 5.

Copying the Filesystem

Firstly, partition and format the USB flash drive to hold an ext4 partition large enough to take the current root partition. Let us assume that this partition on the USB flash drive is called /dev/sdb1 on your Linux like operating system. Then, shut down the Raspberry properly,

sudo shutdown

remove the SD card and connect it with a card reader to your computer. Just as for the USB flash drive, let us assume the card’s partitions are recognized as /dev/sdc1 for the boot partition and /dev/sdc2 for the root partition.

Next, we mount both the old and new root partition,

sudo mkdir /media/usb_root; sudo mount /dev/sdb1 /media/usb_root
sudo mkdir /media/sd_root; sudo mount /dev/sdc2 /media/sd_root

and copy all the files and their attributes from usb_root to sd_root

sudo cp -a /media/sd_root/* /media/usb_root/

This may take a minute.


After copying the filesystem, unmount the USB flash drive and the SD card

sudo umount /media/usb_root /media/sd_root

and connect the SD card only to the Raspberry PI. After powering the Raspberry PI, it will boot as before from the memory card. Login to the PI, open a terminal and connect the USB flash drive to the Raspberry PI. You may find out under what label the USB flash drive’s partition is recognized by scanning through the most recent system logs that the


command will output:

[   90.129945] usb 1-1.3: new high-speed USB device number 4 using dwc_otg
[   90.237528] usb 1-1.3: New USB device found, idVendor=8564, idProduct=1000
[   90.237557] usb 1-1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[   90.237575] usb 1-1.3: Product: Mass Storage Device
[   90.237588] usb 1-1.3: Manufacturer: JetFlash
[   90.237599] usb 1-1.3: SerialNumber: 3POVU7A9
[   90.249596] scsi0 : usb-storage 1-1.3:1.0
[   91.252354] scsi 0:0:0:0: Direct-Access     JetFlash Transcend 32GB   8.07 PQ: 0 ANSI: 4
[   91.254679] sd 0:0:0:0: [sda] 62717952 512-byte logical blocks: (32.1 GB/29.9 GiB)
[   91.255910] sd 0:0:0:0: [sda] Write Protect is off
[   91.255944] sd 0:0:0:0: [sda] Mode Sense: 23 00 00 00
[   91.257156] sd 0:0:0:0: [sda] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[   91.264365]  sda: sda1
[   91.269011] sd 0:0:0:0: [sda] Attached SCSI removable disk

In the second to last line you see, that on my system the USB flash drive is recognized as /dev/sda1.

Next we tell the boot configuration where to search for the new root partition. For this, we open the file /boot/cmdline.txt with root permissions in our favourite editor and change the line from

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait


dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/sda1 rootfstype=ext4 elevator=deadline rootwait

You see how we replace the root option in the kernel argument list. Moreover, open the file /etc/fstab and change the device label of the root filesystem to generic /dev/root. Though this step is not required, it keeps things clean.


We are done. Reboot the Raspberry PI

sudo reboot

Please note that you will not loose any data if things go wrong, as you simply have to revert file /boot/cmdline.txt on a computer to boot from the SD card again.

Once the Raspberry PI booted, check by a

ls -al /dev/root

if the root file system is now mounted from the expected partition. If everything is fine, you may now remove the root partition from the SD card and use the memory for something else.

In my case, redoing the benchmark

dd if=/dev/zero of=/tmp/out bs=1M count=400

gave greatly improved results

419430400 bytes (419 MB) copied, 17.7538 s, 23.6 MB/s


  • Once your root filesystem is on an external drive, you may remove the memory SD card after booting the Raspberry PI. Don’t forget to properly unmount all the memory card’s partitions (e.g. boot).
  • Take care if you connect multiple storage devices to the Raspberry PI’s USB port, this might mess up the partition labeling. To be on the safe side, remove any USB devices other than the flash disk on booting.
  • If you experience error messages like usb 1-1.3: reset high-speed USB device number … using dwc_otg, your USB flash drive might consume more power than a single USB port of the Raspberry PI might provide. See this post here for a more detailed discussion and a solution.


The idea for this post originates from this instructions here to directly install a Raspbian distribution to a USB flash drive.


8 thoughts on “Move an existing Raspbian installation from memory SD card to USB flash drive (USB stick)

  1. Pingback: usb 1-1.3: reset high-speed USB device number … using dwc_otg | zeroset

  2. Olivier

    Thanks for the information, it’ll help me move my partition to my HDD.

    BTW : I’ve a 8GB class 10 Samsung SD Card and you dd command was faster on my RPi :
    419430400 octets (419 MB) copiés, 28,1275 s, 14,9 MB/s
    So, the SD card class is quite important, at least for faster boot. Anyway, I’m mainly moving to a HDD because I don’t want the SD card to become corrupt after some times.

  3. Olivier

    Well, I’ve just tried the speed on my HDD and it’s not very much faster than my SD card :
    419430400 octets (419 MB) copiés, 21,9227 s, 19,1 MB/s
    It’s a 80GB 5400RPM laptop HDD, but I can’t find the brand nor the model. In Raspbian, I can only find the brand/model of the USBIDE adapter : “Super Top USB 2.0 IDE DEVICE”.

  4. Mark Lewis

    Just performed this on/for one of my Pi. Worked perfect. I used a CentOS live CD to do the copy portion because I didn’t have another Linux machine with an SD card slot. Overall time to complete was about 30 min. First boot off HDD took about 15 min because the superblock change. Used a USB 2.0 Seagate 7200 RPM 500 GB HDD.

  5. Pingback: Everything’s on the HDD now | RasPi WordPress

  6. David Griffith

    Very good guide! Might be useful to point out that if you’re using a swap file on the USB drive, the ‘dmesg’ step will list both partitions as (for example) …sda: sda1 sda2.

    It’s a pretty common sense thing to just remember which partition comes first on your partition table (i.e. which one isn’t swap) since I believe most people will have just recently formatted, but tools such as gparted or other partition managers can definitely help you out here if you’re in a pinch. Just thought this was worth mentioning in case anyone gets stuck!

  7. humbolight

    I had to change:
    ~$ sudo cp -a /media/sd_root/* /media/usb_root/
    /media/sd_root/# find . -depth -print0 | cpio –null –sparse -pvd /media/usb_root/
    as the cp -a command was not grabbing hidden files/directories


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s