Dec. 1, 2009, 1:28 p.m.
posted by void
Mount Any Filesystem
Tweak /etc/fstab to control which filesystems are mounted at boot. By default, Ubuntu will automatically detect and configure mount points for any partitions it finds when Ubuntu is installed. However, if you add a new disk to the system, or you want to automatically mount an NFS or SMB share at boot time, you must resort to the tried-and-true Linux method: editing /etc/fstab. The /etc/fstab file (short for filesystem table) keeps track of filesystems that you want to mount in static locations. Here is a standard Ubuntu fstab file, which provides a good example for what each field in the file stands for: # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 /dev/hda1 / ext3 defaults,errors=remount-ro 0 1 /dev/hda5 none swap sw 0 0 /dev/hdc /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/fd0 /media/floppy0 auto rw,user,noauto 0 0 Here you see a list of partitions Ubuntu will mount, where it will mount them, what type of filesystem they use, any special options that might need to be passed to the filesystem, whether the partitions should be included in partitions the dump utility backs up, and what order filesystems are checked at reboot time. It's a lot of information, to be sure, but when you want to add a new filesystem to the mix, there are only a few fields that are crucial. Add a Local PartitionOne of the simpler partitions to add to the fstab file is a local partition. Suppose, for instance, that we added a second IDE hard drive to the system (hdb), and it had a Windows FAT32 partition as the first partition (/dev/hdb1) and a Linux EXT3 partition as its second partition (/dev/hdb2). First, we need to create a place these filesystems will mount, so we create two new directories under /mnt called windows1 and linux1: $ sudo mkdir /mnt/windows1 /mnt/linux1
Now we can add two lines to our /etc/fstab file, one for each of the new partitions: /dev/hdb1 /mnt/windows1 vfat defaults 0 0 /dev/hdb2 /mnt/linux1 ext3 defaults 0 2 Notice the differences between these two lines. Besides the fact that the first column in each line lists a different partition and the second column has a different mount point, notice that in the third column we specified vfat for the filesystem type for the Windows partition and ext3 for Linux. The value that goes here varies depending on what type of partition you are mounting. Figure displays some of the common partition types and what value to put in /etc/fstab.
In the fourth column, both fields list defaults, which mounts the filesystem with default settings. Different filesystems support different mount options, such as whether to mount the filesystem as read-only or read/write, the sorts of ownership that files in a partition might have, and so forth. We can get more information about special options that a filesystem supports from the mount manpage: $ man 8 mount
In the fifth column, we left the values at 0 because we are not planning on using the dump utility to back up these partitions. This is a safe value for most partitions you might want to mount. In the final column, notice we set the Windows partition to 0 and the Linux partition to 2. We did so because we don't want Linux to automatically run fsck on our Windows partition, yet we do want the Linux partition to be among the drives that are checked. We set the Linux partition's value to 2, because the standard is to set the root filesystem (/) to 1 so that it is checked first, then set all other Linux filesystems to 2. Mount the FilesystemsNow that these two filesystems are configured, we can use the mount command to mount them: $ sudo mount /mnt/windows1
$ sudo mount /mnt/linux1
While we could have used the mount command to mount these filesystems manually, without bothering to add any entries to fstab, when we set up the filesystems in fstab, we don't have to list a lot of optionsjust the device or mount point we want to mount. After mounting our devices, we can type either mount or df to see all of our mounted filesystems. Mount Network FilesystemsNetwork filesystems use slightly different syntax than ordinary partitions, so they get a separate section here. Specifically, the syntax you use to describe the filesystem (the first column) is different. For this example, we have an NFS share on host file1 at /mnt/shares, and a SMB file share on host file2 called data. We want to mount the NFS share at /mnt/share1 and the SMB share at /mnt/data1. To mount both of these partitions at boot time, we would add the following lines to our /etc/fstab: file1:/mnt/shares /mnt/share1 nfs defaults 0 0 //file2/data /mnt/data1 smb defaults 0 0 Notice the difference in syntax. NFS shares follow the hostname:/path/to/share syntax, while SMB shares follow the //hostname/share syntax. Other than that, the remaining fields are similar to the first examples, and we could pass special NFS or SMB options in the options field if we needed to.
To mount these shares, we would make sure that the /mnt/share1 and /mnt/data1 directories existed, and then we would type: $ sudo mount /mnt/share1
$ sudo mount /mnt/data1
As with local partitions, we can use the mount or df commands to check the status of these mount points. For more information on the syntax for the /etc/fstab file, and what sorts of mount options you can use for particular filesystems as well as what filesystems Linux can mount, see the fstab(5) and mount(8) manpages, respectively. |
- Comment
