Apparently when I mentioned USB Drive this caused a bit of confusion as to the exact type of device I am using. I should have been more clear on this and referred to “USB Drive” as “USB Hard Drive”. My set up is using one of the following drives I had replaced on my Xbox One when going to a bigger one for it. amazon.com//dp/B00CI3BLPA/. I am quite pleased with it. It has been running for over a year straight 24/7 on the Xbox One and now on the RPi.
Once again had to replace a burned out SD card on my receiver today. Kind of getting sick of swapping out SD cards every month or so, so this time I decided to move the root partition off the SD card and on to a USB drive. Supposedly this should give the set up some much needed durability as well as a performance gain. I am starting over from scratch but this method of moving the root directory over to a USB drive should work with any existing setup. If you decide to do this with an existing setup please BACKUP OR IMAGE YOUR EXISTING SD CARD BEFORE STARTING.
Boot up your running Raspberry Pi and plug in your USB drive and execute the following command.
sudo fdisk –l
The USB drive will generally show up as /dev/sda but make sure by comparing it to the list presented by the previous command.
Now we will need to partition the USB drive which we will do so by running the following command.
sudo fdisk /dev/sda
Delete the partitions by entering “d”. If more than one partition is present you will need to specify the number of the partition repeating this until they are all gone. Do not exit fdisk after doing this we are not done using it yet.
Next we will create a couple new partitions one to being an ext4 file system which will contain the root partition from here on out and another which will be used as a swap partition by the operating system.
First create the partition to be used for swap:
Enter “n” to create the partition, “p” to set it as a primary partition and then “2” to set the partition number to two. Press enter to select the default start sector then enter +2G to specify the size.
Now create the soon to be root partition:
Enter “n” to create the partition, “p” to set it as a primary partition and then “1” to set the partition number to one. Press enter to select the default start sector then select the default end sector to use up the entire disk.
Now finish setting up the swap partition by entering “t” after which we will need to enter “2” as the partition number we wish to work with the enter “82” to make this a Linux Swap partition.
Enter “p” to list the partitions to be written and confirm everything is right.
Enter “w” to write the new partition table to the drive once everything is confirmed to be in order.
Now format the new root partition by using the following command.
sudo mkfs.ext4 /dev/sda1
Initialize the new swap partition.
sudo mkswap /dev/sda2
Mount the new root partition.
sudo mount /dev/sda1 /mnt
Install rsync and copy the files from the SD card to the USB drive.
sudo apt-get install rsync sudo rsync -avz --exclude '/mnt' / /mnt
Now open the file /mnt/etc/fstab in your favorite text editor.
sudo nano /mnt/etc/fstab
Change the the root device from /dev/mmcblk0p2 to /dev/sda1 then add the following line to the file.
/dev/sda2 none swap sw 0 0
Next stop the system from using the swap file it has in the past.
sudo rm /mnt/etc/rc?.d/*dphys-swapfile
Then delete the old swap file.
sudo rm /mnt/var/swap
Open the file /boot/cmdline.txt in your favorite text editor.
sudo nano /boot/cmdline.txt
And change /dev/mmcblk0p2 to /dev/sda1
I ran through this twice both times on different hardware with things booting up great. No activity on my SD card with the USB drive flashing away happily instead.