Mount ext4 USB flash drive to Raspberry Pi

This is just a shameless translation of the german post Raspberry Pi: USB-Stick und USB-Festplatte einbinden from Jan Karres. Jan is also mounting ntfs and fat drives, but I just need ext4 so we will skip his first step. I have also changed some small other things.

Create media directory

Let's create a media directory for the flash drive for our user. The user is for now called gordon and the flash drive gets the name sandisk, cause I have a 128 GB USB flash drive from SanDisk. You should replace both.

sudo mkdir -p /media/gordon/sandisk

Detecting the flash drive

Please make sure that the USB flash drive is plugged and run the following command.

sudo blkid -o list
device              fs_type   label      mount point             UUID
------------------------------------------------------------------------------------------------------
/dev/mmcblk0p1      vfat      boot       /boot                   XXXX-XXXX
/dev/mmcblk0p2      ext4                 /                       xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
/dev/sda1           ext4      SanDisk    (not mounted)           xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
/dev/mmcblk0                             (in use)

The output should look like this. I hope you have identified your drive. If not, just unplug the drive, run the command, plug the drive and run the command again. This should help you to find your flash drive. Important for us is the device column. In my case the SanDisk flash drive has the path /dev/sda1.

Mounting the device

As we now know the path of the device, we can mount it with the following command.

sudo mount -t ext4 -o defaults /dev/sda1 /media/gordon/sandisk

Unmount

We can unmount the device like this.

sudo umount /media/gordon/sandisk

Mount on boot

I want my USB flash drive for my ownCloud instance. So it would be nice if the device is always available after every boot. Jan has also a solution for this. Now we need the column UUID from the output above. Edit the file /etc/fstab with any editor, for example nano.

sudo nano /etc/fstab

Please add the following line at the end of the file. Make sure to replace the UUID and the path of the mounted device.

UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx /media/gordon/sandisk ext4 defaults 0

It would be possible to use also /dev/sda1 instead of UUID=..., but the UUID makes sure that we are mounting this flash drive and not any other one that could be in the same USB slot. Please keep this in mind if you replace the USB flash drive with an other one.

Setup permissions

After that we will change the owner of this media directory to our user.

sudo chown gordon:gordon -R /media/gordon/
Next Previous