Tag Archives: fdisk

Make Raspbian run from an external USB hard drive or USB memory stick

Raspberry Pi can ONLY boot from the SD Card. If you want to use your Raspberry Pi from an external USB hard drive or memory stick, either way you have to install Raspbian in an SD Card an boot from it. You can see how to do it with Mac OS X in “Install Raspbian RAW image into an SD Card in Mac OS X“. Once you have Raspbian installed in the SD Card you have to do just the same in the USB hard drive or memory stick of your choice.

raspberry_pi_usb_harddrive

Plug-in the SD Card to your computer and edit the file cmdline.txt in the boot partition from this:

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

To this:

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

You only have to change the root option to boot from /dev/mmcblk0p2 to /dev/sda2.

Now you’ll boot from the SD Card but the boot system will load the system in the USB drive. That’s why we also installed Raspbian into it. Plug both the SD Card and the USB drive into your Raspberry Pi and boot normally.

raspi-config will show you all the options you can configure (enable SSH server, configure the timezone, etc.) but unfortunately it can’t resize USB drives so we’ll have to do it ourselves.

Run fdisk:

sudo fdisk /dev/sda

Press p to see the partitions. You’ll see something like this:

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            8192      122879       57344    c  W95 FAT32 (LBA)
/dev/sda2          122880     5785599     2831360   83  Linux

Write down the “Start” number in the /dev/sda2 partition because we’ll need that number when we define the new partition. In my case it is 122880. Press d and then 2 to delete that partition (don’t worry, the data on it won’t be deleted).

Create a new partition pressing n, press p for primary partition and then 2 for the partition number. When asked for the first sector use the number we writed down before (122880) and then when asked for the last sector just press enter. Finish the process pressing w to write the changes.

Reboot your Raspberry Pi:

sudo reboot

When Raspbian boots again the last step is to resize the partition:

sudo resize2fs /dev/sda2

Ref: http://www.dingleberrypi.com/2013/05/install-and-run-raspbian-from-a-usb-flash-drive/