Henry Griggs Rambling
Recent TopicsVisit to Australia 2002
Sydney house 2002
Circular Quay 2004
Circular Quay 2002
Centrepoint Tower 2004
Oz Birds 2004
Oz Birds 2002
Bridge Climb 2002
Popular TopicsGallbladder removal
Photo of the day
Geek Alaska 2003
UK in 2003
Geek Caribbean 2002
Photo Of The Day
mount and /etc/fstab
23rd April 2003
I've been meaning to make some notes about mount and /etc/fstab, and I've just made a lot of changes to my system and while it's still fresh in my mind, I'll try and get it all written down.
The mount program will mount a filesystem. That means it will attach a filesystem on some device to a mount point, so the filesystem is accessible. So you can use it.
The man page for mount is very good. It's got clear descriptions of what mount does, and why, and it's got examples. It's almost a tutorial. Man pages are getting better, despite the regular moaning about them that you hear. So do 'man mount' and read it for the fine details. I'm only going to cover my basic usage here.
Before you can mount a filesystem, you have to have somewhere to mount it. You need a mount point. This is a directory, empty or not. Once upon a time, Slackware would supply just /mnt, and expect you to only mount temporary filesystems on that mount point. Slackware has gone with the flow and now provides a series of mount points under /mnt. At installation time, Slackware will set up /mnt/cdrom and /mnt/floppy for you. And if you have DOS or VFAT filesystems for DOS or Windows, you can set them up there too. I usually get it to create /mnt/dosc. After that, it's up to me. I create a few other mount points for the devices I have, like /mnt/camera, /mnt/dvd, /mnt/burner, /mnt/mp3 (for my NFS mp3 system), and /mnt/temp for temporary mounts.
If you mount a filesystem onto a directory that is not empty, then the original contents of that directory are no longer available to you. They disappear and are replaced by the newly mounted filesystem. When you umount, the new filesystem disappears and the original contents reappear. I don't like doing this. I prefer to have temporary mounts set up in /mnt that are always empty and are only used for mounting purposes.
A simple mount
When I want to mount a filesystem, there are three bits of information I have to supply. I have to specify the device that I want to mount, the type of file system it's supposed to have, and where I want to mount it (the mount point). Example:
mount -t ext3 /dev/hdb5 /mnt/temp
Note that to do this sort of thing, I need to be root. If I want to do regular mounting but not as mount, then I need to set up /etc/fstab. I'll describe that later.
In the above example, I am telling mount to find an ext3 filesystem on the first extended partition on my second hard disk (/dev/hdb5) and mount it under /mnt/temp. If mount can find /dev/hdb5, and it contains a valid ext3 filesystem, and the mount point /mnt/temp exists, then mount will mount the filesystem to the mount point. Then I can 'cd /mnt/temp' and explore the file system.
Of course, if any of those conditions are not met (no device, incorrect file system, mount point not found) then I'll get an error. Like these:
mount: /dev/sr12: unknown device mount: wrong fs type, bad option, bad superblock on /dev/sr0, or too many mounted file systems mount: mount point /mnt/dvd does not exist
When I'm finished, I have to get out of the file system, and then I can
If I am still in the file system, or I have another xterm running and in it I have changed directory to within the filesystem under /mnt/temp, or somebody else has telnetted in and changed directory to within that filesystem, then umount will not unmount the file system. It will inform me that the device is busy.
umount: /mnt/temp: device is busy
It's up to you to find where you have changed directory into that filesystem, get out of it, and then you can umount again.
File system types
There are a whole range of types of filesystems that you can supply. To see what's currently supported, do 'man mount' and look down at the -t options. The most common ones you will use will be:
There are others, but they are more specialised. If you need to use them, then you will know what you're doing. Not all of these will be available to you. You have to have support for them compiled into the kernel, or available as modules. To see what is available, go to /usr/src/linux and do 'make menuconfig'. Scroll down to "File Systems" and have a look at the options there. Choose what you need, compile your kernel and/or modules, then install the new kernel and/or modules. If you chose to add them as modules, then just use modprobe to load them in. Otherwise, run lilo, and then reboot.
auto and the default file system type
You can omit the file system type option. Or you could specify a file system type of auto. If you do either of these two things, then the superblock of the device is probed for the file system type. Only a limited number of file systems are tested. Use 'man mount' for the full list.
If this fails, then mount will try and read /etc/filesystems and then probe for all the filesystems listed in that file. Slackware doesn't come with that file installed, so that test will fail. Mount then tries for /proc/filesystems and try and probe for all the filesystems listed in that file, that are not preceded by nodev.
Auto is best used for removable media devices, like floppy disks and cdrom drives. However, it takes time to probe for a few file system types,so I rarely do this. I try and specify the type always.
Here are some examples from my systems.
This is a fairly simple mount. I mount the ext3 filesystem on /dev/hdb5 (first extended partition of second hard disk) to /usr/local.
mount -t ext3 /dev/hdb5 /usr/local
This mounts a CD in my CDROM burner, already set up with SCSI emulation, to /mnt/burner.
mount -t is9660 /dev/sr1 /mnt/burner
This mounts one of my NFS mp3 server drives, so I can access it as a local filesystem.
mount -t nfs mp3server:/music1 /mnt/mp3
Mount does have options. These are keywords supplied with -o. You can use a number of options, comma separated after the -o. These usually specify how you want the filesystem mounted. The ones I generally use are for the Windows filesystems like msdos or vfat. I specify how I want the filesystem mounted so I can easily use it. I set the user id to my user id, the group id to my group id, and the umask to 022 so I can read any, write to and delete files in the filesystem. Example:
mount -t vfat -o uid=1000,gid=100,umask=022 /dev/hda1 /mnt/dosc
One other option I use occasionally is 'loop'. If I have created an ISO image and I want to check it before burning it to a cd, I can mount that ISO image and then just move around inside it. To do that, I have to specify the '-o loop' option. There are other things you can do with loop, but you should read the man page for the fine details. I generally just do this.
mount -t iso9660 -o loop cdimage.iso /mnt/temp
Being able to mount filesystems manually is all well and good. But I want to mount a whole bunch of filesystems at boot up time. To do that, I set up /etc/fstab with a descriptions of all my filesystems that are to be automounted.
/etc/fstab has a simple format. One filesystem per line, 6 columns per line, separated by white space. The first four columns are the same information you type in when using mount manually.
The last two columns contain two numbers.
Some special file system types can be included in /etc/fstab. The three most common ones are the swap partitions, the /proc pseudo device, and the /dev/pts pseudo terminal directory. These will be set up for you ate installation time, and you shouldn't need to fiddle with them.
Here is my fstab set up for the systems that I want loaded at boot time.
/dev/hdb2 swap swap defaults 0 0 /dev/hdb1 / ext3 defaults 1 1 /dev/hdb3 /usr ext3 defaults 1 2 /dev/hdb5 /usr/local ext3 defaults 1 2 /dev/hdb6 /opt ext3 defaults 1 2 /dev/hdb7 /home ext3 defaults 1 2 /dev/hdb8 /data ext3 defaults 1 2 /dev/hda1 /mnt/dosc vfat defaults,uid=1000,gid=100,umask=022 1 0 /dev/hda5 /mnt/dosd vfat defaults,uid=1000,gid=100,umask=022 1 0 devpts /dev/pts devpts gid=5,mode=620 0 0 proc /proc proc defaults 0 0 mp3:/mnt/mp40 /mnt/music1 nfs defaults 0 0 mp3:/mnt/mp80 /mnt/music2 nfs defaults 0 0
/etc/fstab can help you with your regularly mounted removable media. It can save you a lot of typing and remembering. I always set up my removable media in /etc/fstab. For example, I can declare my cdrom in /etc/fstab like this:
/dev/sr0 /mnt/cdrom iso9660 noauto,users,ro 0 0
With the filesystem type and the device and the mount point all pre-declared, this can simplify my mounting. Without this entry in /etc/fstab, I have to mount it manually like this:
mount -t iso9660 /dev/sr0 /mnt/cdrom
But with the entry in /etc/fstab, all I need to do is type:
The rest of the details are pulled from /etc/fstab. Saves me typing it.
Note the options I specified in /etc/fstab.
I used to omit the users keyword. But then I had to be root to mount the device. So I changed it to user. Any user could mount the device, but only the same user could umount it. I eventually ended up with users, so any user could mount it, and any user could umount it. More flexible that way.
Here's my removable devices that I keep in /etc/fstab:
/dev/sr0 /mnt/dvd udf noauto,users,ro 0 0 /dev/sr0 /mnt/cdrom iso9660 noauto,users,ro 0 0 /dev/sr1 /mnt/burner iso9660 noauto,users,ro 0 0 /dev/sda1 /mnt/camera vfat noauto,users 0 0 /dev/fd0 /mnt/floppy auto noauto,users 0 0
Only the read-only devices get the option ro. All of them get the option users. And the fifth and sixth columns are 0, because they don't get dumped and fsck doesn't check them at reboot time. Note that I have the same device, /dev/sr0, in there twice. I can mount it with file type udf under /mnt/dvd, or I can mount it with file type iso9660 under /mnt/cdrom. I just specify "mount /mnt/cdrom" or "mount /mnt/dvd" and it gets the right filesystem type.
If I have an entry in /etc/fstab for a specific mount point, and I try and mount a different device to that mount point, or mount the same device but with a different file system, then I will get an error:
mount: only root can do that
If I want to do something different to what's in /etc/fstab, then I need to be root. I can either use sudo, or su, or login as root, and then mount will let me do it.
mount can work on its own without /etc/fstab, but the two work best together. A fairly basic /etc/fstab will be set up for you at installation, but a little bit of effort spent customising it will bring you a lot of benefits.
Read the man page for the fine details.