Friday, March 19, 2010

Mounting NFS Filesystems

NFS Client Configuration Files

Any NFS share made available by a server can be mounted using various methods. The share can be manually mounted, using the mount command. However, this requires that the root user type the mount command every time the system restarts. Two methods of configuring NFS shares to be mounted automatically at boot time include modifying the /etc/fstab or using the autofs service.

Mounting NFS Filesystems using /etc/fstab

 Placing a properly formatted line in the /etc/fstab file has the same effect as manually mounting the exported file system. The /etc/fstab file is read by the /etc/rc.d/init.d/netfs script at system startup and any NFS shares listed there will be mounted.

A sample /etc/fstab line to mount an NFS export looks like the following:

<server>:</path/of/dir> </local/mnt/point> nfs <options> 0 0
The <server-host> corresponds to hostname, IP address, or fully qualified domain name of the server exporting the file system.
The </path/of/directory> is the path to the exported directory.
The </local/mount/point> specifies where on the local file system to mount the exported directory. This mount point must exist before /etc/fstab is read or the mount will fail.
The nfs option specifies the type of file system being mounted.
The <options> area specifies mount options for the file system.

Mounting NFS Filesystems using autofs

One drawback to using /etc/fstab is that, regardless of how infrequently a user may access the NFS mounted file system, the system must dedicate resources to keep that mount in place. This is not a problem with one or two mounts, but when the system is maintaining mounts to a dozen systems at one time, overall system performance can suffer. An alternative to /etc/fstab is to use the kernel-based automount utility, which will mount and unmount NFS file systems automatically, saving resources.
The autofs script, located in the /etc/rc.d/init.d/ directory, is used to control automount through the /etc/auto.master primary configuration file. While automount can be specified on the command line, it is more convenient to specify the mount points, hostname, exported directory, and options in a set of files rather than typing them all by hand. By running autofs as a service that starts and stops in designated runlevels, the mount configurations in the various files can be automatically implemented.
The autofs configuration files are arranged in a parent-child relationship. A main configuration file (/etc/auto.master) refers mount points on your system that are linked to a particular map type, which take the form of other configuration files, programs, NIS maps, and other less common mount methods. The auto.master file contains lines referring to each of these mount points, organized like this:
<mount-point>    <map-type>
 The <mount-point> element of this line indicates the location of the mount on the local file system. The <map-type> relates to the way in which the mount point will be mounted. The most common method for auto mounting NFS exports is to use a file as the map type for the particular mount point. The map file, usually named auto.<mount-point>, where <mount-point> is the mount point designated in auto.master, contains lines that look like this:
<directory>  <mount-options>  <host>:<exported-file-system>
The <directory>refers to the directory within the mount point where the exported file system should be mounted. Much like a standard mount command, the host exporting the file system, as well as the file system being exported, are required in the <host>:<exported-file system> section. To specify particular options to be used when mounting the exported file system, place them in the <mount-options> section, separated by commas. For NFS mounts that use autofs, place -fstype=nfs in the <mount-options>
section.

Common NFS Mount Options

The following options are the most popular for NFS mounts:
  • hard or soft — specifies whether the program using a file via an NFS connection should stop and wait (hard) for the server to come back online if the host serving the exported file system is unavailable, or if it should report an error (soft).
    If hard is specified, the user cannot terminate the process waiting for the NFS communication to resume unless intr option is also specified.
    If soft, is specified, the user can set an additional timeo=<value> option, where <value> specifies the number of seconds to pass before the error is reported.
  • intr — allows NFS requests to be interrupted if the server goes down or cannot be reached.
  • nolock — is occasionally required when connecting to older NFS server. To require locking, use the lock option.
  • noexec — does not permit the execution of binaries on the mounted file system. This is useful if the system is mounting a non-Linux file system via NFS that contains incompatible binaries.
  • nosuid — does not allow set-user-identifier or set-group-identifier bits to take effect.
  • rsize=8192 and wsize=8192 — may speed up NFS communication for reads (rsize) and writes (wsize) by setting a larger data block size, in bytes, to be transferred at one time. Be careful when changing these values; some older Linux kernels and network cards may not work well with larger block sizes.
  • nfsvers=2 or nfsvers=3 — specify which version of the NFS protocol to use.

 


 


