Reading Non Linux Filesystems in Linux

Typically, any partition you want to access on a regular basis has an entry in /etc/fstab. Listing 10.3 shows a typical /etc/fstab file, including definitions for some non-Linux partitions. Each of this file's lines corresponds to a single partition. Each line has six fields, separated by spaces or tabs: the device identifier, the mount point, the filesystem, the filesystem options, the dump order, and the filesystem check order. Foreign filesystems have 0 entered for the final two fields, meaning that they're never backed up with the dump utility and aren't checked with fsck at boot time, respectively. The device field is typically a Linux device filename, but as Listing 10.3 shows, you can use a filesystem's volume name, preceded by LABEL=, for some filesystem types. Some distributions, such as Red Hat, use this form by default for Linux native filesystems. It has the advantage of surviving some types of partition table changes should you add or delete partitions in the future, but it may break if you reformat the partition in question—say, to change from ext2fs to ReiserFS.

Listing 10.3: A Sample /etc/fstab File

LABEL=/ / ext3 defaults 1 1

/dev/hda9 /home reiserfs defaults 0 0

/dev/hdb5 /other/shared vfat uid=500,umask=0 0 0

/dev/hda3 /other/w2k-boot ntfs uid=500,umask=0,noauto,user,ro 0 0

/dev/hda8 /other/os2-data hpfs uid=500,umask=0,noauto,user 0 0

/dev/hdb4 /other/freebsd ufs noauto,user,ufstype=44bsd 0 0 /dev/fdO /mnt/floppy auto defaults,user,noauto 0 0

The most interesting fields for configuring foreign filesystems are the filesystem type field and the filesystem options field. The filesystem type field contains the filesystem type code. Listing 10.3 demonstrates several of these codes, which are typically named after the filesystem in question, such as vfat for VFAT partitions. The auto filesystem type code is used mainly for removable media; it tells the kernel to try to auto-detect the filesystem type. This option is seldom used on hard disk partitions, which rarely change filesystem type.

The filesystem options field is a comma-separated list of filesystem options. Some options apply to most or all filesystems, but others are filesystem-specific. Table 10.1 summarizes the most popular filesystem options. Consult the mount man page or the documentation for a specific filesystem for more options. (The documentation for most filesystems is stored in the /usr/src/linux/Documentation/filesystems directory.)

Table 10.1: Common Filesystem Options

Option

Supported Filesystems

Description

defaults

All

Uses the default options for this filesystem. It's used primarily to ensure that there's an options field in the /etc/fstab file.

loop

All

Uses the loopback device for this mount. Allows you to mount a file as if it were a disk partition. For instance, typing mount -t vfat -o loop image.img /mnt/image mounts the file image.img as if it were a disk.

auto ornoauto

All

Mounts or does not mount the filesystem at boot time, or when root types mount -a. The default is auto, butnoauto is appropriate for removable media.

user ornouser

All

Allows or disallows ordinary users to mount the filesystem. Default is nouser, but user is often appropriate for removable media. Allows users to type mount Imountpoint, where /mountpoint is the assigned mount point, to mount a disk.

users ornousers

All

Much like user and nouser, but changes the rules for unmounting a filesystem. When user is specified, only root or the user who mounted a filesystem may unmount it.

Option

Supported Filesystems

Description

When users is specified, any user may unmount a filesystem.

ro

All

Specifies a read-only mount of the filesystem. This is the default for filesystems that include no write access, and for some with particularly unreliable write support, such as NTFS.

rw

All read/write filesystems

Specifies a read/write mount of the filesystem. This is the default for most read/write filesystems.

uid=va/ue

Most filesystems that don't support Unix-style permissions, such as vfat, hpfs, ntfs, and hfs

Sets the owner of all files. For instance, uid=500 sets the owner to whoever has Linux user ID 500. (Check Linux user IDs in the /etc/passwd file.)

gid=va/ue

Most filesystems that don't support Unix-style permissions, such as vfat, hpfs, ntfs, and hfs

Works like uid=va/ue, but sets the group of all files on the filesystem. You can find group IDs in the /etc/group file.

con v=coc/e

Most filesystems used on Microsoft and Apple OSs: msdos, umsdos, vfat, hpfs, hfs

If code is b or binary, Linux doesn't modify the files' contents. If code is t or text, Linux auto-converts files between Linux-style and DOS-style or Macintosh-style end-of-line characters. If code is a or auto, Linux applies the conversion unless the file is a known binary file format. It's

Option

Supported Filesystems

Description usually best to leave this at its default value of binary, because file conversions can cause serious problems for some applications and file types.

case=code

hpfs, hfs

When code is lower, Linux converts filenames to all-lowercase; when code is asis, Linux leaves filenames as they are. The default in recent kernels is asis.

Of course, in order to read any filesystem in Linux, the kernel needs to have the filesystem driver available. The driver can be compiled into the kernel proper or as a module. Most distributions ship with most or all common filesystems available, but there are exceptions and limitations. NTFS is usually compiled to provide read-only access; if you want to risk read/write access, you must recompile it. Red Hat ships with no NTFS support at all. UMSDOS support is often omitted, although two other FAT drivers (msdos, for support with 8.3 filenames; and vfat, for support with VFAT long filenames) are usually available. If you recompile your kernel, as described in Chapter 15, "Creating a Custom Kernel," you must ensure that you compile in support for the filesystems you need.

0 0

Post a comment