Mount ext4 USB flash drive to Raspberry Pi
Feb 05, 2016Raspberry 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 ownCloudinstance. 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/sda1instead 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/
NextPrevious
About
My name is Gordon Lesti. I have a B.Sc. degree in Computer Science.
Tags
Art Audio Bluetooth Books Bootstrap CChrome Conference CSS D3 Debian DockerEmail Firefox Food Fpc Gitlab Grunt InkscapeJava JavaScript LaTeX Linux Magento MathMeetup Mysql ownCloud PDF PHP PrismPython QUnit Raspberry Pi Search SVG TalkTesting Time Series Tool Ubuntu VagrantVideo VirtualBox Windows Wordpress
Archives
Jan 18 Dec 17 Oct 17 Aug 17 Jul 17 May 17Apr 17 Mar 17 Feb 17 Jan 17 Dec 16 Nov 16Oct 16 Sep 16 Aug 16 Jul 16 Jun 16 May 16Mar 16 Feb 16 Jan 16 May 15 Apr 15 Mar 15Feb 15 Jan 15 Dec 14 Nov 14 Sep 14 May 14Apr 14 Feb 14 Jan 14 Sep 13 Aug 13 Jul 13May 13 Apr 13
Links
RSS 2.0
Github
This Website is build with Slim, Twig, Grunt,Bootstrap and Prism by Gordon Lesti.
Back to top