Mounting and Unmounting Filesystems from Other Operating Systems


The techniques you've just learned are all well and good for standard FreeBSD filesystems. But what if you need to mount a disk from a Linux box or from a Windows 98 or XP machine? You can do that. FreeBSD supports the filesystems listed in Table 12.2 in the GENERIC (default) kernel.

Table 12.2. Filesystems Supported in the GENERIC Kernel

Filesystem

Name

FFS

Berkeley Fast Filesystem

MFS

Memory Filesystem

NFS

Network Filesystem

MSDOSFS

MS-DOS Filesystem

CD9660

ISO 9660 (CD-ROM) Filesystem

PROCFS

Process Filesystem


There is also support for the filesystems shown in Table 12.3, but they need to be compiled into a custom kernel in order to work (see "Compiling and Installing the Custom Kernel," in Chapter 18).

Table 12.3. Additional Available Filesystems

Filesystem

Name

FDESC

File Descriptor Filesystem

HPFS

OS/2 Filesystem

NTFS

Windows NT Filesystem

NULLFS

NULL Filesystem

NWFS

NetWare Filesystem

PORTAL

Portal Filesystem

SMBFS

SMB/CIFS Filesystem (Windows)

UMAPFS

UID Map Filesystem

UNION

Union Filesystem

CODA

CODA Filesystem

EXT2FS

Ext2 Filesystem (Linux); also includes Ext3FS

REISERFS

ReiserFS Filesystem (Linux)


