FreeBSDwiki:USB storage

From Ubuntuwiki.net

Jump to: navigation, search

This article explains how to mount and unmount a USB removable drive. To provide users access to mounting removable drives see removable drives.

Okay, I just mounted my own 512MB Lexar JumpDrive (USB keychain storage device) on ph34r (my FreeBSD 5.2.1 amd64 box) for the first time. It was pretty easy!

First, I plugged in the JumpDrive. Since I was shelled in instead of logged in at the console, I couldn't see the console messages that pop up when you change devices. So the next thing I did was check the end of /var/log/messages for the kernel messages about the newly attached JumpDrive:

ph34r# tail /var/log/messages

Sep  9 14:18:09 ph34r kernel: umass1: LEXAR MEDIA JUMPDRIVE, rev 2.00/20.00, addr 3
Sep  9 14:18:09 ph34r kernel: GEOM: create disk da4 dp=0xffffff003c46e068
Sep  9 14:18:09 ph34r kernel: da4 at umass-sim1 bus 1 target 0 lun 0
Sep  9 14:18:09 ph34r kernel: da4: <LEXAR JUMPDRIVE 2000> Removable Direct Access SCSI-0 device
Sep  9 14:18:09 ph34r kernel: da4: 1.000MB/s transfers
Sep  9 14:18:09 ph34r kernel: da4: 493MB (1010784 512 byte sectors: 64H 32S/T 493C)

Great! It auto-discovered fine, and it was detected as device da4. Knowing that, let's check to see what we've got in the way of disk partitions and slices on the drive:

ph34r# ls /dev | grep da4
da4
da4s1

Okay, cool - it's a simplified system, one partition, unsliced. No problem. As standard for USB mass storage devices, I already know this device is going to have a FAT file system on it - but if I wasn't sure, I could of course have plugged it into a Win2K/XP machine, gone to Disk Manager, and checked the properties on it. You never know, ONE day they might start making these things with NTFS as the standard filesystem... but I wouldn't hold my breath, if I were you. Anyway, yes, it's FAT, so off we go with making a directory to mount it on and mounting it:

ph34r# mkdir /mnt/usbdrive
ph34r# mount -t msdos /dev/da4s1 /mnt/usbdrive
ph34r# ls /mnt/usbdrive
FireFox 0.9.2 + MPClassic       Partition Magic 8.0
Malware Removal                 Undelete
NFS-Server(true-grid-pro)1.0    NT - 2K password reset util
putty.exe                       OpenOffice 1.1.2
OpenVPN-Win32                   vnc-4.0-x86_win32.exe
vnc-4.0-x86_win32_viewer.exe
ph34r#

Tada! Everything's mounted, and I can see all of my work-related files are in there just where they're supposed to be. Now I'll just add an entry to /etc/fstab to make mounting it a little easier next time:

ph34r# cat /etc/fstab
# Device                Mountpoint      FStype  Options         Dump    Pass#
/dev/ad4s1b             none            swap    sw              0       0
/dev/ad4s1a             /               ufs     rw              1       1
/dev/ad4s1e             /tmp            ufs     rw              2       2
/dev/ad4s1f             /usr            ufs     rw              2       2
/dev/ad4s1d             /var            ufs     rw              2       2
/dev/ad6s1e             /data           ufs     rw              2       2
/dev/acd0               /cdrom          cd9660  ro,noauto       0       0
/dev/da4s1              /mnt/usbdrive   msdos   rw,noauto       0       0

And voila! Now from here on out I can just mount /mnt/usbdrive and umount /mnt/usbdrive without issues. Notice that for the USB drive, I set FStype to msdos, Options to rw (read and write) and noauto (do not automatically attempt to mount the volume at boot time - the media won't always be present!), and set dump and pass to 0 each, to tell the system also not to try to automatically fsck the USB drive at boot time either.

One final note: don't forget to umount the USB drive before you disconnect it - you could lose data or even leave the filesystem itself with some problems if you just yank the drive out and it turns out that there were still cached writes pending that you didn't know about.

Personal tools