3    The UNIX Shell

This chapter contains the following information:

3.1    Overview

The UNIX shell option is a way to access standard UNIX commands during a Full Installation. The primary purpose of the UNIX shell option is to provide a way to perform disk and file system maintenance before or during a Full Installation. The UNIX shell provides a way to access all UNIX commands that help you recover from serious problems such as / (root) file system corruption and enables you to perform general file system and disk maintenance tasks. It is usually not necessary to access the UNIX shell during an installation, but the option to do so is offered just in case you need it.

The base operating system distribution media (CD-ROM or RIS) contains file systems that are laid out just as the software would be installed on the system and provides direct access to the /, /usr, and /var directories. The distribution media contains a mixture of compressed and uncompressed software subsets. This format makes all commands and utilities in the uncompressed software subsets available in the UNIX shell even if your operating system is not yet fully functional. In effect, the mounted installation media is almost a full operating system environment. The UNIX shell option enables you to use the installation media as a tool for disaster recovery.

You should perform system management activities in the UNIX shell only if you have previous UNIX operating system experience.

3.2    Invoking the UNIX Shell

How you invoke the UNIX shell from the installation procedure depends upon whether you are using the graphical or text-based interface. When you invoke the UNIX shell option, the system is in a Bourne shell in single-user mode with superuser privileges. See the Command and Shell User's Guide for more information about shells and privileges.

After you boot your system from the distribution media to start a Full Installation, you will see an Installation window on systems capable of graphical display. To invoke the UNIX shell, select the Shell Window menu item from the File menu at the top of the dialog box.

On systems that do not have graphics capabilities, there are two ways to invoke the UNIX shell from the text-based Full Installation interface. The first is to choose menu option 3 from the first screen of the text-based interface. The second method is to press Ctrl/c (at any time except during software subset loading).

Note

Any installation selections you have made before invoking the UNIX shell from the text-based interface are lost. Follow this procedure to restart the text-based installation and start the selection process again:

# cd /
# restart

3.3    UNIX Shell Capabilities

Using the UNIX shell in the installation environment provides most of the capabilities of a full operating system environment. The difference between using the UNIX shell in the installation environment and a normal operating system environment is that it works without a swap device and with very limited capacity within the memory file systems (MFS) that are available during a Full Installation. These two factors mean that tasks requiring large amounts of memory that create the need to swap, or tasks requiring large amounts of disk space (such as /tmp space), are likely to encounter failures in the installation environment.

Note

The / (root) file system is located on the CD-ROM or the RIS server, and after the installation distribution media is booted, it is mounted with read-only permissions. The memory file systems (MFS) at /var, /dev, and /devices are mounted with read-write permissions. Any changes you make to files in /var, /dev, and /devices are volatile and will not be saved when you halt the installation and return to the console prompt ( >>> ).

Here is a sample of the types of tasks you can perform from the UNIX shell; some of these tasks are documented in this chapter:

3.4    Creating Swap Space

If you need to perform a task that requires swap space, you can turn swapping on in the UNIX shell. The only suggestion for turning on swap space in the UNIX shell environment is that you should not use a partition that contains data you want to preserve because it will be overwritten. To avoid this problem, use a disk partition that previously has been used for swap space.

Follow this procedure to turn on swapping in the UNIX shell:

  1. Decide which device (that is, the device name and partition) you want to use for the swap area. Be careful not to choose an area that has data that you want to preserve.

    Note

    A disk partition that previously was used for swap space will be labeled as swap in the disklabel and can be used without harm.

  2. Change to the /dev/disk directory:

    # cd /dev/disk
    

  3. Turn the swap device on. In this example, the swap device is dsk0b:

    # swapon dsk0b
    

  4. Verify that the swap device is turned on:

    # swapon -s
    

Note

The restart command, which is used to restart the installation from the UNIX shell, is no longer available after swap space has been enabled. To restart the installation, halt the system and reboot from the distribution media.

3.5    Mounting File Systems

The UNIX shell can be used to perform maintenance operations on existing file systems. For instance, if the kernel (the file called  vmunix ) in your / (root) file system becomes damaged and you have a good backup copy of the kernel, you can mount your / file system and replace the damaged kernel. If you are using LSM volumes for the / file system, see the Installation Guide for information about how to restart LSM.

Follow this procedure to mount an existing root file system located on /dev/disk/dsk0a to another mount point.

  1. Create a mount point in /var:

    # mkdir /var/mnt
    

  2. Mount the file system:

    1. For UNIX file systems (UFS), enter:

      # fsck -y /dev/disk/dsk0a
      # mount /dev/disk/dsk0a /var/mnt
      

    2. For Advanced File Systems (AdvFS), enter:

      # mkdir -p /etc/fdmns/root_domain
      # cd /etc/fdmns/root_domain
      # ln -s /dev/disk/dsk0a dsk0a
      # mount root_domain#root /var/mnt
      

The existing / file system is accessible at /var/mnt and can be modified at this point.

3.6    Restoring File Systems from Backup

The UNIX shell is ideal for restoring damaged / (root) file systems, but you can use the UNIX shell to restore file systems other than the / file system.

It is recommended to restore file systems from a full operating system environment. If such an environment is unavailable due to the need to restore either /var or /usr, boot your system to single-user mode by using your existing or restored / file system to provide more writable disk space than is available in the installation environment. Swap space can be made available in the UNIX shell as shown in the instructions in Section 3.4.

Section 3.6.1 describes how to restore UFS file systems, and Section 3.6.2 describes how to restore AdvFS file systems. Both sets of procedures assume that you are restoring the file system to the same disk.

3.6.1    Restoring UNIX File Systems (UFS) from Tape Backup

Use the following procedure to restore a UNIX file system to the same disk on which it originally resided. The size of the partition you are restoring must be larger than the size of the dump file.

Note

These instructions assume that your system has been booted from the distribution media, and you have exited the installation procedure from the File menu to the UNIX shell.

  1. Read the disk label on the disk with the corrupted file system to determine the disk type:

    # disklabel -r /dev/disk/dskna | more
    

    The disk type is shown next to the disk: field. Record the disk type here: ____________

    If the disk does not have a disk label, proceed to Section 3.8 to create one.

  2. Create a new / (root) file system by using the following command syntax:

    newfs device_name disk_type

    The device_name parameter specifies the full device pathname of the affected disk. The / (root) file system must reside on the a partition. As an example, to create a new file system on an RZ58 type disk on partition a, enter the following command:

    # newfs /dev/disk/dsk0a rz58
    

  3. Create a mount point in /var to prepare to mount the file system :

    # mkdir /var/mnt
    

    Create mount points under the /var or /tmp directories because these are the only directories that are writable from the UNIX shell.

  4. Mount the damaged file system by using the following command syntax:

    mount device_name mount_point

    The device_name parameter specifies the full device pathname of the disk device. For example, to mount the file system created in the previous step, enter the following command:

    # mount /dev/disk/dsk0a /var/mnt
    

  5. Verify that the tape device is powered up and is connected to the system.

    Note

    If the tape device was not powered up when the system initialized, it may not be visible to the system. In that case, shut down the system, power up the tape device, and reboot the system.

  6. Determine whether or not a tape device special file exists. Use the following command to obtain information about all devices on the system:

    # hwmgr -view device
    

    If the output from this command does not indicate the presence of a device name similar to /dev/tape/tape0, create the tape device special file as described in Step 7. If a tape device is present, proceed to Step 9.

  7. Create a device special file for the tape device:

    # /sbin/dn_setup -install_tape
    

    You may see messages such as +tape0 that list the device names that are created during this operation. The plus sign indicates that the device is being added.

  8. Use the hwmgr command again to see the full path to the tape device name. You will use this device name in Step 9.

    # hwmgr -view device
    

  9. Restore the root file system. If you are restoring dump files from a local file system, change to the /var/mnt directory, insert the medium containing the dump file, and enter the restore command with the following command syntax:

    restore -rf tape_device

    The tape_device parameter specifies the full path to the tape device containing the dump data. For example, enter the following commands:

    # cd /var/mnt
    # restore -rf /dev/tape/tape_device
    

  10. Shut down and halt the system:

    # shutdown -h now
    

  11. Reboot the system from the restored disk (use the show dev command if you do not know the console device name associated with the restored disk):

    # show dev
    # boot console_device_name
    

3.6.2    Restoring Advanced File Systems (AdvFS) from Tape Backup

Use the following procedure to restore an AdvFS file system to the same disk on which it originally resided.

Note

