The Iriver IHP and Mounting the Smart Way

Having access to all of your hard disks and removable storage media is incredibly useful for transfering and storing files between your operating systems and other computers. In this section we'll discuss the good way to mount devices, and how to set up FreeBSD for usage with the Iriver IHP (or any mp3 players that work as removeable hard drives).

Mounting Filesystems
The Iriver IHP
Mounting with Users

Mounting Filesystems (The Smart Way)

If you're running multiple Operating Systems, or have multiple hard drives, you proably want to give FreeBSD access to them. I have a Fat 32 partition that I use to store files for both Windows and FreeBSD on. It's definately something I want to mount automatically at startup. First I need to create a mountpoint. As root:

mkdir /fat
chown xaenn /fat
vi /etc/fstab

Replace /fat with whatever you want your mountpoint to be. In that second line I change the ownership /fat to xaenn. That way he can read and write to that directory. You could also give read/write permissions to everyone, but I don't recommend that. /etc/fstab is a file which holds entries for all filesystems we want to either mount at startup, or want to be able to mount quickly. Don't mess with the top lines, or you could screw up your system. At the bottom add this line:

/dev/ad1s2 /fat msdos rw 0 0

Don't add that line verbatim! Unless you coincidentaly have the same partitioning scheme as me. The file kind of lays it out for you, but I'll explain it better. The first line is the device, be it a hard disk, floppy drive, or mp3 player. In our case it's a hard drive (or more correctly a partition). Second is the mountpoint, which is where you will access the files from. Next is the File System type, which is in our case Fat 32, which is referred to as msdos by FreeBSD (as are Fat 16 and 8 for that matter). Fourth are options, which can be pretty important in some cases. In our case, we use only rw, which means it should be read and written to. In the case of a cdrom, it would be ro (read only). Finally dump and pass we will leave at 0; they have to do with filesystem checks at startup. Now type this line:

mount /fat
cd /fat
ls

If all went well you should be browsing your newly mounted partition! Take note that you will no longer have to manually mount it, as FreeBSD will do it automatically at startup.

The Iriver IHP

In my opinion, the Iriver IHP is the one of the best mp3 players on the market right now (much better than the IPOD). And fortunately for us FreeBSD users Iriver doesn't tie us down to any proprietary software in order to upload/download music to it (technically you need Windows for setting up the database, but I wasn't impressed with the database functions anyway). First plug in the Iriver and turn it on (you don't need a guide for this, right?). Be sure you are su'ed to root. We have to mount stuff as root for now, but that's something we can change.

mkdir /mp3
chown xaenn /mp3
vi /etc/fstab

Replace /mp3 with whatever you want your mountpoint to be. In that second line I change the ownership /mp3 to xaenn. Now add the following line in /etc/fstab:

/dev/da0s1 /mp3 msdos rw,noauto 0 0

There are two noteworthy things here. /dev/da0s1 is the first usb hard drive, and the noauto tells FreeBSD not to mount it at startup, as our mp3 player won't necessarily be plugged in at that time. Now to mount our mp3 player just type:

mount /mp3

Do note that if you hadn't set it up in fstab then you could mount it by defining the options explicitly as follows:

mount /dev/ad0s1 -t msdos /mp3

I'm sure you can see how fstab is useful for filesystems you don't mount at startup. Be careful though. DON'T unplug your mp3 player without unmounting it first. FreeBSD will get very angry with you. Bad things will happen, and you will have no one to blame but yourself when they do. However, all you have to do is type:

umount /mp3

This is regardless of how you mounted it, explictly or through fstab. A word of caution though, you cannot unmount your mp3 player if you are browsing its files or using it in anyway (such as listening to music with BMP).

Mounting With Users

Allowing our user to mount is good for people lazy like me, who don't want to su everytime they want to mount something. It's taken me a long time to figure it out, but now here's the method to do it:

vi /etc/sysctl.conf

Now add this single line:

vfs.usermount=1

This will automatically take effect when you restart, but to enable it right now, run the following command:

sysctl vfs.usermount=1

Now let's make ourselves some mountpoints for our filesystems:

mkdir /dvd /cdrw /mp3
chown xaenn /dvd /cdrw /mp3

Make whatever directories you want, appropriately for your filesystems. You need to own a directory in order to mount to it. So you can put those wherever you want. If you're running a multiple user system, it'd probably be better to put them in their user's home directories. Now we need to configure devfs. It is the new system in FreeBSD for managing your devices. Because it does so dynamically, we can't just chown/chmod the dev entries, but need to set it up in devfs' config files:

vi /etc/devfs.conf

This file contains information for devices that will always exist when you boot your system, such as cdrom drives. You can set the permissions, owner and a few other things. Here is an excerpt from my config, which will allow users in the group operator to mount both cdroms and the floppy drive.

own acd0 root:operator
perm acd0 0664
own acd1 root:operator
perm acd1 0664
own fd0 root:operator
perm fd0 0664

That's pretty straight forward, so if you need to add any other devices, just follow that same syntax. However, we also want to configure for our iriver, so we need to modify /etc/devfs.rules with the following:

[login=100]
add path 'da0s1' group operator mode 664

Now whenever you plug in the iriver it will have those permissions. Do the same for other devices you might have (USB keys should be the same, just add da0s2 if you have multiple ones). Now there is just one last step, we need to add one line to /etc/rc.conf to tell it to use this ruleset.

devfs_system_ruleset="login"

Let's issue one command in order to restart devfs with our new settings

/etc/rc.d/devfs restart

Now your user just needs to be in the group operator in order to mount the devices. If your user is not already in the group:

pw groupmod operator -m xaenn

As always, replace xaenn with your user. You will need to reboot before the usermount will take place. When you reboot, you should be able to happily mount away!