Setting Up Raspberry Pi 2 (Including Moving rootfs to USB Drive)

Finally got myself a Raspberry Pi! And can’t wait to set it up 🙂

RPi had a reputation of corrupting SD cards whether it is due to running a desktop OS on an SD card wearing it down or improper shutdowns (considering most of the time it runs headless) by yanking the power cord, I have decided to reduce my chances by moving the rootfs to an external USB stick.


  • Raspberry Pi 2
  • 8GB Class 10 SD card. Though, anything above 4GB Class 4 should do as we are only using it for boot
  • 2A power supply (with up to 1.2A available for USB hub, its best to get 2A. Apparently anything above 2A is a waste as the polyfuse is rated at 2A anyway)
  • USB Wi-Fi Adapter (RTL8188CUS or RTL8192CU chipsets. Mine is an Adafruit 814  on RTL8192CU)
  • (optional) Enclosure
  • (optional) HDMI cable


  • Download NOOBS (New Out Of Box Software) or Raspbian (RPi version of Debian)
  • Use SDFormatter to format your SD card (use option: Quick Erase + Size Adjustment On)
  • Unzip and copy the files across if you are using NOOBS
  • or use Win32DiskImager to copy the .img file on a bit level. (Win32DiskImager is also useful for backing up your SD cards as it does not care what is on your card when you need to restore it, it will just overwrite everything and restore back to its former glory)
  • Pop that card in the Pi and boot it up!
  • Once it is all booted up, find out the IP address and use PuTTY to login remotely.

Moving rootfs to USB Stick (ref, ref2):

Pre-start Checks:

Connect to internet via ethernet (as we have not yet configured our Wi-Fi networks)

Check that the system detects your USB flash drive by using this command and you should something like this with a mention of the flash drive

pi@raspberrypi ~ $ lsusb
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 0930:6544 Toshiba Corp. Kingston DataTraveler 2.0 Stick (2GB)
Bus 001 Device 005: ID 0bda:8176 Realtek Semiconductor Corp. RTL8188CUS 802.11n WLAN Adapter

If this is the only USB flash drive you have plugged in, it would be called “sda”. But we can check by doing this

pi@raspberrypi ~ $ tail /var/log/messages


Jun  6 21:19:35 raspberrypi kernel: [   23.974941]  sda: sda1


with that, the USB can be called


with the first partition known as


Partitioning USB Stick:

First, we gotta get gdisk since we will be formatting this partition to the GPT format

sudo apt-get install gdisk

Then partition the relevant drive (in this case, /dev/sda)

sudo gdisk /dev/sda

  • First, delete all partitions on the drive by typing in “d” (for delete)
  • Then, “n” for new
  • Finally “w” for write
  • And “i” for info when it is all done
  • At anytime, you can quit by doing “q”

After that’s all been done, we should see something like this

pi@raspberrypi ~ $ sudo gdisk /dev/sda
GPT fdisk (gdisk) version 0.8.5

Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help): i
Using 1
Partition GUID code: xxxxxxx (Linux filesystem)
Partition unique GUID: xxxxSome-GUIDxxxx
First sector: 2048 (at 1024.0 KiB)
Last sector: 15155166 (at 7.2 GiB)
Partition size: 15153119 sectors (7.2 GiB)
Attribute flags: 0000000000000000
Partition name: 'Linux filesystem'

Keep note of the “Partition unique GUID” so that you can add that into /boot/cmdline.txt

sudo nano /boot/cmdline.txt

Change the contents to look like this

pi@raspberrypi ~ $ cat /boot/cmdline.txt
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=PARTUUID=xxxxSome-GUIDxxxx rootfstype=ext4 elevator=deadline rootwait rootdelay=5

Note the change of “root=” and the addition of “rootdelay=5”. This rootdelay is to tell the system to wait 5s on boot time to allow time for the USB to be mounted properly and ready for action.

Now, we format and rsync the drives

sudo mke2fs -t ext4 -L rootfs /dev/sda1
sudo mount /dev/sda1 /mnt
sudo rsync -axv / /mnt

While waiting for it to complete rsync, we can create a new SSH session and start working on other things such as editing the fstab

pi@raspberrypi ~ $ sudo tune2fs -l /dev/sda1
tune2fs 1.42.5 (29-Jul-2012)
Filesystem volume name: rootfs
Last mounted on: /
Filesystem UUID: xxxx-Some-FS-UUID-xxxx
Filesystem magic number: 0xEF53

Keep note of the Filesystem UUID and modify /etc/fstab to look something like this

/dev/disk/by-uuid/xxxx-Some-FS-UUID-xxxx / ext4 defaults,noatime 0 1

#/dev/mmcblk0p2 / ext4 defaults,noatime 0 1

We commented out the original root mount point and add our new mounting point.

Once that is all done (make sure the rsync is done too!) then you can finally reboot to get all the changes in place.

sudo reboot


Once that is all done, you can finally update the entire system

sudo apt-get update

sudo apt-get upgrade

sudo rpi-update

Wi-Fi Setup:

Easiest way to do this is to boot into GUI using this command


and add your Wi-Fi password manually.

Backup, Backup, Backup:

Ah, that all take some effort, lets back them up using Win32DiskImager!

But first, remember to shutdown properly using

sudo halt

Enjoy 🙂

This entry was posted in Raspberry Pi and tagged , . Bookmark the permalink.

One Response to Setting Up Raspberry Pi 2 (Including Moving rootfs to USB Drive)

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s