Опубликован: 06.08.2012 | Уровень: специалист | Доступ: платный
Лекция 10:

File systems and devices

< Лекция 9 || Лекция 10: 1234 || Лекция 11 >

File system types

FreeBSD supports a number of file system types. The most important are:

  • UFS is the UNIX File System1Paradoxically, although BSD may not be called UNIX, its file system is called the UNIX File System. The UNIX System Group, the developers of UNIX System V.4, adopted UFS as the standard file system for System V and gav e it this name. Previously it was called the Berkeley Fast File System, or ffs. All native disk file systems are of this type. Since FreeBSD 5.0, you have a choice of two different versions, UFS 1 and UFS2. As the names suggest, UFS 2 is a successor to UFS 1. Unlike UFS 1, UFS 2 file systems are not limited to 1 TB (1024 GB) in size. UFS 2 is relatively new, so unless you require very large file systems, you should stick to UFS 1.
  • cd9660 is the ISO 9660 CD-ROM format with the so-called Rock Ridge Extensions that enable UNIX-like file names to be used. Use this file system type for all CD-ROMs, even if they don't have the Rock Ridge Extensions.
  • nfs is the Network File System a means of sharing file systems across a network. We'll look at it in "Chapter 25" .
  • FreeBSD supports a number of file systems from other popular operating systems. You mount the file systems with the mount command and the -t option to specify the file system type. For example:
    # mount -t ext2fs /dev/dalsl /linux    mount a Linux ext2 file system
    # mount -t msdos /dev/da2s1 /C:        mount a Microsoft FAT file system
    

    Here’s a list of currently supported file systems:

Таблица 10.3. File system support
File system mount option
CD-ROM cd9660
DVD udf
Linux ext2 ext2fs
Microsoft MS-DOS msdosfs
Microsoft NT ntfs
Novell Netware nwfs
Microsoft CIFS smbfs

Soft updates

Soft updates change the way the file system performs I/O. They enable metadata to be written less frequently. This can give rise to dramatic performance improvements under certain circumstances, such as file deletion. Specify soft updates with the –U option when creating the file system. For example:

# newfs -U /dev/da1s2h

If you forget this fag, you can enable them later with tunefs :

# tunefs -n enable /dev/da1s2h

You can't perform this operation on a mounted file system.

Snapshots

One of the problems with backing up file systems is that you don't get a consistent view of the file system: while you copy a file, other programs may be modifying it, so what you get on the tape is not an accurate view of the file at any time. Snapshots are a method to create a unified view of a file system. They maintain a relatively small file in the file system itself containing information on what has changed since the snapshot was taken. When you access the snapshot, you get this data rather than the current data for the parts of the disk which have changed, so you get a view of the file system as it was at the time of the snapshot.

Creating snapshots

You create snapshots with the mount command and the -o snapshot option. For example, you could enter

# mount -u -o snapshot /var/snapshot/snapl /var

This command creates a snapshot of the /var file system called /var/snapshot/snapl. Snapshot files have some interesting properties:

  • You can have multiple snapshots on a file system, up to the current limit of 20.
  • Snapshots have the schg fag set, which prevents anybody writing to them.
  • Despite the schg fag, you can still remove them.
  • They are automatically updated when anything is written to the file system. The view of the file system doesn't change , but this update is necessary in order to maintain the "old" view of the file system.
  • They look like normal file systems. You can mount them with the md driver. We'll look at that on page 193.

Probably the most useful thing you can do with a snapshot is to take a backup of it. We'll look at backups on page 253.

At the time of writing, snapshots are still under development. It's possible that you might still have trouble with them, in particular with deadlocks that can only be cleared by rebooting.

It takes about 30 seconds to create a snapshot of an 8 GB file system. During the last five seconds, file system activity is suspended. If there's a lot of soft update activity going on in the file system (for example, when deleting a lot of files), this suspension time can become much longer, up to several minutes. To remove the same snapshot takes about two minutes, but it doesn't suspend file system activity at all.

Mounting file systems

Microsoft platforms identify partitions by letters that are assigned at boot time. There is no obvious relation between the partitions, and you have little control over the way the system assigns them. By contrast, all UNIX partitions have a specific relation to the root file system, which is called simply /.This flexibility has one problem: you have the choice of where in the overall file system structure you put your individual file systems. You specify the location with the mount command. For example, you would typically mount a CD-ROM in the directory /cdrom, but if you have three CD-ROM drives attached to your SCSI controller, you might prefer to mount them in the directories /cd0, /cd1, and /cd2. To mount a file system, you need to specify the device to be mounted, where it is to be mounted, and the type of file system (unless it is ufs). The mount point (the directory where it is to be mounted) must already exist. To mount your second CD-ROM on /cd1, you enter:

