benrett
Posts: 9
Joined: Wed Nov 21, 2012 11:01 am
Location: Sydney, Australia
Contact: Website

Cheat Sheet - USB drives

Tue Mar 26, 2013 9:45 am

The following is a cheat sheet of some of the more common commands for using a USB drive with a Pi. I've written an extensive tutorial on using USB drives on a Pi shell at http://ipggi.wordpress.com/2013/03/21/u ... pberry-pi/. It covers power supply issues, mounts, performance, disk file formats, compatibility and formating.

To mount a USB drive:

Code: Select all

sudo mkdir /mnt/usbdrive
sudo mount /dev/sda1 /mnt/usbdrive
ls /mnt/usbdrive
To list your file systems:

Code: Select all

sudo fdisk -l
sudo mount -l
df -h
Before disconnecting a USB drive:

Code: Select all

sudo umount /dev/sda1
Format a drive to Linux EXT4

Code: Select all

sudo mkfs.ext4 /dev/sda1 -L untitled
Add Apple OS X HFS+ read/write support

Code: Select all

sudo apt-get install hfsutils hfsprogs hfsutils
Format a drive to HFS+

Code: Select all

sudo mkfs.hfsplus /dev/sda1 -v untitled
Add Windows NTFS read/write support

Code: Select all

sudo apt-get install ntfs-3g
Format a drive to NTFS

Code: Select all

sudo mkfs.ntfs /dev/sda1 -f -v -I -L untitled
Add Windows/DOS FAT32 read/write support

Code: Select all

sudo apt-get install dosfstools
Format a drive to FAT32

Code: Select all

sudo mkfs.vfat /dev/sda1 -n untitled
My Pi Guides: https://devtidbits.com/category/raspberry-pi/

klricks
Posts: 5765
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: Cheat Sheet - USB drives

Sat Mar 30, 2013 3:26 am

Good but you might add a section about permissions.
Especially important when attaching a drive which has been in use on another system then attached to the RPi.
My 2T drive (ext3) was attached to an ARM based NAS with Snake (Linux) and had lots of files, but when moved to the RPi, I could only access the files as root.
Finally figured out that I had to chown and chmod all the existing directories and files.
Unless specified otherwise my response is based on the latest and fully updated Raspbian Stretch w/ Desktop OS.

benrett
Posts: 9
Joined: Wed Nov 21, 2012 11:01 am
Location: Sydney, Australia
Contact: Website

Re: Cheat Sheet - USB drives

Sun Mar 31, 2013 11:59 am

That’s a very good point klricks and is something some people may forget. Linux permissions and ownerships propagate on EXT drives.
My Pi Guides: https://devtidbits.com/category/raspberry-pi/

philhudson91
Posts: 7
Joined: Sat Apr 06, 2013 4:03 pm

Re: Cheat Sheet - USB drives

Sun May 19, 2013 7:02 pm

Very useful post. Thanks

User avatar
jbeale
Posts: 3360
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: Cheat Sheet - USB drives

Tue Oct 29, 2013 6:00 pm

Mount a VFAT format USB drive so that user 'pi' can write to it:

Code: Select all

sudo mount -o uid=pi,gid=pi /dev/sda1 /mnt/usbdrive
If your USB drive has 'ext4' format, the above command will not work: EXT4-fs (sda1): Unrecognized mount option "uid=1000" or missing value

To mount a EXT4 format USB drive so that user 'pi' can write to it:

Code: Select all

sudo mount /dev/sda1 /mnt/usbdrive
sudo chown pi:pi /mnt/usbdrive
sudo chmod 777 /mnt/usbdrive

DavidA
Posts: 23
Joined: Tue Apr 28, 2015 7:48 pm

Re: Cheat Sheet - USB drives

Sun Jan 10, 2016 6:11 pm

Hi, I formatted a USB drive with a small ext4 system partition and a large NTFS data partition. It works fine on the Pi, but when I plug the drive into a Windows 7 laptop Windows doesn't recognise the format of the data partition.

For the data partition I used:

sudo mkfs.ntfs -Q -L Data /dev/sda2

Please can you suggest what I can do to fix this please?

(I want Windows to be able to access the drive so that I can directly copy large amounts of data to it.)

MrEngman
Posts: 3711
Joined: Fri Feb 03, 2012 2:17 pm
Location: Southampton, UK

Re: Cheat Sheet - USB drives

Sun Jan 10, 2016 6:18 pm

DavidA wrote:Hi, I formatted a USB drive with a small ext4 system partition and a large NTFS data partition. It works fine on the Pi, but when I plug the drive into a Windows 7 laptop Windows doesn't recognise the format of the data partition.

For the data partition I used:

sudo mkfs.ntfs -Q -L Data /dev/sda2

Please can you suggest what I can do to fix this please?

(I want Windows to be able to access the drive so that I can directly copy large amounts of data to it.)
I expect Windows cannot access the drive because the first partition is not ntfs and it does not recognise Linux partitions.



MrEngman
Simplicity is a prerequisite for reliability. Edsger W. Dijkstra

Please post ALL technical questions on the forum. Please Do Not send private messages.

John Mc
Posts: 43
Joined: Wed Feb 22, 2017 1:22 am

Re: Cheat Sheet - USB drives

Mon Jan 22, 2018 4:51 pm

This is a great resource, Thank you for posting it.
I also found the more detailed write up you posted Use USB hard disk & flash drives with your Raspberry Pi very helpful.

I thought I'd mention that there are utilities out there that add the ability to create, read, and write ExFAT formatted drives from within Raspian. You can install this with the following command:

Code: Select all

sudo apt-get install exfat-fuse exfat-utils
Once installed, I believe the command to format a drive to ExFAT is

Code: Select all

mkfs.exfat
This has made things very convenient for me, since I work in a mixed Mac/Windows/Raspian environment. and sometimes need to shuffle .img files that are larger than the FAT32 4GB limit. Also, my larger USB thumb drives all seem to come pre-formatted as ExFAT.

You may want to update this cheat sheet as well as your excellent more detailed guide, Use USB hard disk & flash drives with your Raspberry Pi.

Another mention: It seems the Raspian-stretch OS will automatically mount drives when they are plugged in. They do not mount to the /mnt folder however.

Return to “General discussion”

Who is online

Users browsing this forum: Burngate, DirkS, DougieLawson, Ernst, fbe, jbudd, W. H. Heydt, wmnally5 and 50 guests