Volume Management

Volume management (not to be confused with SVM described in Chapter 11), with the vold daemon, is the mechanism that manages removable media, such as the CD-ROM and floppy disk drives. I mentioned vold in Chapter 11, when I described USB devices. Mounting and unmounting a file system requires root privileges. How do you let users insert, mount, and unmount CD-ROMs and floppy disks without being the administrator (root)? After a file system has been mounted and you remove the medium, what happens to the mount? Usually when you disconnect a disk drive while it is mounted, the system begins displaying errors and messages. The same thing happens if you remove a floppy disk or CD-ROM while it is mounted.

Volume manager, with its vold daemon, provides assistance to overcome these problems. The vold daemon simplifies the use of disks and CDs by automatically mounting them.Volume manager provides three major benefits:

  • By automatically mounting floppy disks and CDs, volume management simplifies their use.

  • Volume manager enables the user to access floppy disks and CDs without having to be logged in as root.

  • Volume manager lets the administrator (root) give other systems on the network automatic access to any floppy disks and CDs that the users insert into your system.

To begin, let’s look at the two devices the system administrator needs to manage: the floppy disk drive and the CD-ROM.Volume manager provides access to both devices through the /vol/dev directory. In addition, volume manager creates links to the floppy disk, CD-ROM, and USB devices through various directories, as shown in Table 14.11.

Table 14.11. Volume Manager Directories and Links
Link Description
/vol/dev/diskette0 The directory providing block device access for the medium in floppy drive 0
/vol/dev/rdiskette0 The directory providing character device access for the medium in floppy drive 0
/vol/dev/aliases/floppy0 The symbolic link to the character device for the medium in floppy drive 0
/dev/rdiskette The directory providing character device access for the medium in the primary floppy drive, usually drive 0
/vol/dev/aliases/cdrom0 The directory providing character device access for the medium in the primary CD-ROM drive
/vol/dev/dsk/ The directory providing access to the CD-ROM buffered, or block, device
/vol/dev/rdsk/ The directory providing access to the CD-ROM character, or raw, device
/cdrom/cdrom0 The symbolic link to the buffered device for the medium in CD-ROM drive 0
/floppy/floppy0 The symbolic link to the buffered device for the medium in floppy drive 0
/rmdisk/zip0 The symbolic link to the mounted Zip medium in the local Zip drive.
/rmdisk/jaz0 The symbolic link to the mounted Jaz medium in the local Jaz drive.

The vold daemon automatically mounts CD-ROM and file systems when removable media containing recognizable file systems are inserted into the devices. When a CD is inserted, vold automatically mounts the CD-ROM file system into the /vol/dev directories just described. With a floppy disk, however, the floppy’s file system is not automatically mounted until you issue the volcheck command. The volcheck command instructs vold to look at each device and determine whether new media has been inserted into the drive. On floppy disks, don’t have vold continually poll the disk drive like it does on a CD because of the hardware limitation in floppy drives. Continuously polling a floppy disk for media causes a mechanical action in the floppy disk drive and causes the drive to wear out prematurely.

The vold daemon is the workhorse behind volume manager. It is automatically started by the /etc/init.d/volmgt script. vold reads the /etc/vold.conf configuration file at startup. The vold.conf file contains the volume manager configuration information that vold uses. This information includes the database to use, labels that are supported, devices to use, actions to take if certain media events occur, and the list of file systems that are unsafe to eject without unmounting. The vold.conf file looks like this:

# ident "@(#)vold.conf  1.26    00/07/17 SMI" 
# 
# Volume Daemon Configuration file 
# 

# Database to use (must be first) 
db db_mem.so 

# Labels supported 
label cdrom label_cdrom.so cdrom 
label dos label_dos.so floppy rmdisk 
label sun label_sun.so floppy rmdisk 

