How to: Boot from External HDD on Raspberry Pi

Step 1: Prerequisutes

apt-get update
apt-get install nano rpi-update raspi-config usbutils dosfstools apt-utils

Note that you need to have an external power adapter for the harddrive, as Raspberry Pi only can output 500 mA through the USB ports.

Step 2: Insert HDD

Type in “df -h” to check the file system:

root@raspiserver:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       705M  476M  179M  73% /
devtmpfs        483M     0  483M   0% /dev
tmpfs           487M     0  487M   0% /dev/shm
tmpfs           487M  6.4M  481M   2% /run
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           487M     0  487M   0% /sys/fs/cgroup
/dev/mmcblk0p1   61M   20M   42M  32% /boot

Check to see if your USB harddrive is recognized by typing:

root@raspiserver:~# lsusb
Bus 001 Device 004: ID 0411:01d9 BUFFALO INC. (formerly MelCo., Inc.)
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

As you can see, the Buffalo Inc. is the 500GB harddrive I’ve attached the raspiserver.

Step 3: Formatting the Harddrive

Before we can use the harddrive, we need to format it to EXT4 instead of FAT32 or NTFS. We need to do this, as NTFS can be a bit slow when mounted as a harddrive for linux.

root@raspiserver:~# fdisk -l
Device         Boot  Start     End Sectors  Size Id Type
/dev/mmcblk0p1          16  125055  125040 61.1M  b W95 FAT32
/dev/mmcblk0p2      125056 1626112 1501057  733M 83 Linux

Device     Boot Start       End   Sectors   Size Id Type
/dev/sda1          64 976768064 976768001 465.8G  7 HPFS/NTFS/exFAT

The harddrive is, as stated, formatted for windows on /dev/sda1. We need to change this.

root@raspiserver:~# fdisk /dev/sda1

Welcome to fdisk (util-linux 2.25.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help):

Enter p, the command to list the partitions.

root@raspiserver:~# fdisk /dev/sda1

Welcome to fdisk (util-linux 2.25.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p
Disk /dev/sda1: 465.8 GiB, 500105216512 bytes, 976768001 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x73736572

Device      Boot      Start        End    Sectors   Size Id Type
/dev/sda1p1      1920221984 3736432267 1816210284   866G 72 unknown
/dev/sda1p2 ?    1936028192 3889681299 1953653108 931.6G 6c unknown
/dev/sda1p3 ?             0          0          0     0B  0 Empty
/dev/sda1p4        27722122   27722568        447 223.5K  0 Empty

Partition table entries are not in disk order.

There are three partitions which we need to reformat.
Enter d to delete partion(s) and enter the value of partition you want to delete. In my case, I started with d = 4, then d = 3, d = 2 and lastly d = 1

Before closing, we need to write the changes to the disk.

Command (m for help): d
Partition number (1-4, default 4): 4

Partition 4 has been deleted.

Command (m for help): d
Partition number (1-3, default 3): 3

Partition 3 has been deleted.

Command (m for help): d
Partition number (1,2, default 2): 2

Partition 2 has been deleted.

Command (m for help): d
Selected partition 1
Partition 1 has been deleted.

Command (m for help): p
Disk /dev/sda1: 465.8 GiB, 500105216512 bytes, 976768001 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x73736572



Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: Invalid argument

The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8).

Reboot to Enable Changes

root@raspiserver:~# reboot

Step 4: Format HDD Attached to Raspberry Pi

root@raspiserver:~# mke2fs -t ext4 -L rootfs /dev/sda1

Before we can use it, we need to mount it

root@raspiserver:~# mount /dev/sda1 /mnt

… and check to see if it works

root@raspiserver:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       705M  476M  179M  73% /
devtmpfs        483M     0  483M   0% /dev
tmpfs           487M     0  487M   0% /dev/shm
tmpfs           487M  6.4M  481M   2% /run
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           487M     0  487M   0% /sys/fs/cgroup
/dev/mmcblk0p1   61M   20M   42M  32% /boot
/dev/sda1       459G   70M  435G   1% /mnt

Step 5: Move Content from MicroSD to HDD on Raspberry Pi

We can move the files using dd, but the bit copy program also copies the empty space. Installing rsync so we can mirror the data.

root@raspiserver:~# apt-get install rsync

Rsync the content by typing (Please allow some time. It took me just under a minute on the Raspberry Pi 2):

root@raspiserver:~# rsync -axv / /mnt

Step 6: Change Boot Order on Raspberry Pi

We need to change the file /boot/cmdline.txt
However, please be aware that if something screws up here we need to start all over.
Start by creating a copy:

sudo cp /boot/cmdline.txt /boot/cmdline.backup

Change the file content from:

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

To this:

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/sda1 rootfstype=ext4 elevator=deadline rootwait rootdelay=7 program_usb_timeout=1

We have changed the reference from the SD card (root=/dev/mmcblk0p2) to the new USB disk (root=/dev/sda1).
As the harddrive might boot up a little later than the SD card, we have added a 7 seconds wait (rootdelay=7) and added program_usb_timeout=1 to the end. Make sure it is only one line.

Next we need to alter the filesystem table:

nano /mnt/etc/fstab

Just change the line

/dev/mmcblk0p2

to

/dev/sda1

and leave the rest intact.

We leave the reference to the boot intact, so the SD card is only used for booting the raspiserver. The file should look like this:

proc /proc proc defaults 0 0
/dev/mmcblk0p1 /boot vfat defaults 0 2
/dev/sda1 / ext4 defaults,noatime 0 1

Reboot the system (and cross your fingers)

reboot

Leave a Comment

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