Monday, January 12, 2009

How to setup NFS Configuration files (/etc/exports)?

An entry in /etc/exports will typically look like this:

directory host1(option1,option2) host2(option3,option4)

Where,

directory - the directory or file system you want to share

host1, host2 - Allowed hosts to mount your shared folder. Using IP Address is better idea rather than host name. If the hosts are in your local network, mention their private IP address.

optionXX

ro: The directory is shared read only; the client machine will not be able to write it. This is the default.

rw: The client machine will have read and write access to the directory.

no_root_squash: By default, any file request made by user root on the client machine is treated as if it is made by user nobody on the server. (Exactly which UID the request is mapped to depends on the UID of user "nobody" on the server, not the client.) If no_root_squash is selected, then root on the client machine will have the same level of access to the files on the system as root on the server. This can have serious security implications, although it may be necessary if you want to perform any administrative work on the client machine that involves the exported directories. You should not specify this option without a good reason.

no_subtree_check: If only part of a volume is exported, a routine called subtree checking verifies that a file that is requested from the client is in the appropriate part of the volume. If the entire volume is exported, disabling this check will speed up transfers.

sync: By default, all but the most recent version (version 1.11) of the exportfs command will use async behavior, telling a client machine that a file write is complete - that is, has been written to stable storage - when NFS has finished handing the write over to the filesystem. This behavior may cause data corruption if the server reboots, and the sync option prevents this.


Related Topic - How to setup Network File System (NFS)?

How to setup Network File System (NFS)?

NOTE: This document does not provide in depth about the configuration file. Also, Please note that installing required modules/packages is not the scope of this document. I will try to provide different article about configuration of /etc/exports (now available here), /etc/sysconfig/nfs and available mount options.

What is NFS?

Network File System (NFS) allows mounting the file system of Remote machine as if it is local file system.

How to Setup an NFS Server?

1. On both NFS Server and Client, make sure your kernel has nfs support. To check

$ cat /proc/filesystems
minix

ext2
msdos
nodev proc
nodev nfs

If you donot see nfs, you have to compile your own kernel with NFS enabled, or have to load the kernel module if your NFS support was compiled as a module.

2. Portmapper – To offer NFS service, portmapper (or rpc.portmap) should be running before starting NFS daemons. To start manually, run rcportmap start.

To check whether portmapper is running or not, run rpcinfo –p. If it is running, you can see portmapper daemon, its version, protocol and port numbers as follows:

$ rpcinfo -p
program vers proto port
100000 2 tcp 111 portmapper
100000 2 udp 111 portmapper
100003 2 udp 2049 nfs
100003 3 udp 2049 nfs
100003 4 udp 2049 nfs
100003 2 tcp 2049 nfs
100003 3 tcp 2049 nfs
100003 4 tcp 2049 nfs
100024 1 udp 32770 status
100021 1 udp 32770 nlockmgr
100021 3 udp 32770 nlockmgr
100021 4 udp 32770 nlockmgr
100024 1 tcp 32769 status
100021 1 tcp 32769 nlockmgr
100021 3 tcp 32769 nlockmgr
100021 4 tcp 32769 nlockmgr
100005 1 udp 644 mountd
100005 1 tcp 645 mountd
100005 2 udp 644 mountd
100005 2 tcp 645 mountd
100005 3 udp 644 mountd
100005 3 tcp 645 mountd

3. Make necessary configuration such as directory to be shared, hosts allowed to use the shared directories and other options in /etc/exports. Addition to that, you may configure such as number of nfs threads required at /etc/sysconfig/nfs


4. Start nfsserver from /etc/init.d, which start all required daemons (rpc.nfsd, rpc.lockd, rpc.statd, rpc.mountd, rpc.rquotad). You may also start these daemons one by one manually.

How to Setup an NFS Client?

To begin using machine as an NFS client, you will need the portmapper running on that machine, and to use NFS file locking, you will also need rpc.statd and rpc.lockd running on both the client and the server

To mount from command line, run as follow (master.foo.com is nfs server, home is the shared folder on that server. /mnt/home is the local mount point):

# mount master.foo.com:/home /mnt/home