# Devices to use 
use cdrom drive /dev/rdsk/c*s2 dev_cdrom.so cdrom%d 
use floppy drive /dev/rdiskette[0-9] dev_floppy.so floppy%d 
use rmdisk drive /dev/rdsk/c*s2 dev_rmdisk.so rmdisk%d  
# Actions 
eject dev/diskette[0-9]/* user=root /usr/sbin/rmmount 
eject dev/dsk/* user=root /usr/sbin/rmmount 
insert dev/diskette[0-9]/* user=root /usr/sbin/rmmount 
insert dev/dsk/* user=root /usr/sbin/rmmount 
notify rdsk/* group=tty user=root /usr/lib/vold/volmissing -p 
remount dev/diskette[0-9]/* user=root /usr/sbin/rmmount 
remount dev/dsk/* user=root /usr/sbin/rmmount 

# List of file system types unsafe to eject 
unsafe ufs hsfs pcfs udfs 

Each section in the vold.conf file is labeled with its function. Of these sections, you can safely modify the devices to use, which are described in Table 14.12, and actions, which are described in Table 14.13.

The “Devices to Use” section describes the devices for vold to manage. vold has the following syntax:

use <device> <type> <special> <shared_object> <symname> [ options ] 

Table 14.12. vold.conf Devices to Use
Parameter Field Description
device The type of removable media device to be used. Legal values are cdrom, floppy, pcmem, and rmdisk.
type The device’s specific capabilities. The legal value is drive.
special The device or devices to be used.The path usually begins with /dev.
shared_object The name of the program that manages this device. vold expects to find this program in /usr/lib/vold.
symname The symbolic name that refers to this device. The symname is placed in the device directory.
options The user, group, and mode permissions for the medium inserted (optional).

The special and symname parameters are related. If special contains any shell wildcard characters (that is, has one or more asterisks or question marks in it), symname must have a %d at its end. In this case, the devices that are found to match the regular expression are sorted and then numbered. The first device has a 0 filled in for the %d, the second device found has a 1, and so on.

If the special specification does not have shell wildcard characters, the symname parameter must explicitly specify a number at its end.

The “Actions” section specifies which program should be called if a particular event (action) occurs. The syntax for the Actions field is as follows:

insert regex [ options ] <program> <program_args> 
eject regex [ options ] <program> <program_args> 
notify regex [ options ] <program> <program_args> 

The different actions are listed in Table 14.13.

Table 14.13. vold.conf Actions
Parameter Description
insert|eject|notify The media action prompting the event.
regex This Bourne shell regular expression is matched against each entry in the /vol file system that is being affected by this event.
[options] Which user or group name this event is to run (optional).
<program> The full pathname of an executable program to be run if regex is matched.
program_args Arguments to the program.

In the default vold.conf file, you see the following entries under the “Devices to Use” and “Actions” sections:

# Devices to use 
use cdrom drive /dev/rdsk/c*s2 dev_cdrom.so cdrom%d 
use floppy drive /dev/rdiskette[0-9] dev_floppy.so floppy%d 
use pcmem drive /dev/rdsk/c*s2 dev_pcmem.so pcmem%d forceload=true 
use rmdisk drive /dev/rdsk/c*s2 dev_rmdisk.so rmdisk%d 
# Actions 
eject dev/diskette[0-9]/* user=root /usr/sbin/rmmount 
eject dev/dsk/* user=root /usr/sbin/rmmount 
insert dev/diskette[0-9]/* user=root /usr/sbin/rmmount 
insert dev/dsk/* user=root /usr/sbin/rmmount 
notify rdsk/* group=tty user=root /usr/lib/vold/volmissing –p 
remount dev/diskette[0-9]/* user=root /usr/sbin/rmmount 
remount dev/dsk/* user=root /usr/sbin/rmmount 

When a CD is inserted into the CD-ROM named /dev/dsk/c0t6d0, the following happens:

1.
vold detects that the CD has been inserted and runs the /usr/sbin/rmmount command. rmmount is the utility that automatically mounts a file system on a CD-ROM and floppy. It determines the type of file system, if any, that is on the medium. If a file system is present, rmmount mounts the file system (for a CD-ROM, in /cdrom0).

If the medium is read-only (either a CD-ROM or a floppy with the write-protect tab set), the file system is mounted as read-only. If a file system is not identified, rmmount does not mount a file system.

2.
After the mount is complete, the action associated with the media type is executed. The action allows other programs to be notified that a new medium is available. For example, the default action for mounting a CD-ROM or a floppy is to start the File Manager.

These actions are described in the configuration file /etc/rmmount.conf. Following is an example of the default /etc/rmmount.conf file:

# ident "@(#)rmmount.conf       1.12    00/08/29 SMI" 
# 
# Removable Media Mounter configuration file. 
# 

# File system identification 
ident hsfs ident_hsfs.so cdrom 
ident ufs ident_ufs.so cdrom floppy rmdisk 
ident pcfs ident_pcfs.so floppy rmdisk 
ident udfs ident_udfs.so cdrom floppy rmdisk 

# Actions 
action cdrom action_filemgr.so 
action floppy action_filemgr.so 
action rmdisk action_filemgr.so 

# Mount 
mount * hsfs udfs ufs -o nosuid 

3.
If the user issues the eject command, vold sees the media event and executes the action associated with that event. In this case, it runs /usr/sbin/ rmmount. rmmount unmounts mounted file systems and executes actions associated with the media type called out in the /etc/rmmount.conf file. If a file system is “busy” (that is, it contains the current working directory of a live process), the eject action fails.

The system administrator can modify vold.conf to specify which program should be called if media events happen, such as eject or insert. If the vold.conf configuration file is modified, vold must be told to reread the /etc/vold.conf file. Do this by stopping and starting vold as follows. Type the following:

/etc/init.d/volmgt stop 

Then type the following:

/etc/init.d/volmgt start 

Several other commands help you administer volume manager on your system. They are described in Table 14.14.

Table 14.14. Volume Manager Commands
Command Description
rmmount Removable media mounter. Used by vold to automatically mount a /cdrom, /floppy, Jaz, or Zip drive if one of these media types is installed.
volcancel Cancels a user’s request to access a particular CD-ROM or floppy file system. This command, issued by the system administrator, is useful if the removable medium containing the file system is not currently in the drive.
volcheck Checks the drive for installed media. By default, it checks the drive pointed to by /dev/diskette.
volmissing Specified in vold.conf, and notifies the user if an attempt is made to access a removable media type that is no longer in the drive.
vold The volume manager daemon, controlled by /etc/vold.conf. volrmmount Simulates an insertion so that rmmount will mount the media, or simulates an ejection so that rmmount will unmount the media.

To some, volume management might seem more trouble than it’s worth. To disable volume management, remove (or rename) the file /etc/rc2.d/ S92volmgt. Then issue the command /etc/init.d/volmgt stop. If you want to have volume management on the CD but not the floppy disk, comment out the entries in the “Devices to Use” and “Actions” sections of the vold.conf file with a #, as follows:

# Devices to use 
use cdrom drive /dev/rdsk/c*s2 dev_cdrom.so cdrom%d 
#use floppy drive /dev/rdiskette[0-9] dev_floppy.so floppy%d 
use pcmem drive /dev/rdsk/c*s2 dev_pcmem.so pcmem%d forceload=true 
# use rmscsi drive /dev/rdsk/c*s2 dev_rmscsi.so rmscsi%d 

# Actions 
#insert dev/diskette[0-9]/* user=root /usr/sbin/rmmount 
insert dev/dsk/* user=root /usr/sbin/rmmount 
#eject dev/diskette[0-9]/* user=root /usr/sbin/rmmount 
eject dev/dsk/* user=root /usr/sbin/rmmount 
notify rdsk/* group=tty user=root /usr/lib/vold/volmissing –p 

With the changes made to /etc/vold.conf, when the vold daemon starts up, it manages only the CD-ROM and not the floppy disk.

vold is picky. Knowing this is the key to keeping vold from crashing or not working for some reason. With other computers, such as PCs, you can eject CD-ROMs with no problems. With Solaris, vold isn’t that robust, so the system administrator needs to follow a few ground rules when using volume manager:

  • Always use vold commands for everything to do with CD-ROMs and floppy disks. Use the commands listed in Table 14.14 to accomplis your task.

  • Before pressing the button on the outside of the box to eject a CD-ROM disk, be sure to type eject cdrom. This is to ensure that you don’t already have a CD in the reader.

  • Never press the button to eject a CD when a CD is already in the machine. This could cause vold to stop working. Again, use the eject cdrom command instead.

  • If you can’t stop or start vold using the /etc/init.d/volmgt script, you need to restart the system to get vold working properly.

Exercise 14.8 Using the Removable Media Manager GUI

I have found that the most reliable way to use floppy disks is via the removable media manager GUI in the common desktop environment (CDE). Problems seem to be minimized when using floppy disks if I go through the media manager GUI versus the command line. To use the removable media manager, follow these steps:

1.
Open the File Manager GUI from the CDE front panel located at the bottom of the screen, as shown in Figure 14.1.

Figure 14.1. Front panel.


The File Manager appears.

2.
Click the File menu located in the menu bar, as shown in Figure 14.2.

Figure 14.2. File Manager.


A pull-down menu will appear.

3.
Select Removable Media Manager from the pull-down menu. The Removable Media Manager appears, as shown in Figure 14.3.

Figure 14.3. Removable Media Manager.


Troubleshooting Volume Manager

You might sometimes have problems with mounting a floppy or a CD-ROM. First, check to see if volume manager knows about the device. The best way to do this is to look in /vol/dev/rdiskette0 and see if something is there. If not, the volcheck command has not been run or a hardware problem exists. If references to /vol lock up the system, it means that the daemon has died, and you need to restart the vold daemon as described earlier.

If vold is working properly, insert a formatted floppy disk and type the following:

ls -l /vol/dev/rdiskette0 

The system responds with this:

total 0 
crw-rw-rw-   1 nobody   nobody    91,  7 Oct 13 14:56 unlabeled 

Note

The volume is unlabeled; therefore, the file in /vol/dev/rdiskette0 is called unlabeled.


Check to make sure that a link exists in /floppy to the character device in /vol/dev/rdiskette0. Type the following:

ls -l /floppy0 

The system responds with this:

total 18 
lrwxrwxrwx   1 root     nobody        11 Oct 13 14:56 floppy0 -> ./unlabeled 

If a name is in /vol/dev/rdiskette0, as previously described, and nothing is mounted in /floppy/<name_of_media>, it’s likely that data on the medium is an unrecognized file system. For example, perhaps it’s a tar archive, a cpio backup, or a Macintosh file system. Don’t use volume manager to get to these file types. Instead, access them through the block or character devices found in /vol/dev/rdiskette0 or /vol/dev/diskette0, with user tools to interpret the data on them, such as tar, dd, or cpio. For example, if you’re trying to access a tar archive on a floppy disk, use this command:

tar tvf /vol/dev/rdiskette0/unlabeled 

All tar files on the floppy disk will be listed.

To create a tar file on a floppy disk, the disk must contain a SunOS volume label. Use the fdformat command to format a floppy disk and add a volume label. The syntax of the fdformat command is as follows:

fdformat [options] [<devname>] 

This command is described in Table 14.15.

Table 14.15. The fdformat Command
Option Description
-b <label> Labels the medium with a volume label. A SunOS volume label is restricted to eight characters. A DOS volume label is restricted to all uppercase characters.
-B <filename> Installs a special startup loader in <filename> on an MS-DOS disk. This option is meaningful only when the -d option (or -t dos) is also specified.
-d Formats MS-DOS media.
-D Formats a 720KB (3 1/2-inch) or 360KB (5 1/4-inch) double-density disk. This is the default for double-density type drives. It is needed if the drive is a high-density or extended-density type.
-e Ejects the disk when it is finished.
-E Formats a 2.88MB (3 1/2-inch) extended-density disk. This is the default for extended-density type drives.
-f Force. Does not ask for confirmation before starting format.
-H Formats a 1.44MB (3 1/2-inch) or 1.2MB (5 1/4-inch) high-density disk. This is the default for high-density type drives; it is needed if the drive is the extended-density type.
-l Formats a 720KB (3 1/2-inch) or 360KB (5 1/4-inch) double-density disk.
-L Formats a 720KB (3 1/2-inch) or 360KB (5 1/4-inch) double-density disk.
-m Formats a 1.2MB (3 1/2-inch) medium-density disk.
-M Writes a 1.2MB (3 1/2-inch medium-density format on a high-density disk (use only with the -t nec option).
-U Unmounts any file systems and then formats the disk.
-q Quiet; does not print status messages.
-v Verifies each block of the disk after the format.
-x Skips the format and writes only a SunOS label or an MS-DOS file system.
-t dos Installs an MS-DOS file system and startup sector formatting. This is equivalent to the DOS format command or the -d option.
-t nec Installs an NEC-DOS file system and startup sector on the disk after formatting. This should be used only with the -M option.

With the fdformat command, the device specified for <devname> depends on whether you’re using volume manager. On systems using volume manager, replace <devname> with floppy0. If you’re not using volume manager, replace <devname> with rdiskette0.

If <devname> is omitted, the default disk drive (/vol/dev/rdiskette0/ unlabeled), if one exists, is used.

By default, fdformat uses the configured capacity of the drive to format the disk. For example, a 3 1/2-inch high-density drive uses disks with a formatted capacity of 1.44MB. After formatting and verifying, fdformat writes an operating-system label on block 0. Use the -t dos option (the same as the -d option) to put an MS-DOS file system on the disk after the format is done. Otherwise, fdformat writes a SunOS label in block 0.

To format the default disk device with a SunOS label so that it can be used to create a tar archive, insert the floppy disk and issue the following command:

fdformat <cr> 

The system responds with this:

Formatting 1.44 MB in /vol/dev/rdiskette0/unlabeled 
Press return to start formatting floppy 

Press the Enter key. The system displays a series of dots, as follows, until formatting is complete:

..................................... 

You can then create a tar archive on the disk. Type the following:

tar cvf /vol/dev/rdiskette0/unlabeled /etc/hosts 

The /etc/hosts file is written to the disk in tar format.

If you’re still having problems with volume manager, one way to gather debugging information is to run the rmmount command with the debug (-D) flag. To do this, edit /etc/vold.conf and change the lines that have /usr/sbin/rmmount to include the -D flag. For example:

insert /vol*/dev/diskette[0-9]/* user=root /usr/sbin/rmmount –D 

This causes various debugging messages to appear on the console.

To see debugging messages from the volume manager daemon, run the daemon, /usr/sbin/vold, with the -v -L 10 flags. It logs data to /var/ adm/vold.log. This file might contain information that could be useful in troubleshooting.

You might also want to mount a CD-ROM on a different mount point using volume management. By default, vold mounts the CD-ROM on the mount point /cdrom/cdrom0, but the user can mount it on a different mount point by following these instructions.

Exercise 14.9 Mounting a CD-ROM on a Different Mount Point

1.
If volume manager is running, bring up the File Manager and eject the CD-ROM by issuing the following command:

eject cdrom 

2.
Stop the volume-management daemon by typing the following:

/etc/init.d/volmgt stop 

3.
Create the directory called /test:

mkdir /test 

4.
Insert the CD-ROM into the CD drive and issue this command:

/usr/sbin/vold -d /test & 

Now, instead of using the /vol directory, vold will use /test as the starting directory.

Displaying a File System’s Disk Space Usage

Use the df command and its options to see the capacity of each file system mounted on a system, the amount of space available, and the percentage of space already in use. Use the du (directory usage) command to report the number of free disk blocks and files.

Note

File systems at or above 90 percent of capacity should be cleared of unnecessary files. You can do this by moving them to a disk, or you can remove them after obtaining the user’s permission.


The following is an example of how to use the df command to display disk space information. The command syntax is as follows:

df -F fstype -g -k -t <directory> 

Table 14.16 explains the df command and its options.

Table 14.16. The df Command
Command Description
df With no options, lists all mounted file systems and their device names. It also lists the total number of 512-byte blocks used and the number of files.
<directory> Is the directory whose file system you want to check. The device name, blocks used, and number of files are displayed.
-F <fstype> Displays the unmounted file systems, their device names, the number of 512-byte blocks used, and the number of files on file systems of type fstype.
-H Scales disk space values to a more readable format.
-k Lists file systems, kilobytes used, free kilobytes, percent capacity used, and mount points.
-t Displays total blocks as well as blocks used for all mounted file systems.

The following example illustrates how to display disk space information with the df command. Type the following:

df –k 

The system responds with this:

Filesystem            kbytes    used   avail capacity  Mounted on 
/dev/dsk/c0t0d0s1     480620   66827  365731    16%    / 
/dev/dsk/c0t0d0s5    1982988 1815510  107989    95%    /usr 
/proc                      0       0       0     0%    /proc 
mnttab                     0       0       0     0%    /etc/mnttab 
fd                         0       0       0     0%    /dev/fd 
/dev/dsk/c0t0d0s3     192056   44068  128783    26%    /var 
swap                  606168      40  606128     1%    /var/run 
swap                  606440     312  606128     1%    /tmp 
/dev/dsk/c0t0d0s7     425743   33800  349369     9%    /data 
/dev/dsk/c0t0d0s4     192056  184328       0   100%    /opt 
/dev/dsk/c0t0d0s6     192056    2471  170380     2%    /export/home 

In this example I’ll use the –H option to output the information in a more readable format so you can see the difference:

df –H 

The system responds with this:

Filesystem             size   used  avail capacity  Mounted on 
/dev/dsk/c0t0d0s1      492M    68M   375M    16%    / 
/dev/dsk/c0t0d0s5      2.0G   1.9G   111M    95%    /usr 
/proc                    0K     0K     0K     0%    /proc 
mnttab                   0K     0K     0K     0%    /etc/mnttab 
fd                       0K     0K     0K     0%    /dev/fd 
/dev/dsk/c0t0d0s3      197M    45M   132M    26%    /var 
swap                   621M    40K   621M     1%    /var/run 
swap                   621M   319K   621M     1%    /tmp 
/dev/dsk/c0t0d0s7      436M    35M   358M     9%    /data 
/dev/dsk/c0t0d0s4      197M   189M     0K   100%    /opt 
/dev/dsk/c0t0d0s6      197M   2.5M   174M     2%    /export/home 

Notice that the –H option scales the values to a more readable format.

In both examples, you’ll see disk usage information displayed for each currently mounted file system.

Displaying Directory Size Information

By using the df command, you display file system disk usage. You can use the du command to display the disk usage of a directory and all its subdirectories in 512-byte blocks. When used with the –H option, values are scaled to a more readable format.

The du command shows you the disk usage of each file in each subdirectory of a file system. To get a listing of the size of each subdirectory in a file system, type cd to the pathname associated with that file system and run the following pipeline:

du -s* | sort -r –n 

This pipeline, which uses the reverse and numeric options of the sort command, pinpoints large directories. Use ls -l to examine the size (in bytes) and modification times of files within each directory. Old files or text files greater than 100KB often warrant storage offline.

The following example illustrates how to display the amount of disk space being consumed by the /var/adm directory using the du command. The largest files are displayed first, and the -k option displays the file size in 1024 bytes. Type the following:

du -k /var/adm|sort -r –n 

The system responds with this:

2230    /var/adm 
1785    /var/adm/sa 
4       /var/adm/acct 
1       /var/adm/streams 
1       /var/adm/sm.bin 
1       /var/adm/passwd 
1       /var/adm/log 
1       /var/adm/exacct 
1       /var/adm/acct/sum 
1       /var/adm/acct/nite 
1       /var/adm/acct/fiscal 

In this example I’ll use the –H option to output the information in a more readable format so you can see the difference:

du -H /var/adm|sort -r -n 

The system responds with this:

  4K   /var/adm/acct 
2.3M   /var/adm 
1.8M   /var/adm/sa 
  1K   /var/adm/streams 
  1K   /var/adm/sm.bin 
  1K   /var/adm/passwd 
  1K   /var/adm/log 
  1K   /var/adm/exacct 
  1K   /var/adm/acct/sum 
  1K   /var/adm/acct/nite 
  1K   /var/adm/acct/fiscal 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset