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.
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 ]
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.
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:
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.
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.
|
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.
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. | |
2. |
Stop the volume-management daemon by typing the following: /etc/init.d/volmgt stop |
3. |
Create the directory called /test: mkdir /test |
4. |
Now, instead of using the /vol directory, vold will use /test as the starting directory.
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.
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.
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