There are a number of variations to the process, but basically, the steps are:
o Install OS on SD Card and boot
o Plug in external hard drive
o Partition and Format hard drive
o Copy system to hard drive
o Mount the new system and modify configuration to use the hard drive
I decided not to re-invent the wheel. The following instructions are just my variations on the instructions provided by Rattus here:
Note about the sudo command: All of the following must be done as root. You must put sudo before each of the commands. Or, you can follow the (not recommended, bad practice) habit I have and just enter sudo bash to run a shell as root and skip saying sudo all the time.
Load SD Card with Raspbian in the usual way. Update the system software and firmware with the following three commands. This can take quite a while to complete.
apt-get update
apt-get upgrade
rpi-update
reboot
List the partitions This should show only the /boot and / partitions on the SD card.
fdisk –l
Plug external hard drive into USB and list the partitions again. This should show another HD probably at /dev/sda
Modify the partition table for the external drive.
fdisk /dev/sda
Delete partitions by entering “d” and then the number of the partition to delete. Delete all the partitions. Entering “p” will list the partitions.
At this point, you have a few options.
a) Create a single partition and move the root there. This will leave the swap file on the SD card.
b) Create a root partition that fills most of the drive and a small swap partition.
c) Create a partition for the OS, a small swap partition, and a large partition for application data.
I
am using the third option. The following
instructions are fairly easy to change to use one of the other options. While still in the fdisk program, do these
steps.
- Create the root partition: I made mine 16GB. Enter “n” to create a partition, “p” to select primary partition and then “1” to select partition number one. Select the default start sector. Enter +16G to specify the size.
- Create the swap partition: Enter “n” to create a partition, “p” to
select primary partition and then “2” to select partition number two. Select the default start sector. Enter +2G to specify the size. Enter “t” to set the type of a partition. Enter “2” and then “82” to make this one a
swap partition.
- Create the data partition: Enter “n” to create a partition, “p” to select primary partition and then “3” to select partition number three. Select the default start sector and default end sector to fill up the rest of the disk.
- Enter “p” to list the partitions and verify
things are like you expect.
- Enter “w” to write the new partition table and exit.
Create (format) the data partition with an EXTv4 file system. This command takes a few minutes to finish. There is no need to format the first partition since we are going to do a raw copy of an existing file system over it anyway.
mkfs.ext4 /dev/sda3
Initialize the swap partition
mkswap /dev/sda2
Mount the new root partition.
mount /dev/sda1 /mnt
Use rsync to clone the root partition from the sdcard to the new partition on your hard disk, Note the exclude of /mnt. This takes a while.
rsync -avz --exclude '/mnt' / /mnt
Change the mount configuration file on the new root.
vi /mnt/etc/fstab
Change the root device /dev/mmcblk0p2 to be /dev/sda1
Add /dev/sda2 as a swap partition by adding this line.
/dev/sda2 none swap sw 0 0
Finally, stop the system from using the swap file that it normally uses.
rm /mnt/etc/rc?.d/*dphys-swapfile
And delete the old swap file.
rm /mnt/var/swap
Use your editor of choice (I use vi) to modify the boot configuration to use the new root partition. First make a backup copy.
cp /boot/cmdline.txt /boot/cmdline.orig
vi /boot/cmdline.txt Change /dev/mmcblk0p2 to be /dev/sda1
Now the system is ready to reboot. It should come up normally with the external hard drive mounted as root.
reboot
If the system fails, use another machine to copy /boot/cmdline.orig to /boot/cmdline.txt and then reboot again.
One problem that some people have run into is controllers that take too long to complete the USB discovery. This can be compensated for by adding delays in the /boot/cmdline.txt file with the bootdelay and rootdelay options.
- Create the root partition: I made mine 16GB. Enter “n” to create a partition, “p” to select primary partition and then “1” to select partition number one. Select the default start sector. Enter +16G to specify the size.
- Create the data partition: Enter “n” to create a partition, “p” to select primary partition and then “3” to select partition number three. Select the default start sector and default end sector to fill up the rest of the disk.
- Enter “w” to write the new partition table and exit.
Create (format) the data partition with an EXTv4 file system. This command takes a few minutes to finish. There is no need to format the first partition since we are going to do a raw copy of an existing file system over it anyway.
mkfs.ext4 /dev/sda3
Initialize the swap partition
mkswap /dev/sda2
Mount the new root partition.
mount /dev/sda1 /mnt
Use rsync to clone the root partition from the sdcard to the new partition on your hard disk, Note the exclude of /mnt. This takes a while.
rsync -avz --exclude '/mnt' / /mnt
Change the mount configuration file on the new root.
vi /mnt/etc/fstab
Change the root device /dev/mmcblk0p2 to be /dev/sda1
Add /dev/sda2 as a swap partition by adding this line.
/dev/sda2 none swap sw 0 0
Finally, stop the system from using the swap file that it normally uses.
rm /mnt/etc/rc?.d/*dphys-swapfile
And delete the old swap file.
rm /mnt/var/swap
Use your editor of choice (I use vi) to modify the boot configuration to use the new root partition. First make a backup copy.
cp /boot/cmdline.txt /boot/cmdline.orig
vi /boot/cmdline.txt Change /dev/mmcblk0p2 to be /dev/sda1
Now the system is ready to reboot. It should come up normally with the external hard drive mounted as root.
reboot
If the system fails, use another machine to copy /boot/cmdline.orig to /boot/cmdline.txt and then reboot again.