08) Set up a USB Drive

<– Previous    Next –>

This page describes how to use a USB Drive in the Raspberry Pi for the location of the web files and database files.

This is an optional step in that you do not have to have a USB drive but you can use one to store your web site files leaving the SD card for the Debian or Ubuntu operating system.  Also a USB Drive should be faster than the SD card.

We could use a more conventional external Hard Disk Drive but you have to be aware that you may need to power it using an external power source.

To use a USB flash drive we have to format it, mount it and then configure Apache to use the required folder instead of the default folder.

This procedure will work on Debian or Ubuntu systems.

WARNING: DELETING partitions, MODIFYING and FORMATTING filesystems destroys data so double check you are working with the USB Drive.

Plug the drive into a USB port and then in the terminal window type:

sudo fdisk -l

This will list all the storage devices. One will be the SD card which will look something like dev/mmcblko and the other one will be the USB drive which will probably be dev/sda1 although yours may be different.

First, we have to format the USB drive which in my case is:

sudo mkfs.ext4 /dev/sda1


Now create a directory name for the files:

sudo mkdir /websites

Now we mount the drive using the new directory name:

sudo mount /dev/sda1 /websites

and then create a subfolder under websites using:

sudo mkdir /websites/www

and another using:

sudo mkdir /websites/www/html

It will be this folder were we place our web files.

Check the ownership of the files by:

ls -l

You will need to change the ownership at some stage to allow uploads to the folder. This is explained in the section that describes uploading with FileZilla.

We now have to set up mounting when the Raspberry Pi is rebooted by editing “/etc/fstab”:

sudo nano /etc/fstab

In this file we need to add a new line at the bottom, separating each item with a tab.

/dev/sda1 [tab] /websites [tab] ext4 [tab] defaults [tab] 0 [tab] 2

To exit the editor, press Ctrl+X to exit, Y then Enter to save.

Now, if the Raspberry Pi is rebooted, the USB flash drive will be mounted.

<– Previous    Next –>




Leave a Reply