Monday, March 15, 2010

How do I reinstall a corrupted boot partition in Red Hat Enterprise Linux?

Issue

In a system where the "/boot" partition is a separate partition, when /boot is corrupted or be formatted mistakenly, you can not boot the system but do not want to reinstall the whole system.

Environment

  • Red Hat Enterprise Linux, all versions
  • /boot partition is installed on the first partition of your first disk
  • x86 architecture

Resolution

Reinstall /boot partition manually with the following steps:

1. Boot the system into rescue mode:

Insert the Red Hat Enterprise Linux CD #1 and boot your system. At boot prompt, type "linux rescue". This will start the rescue mode program.

You will be prompted for your keyboard and language requirements. Enter these values as you would during the installation of Red Hat Enterprise Linux.

Next, a screen will appear telling you that the program will now attempt to find a Red Hat Enterprise Linux installation to rescue. Select "Continue" on this screen.

At the "sh-3.1" prompt, chroot to /mnt/sysimage:

# chroot /mnt/sysimage

2. Make sure the boot partition is labeled as described in /etc/fstab. (Assuming the boot partition is /dev/sda1):

# e2label /dev/sda1 /boot

3. Make sure the boot partition is mounted:

# mount /dev/sda1 /boot

4. Mount the CD to install the following rpms:

# mkdir /mnt/iso 
# mount -o loop,ro /dev/hdc /mnt/iso
# cd /mnt/iso/Server
# rpm -Uvh --replacefiles --replacepkgs grub-0.97-13.i386.rpm
# rpm -Uvh --replacefiles --replacepkgs redhat-logos-4.9.16-1.noarch.rpm
# rpm -ivh --replacefiles --replacepkgs kernel-2.6.18-8.el5.i686.rpm

5. Install the GRUB:

# grub-install /dev/sda

6. If /boot/grub/grub.conf is lost, you need to create it manually. The following is a sample of grub.conf, please make sure the the file "vmlinuz-2.6.18-8.el5" and "initrd-2.6.18-8.el5.img" exist under the directory of /boot (which should be installed after step 4).
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu

title Red Hat Enterprise Linux (2.6.18-8.el5)
        root (hd0,0)
        kernel /vmlinuz-2.6.18-8.el5 ro root=LABEL=/
        initrd /initrd-2.6.18-8.el5.img

7. Make a soft link to grub.conf:
# cd /boot/grub 
# ln -s grub.conf menu.lst

Saturday, March 6, 2010

Logical Volume Manager (LVM)

LVM is a method of allocating hard drive space into logical volumes that can be easily resized instead of partitions.
With LVM, a hard drive or set of hard drives is allocated to one or more physical volumes. A physical volume cannot span over more than one drive.
The physical volumes are combined into logical volume groups, with the exception of the /boot/ partition. The /boot/ partition cannot be on a logical volume group because the boot loader cannot read it. If the root (/) partition is on a logical volume, create a separate /boot/ partition which is not a part of a volume group.
Since a physical volume cannot span over multiple drives, to span over more than one drive, create one or more physical volumes per drive.
 

FIG:Logical Volume Group
The logical volume group is divided into logical volumes, which are assigned mount points, such as /home and /m and file system types, such as ext2 or ext3. When "partitions" reach their full capacity, free space from the logical volume group can be added to the logical volume to increase the size of the partition. When a new hard drive is added to the system, it can be added to the logical volume group, and partitions that are logical volumes can be expanded .

FIG:Logical Volume 
On the other hand, if a system is partitioned with the ext3 file system, the hard drive is divided into partitions of defined sizes. If a partition becomes full, it is not easy to expand the size of the partition. Even if the partition is moved to another hard drive, the original hard drive space has to be reallocated as a different partition or not used.
LVM support must be compiled into the kernel, and the default Red Hat kernel is compiled with LVM support.