RASPI – Part 3 — Moving /root from microSD card to external drive

05/08/16:  This procedure was written quite a while ago for the Rasparian operating system and should still be applicable.  I now use Ubuntu Mate on my Pi2s and 3s and have used this same procedure as a guideline.  The naming conventions for partitions will be different but can easily be adjusted.  Read once to see where we are going and read a second time to learn how to get there.

Prerequisites:

  • bootable SD card – Raspian “Wheezy” installed
  • bootable Pi
  • network hardware installed
  • functional Pi networking (wired or wireless)
  • external hard drive – the bigger the better, especially if you are going to be capturing video
  • all work done on the Pi

Do not update packages or update your pi.   Install on your Pi the following.

sudo apt-get gparted

Note:  all images used can be “double clicked” to get a larger image for easier reading.

We will be using gparted to partition the USB hard drive rather then fdisk.  Why, I found it much easier to use than fdisk.  The procedure here was done on a 40Gig USB hard drive so the values you will see are for that drive.  Your values will be different unless you too use a 40Gig.

1.  boot your Pi without the external disk drive plugged in

2.  use “df” to see your current Pi filesystem structure.   Look at it carefully because in the next step it will change slightly

3.  plug in your USB external hard disk drive

4.  use df again and from this output identify your external hard disk drive as your Pi OS sees it.  For me it looked like:

/dev/sdb1       36285144   180104  34261840   1% /media/sdb1

it is important that you correctly identify your external hard disk drive because we are going to use gparted to partion it for the Pi.  Partiontion the wrong device will destroy you current Pi setup and force you to start all over from the beginning.  Back to the point of rebuilding your SD card.

5.  launch gparted from the icon.  it will look like:

gparted1

yours might look a bit different.  by default it open to your default Pi (SD card) configuration.  Look at the top right and see a tab selection. Click it.  Select the device you saw in stpp 4.  “/dev/sdb1”.  Again your might be different.

6.  Having selected the external drive we will now partition the entire drive so that it might receive the Pi OS later in this procedure

select the “unallocated” partition as shown in this diagram:

gparted2

now select the icon with a “+” sign show below

gparted3

in the default values shown we will modify two:

a.  Create as:  “Primary Partition”

b.  “File system”:  ext4

Leave the fields on the left alone unless you know what you are doing.

see pic below.

 

gparted4

Click “Add”

Notice the bottom of the screen will now contain this partition is a ready state.  Look carefully because this the “DRIVE” that will be effected in the next step.  So if you have selected the wrong drive now is a good time to cancel.

 

7.  Now partition this drive by click the “check mark” at the top.  Your gparted might have a different symbol.  Gparted will now slice this disk to it full capacity.

When complete exit open a terminal window and:

sudo mkdir /media/sdb1

sudo mount /dev/sdb1 /media/sdb1

df – this should show the following among other entries

         /dev/sdb1       36285144   180104  34261840   1% /media/sdb1

8.  cd /

9.  sudo rsync -avx / /media/sdb1 – note the red / – this will take time.  It will copy your OS files from your SD card to the new formatted partition on your external drive.

10.  when the above copy is complete

11.  cd /media/sdb1/etc

12 . vi fstab (the /media/sdb1/etc/fstab) and make the following changes

comment out the /dev/mmcblk0p2 line

add

/dev/sdb1        /               ext4    defaults,noatime  0       1

it should now look like:

proc            /proc           proc    defaults          0       0
/dev/mmcblk0p1  /boot           vfat    defaults          0       2
# /dev/mmcblk0p2  /               ext4    defaults,noatime  0       1
/dev/sdb1    /               ext4    defaults,noatime  0       1
# a swapfile is not a swap partition, so no using swapon|off from here on, use  dphys-swapfile swap[on|off]  for that

13.  cd /boot

14.  cp cmdline.txt cmdline.txt_bu –  make a safe copy incase you hose the original

15. vi cmdlinte.txt and make it look like:

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

two items to note in the above:  1.  root=/dev/sdb1 AND 2.  rootdelay=5

your are telling the boot logic on the SD card to now use the external hard drive AND the delay will make the boot process wait for the external USB hard drive to become available.  Without the delay you man not get the the desired result.

16.  Reboot

17.  If all has gone well then you should see something like the following ( this is mine note the drive is a 1TB drive):

 

pi@raspi ~ $ df
Filesystem     1K-blocks    Used Available Use% Mounted on
rootfs         959385032 1879992 908771040   1% /
/dev/root      959385032 1879992 908771040   1% /
devtmpfs          216132       0    216132   0% /dev
tmpfs              44880     292     44588   1% /run
tmpfs               5120       0      5120   0% /run/lock
tmpfs              89740       4     89736   1% /run/shm

 

the “rootfs” is mounted to the large drive.

 

18.  When you are sure that all is working you can now remove the old OS off of the SD card if you desire.

 

DONE

6 comments on “RASPI – Part 3 — Moving /root from microSD card to external drive”

  1. greenbag Reply

    A quicker way, is to just write the original image to both the microsd and the external drive. Then just point root to /dev/sdb2. I have mine on /dev/sda2.

  2. Ron Reply

    thanks for the comment. while I have not done this it seems like a reasonable solution also.

  3. Wellington Oliveira Reply

    Thank you so much!
    It works!!
    Now I can use my rasp to install plex and download any series and movies!!

  4. Ron Reply

    Chris, Happy it worked for you. I try to write procedures that are accurate. This is not always the case with other posts “Online”.

Leave A Reply

Your email address will not be published. Required fields are marked *

*

Bad Behavior has blocked 159 access attempts in the last 7 days.