To automate this while booting, add an entry as below in /etc/fstab file:
# device mountpoint fs-type options dump fsckorder
...
master.foo.com:/home /mnt nfs rw 0 0
...


Related topic - How to setup NFS Configuration files (/etc/exports)?

Saturday, December 20, 2008

How to create/increase swap on the fly in Linux?

We can either create swap file or swap partition and make it as swap space.

How to create swap space from file?

To create 512MB swap file, run below commands. Make sure the file system has enough diskspace, where you are creating swap file.

dd if=/dev/zero of=swapfile bs=1024 count=524288
chmod 600 swapfile
mkswap swapfile
swapon swapfile

To automate this while rebooting, add following entry to /etc/fstab. (Assumed that you created swapfile under /opt)

/opt/swapfile swap swap defaults 0 0

How to create swap space from partition?

Create a partition using "fdisk" with type swap i.e. make partition type to 82. Type "t" to set the partition type. (Assumed that you created a partition /dev/hdb1 as swap). To activate, run following commands

mkswap /dev/hdb1
swapon /dev/hdb1

To automate this while rebooting, add following entry to /etc/fstab.

/dev/hdb1 swap swap defaults 0 0

Use "free" command before and after executing above methods to verify that the swap has been created / increased

Have Fun .....

Sikkandar.Linux at Gmail.Com

Saturday, December 6, 2008

How to Setup or Check Network Speed and Duplex on Linux?

What is Half and Full Duplex?

In Full duplex, the data (signal) can flow in both directions

In Half duplex, the data (signal) can flow in one direction at a time

So, the duplex settings is very important. To check duplex and speed settings, ethtool is the best tool.

To see the duplex and speed setting of interface eth0 just run following command

# ethtool eth0

To setup, 100 Mbps speed, Full duplex and make it static on interface eth0 , run below command:

# ethtool -s eth0 autoneg off duplex full speed 100

autoneg off make sure that this setting does not change in response to the port setting on which this interface is connected, such as switch.

In newer version, this settings can be done in configuration file. For example in newer version SUSE such as 10.x, this setting can be done in respective interface configuration file, which can be found under /etc/sysconfig/network. The interface configuration file looks like ifcfg-eth-id-00:c0:0d:01:75:05

In older versions such as SUSE 9, we need to set up manually. I added this settings in a bash shell script and placed under /etc/sysconfig/network/scripts and created symbolic links from /etc/sysconfig/network/if-up.d.

# ls -al
total 8
drwxr-xr-x 2 root root 4096 Apr 22 2008 .
drwxr-xr-x 6 root root 4096 Feb 19 2008 ..
lrwxrwxrwx 1 root root 21 Apr 22 2008 eth0-setup -> ../scripts/eth0-setup

# cat ../scripts/eth0-setup

#!/bin/bash
#
# This script has been added by Sikkandar to make sure
# that the NIC Configuration is set to FULL DUPLEX with SPEED 100
#
# Date : 04.Oct.2007
#
# OS : SUSE LINUX Enterprise Server 9
#
/usr/sbin/ethtool -s eth0 autoneg off duplex full speed 100


Have Fun ........


Sikkandar.Linux at GMail.Com

Wednesday, December 3, 2008

What is "/etc/fstab" and how it is important for "mount" command.

fstab stands for File System Table, contains device or partitions details and indicates how they are to be initialized. This file is mostly used by mount command.

Let us have a look at what each column means on this file:

Sample content of /etc/fstab (on Solaris it is /etc/vfstab)

1st Column (device-name): This column contains devices or partitions name

2nd Column (mount point):Mount point of device or partition

3rd Column (fs-type): The type of file system

4th Column (mount-options): Mount options such as ro, rw, noauto, user, exec and acl, etc. use man

5th Column (dump-frequency): useful when we use dump command for backup larger numbers than one are to avoid too many backups of idle file-systems

6th Column (pass-number): This tells on which order, the fsck to be done while booting. "0" zero means don't do fsck.

Whenever we issue mount -a, it reads the /etc/fstab and mount the file systems according to the settings. If it is "noauto" on mount-options for any file systems, it will not mount. Default is auto.

For more, do a "man mount"

Have a fun ....

Sikkandar.Unix at Gmail.Com