These instructions assume that your system has been booted from the distribution media, and you have exited the installation procedure to the UNIX shell.

  1. Read the disk label of the disk with the corrupted file system to make sure that it has a valid disk label:

    # /usr/sbin/disklabel -r /dev/disk/dskna | more
    

    If the disk does not have a disk label, proceed to Section 3.8 to create one.

  2. Create a new / (root) file domain by using the following command syntax:

    mkfdmn -orF device_name domain

    The device_name parameter specifies the full device pathname of the disk device on your system. For example, to create a new file system on partition a on dsk0, enter the following command:

    # mkfdmn -orF /dev/disk/dsk0a root_domain
    

  3. Create a root fileset in the root_domain file:

    # mkfset domain fileset
    

    The domain parameter specifies the name of the domain in which to create the fileset. For example:

    # mkfset root_domain root
    

  4. Create a mount point in /var or /tmp to prepare to mount the fileset:

    # mkdir /var/mnt
    

    It is recommended that you create mount points under the /var or /tmp directories because these are the only directories that are writable from the UNIX shell.

  5. Mount the root fileset by using the following command syntax:

    mount domain#fileset mount_point

    The domain#fileset parameter specifies the root file domain and the root fileset. For example, to mount the fileset created in the previous steps, enter the following command:

    # mount root_domain#root /var/mnt
    

  6. Verify that the file domain and fileset are indeed mounted:

    # showfdmn root_domain
    # showfsets root_domain
    

  7. Verify that the tape device is powered up and is connected to the system.

    Note

    If the tape device was not powered up when the system initialized, it may not be visible to the system. In that case, shut down the system, power up the tape device, and reboot the system.

  8. Determine whether or not a tape device special file exists. Use the following command to obtain information about all devices on the system:

    # hwmgr -view device
    

    If the output from this command does not indicate the presence of a device similar to /dev/tape/tape0_d0, create the tape device special file as described in Step 9. Otherwise, skip to Step 11.

  9. Create a device special file for the tape device:

    # /sbin/dn_setup -install_tape
    

    Messages such as +tape0 list the device names that are created during this operation. The plus sign indicates that the device is being added. When all tape device special files are created, proceed to Step 11 to continue with the recovery of the damaged / file system.

  10. Use the hwmgr command again to see the full path to the tape device name. You will enter this device name in Step 11.

    # hwmgr -view device
    

  11. Restore the fileset using the vrestore command. To restore files from a local file system, change to the /var/mnt directory, insert the medium containing the dump file, and enter the vrestore command using the following syntax:

    vrestore -vxf tape_device_name

    The tape_device_name parameter obtained in Step 10 specifies the pathname of the tape device containing the dump data.

    # cd /var/mnt
    # vrestore -vxf /dev/tape/tape_device_name
    

    Note

    You can restore a UFS format dump tape to AdvFS (for instance if you are converting a UFS / file system to AdvFS) and you can make a vdump tape on UFS. The restore command you use depends on the format of the tape (dump or vdump). Use vrestore to restore AdvFS dumps performed with the vdump command and restore to restore UFS dumps performed with the dump command. The corresponding restore command is used regardless of the target file system type.

  12. Verify the contents of the /etc/fstab file and the /etc/fdmns directory. The mkfdmn command added /etc/fdmns/root_domain to the temporary / file system in the UNIX shell, which is deleted when you reboot the system.

  13. Shut down and halt the system:

    # shutdown -h now
    

  14. Reboot the system from the restored disk (use the show dev command if you do not know the console device name associated with the restored disk):

    # show dev
    # boot console_device_name
    

You can use the UNIX shell to restore other file systems, but it is recommended that you perform file system restores from a full operating system environment. If such an environment is unavailable due to the need to restore either /var or /usr, you should boot your system to single-user mode by using your existing or restored / file system. In the single-user mode, more disk space is available, and swap space can be made available by issuing the following command:

# swapon -a

3.7    Restoring the Root File System Image from a Damaged Disk to a New Disk

This procedure describes how to restore a saved root file system image from a bad or damaged disk to a new disk and then rename the new disk with the old system disk name.

The process of introducing a new system disk is more complicated than just updating the /etc/fstab file because the installation kernel may assign a different device name to the devices on the system than the ones that were assigned on the saved system image. As a result, the restored system image will disagree with the kernel used to restore the image, and you cannot assume that it is possible to determine what the mapping is between them.

Note

The following procedure assumes you have restored the root file system image to a new disk as described in Section 3.6 .

  1. Halt the system:

    # shutdown -h now
    

  2. Determine the console disk device names on the system. The console device name usually is shown in the middle column of the command output. Console device names are similar to DKA100, DKC0, and so on.

    >>> show dev
    

    Record the console device name of the damaged disk here: ____________ and the console device name of the new disk here: ____________

  3. Boot the system to single user mode using the console device name of the new disk (obtained in Step 2) with the restored image :

    >>> boot -fl s console_device_name
    

  4. In single user mode, mount the / file system as writable:

    # /sbin/mountroot
    

    This process creates a device entry for the newly found disk. You will see several processing messages ending with output that is similar to the following:

    dskNa dskNb dskNc ...
    

    In the previous example, N is the disk number assigned to the new disk that is being seen for the first time and should be the disk that was restored. However, if more than one disk is shown in the output, you have added multiple disks since the system disk was last saved.

    Record the new disk name here: _____________

    Proceed to Step 5 to determine the disk name associated with the old damaged disk.

  5. Determine the old boot disk name:

    # /sbin/consvar -g bootdef_dev
    

    Output from this command is similar to the following.

    bootdef_dev = dskN
    

    In the previous command output, dskN is the old_disk_name.

    Record the old disk name here: _____________

  6. Exchange the old disk name with the new disk name:

    # dsfmgr -e  new_disk_name old_disk_name
    

    In the command line, substitute new_disk_name with the disk name obtained in Step 4, and substitute old_disk_name with the disk name returned in Step 5.

    Note

    A message is displayed if the old, damaged disk has been removed and is not active. In that situation, use the move flag (-m) instead:

    # dsfmgr -m  new_disk_name old_disk_name
    

  7. Reset the boot device:

    # /sbin/consvar -s bootdef_dev new_disk_name
    

  8. Optionally perform additional maintenance tasks, or if you are finished, boot the system to multiuser mode:

    # init 3
    

