Jump to content

[Raspbian] Guide to running off of External HDD


Recommended Posts

 

 

Running Raspbian From an HDD

 

LQ5Im7t.jpg

 

 

Disclaimer: I am no Linux or security genius, so if anything goes wrong, it is absolutely your own fault.

 

USB Bus Disclaimer: It is good to keep in mind that the USB and Ethernet bus are shared. This means ethernet speed and usb read/write speeds affect each other negatively.

 

Intro:

I will try to whip up a few guides based on my own current setup with my Pi. This one is fairly simple, all you are doing is moving stuff from the SD card to your USB storage. This is necessary if you are going to be torrenting on your Raspberry Pi, otherwise you will be enjoying constant SD card corruption.

 

Understand that the SD card is still required, even after completing this guide. The Raspberry Pi only looks at the SD card for boot instructions, this tutorial guides you through copying the contents of the SD card to your HDD and editing the boot files on the SD card to point to the HDD instead of the SD card during boot.

 

Prerequisites:

- Already Running Raspbian from an SD card

- Have SSH enabled on your Pi

- An externally powered External Enclosure on your HDD. (Recommended) I use this one: Sabrent

or

- A GOOD powered USB hub that can put out the needed power to your HDD. (Not Recommended, but doable)

 

Part 1: The Main Course ~Copying SD to HDD~

This guide won't have many pictures and I seriously hope you do not need me to show you Terminal pics of every command to put in...

 

1. Format your External HDD fully or just the partition you want your Pi to run off of to ext4. You can do this using a liveUSB or liveCD version of Ubuntu using gparted. I also highly recommend also adding a linux swap partition of 1gb to the HDD.

 

2. SSH into your Pi and make sure it's up to date.

 

 
sudo apt-get update && sudo apt-get upgrade -y

3. If there were any updates, I do suggest you restart it real quick before proceeding:

 
sudo shutdown -r now

4. Plug in, or make sure your External HDD is plugged in. 5. Mount your ext4 partition Look for the partition you want to copy to:

 
sudo fdisk -l

Here's an example of what you will see: LApLldY.jpg Keep in mind, mine is already set up, so what you will see will likely be a tad different than what's in that picture. After you have found out what partition it is you need to mount, run:

 
sudo mount /dev/sd## /mnt

Where # = the letter and number of the partition you chose. 6. Copy the data [all and don't traverse file systems]

 
sudo rsync -ax / /mnt/

This will probably take a good long while, do not be alarmed. Make some coffee or look at some youtube videos in the meantime. 7. Change the rootfs locations (I will be using /dev/sda1, you use whatever you chose above)

 
sudo nano /boot/cmdline.txt

and change /dev/mmcblk0p1 to be /dev/sda1 (ctrl + x then hit y to save)

 
sudo nano /mnt/etc/fstab

so / points to /dev/sda1 #[not strictly necessary but good practice] and add a swap file/drive there. ***Adding a swap file guide below*** Remember to replace /dev/sda1 in the above directions with the partition that you chose in step 5! 8. Reboot and pray that everything is ok.

 
sudo shutdown -r now

Part 2: Dessert ~Adding that darn swap file~ 1. Run the following command to find out the UUID of your swap partition:

 
sudo blkid

You should get something like this spat out at you: fiYBllA.jpg The one that says TYPE="swap" is the one you are looking for. 2. Copypasta that UUID that it gives you into a txt using notepad or something so you have quick access to it. 3. Replace the example UUID in here with your own:

 
UUID=65ccf943-2f4b-43e2-b8a2-1df57618e701 none   swap    sw      0       0

Copypasta that ^ into your notepad and delete the example uuid and paste in your own. 4. Copy and paste that UUID line you edited just now into fstab, below the last drive.

 
sudo nano /etc/fstab

Then ctrl + x and y to save it.

5. Reboot.

 
sudo shutdown -r now

 

And that should be it. Your Pi should be running off of the USB HDD.

 

To verify that your swap is mounted correctly:

cat /proc/swaps


This should list swap partitions you have in use. Perhaps useless in modern PCs, but then a Pi isn't quite so resource equipped.

 

I am open to any suggestions and constructive criticisms, so please reply in this thread if you see something wrong or know how to improve any portion of this tutorial at all.

Edited by Cheesethief
  • Upvote 4
Link to post
Share on other sites

Thanks for the tutorial @Cheesethief :-) I have never played about with Raspberry Pi before but might just have a play with it sometime now I know it can be used with a HDD

Link to post
Share on other sites

Thanks for the tutorial @Cheesethief :-) I have never played about with Raspberry Pi before but might just have a play with it sometime now I know it can be used with a HDD

No problem. I have a few more I want to type up in the future.

It can be used with an HDD, but you still need the SD card, since that is where it looks for directions to boot.

Link to post
Share on other sites

Cheers buddy, If I come across any issues I know who to ask for help :-p

Looking forward to the rest of your tutorials

Link to post
Share on other sites
  • 1 year later...

Since I got my Raspberry Pi 2, I have been going through this stuff in Raspbian Jessie (actually Minibian Jessie to keep my setup light). This guide works just fine.

Link to post
Share on other sites
On ‎8‎/‎30‎/‎2014‎ ‎9‎:‎39‎:‎09‎, Cheesethief said:

 

 

No problem. I have a few more I want to type up in the future.

 

It can be used with an HDD, but you still need the SD card, since that is where it looks for directions to boot.

 

can something be modified so it looks for boot files on the hdd instead of sd card? is it something in a flash memory?

9 minutes ago, ps3dev said:

 

can something be modified so it looks for boot files on the hdd instead of sd card? is it something in a flash memory?

 

after further investigation, it appears the portion of code needed to be modified  (first-stage bootloader) is stored in ROM on the Broadcom BCM 2835, its actually the GPU side of the chip that controls the boot process.. so to look at another device for boot instructions would mean modifying the ROM on the BCM2835, which I'm assuming isn't possible? however Broadcom did open source this.

 

so with that in mind id like to say thanks for the guide and keep up the good work :)

Link to post
Share on other sites
36 minutes ago, ps3dev said:

 

can something be modified so it looks for boot files on the hdd instead of sd card? is it something in a flash memory?

 

after further investigation, it appears the portion of code needed to be modified  (first-stage bootloader) is stored in ROM on the Broadcom BCM 2835, its actually the GPU side of the chip that controls the boot process.. so to look at another device for boot instructions would mean modifying the ROM on the BCM2835, which I'm assuming isn't possible? however Broadcom did open source this.

 

so with that in mind id like to say thanks for the guide and keep up the good work :)

When you do sudo apt-get update and then apt-get upgrade on Raspbian, it will, at times, update the firmware of Pi itself (when such updates are available). So perhaps it is somehow possible to change the boot to another location, but is it worth it?

 

My old Raspberry Pi has been running for 2+ years off of an external HDD with boot being on the SD card. Right now I am wondering what project I should try out with my old Pi...

Edited by Cheesethief
Link to post
Share on other sites
  • 3 years later...

There are certainly other ways to do this now, but I still find the way I did it in this thread to be the most stable and reversible. As compared to the official USB boot method which requires permanently setting a bit in the boot code to boot from USB. Not to mention that the official method is not supported in anything older than the Pi3, was it?

 

I was trying to find a way to edit my original post to update the tutorial with more current information, but I guess all of the updates and changes in forum software make it impossible :S. Anywho, for anyone reading this thread and being confuzzled:

 

Ever since Raspbian got updated to Stretch, it no longer uses "/dev/mmcblk*" as identifiers, but instead uses "PARTUUID." Everything else should be pretty darn similar to what is posted in the tutorial. 

Edited by Cheesethief
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...