Cheat Sheet - USB drives


7 posts
by benrett » 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/using-usb-external-hard-disk-flash-drives-with-to-your-raspberry-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/
Posts: 9
Joined: Wed Nov 21, 2012 11:01 am
Location: Sydney, Australia
by klricks » 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.
Go here for my RPi writeup. Basic config, Serial Port add-on etc:
http://blackeagle12.net/Comp/RPi/Rpi.html Click web icon on right side --->
Posts: 4422
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
by benrett » 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/
Posts: 9
Joined: Wed Nov 21, 2012 11:01 am
Location: Sydney, Australia
by philhudson91 » Sun May 19, 2013 7:02 pm
Very useful post. Thanks
Posts: 7
Joined: Sat Apr 06, 2013 4:03 pm
by jbeale » 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
User avatar
Posts: 3251
Joined: Tue Nov 22, 2011 11:51 pm
by DavidA » 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.)
Posts: 23
Joined: Tue Apr 28, 2015 7:48 pm
by MrEngman » 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.
Posts: 3470
Joined: Fri Feb 03, 2012 2:17 pm
Location: Southampton, UK