To mount a USB drive:
sudo mkdir /mnt/usbdrive sudo mount /dev/sda1 /mnt/usbdrive ls /mnt/usbdrive
To list your file systems:
sudo fdisk -l sudo mount -l df -h
Before disconnecting a USB drive:
sudo umount /dev/sda1
Format a drive to EXT4
sudo mkfs.ext4 /dev/sda1 -L untitled
Add Apple OS X HFS+ read/write support
sudo apt-get install hfsutils hfsprogs hfsutils
Format a drive to HFS+
sudo mkfs.hfsplus /dev/sda1 -v untitled
Add Windows NTFS read/write support
sudo apt-get install ntfs-3g
Format a drive to NTFS
sudo mkfs.ntfs /dev/sda1 -f -v -I -L untitled
Add Windows/DOS FAT32 read/write support
sudo apt-get install dosfstools
Format a drive to FAT32
sudo mkfs.vfat /dev/sda1 -n untitled
Mounting A Drive
I will call my mount point ‘usbdrive‘. First we need to create a mount point.
sudo mkdir /mnt/usbdrive
Linux has the /dev directory that is in use to store special files that allow access to the computer’s hardware. The /dev/sd* collection of files represent drives. Each drive connected to your Raspberry Pi is given a letter.
/dev/sda Would be your first connected drive. /dev/sdb Would be your second drive.
To mount the drive to your mount point ‘usbdrive‘.
sudo mount /dev/sda1 /mnt/usbdrive
The numeric 1 at the end of /dev/sda is a requirement and tells Linux to mount the first partition.
Partitions are beyond the scope of this article, but you can learn more about that at the Ubuntu Community Docs.
mkdir mnt usbdrive
Disconnect / Unmount A Drive
It is always advisable that you unmount a USB drive before unplugging it from its power source. This forces all queued data to be written to the drive before it loses power.
sudo umount /dev/sda1
You may need to use the -f force option if the drive will not dismount.
sudo umount -f /dev/sda1
If you use the shutdown -P -h 0 command to power down your Pi you do not need to use unmount.
Disk File Systems
A disk file system is the method an operating system stores and reads data on a drive. There is an endless list of disk file systems out there as each operating system seems to have their own native but incompatible system.
Linux as a number of native file formats but generally today the most common is the EXT (Extended File System) series which include ext2, ext3 and ext4.
Apple OS X uses HFS+ (Hierarchical File System Plus) otherwise known as Mac OS Extended.
Modern Microsoft Windows systems mostly use NTFS (New Technology File System).
Legacy Microsoft Windows systems and ancient Microsoft DOS systems generally use a variation of the FAT (File Allocation Table) which includes FAT, VFAT, FAT32 and exFAT.
High CPU usage with the ntfs-3 driver Excessive CPU usage with the ntfs-3 driver that slows Samba (smdb) transfers xxx With EXT4 the file transfer using Samba has an additional 250%+ CPU resource available for use Disk File Systems Compatibility
EXT has native support in Linux and the Raspberry Pi. It has no official support in Windows. There are free third party drivers available for Windows offering limited read/write EXT support such as the open source EXT2FSD or EXT2Read. Apple OS X users need to use the commercial Paragon ExtFS to enable full EXT support.
To enable Linux EXT4 support: It is turned on by default on the Raspberry Pi.
HFS+ has restricted support in Linux. It can read HFS+ formatted drives but can only write to them if journaling is disabled. Windows has no native HFS+ support but there are paid solutions such as Paragon HFS+ for Windows.
To enable Linux HFS+ support: sudo apt-get install hfsutils hfsprogs hfsutils
FAT is probably the most supported file system but it is also the most limited. Linux, Windows and Apple OS X all support FAT, VFAT and FAT32. ExFAT otherwise known as FAT64 is native to modern Windows and Apple OS X but has no support in Linux due to patient incompatibilities.
To enable Linux FAT32 support: sudo apt-get install dosfstools
NTFS has read only support in Linux and Apple OS X. Third party drivers are available to add write support including the commercial Paragon NTFS and the open source NTFS-3g.
To enable Linux NTFS support: sudo apt-get install ntfs-3g
Performance Issues & Which Disk File System To Use?
As a non-scientific test I took a 4GB video file and copied it to various file systems using my Raspberry Pi and the USB hard drive.
The worst performer by far was the NTFS-3g driver for Linux NTFS read and write support.
The transfer that 4GB file from my Windows 7 PC to the NTFS formatted USB hard drive took around a minute or two. The same file from the Raspberry Pi’s SD memory card to the NTFS formatted USB drive took 30 minutes to write and 23 minutes to read!
Performance for EXT3, EXT4 and FAT32 were about the same at 12-14 minutes to both read and write. This suggests that there is a bottleneck with either the SD memory card or USB drivers and not the file system.
If your drives are mostly used by the Pi my recommendation would be to use EXT4 on your USB drives. EXT4 is mostly the same as EXT3 with some extra minor features but it is widely supported in the Linux world, plus it is backwards compatible with EXT3 and EXT2.
FAT32 is the most compatible file system but has a restrictive 4GB file size limit.
EXT2, HFS+ on Linux and FAT32 lack journaling support that makes them prone to errors when used on portable drives. As these file systems can’t elegantly recover if they unexpectedly lose power.
FAT32, NTFS can not store Linux file or user permissions.
Format A Drive
To change the file system of a drive you need to format it. Linux allows you to format any supported disk format using the mkfs tool.
In the examples below you will notice an option followed by ‘untitled‘. These are optional volume labels to name your drive.
First you must unmount the drive you wish to format.
sudo umount /dev/sda1
To format a drive to EXT3 (Linux): sudo mkfs.ext3 /dev/sda1 -L untitled
To format a drive to EXT4 (Linux): sudo mkfs.ext4 /dev/sda1 -L untitled
To format a drive to HFS+ (Mac OS X): sudo mkfs.hfsplus /dev/sda1 -v untitled
To format a drive to FAT32 (DOS and legacy Windows): sudo mkfs.vfat /dev/sda1 -n untitled
To format a drive to NTFS (Windows): sudo mkfs.ntfs /dev/sda1 -f -v -I -L untitled
I have applied a few options here that I will explain. -f Fast Format. Due to the poor performance of 3g.ntfs on the Pi I highly recommend using the less CPU intensive fast format mode. -v Verbose. By default the NTFS status output is limited so this lets you know what is happening. -I Disable Windows Indexing. This improves the write performance of the drive but it will mean Windows Search queries used on this drive will take longer.
Format NTFS Format NTFS Format HFS+ Format HFS+ Format FAT32 (vfat) Format FAT32 (vfat) Format EXT4 Format EXT4 Automatically Mount A Drive
To simplify the process of mounting a drive you can add the drive’s information to the fstab settings file located in /etc/. I would recommend taking a look at the Ubuntu FSTAB community page for a deeper understanding of this file.
First run nano to edit fstab. The -Bw options tell nano to backup the file and not to use any line-wrap.
sudo nano -Bw /etc/fstab
You should already see some existing entries. Do NOT change these as the two /mnt/mmcblk0p entries are there to mount the SD card.
Add the following to the bottom of the file.
/dev/sda1 /mnt/usbdisk auto defaults,user 0 1
These are explained:
/dev/sda1 Is the location of the drive to mount. /mnt/usbdisk Is the mount point, which is the folder to access the content of the drive. auto Is the file system type, here you can set ‘auto‘ or force a file system type such as ext2, ext3, ext4, hfsplus, ntfs, vfat. defaults,user Are mount options. You normally need to only supply ‘defaults‘. Though there are some others that maybe useful such as ‘ro‘ for read-only or ‘user‘ to enable write permission for all users. Use a non-spaced comma to separate multiple options. 0 A binary value used for debugging. It is best to keep this set at zero. 1 Pass number for a file system check at boot. ‘0‘ (zero) to disable or ‘2‘ to enable.
Save the changes to fstab.
[Ctrl] x Y at the Save modified buffer prompt. [Enter] for the File name to Write: /etc/fstab prompt.
nano etc fstab
The drive will mount at boot as long as it is attached to the Pi. If you want to mount the drive after you have plugged it in use mount with the automatic option.
sudo mount -a