So after about two weeks of using the Raspberry Pi 2, it ran out of space. I had only the 4GB SD Card that came with it. Daniel Wayne Amstrong has a detailed blog at his Circuidipity website, that shows exactly how to move the RasPi 2 to a USB drive.
Since I am doing this well after the initial install, and am already running as root, I decided to skip a few of the steps and commands given in Daniel’s post. Here is what I did:
Remember, I am doing this on a system running Raspbian OS “Wheezy” installed on a 4GB SD Card. I already have Bind, Apache and MySQL running on this system and hosting this WordPress blog.
I did not have a USB hard drive ready, so I decided to use an old HP 32GB thumb drive instead. Deviating from Daniel’s blog, I will be using the entire 32GB for my rootfs partition that will be mounted as “/
”.
What follows is just the flow on the command line. My comments are interspersed where required with a “//
” at the start of the line…
# lsusb
// my device was shown as mounted on /dev/sda
# fdisk /dev/sda
Command (m for help): p
// shows partition list
Command (m for help): n
// new partition
Partition type:
p primary
e extended
Select (default p): [ENTER]
Partition number (1-4, default 2): [ENTER]
// partition is created
Command (m for help): w
// partition is committed, tool quits
# mke2fs -t ext4 -L rootfs /dev/sda1
// format the newly created partition to ext4 and label it "rootfs"
# mkdir /mnt/tmp
# mount -t ext4 /dev/sda1 /mnt/tmp
// create a folder in /mnt called "tmp", mount the new drive there
# rsync -axv / /mnt/tmp
// copy all the files from current "/" partition on the SD card to the new rootfs partition
// we just created. This will take a LONG time.
# nano /boot/cmdline.txt
In nano, find the entry for “root=
” and point it to our USB stick (/dev/sda1) and add a timeout (rootdelay=5
) so that Raspbian waits appropriately for the device to become available. Ignore anything else in that file. The new statement should look as below:
dwc_otg.lpm_enable=0 ... root=/dev/sda1 ... rootdelay=5
Since we are not mounting any storage partitions (like Daniel), we are done and need to reboot to our new drive now.
# reboot
Have fun!