Some of these latter filesystems are more stable than others, and some lack critical features (for instance, some of these filesystems can only be mounted read-only; you can't write new data to them). As you saw earlier, union filesystems are available as an option, but they are only partially in a working state (and can damage your system). Therefore, it is not recommended that you use them unless absolutely necessary. EXT2FS and NTFS support is also given a caveat about completeness and stability. Filesystems that are not built in to the GENERIC kernel, in general, are not included for a reason.

The ideal circumstance for a filesystem type that isn't part of the existing kernel is to be available as a kernel module in /boot/kernel, as many of the filesystems listed in the preceding tables are. If the filesystem is available as a kernel module, it will be automatically loaded when you try to mount the filesystem. At the time of this writing, these available module-driven filesystems include Ext2FS, ReiserFS, FDESC, CODA, PORTAL, NWFS, NULL, NTFS, UNION, SMBFS, and some others that are already compiled into the GENERIC kernel and are provided in /boot/kernel for compatibility.

If you're mounting a filesystem (MSDOSFS, for example) that is supported in the default kernel, or if you decide to accept the risks and plunge ahead with mounting a filesystem that isn't initially built in, you'll find that FreeBSD does provide some handy tools for doing the actual mounting. The following tools are available in /sbin (although their names may vary according to your version of FreeBSD):

mount_cd9660     mount_linprocfs   mount_nfs4       mount_portalfs    mount_std mount_devfs      mount_mfs         mount_ntfs       mount_procfs      mount_udf mount_ext2fs     mount_msdosfs     mount_nullfs     mount_reiserfs    mount_umapfs mount_fdescfs    mount_nfs         mount_nwfs       mount_smbfs       mount_unionfs


Each of these variations on mount corresponds to one of the supported filesystems and operates in the same way as mount. The idea is that these mount_* tools serve as an extension to the -t option to mount. The -t option recognizes only a couple internal filesystem types; if you give it an unrecognized argument, it will execute the corresponding self-contained command from the preceding list. For example, if you use mount -t nfs /mnt, the tool will actually execute mount_nfs /mnt. Knowing this, it is often easier simply to run the latter tool directly.

Note

As a further note on the stability and completeness issues regarding the not fully supported filesystem types, you should read the man mount_* pages. Each one gives a good account of what is deficient in that filesystem's support. For example, man mount_ntfs discusses the lack of full write capabilities and support for compressed files, and man mount_union warns about the feature's limited functionality and potential to damage data. Be informed!


Mounting a Windows/MS-DOS Filesystem

Let's first look at mounting a Windows 98 disk, which will be MSDOSFS for FreeBSD's purposes. The command you use for this operation is mount_msdos. This command can take some special options that we do not need to cover fully here. Examples are -W and -L, which control the locale-based character mapping for the long filenames associated with FAT32/VFAT filesystems. For this example, you can use the default settings, which assume that the ISO 8859-1 encoding will be used and that you will read and write to the filesystem as root:

# mount_msdosfs /dev/ad1s1 /mnt


Note

Bear in mind that what DOS and Linux systems call partitions are called slices in FreeBSD, to avoid confusing them with traditional BSD partitions (which are subdivisions of slices). The slice number is the s in the device name, thus s1 indicates the first slice, or MS-DOS partition. MS-DOS partitions don't contain any subpartitions, such as the BSD partitions a through g; therefore, because your Windows 98 filesystem on /dev/ad1s1 is effectively using a slice rather than a partition, you can address it simply by its slice number rather than specifying additional suffixes, as when mounting standard FreeBSD filesystems where you use /dev/ad1s1g.

You only get four MS-DOS partitions on a disk, but you can also use "extended DOS partitions," which are the MS-DOS and Linux way of doing subpartitions. If you're using an extended DOS partition, you may get an "Invalid argument" error. If this happens, note that extended DOS partitions are numbered beginning with 5, so your device name will be /dev/ad1s5.


You can perform additional tricks when mounting an MS-DOS filesystem, such as mounting it as a non-root UID/GID, mounting it with a permissions mask for controlling users' access to the filesystem's contents, listing it with long filenames (instead of short "8.3" filenames), and so forth. Refer to man mount_msdos for the full documentation on these options.

Tip

A Windows floppy disk contains filenames that can be in the standard MS-DOS "8.3" short format or in the Windows 95/98 long format, which is derived from metadata in the filesystem. If you mount a Windows floppy disk using mount_msdos, FreeBSD attempts to find any of these long filenames on the disk. If it finds any, it uses that format to list and interact with the files. However, if it finds none of these long filenames but does find short ones, it will use the short format. To force mount_msdos to use the long format, use the -l option. The -s option forces the use of the short format.


Mounting a Linux Filesystem

Most Linux systems use Ext2FS (or Ext3FS, which is also handled by FreeBSD's Ext2FS kernel module). Because EXT2FS support is not built into the GENERIC kernel, this task can involve an extra step.

If you have to mount a Linux disk for temporary work, such as copying files off it in a one-time operation, you can simply mount the disk using the mount_ext2fs command, which automatically loads the ext2fs.ko kernel module and adds temporary support for the Ext2FS filesystem to FreeBSD. This is very convenient, but it has the side effect of leaving the kernel module loaded after you're done with your work, and in general it's a little less safe to rely on loading a kernel module (which might destabilize the system or cause a crash) than to have Ext2FS support built into the kernel. If you intend to interoperate with Linux disks on a regular basis, you should build a custom kernel with Ext2FS support enabled.

Chapter 18 discusses the steps involved in compiling and installing a custom kernel; the line you want to add to your custom kernel configuration file (preferably at the end of the block of options lines) is the following:

options     EXT2FS


After your system is up and running with the new kernel, you can use the following command:

# mount_ext2fs /dev/ad1s1 /mnt


Other than the issues surrounding kernel support and automatically loading the kernel module when needed, mount_ext2fs behaves almost identically to standard mount, so the surprises should be minimal.

Using fdisk to Gather Partition Information

You can determine what filesystem you're working with by using the fdisk command. Here's an example:

# fdisk /dev/ad1 ******* Working on device /dev/ad1 ******* parameters extracted from in-core disklabel are: cylinders=1247 heads=255 sectors/track=63 (16065 blks/cyl) Figures below won't work with BIOS for partitions not in cyl 1 parameters to be used for BIOS calculations are: cylinders=1247 heads=255 sectors/track=63 (16065 blks/cyl) Media sector size is 512 Warning: BIOS sector numbering starts with sector 1 Information from DOS bootblock is: The data for partition 1 is: sysid 131,(Linux filesystem)     start 63, size 2104452 (1027 Meg), flag 0         beg: cyl 0/ sector 1/ head 1;         end: cyl 130/ sector 63/ head 254 The data for partition 2 is: sysid 130,(Linux swap or Solaris x86)     start 2104515, size 787185 (384 Meg), flag 0         beg: cyl 131/ sector 1/ head 0;         end: cyl 179/ sector 63/ head 254 The data for partition 3 is: sysid 131,(Linux filesystem)     start 2891700, size 17141355 (8369 Meg), flag 0         beg: cyl 180/ sector 1/ head 0;         end: cyl 1023/ sector 63/ head 254 The data for partition 4 is: <UNUSED>


For each partition (or slice, as FreeBSD has it), there's a "sysid" number. 131 corresponds to an EXT2FS Linux filesystem, and 165 is FreeBSD. Everything else fdisk recognizes can be found by perusing /usr/src/sbin/i386/fdisk/fdisk.c, where the partition IDs are given in hexadecimal values.





FreeBSD 6 Unleashed
FreeBSD 6 Unleashed
ISBN: 0672328755
EAN: 2147483647
Year: 2006
Pages: 355
Authors: Brian Tiemann

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net