3.8    Changing the Size of a Disk Partition Using the disklabel Command

If you are using the text-based installation interface, use the disklabel command to change the drive identification or the disk partitions on the drive or to replace a damaged label or bootstrap. See disklabel(8) for more information.

To look at the existing disk partition layout, enter the disklabel command in the following format and replace the variable n with the unit number of the disk. For example, to look at the existing disk partition layout of disk, enter the following command:

# disklabel -r /dev/disk/dskn

The following example uses an rz26l disk. In this example, the size of the b partition is decreased, and the size of the a partition is increased to 128 MB, which is the minimum size to hold the / ( root) file system. Follow this procedure to change the size of disk partitions.

  1. Read the disk label on dsk0:

    # disklabel -r dsk0
    

  2. Set the EDITOR environment variable to use the ed editor:

    # EDITOR=ed
    # export EDITOR
    

    Note

    If you have a VGA monitor and want to use the vi editor, you first have to set the following variables:

    # TERM=vt100
    # export TERM
    # EDITOR=vi
    # export EDITOR
    

    Then, use the corresponding vi commands instead of the commands shown in this procedure to make the disk label changes. The rest of this procedure uses the ed text editor.

  3. Copy the disk label for dsk0 to a temporary file:

    # disklabel -r dsk0 > /tmp/old_disklabel
    

  4. Edit the copy of the disk label to protect against introducing errors on the real disk label:

    # ed /tmp/old_disklabel
    

  5. Display the disk label:

    1,$p
    

  6. Search for the b partition:

    /b: 
    

    Information similar to the following is displayed:

    b:  262144  131072  unused  1024  8192  #  (Cyl. 164*- 492*)
    

  7. Change the size of the b partition from 262144 sectors to 131072 sectors :

    s/262144/131072/p
    

    This reduces the size of the b partition from 128 MB to 64 MB. The revised information is displayed:

    b:  131072  131072  unused  1024  8192  # (Cyl. 164*- 402)
    

    There is no need to modify cylinder information; cylinder information automatically is modified when you save and exit the file.

  8. Change the offset of the b partition from 131072 sectors to 262144 sectors :

    s/131073/262144/2p
    

    This changes the offset of the b partition to start at position 262144. The revised information is:

    b:  131072  262144  unused  1024  8192  # (Cyl. 164*- 402)
     
    

    There is no need to modify cylinder information; cylinder information automatically is modified when you save and exit the file.

  9. Search for the a partition:

    /a: 
    

    Information similar to the following is displayed:

    a:   131072  0    unused    0     0   # (Cyl. 0 -164*)
    

  10. Because the size of the b partition was reduced by 131072 sectors, the size of the a partition should be increased by 131072 sectors. Change the size of the a partition from 131072 sectors to 262144 sectors:

    s/131072/262144/p
    

    This increases the size of the a partition from 64 MB to 128 MB.

  11. Display the disk label again to verify your changes:

    1,$p
    

  12. Save your edits and quit the editor:

    wq
    

  13. Apply the new disk label to the disk:

    # disklabel -R dsk0 /tmp/old_label
    

  14. Display the newly customized disk label:

    # disklabel -r dsk0
    

  15. Exit the shell or restart the Full Installation.

3.9    Returning to the Installation Procedure from the UNIX Shell

The procedure for returning to Full Installation from the UNIX shell depends upon whether you are using the text-based or graphical interface.

3.9.1    Text-Based Interface

If you entered the UNIX shell from the text-based interface or from the Quit button on the Summary window, enter the following commands to restart the Full Installation interface from the UNIX shell:

# cd /
# restart

If you have a system console with graphics capability and you want to restart the installation procedure with the text-based interface instead of the graphical user interface, enter the following command:

# cd /
# restart nogui

Any installation selections you made up to the point you exited to the UNIX shell are lost. When you restart the Full Installation, you have to make your selections again.

3.9.2    Graphical Interface

If you entered the UNIX shell from the File menu in the graphical interface, you can resume the Full Installation at any time just by clicking back in the Full Installation window. You do not have to exit the shell window; however, if you want to exit the shell window, enter exit at the # prompt within the shell window.

If you entered the UNIX shell from the Quit button on the Summary window, use the procedure shown in Section 3.9.1 to restart the Full Installation.