Test of description

Linux On An External Drive

Running A RootFS On An External Disk

Comments (4)
AdministratorJuly 15th 2016
This tutorial explains how to run your Linux operating system on an external hard disk or thumb drive for the Pine 64.
What You Need
Pine A64/A64+ Board
External Disk Drive
An Additional Power Source For The Drive
Step 1 Preparation
This tutorial assumes that you have already installed a Linux distrobution using the methods described in the Getting Started - Linux guide.

At this point login to your Linux OS by either remotely logging in via ssh or directly with a monitor/keyboard hooked up to your Pine 64.

Once logged in execute the following:
sudo -i
You should see output similar to what's shown in the following screen.
What we are looking for are disks named "sdx" (in this example sda) to partition and transfer the current rootfs over to. We will be setting up a root partition and a swap partition for the Pine64 in this tutorial. As a general rule be sure to set your swap partition size to double the size of your RAM (if you have 512MB then make the swap partition 1GB).

The utility we will be using to partition the disk is called cfdisk as it is quite easy to use for even the most novice of users.
This is what cfdisk looks like.
We need to create the first partition by selecting "[ New ]" (located at the bottom of the UI) with the "arrow keys" followed by pressing "enter". At this point you will be required to type in the size you want the partition to be.

In this scenario my hard disk is 931.5GB in size and I want to ensure I have 2GB partition set aside for swap (I am using an A64+ with 1GB RAM) so I will be entering "929.5G" followed by selecting "[ primary ]".
With the new partition selected scroll to the "[ Type ]" option and select "83 Linux" from the list followed by the "[ Write ]" option. At this point you will be required to type in the "yes" in order to write the partition to disk.
Now for the swap partition you must scroll down to "Free space" then to "[ New ]" followed by "2G" (or whatever your remaining free space is) and finally "[ extended ]".
Now go to the "[ Write ]" option then type "yes" to write the new extended partition.
Finally we set will setup the swap partition. Scroll down to "Free space" then select "[ New ]" followed by "2G" (or whatever your remaining free space is).
Now select "[ Type ]" followed by "82 Linux swap / Solaris".
Finally we write the partition to disk by selecting "[ Write ]" then type "yes" followed by "[ Quit ]".
Finally we set/format the partitions for use (in this case sda1 is the new rootfs and sda5 is the new swap area to be used).
mkfs.ext4 /dev/sda1
mkswap /dev/sda5
Let's proceed with transferring and setting up the new rootfs.
Step 2 Transfer & Setup The RootFS
Now we mount the new rootfs and transfer the current contents of the rootfs (SD card) to it after we clear out some files (This example uses Debian/Ubuntu you may need to tweak it to work for other Linux distributions).
sudo -i
apt-get autoremove
apt-get clean
apt-get autoclean
cd /
mkdir /tmp/newrootfs
mount /dev/sda1 /tmp/newrootfs
cp -ax / /tmp/newrootfs
Once the rootfs has been copied over we need to set a few things up with fstab and uEnv.txt in order for things to work.
echo 'root=/dev/sda1' >> /boot/uEnv.txt
echo 'rootwait' >> /boot/uEnv.txt
echo '/dev/mmcblk0p1 /boot vfat defaults 0 2' > /tmp/newrootfs/etc/fstab
echo '/dev/sda1 / ext4 defaults,noatime 0 1' >> /tmp/newrootfs/etc/fstab
echo '/dev/sda5 none swap sw 0 0' >> /tmp/newrootfs/etc/fstab
umount /dev/sda1
Once rebooted you should be running things off the external drive.
AdministratorJuly 7th 2017
Got everything back up and running again with the site.

If anything needs to be updated with this tutorial please post here and I will make the necessary changes.
ralchevJanuary 8th 2017
Thank you for the great tutorial!

Could anyone please help with the following. I would like to also eject the external disk (2.5", powered through a USB hub) on shutdown. How is that possible?

im0December 5th 2016
Very clear and detailed tutorial. What I'm missing is a small introduction on this method. Why would I want to do this? What's the performance? Better or worse than a MicroSD install? I imagine you could have more storage.
JamesRAugust 8th 2016
Brilliant tutorial. I was up and running from a USB3.0 64GiB Flash Drive in minutes :). I completed this tutorial, followed by the Desktop Environment Tutorial and my Pine has never been happier!
Notice To All Visitors
Hello folks, just wanted to let you all know that we are currently upgrading various modules here at Pine 64 Pro.

With these new upgrades registered members will be able to submit articles/tutorials, showcase their Pine 64 Projects and communicate with other members. Along with the previously mentioned additions all tutorial content will be tied into/cross shared with Pine 64's official site(s).

Once all upgrades have been completed we will notify everyone via email.

Thanks for your patience,

Lenny Raposo.
Pine 64 Developer Fund