# mkdir /cdl                    only if it doesn't exist
# mount -t cd9660 -o ro /dev/cdla /cdl

When the system boots, it calls the startup script /etc/rc, which among other things automatically mounts the file systems. All you need to do is to supply the information: what is to be mounted, and where? This is in the file /etc/fstab. If you come from a System V environment, you'll notice significant difference in format—see the man page fstab(5), for the full story. A typical /etc/fstab might look like:

/dev/ad0s1a           /                   ufs        rw         1 1  root file system
/dev/ad0s1b           none                swap       sw         0 0  swap
/dev/ad0s1e           /usr                ufs        rw         2 2  /usr file system
/dev/dalsle           /src                ufs        rw         2 2  additional file system
/dev/da2s1            /linux              ext2fs     rw         2 2  Linux file system
/dev/adlsl            /C:                 msdos      rw         2 2  Microsoft file system
proc                  /proc               procfs     rw         0 0  proc pseudo-file system
linproc               /compat/linux/proc  linprocfs  rw         0 0  
/dev/cd0a             /cdrom              cd9660     ro         0 0  CD-ROM
presto:/              /presto/root        nfs        rw         0 0  NFS file systems on other systems
presto:/usr           /presto/usr         nfs        rw         0 0  
presto:/home          /presto/home        nfs        rw         0 0  
presto:/S             /S                  nfs        rw         0 0  
//guestasamba/public  /smb                smbfs      rw,noauto  0 0  SMB file system

The format of the file is reasonably straight forward:

  • The first column gives the name of the device (if it's a real file system), a keyword for some file systems, like proc or the name of the remote file system for NFS mounts.
  • The second column specifies the mount point. Swap partitions don't have amount point, so the mount point for the swap partition is specified as none.
  • The third column specifies the type of file system. Local file systems on hard disk are always ufs and file systems on CD-ROM are cd9660. Remote file systems are always nfs. Specify swap partitions with swap, and the proc file system with proc
  • The fourth column contains rw for file systems that can be read or written, ro for file systems (like CD-ROM) that can only be read, and sw for swap partitions. It can also contain options like the noauto in the bottom line, which tells the system startup scripts to ignore the line. It's there so that you can use the shorthand notation mount /smb when you want to mount the file system.
  • The fifth and sixth columns are used by the dump and fsck programs. You won't normally need to change them. Enter 1 for a root file system, 2 for other UFS file systems, and 0 for everything else.
Mounting files as file systems

So far, our files have all been on devices, also called special files. Sometimes, though, you may want to access the contents of a file as a file system:

  • It's sometimes of interest to access the contents of a snapshot, for example to check the contents.
  • After creating an ISO image to burn on CD-R, you should check that it's valid.
  • Also, after downloading an ISO image from the Net, you may just want to access the contents, and not create a CD-R at all.

In each case, the solution is the same: you mount the files as a vnode device with the md driver.

The md driver creates a number of different kinds of pseudo-device. See the man page md(4).. We use the vnode device, a special file that refers to file system files. Support for md is included in the GENERIC kernel, but if you've built a kernel without the md drive, you can load it as a kld. If you're not sure, try loading the kld anyway.

In the following example, we associate a vnode device with the ISO image iso-image using the program mdconfig:

# kldload md                          load the kld module if necessary
kldload: can't load md: File exists   already loaded or in the kernel
# mdconfig -a -t vnode -f iso -image  and configure the device
md0                                   this is the name assigned in directory /dev
# mount -t cd9660 /dev/md0 /mnt       then mount it

After this, you can access the image at /mnt as a normal file system. You specify -t cd9660 in this case because the file system on the image is a CD9660 file system. You don't specify this if you're mounting a UFS file system, for example a snapshot image.

Older versions of FreeBSD used the vn driver, which used different syntax. Linux uses loop mounts, which FreeBSD doesn't support.

< Лекция 9 || Лекция 10: 1234 || Лекция 11 >
Бехзод Сайфуллаев
Бехзод Сайфуллаев
Узбекистан, Бухара, Бухарский институт высоких технологий, 2013
Василь Остапенко
Василь Остапенко
Россия