Pages

Friday, 16 September 2011

RHEL 5 Linux : configure Kdump on Red Hat Enterprise Linux 5


RHEL 5 Linux : configure Kdump on Red Hat Enterprise Linux 5

Installing required packages

RHEL 5 has the Kdump packages installed by default. If for any reason they are not installed, you need to install the packages “kexec-tools-<version>.rpm” and “system-config-kdump-<version>.rpm” with the following commands:

# rpm -ivh kexec-tools-<version>.rpm system-config-kdump-<version>.rpm


or, if your system is registered at the Red Hat Network, by running# yum install kexec-tools system-config-kdump

Configuration of Kdump

First you need to enable Kdump. There is a configuration dialog available which can be started under a graphical environment by using:# system-config-kdump


Please check the option box “Enable kdump” at the top of the Dialog.

Nex,t you have to define the memory to reserve for Kdump In the dialog you see the memory information for your system and the usable memory for Kdump. On most systems a value of “128MB” Kdump memory should be enough.

Finally, you need to define a location where to store the dump file. You have the choice between “file”, “nfs”, “ssh”, “raw”, “ext2″, and “ext3″. This setup is straight forward, please configure the kdump as it fit’s best into your environment. The simplest configuration for the location is “file:///var/crash“.

You need to take care that you have enough disk space on the configured location, at least the physically memory of the system which is expected to dumped.

After you have configured kdump, you need to reboot the system to activate the settings.

More information about the configuration can be found in the file “/usr/share/doc/kexec-tools-*/kexec-kdump-howto.txt“

Checking the configuration

To make sure that the configuration is working, you can test by using the magic SysRq feature of the kernel.

WARNING: Please make sure that no other users are logged into the system and that all work is saved before following the next steps, otherwise this may lead to data loss.

First you need to enable it with the following command:# echo 1 > /proc/sys/kerne/sysrq


Next you should sync the data of your hard disks to minimize the risk of lost data by# echo s > /proc/sysrq-trigger


And finally you can force the system to “crash” by# echo c > /proc/sysrq-trigger


You should see some panic output and the system will restart into the kdump kernel to save the crash dump data. This will take some time depending on the amount of memory of your system and the speed of the device the dump is written to. After the dump is finished the system will reboot back to the normal service.

If you follow the example above you should now find the core file at “/var/crash/<YYYY-MM-DD-HH:MM>/vmcore” which indicating the the setup is working.

Linux Troubleshooting – Root Password Reset


Linux Troubleshooting – Root Password Reset


The General problem that we see in an enterprise environment, where there is no centralized automated password management tool is …. missing root passwords for the servers.

Missing root passwords are also common when the servers initially managed by one team and later handed over to other team, but not all the changes to root passwords are not handed over to new teams.




Below procedure, to reset root password, can be used on a linux machine if you are having access to server console:

1. Reboot the machine

2. When you notice GRUB loader that shows the Linux Operating system to be booted Just press the button “e”

3. Highlight the kernel line using the arrow keys and then hit “e” again

4. That will take you to the command interface where you can edit the line. you just have to go end of line add “init=/bin/bash” ( no need to enter double quotes )

5. And then hit the button “b” to boot from that kernel entry

This will dump you to a bash prompt much earlier than single user mode, and a lot less has been initialized, mounted, etc. And root filesystem is in “read only” state at this level.

To make any modifications related to password we should remount the ”/” filesystem in “rw” mode.

Just use the command:

# mount -o remount,rw /

take the backup copies of /etc/passwd and /etc/shadow before modifying them, and then make modifications to the “root” entry in /etc/shadow as below

# original line
root:$1$EYBTVZHP$QtjkCG768giXzPvW4HqB5/:12832:0:99999:7:::
# after editing

root::12832:0:99999:7::: –> we have removed the encrypted password field from the root entry, to make password empty.

And now reboot the machine to normal mode and once you login with empty password ….. Just dont forget to reset root password. Otherwise you know what happens your Server will turn into “Public toilet”

Redhat Linux : Setting Kernel Parameter


Redhat Linux : Setting Kernel Parameter


To modify kernel parameters a common way is to change /proc file system:
1. Log in as root user.
2. Change to the /proc/sys/kernel directory.
3. echo <desired list of values> > <group of parameters>

But this update is not permanent and after system reboot, your kernel parameters’s values will be the same as before. A way to set kernel parameter modifications permanently, on Linux, is to include them in a shell script. This could be run as root user, or in an automatic way at startup process
- Create file /etc/init.d/set_kernel_parameters


#!/bin/sh
#
#
echo -n quot;Start Setting kernel parameters on "
echo 250 32000 100 128 > /proc/sys/kernel/sem #This sets SEMMSL, SEMMNS, SEMOPM, SEMMNI
echo 2097152 > /proc/sys/kernel/shmall
echo 2147483648 > /proc/sys/kernel/shmmax
echo 4096 > /proc/sys/kernel/shmmni
#
echo 65536 > /proc/sys/fs/file-max
#
echo 1024 65000 > /proc/sys/net/ipv4/ip_local_port_range
#
echo 4194304 > /proc/sys/net/core/rmem_default
echo 4194304 > /proc/sys/net/core/rmem_max
echo 262144 > /proc/sys/net/core/wmem_default
echo 262144 > /proc/sys/net/core/wmem_max
#
ulimit -n 65536 >/dev/null 2>&1
ulimit -u 16384 >/dev/null 2>&1
#
echo -n quot;End Setting kernel parameters on "
echo

- grant execute rights on this file
$ chmod 755 /etc/init.d/set_kernel_parameters

- create symbolic link to run at startup
$ ln -s /etc/init.d/set_kernel_parameters /etc/rc.d/rc5.d/S55kernel
$ ln -s /etc/init.d/set_kernel_parameters /etc/rc.d/rc3.d/S55kernel


- make the kernel parameters active by running as root
$ /etc/init.d/set_kernel_parameters









Second Procedure to modify kernel parameters a common way is to change /proc file system:
1. Log in as root user.
2. Change to the /proc/sys/kernel directory.
3. echo <desired list of values> > <group of parameters>

But this update is not permanent and after system reboot, your kernel parameters’s values will be the same as before. A way to set kernel parameter modifications permanently, on Linux, is to include them in a shell script. This could be run as root user, or in an automatic way at startup process

- Create file /etc/init.d/set_kernel_parameters
#!/bin/sh
#
#
echo -n quot;Start Setting kernel parameters on "
echo 250 32000 100 128 > /proc/sys/kernel/sem #This sets SEMMSL, SEMMNS, SEMOPM, SEMMNI
echo 2097152 > /proc/sys/kernel/shmall
echo 2147483648 > /proc/sys/kernel/shmmax
echo 4096 > /proc/sys/kernel/shmmni
#
echo 65536 > /proc/sys/fs/file-max
#
echo 1024 65000 > /proc/sys/net/ipv4/ip_local_port_range
#
echo 4194304 > /proc/sys/net/core/rmem_default
echo 4194304 > /proc/sys/net/core/rmem_max
echo 262144 > /proc/sys/net/core/wmem_default
echo 262144 > /proc/sys/net/core/wmem_max
#
ulimit -n 65536 >/dev/null 2>&1
ulimit -u 16384 >/dev/null 2>&1
#
echo -n quot;End Setting kernel parameters on "
echo

- grant execute rights on this file
$ chmod 755 /etc/init.d/set_kernel_parameters

- create symbolic link to run at startup
$ ln -s /etc/init.d/set_kernel_parameters /etc/rc.d/rc5.d/S55kernel
$ ln -s /etc/init.d/set_kernel_parameters /etc/rc.d/rc3.d/S55kernel


- make the kernel parameters active by running as root
$ /etc/init.d/set_kernel_parameters



Every time the system boots, the ‘/etc/rc.d/rc.sysinit‘ script is executed by init process. This shell script contains a call to sysctl command and reads the values from /etc/sysctl.conf file as the ones to be set . Therefore, any values added to /etc/sysctl.confwill take effect after the system boot or without downtime using “sysctl -p” command



sysctl.conf is a simple file containing sysctl values to be read in and set by sysctl (see man 8 sysctl).

The syntax is simply as follows:
# comment
; comment



token = value

Note that blank lines are ignored, and whitespace before and after a token or value is ignored, although a value can contain whitespace within. Lines which begin with a # or ; are considered remarks / comments and ignored.

Example:
# sysctl.conf sample
#
kernel.sysrq = 1
kernel.sem = 250 32000 100 128 #This sets SEMMSL, SEMMNS, SEMOPM, SEMMNI
kernel.shmmax = 2147483648
kernel.shmall = 2097152
kernel.shmmni = 4096
;
fs.file-max = 65536
;
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.ip_local_port_range = 1024 65000
;
net.core.rmem_default = 4194304
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 262144


The sysctl command is used to view, set, and automated kernel settings in the /proc/sys/ directory. To get a quick overview of all settings configurable in the /proc/sys/ directory, type the sysctl -acommand as root

Linux : Quick Reference for Sendmail Issues


Linux : Quick Reference for Sendmail Issues



Just discussing some of the common sendmail issues and troubleshooting procedures in linux



Problem: Sendmail can not send mail to users in other domains.



Symptom:It can send mail to internal email account but can’t send mail to outside of the company or users in other domains.

Solution: To implement the solution, please execute the following steps:

1. Edit /etc/mail/sendmail.mc to have:

define(`SMART_HOST’,`<your full smtp server address>’)

and

DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA’)dnl

Do NOT edit /etc/mail/sendmail.cf as it may cause unexpected results.

(The “DAEMON_OPTIONS” line is a security measure – it allows sendmail to accept e-mail only from the local server. If you do not need otherwise, this is a good security practice. )

2. Regenerate sendmail.cf from sendmail.mc:

# m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf

3. Restart the sendmail service:

# service sendmail restart

Linux : NTP Error Message "kernel time sync error 0001"


Linux : NTP Error Message "kernel time sync error 0001"


This error message is logged by NTP daemon, and this means that the ntpd fails to adjust OS internal clock for some reasons.

NTP daemon adjusts OS internal clock by invoking system call named adjtimex(). Linux kernel expects the system call to be invoked regularly, as NTP daemon does so normally. When the interval becomes longer than kernel expects, this error message is logged.

Therefore, this error message is logged when NTP daemon:
can not get accurate time information from network time server.
has not invoked adjtimex() for a long time, longer than kernel expects.

Actually, there are no bad effects to the system even if you see this message in system log. Because OS continues to tick the OS internal clock without ntpd adjustments. Also ntpd continues to work, even after ntpd fails to get accurate time from network time server.

Solution
You can just ignore this message, since this is not fatal error but notice level message. This message can not be suppressed.

It is better to check your network, or check the network connection between NTP daemon and network time server.

Linux – dynamically add/remove scsi from linux


Linux – dynamically add/remove scsi from linux


1. SCSI Device Addressing

A four-part addressing scheme is used to define the location of SCSI devices within a system. The attributes include:

<H>ost: Instance of hostadapter to which device is attached
<B>us: SCSI Bus or Channel on the hostadapter
<T>arget: SCSI Id assigned to an individual device
<L>un: Logical unit number on the device

Each attribute, <H> <B> <T> <L>, refers to a part of the device location, similar to how number, street, suburb and state all form an address.



References to device addresses are readily visible from system logs and various command output, though the availability of certain commands or utilities depends on the distribution and operating system version used. The lsscsi(8) utility, for example, is natively available on Enterprise Linux 5.

The following denotes the use of several commands to describe a relatively simple SCSI system.
# dmesg
...
SCSI subsystem initialized
libata version 2.21 loaded.
ata_piix 0000:00:07.1: version 2.12
scsi0 : ata_piix
scsi1 : ata_piix
ata1: PATA max UDMA/33 cmd 0x000101f0 ctl 0x000103f6 bmdma 0x0001ffa0 irq 14
ata2: PATA max UDMA/33 cmd 0x00010170 ctl 0x00010376 bmdma 0x0001ffa8 irq 15
ata1.00: ATA-5: IC35L040AVVA07-0, VA2OA51A, max UDMA/100
ata1.00: 78165360 sectors, multi 8: LBA
ata1.01: ATA-5: WDC WD400BB-32CLB0, 05.04E05, max UDMA/100
ata1.01: 78165360 sectors, multi 8: LBA
ata1.00: configured for UDMA/33
ata1.01: configured for UDMA/33
ata2.00: ATA-5: QUANTUM FIREBALLP AS60.0, A1Y.1500, max UDMA/100
ata2.00: 117266688 sectors, multi 8: LBA
ata2.01: ATAPI: JLMS DVD-ROM XJ-HD166, DD05, max UDMA/33
ata2.00: configured for UDMA/33
ata2.01: configured for UDMA/33
scsi 0:0:0:0: Direct-Access ATA IC35L040AVVA07-0 VA2O PQ: 0 ANSI: 5
sd 0:0:0:0: [sda] 78165360 512-byte hardware sectors (40021 MB)
sd 0:0:0:0: [sda] Write Protect is off
sd 0:0:0:0: [sda] Mode Sense: 00 3a 00 00
sd 0:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
sd 0:0:0:0: [sda] 78165360 512-byte hardware sectors (40021 MB)
sd 0:0:0:0: [sda] Write Protect is off
sd 0:0:0:0: [sda] Mode Sense: 00 3a 00 00
sd 0:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
sda: sda1 sda2 sda3
sd 0:0:0:0: [sda] Attached SCSI disk
scsi 0:0:1:0: Direct-Access ATA WDC WD400BB-32CL 05.0 PQ: 0 ANSI: 5
sd 0:0:1:0: [sdb] 78165360 512-byte hardware sectors (40021 MB)
sd 0:0:1:0: [sdb] Write Protect is off
sd 0:0:1:0: [sdb] Mode Sense: 00 3a 00 00
sd 0:0:1:0: [sdb] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
sd 0:0:1:0: [sdb] 78165360 512-byte hardware sectors (40021 MB)
sd 0:0:1:0: [sdb] Write Protect is off
sd 0:0:1:0: [sdb] Mode Sense: 00 3a 00 00
sd 0:0:1:0: [sdb] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
sdb: sdb1 sdb2
sd 0:0:1:0: [sdb] Attached SCSI disk
scsi 1:0:0:0: Direct-Access ATA QUANTUM FIREBALL A1Y. PQ: 0 ANSI: 5
sd 1:0:0:0: [sdc] 117266688 512-byte hardware sectors (60041 MB)
sd 1:0:0:0: [sdc] Write Protect is off
sd 1:0:0:0: [sdc] Mode Sense: 00 3a 00 00
sd 1:0:0:0: [sdc] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
sd 1:0:0:0: [sdc] 117266688 512-byte hardware sectors (60041 MB)
sd 1:0:0:0: [sdc] Write Protect is off
sd 1:0:0:0: [sdc] Mode Sense: 00 3a 00 00
sd 1:0:0:0: [sdc] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
sdc: sdc1
sd 1:0:0:0: [sdc] Attached SCSI disk
scsi 1:0:1:0: CD-ROM JLMS DVD-ROM XJ-HD166 DD05 PQ: 0 ANSI: 5
...



# lspci | grep -i ide
00:07.1 IDE interface: Intel Corporation 82371AB/EB/MB PIIX4 IDE (rev 01)

# lsscsi
[0:0:0:0] disk ATA IC35L040AVVA07-0 VA2O /dev/sda
[0:0:1:0] disk ATA WDC WD400BB-32CL 05.0 /dev/sdb
[1:0:0:0] disk ATA QUANTUM FIREBALL A1Y. /dev/sdc
[1:0:1:0] cd/dvd JLMS DVD-ROM XJ-HD166 DD05 /dev/sr0

# cat /proc/scsi/scsi
Attached devices:
Host: scsi0 Channel: 00 Id: 00 Lun: 00
Vendor: ATA Model: IC35L040AVVA07-0 Rev: VA2O
Type: Direct-Access ANSI SCSI revision: 05
Host: scsi0 Channel: 00 Id: 01 Lun: 00
Vendor: ATA Model: WDC WD400BB-32CL Rev: 05.0
Type: Direct-Access ANSI SCSI revision: 05
Host: scsi1 Channel: 00 Id: 00 Lun: 00
Vendor: ATA Model: QUANTUM FIREBALL Rev: A1Y.
Type: Direct-Access ANSI SCSI revision: 05
Host: scsi1 Channel: 00 Id: 01 Lun: 00
Vendor: JLMS Model: DVD-ROM XJ-HD166 Rev: DD05
Type: CD-ROM ANSI SCSI revision: 05

# grep host /etc/modprobe.conf
alias scsi_hostadapter ata_piix

# ls -ld /sys/class/scsi_host/host*/
drwxr-xr-x 2 root root 0 2008-08-06 17:25 /sys/class/scsi_host/host0/
drwxr-xr-x 2 root root 0 2008-08-06 17:25 /sys/class/scsi_host/host1/

# cat /sys/class/scsi_host/host[0-1]/proc_name
ata_piix
ata_piix

Above, it’s evident that four devices are attached to two hostadapters, both of type ata_piix i.e. host0: sda sdb, host1: sdc sr0.

Note too, there is sufficient overlap between various command output that device addresses and naming can be easily identified and mapped.
2. SCSI Device Naming

The name assigned to a SCSI device is completely independent to it’s SCSI address. In fact, taking the linux 2.6 kernel as an example, the device naming system used, udev(8), dynamically allocates device names upon each boot.

During system initialisation, hardware is scanned and devices are named according to their discovery order. This means, however, that the same device may not always be assigned the same name. This may have implications on some systems, especially those that solely rely on device names such as file /etc/fstab for mounting filesystems.


For such cases, explicit udev(8) configuration may be required to guarantee cross-reboot persistency of device naming. Alternatively, other methods, such as mount-by-label (where supported), may be employed to ensure that only intended devices are selected and used, regardless of their arbitrary device name. udev(8), though mentioned here, is not described in any detail – it’s relevance, however, becomes more apparent later. Refer to the udev(8) and mount(8) man pages and references below for more information.
3. Scanning, Adding and Removing Devices

From time to time, it may be necessary to add, remove, replace or even reorganise SCSI devices in a system. Broadly speaking, there are two main approaches to how this can be achieved – offline and online.

The method one might choose to add or remove devices usually depends on several factors, such as:
distribution, operating system and version
hardware type, driver version/capability
system availability requirements
storage availability requirements
availability of backup/redundant systems
familiarity of system, I/O stack and storage
acceptance of associated risk

Following are several methods of device addition and removal. Regardless of which method you use, always ensure to perform thorough testing before use within a production environment.
3.1 System reboot

Adding and removing devices when a system is shutdown is considered the simplest and safest method. Clean filesystem unmount and ordered shutdown of all of components/drivers involved in the I/O path avoids the potential risks associated with online (dynamic) device removal. On boot, ordered driver load allows newly added or removed devices to be correctly discovered and identified. This method, obviously, necessitates total system unavailability.
3.2 Reload hostadapter driver

The installation (loading) of common host bus adapter (HBA) driver modules initiates a scan (or rescan) of the associated device, resulting in the (re)discovery of any newly added/removed devices. Whilst performed with the system online, to be able to reload the hostadapter module, it must first be unloaded. This, therefore, means that any (all) filesystem, volume or array on devices associated with the driver must first be offlined (in the case of arrays or logical volumes) and/or unmounted. In fact, depending on the complexity of the I/O stack involved, this method is likely to also require the shutdown of related storage services and the unloading of other related or dependent modules e.g. multipathing.
3.3 procfs /proc/scsi/scsi (2.4 kernel)

Linux provides the ability to dynamically interact with the running kernel via the /proc (procfs) filesystem. Dynamically adding or removing devices can be accomplished via the /proc/scsi/scsi interface i.e.:

To remove a specific device:
# echo "scsi remove-single-device <H> <B> <T> <L>" > /proc/scsi/scsi

where <H> <B> <T> <L> refers to Host, Bus, Target and Lun

To add a specific device:
# echo "scsi add-single-device <H> <B> <T> <L>" > /proc/scsi/scsi

where <H> <B> <T> <L> refers to Host, Bus, Target and Lun

This method allows for all filesytems, volumes and arrays, except those immediately involved in specific device removal, to remain online and mounted. However, this method carries a high element of risk. Strong knowledge of the system and all storage layers/devices involved in the I/O path is required. Removal of an incorrect device or premature removal of an intended device may result in volume corruption or, in the presence of Clusterware (e.g. Oracle Cluster File System 2 (OCFS2) or Real Application Clusters (RAC)), could result in node eviction.

Use this method as required if using a 2.4 kernel. The 2.6 kernel provides an improved sysfs interface (/sys, described below) for managing devices.

The following example illustrates the removal, then addition of a SCSI device:
# lsscsi
[0:0:0:0] disk ATA IC35L040AVVA07-0 VA2O /dev/sda
[0:0:1:0] disk ATA WDC WD400BB-32CL 05.0 /dev/sdb
[1:0:0:0] disk ATA QUANTUM FIREBALL A1Y. /dev/sdc
[1:0:1:0] cd/dvd JLMS DVD-ROM XJ-HD166 DD05 /dev/sr0



# echo "scsi remove-single-device 1 0 0 0" > /proc/scsi/scsi

# lsscsi
[0:0:0:0] disk ATA IC35L040AVVA07-0 VA2O /dev/sda
[0:0:1:0] disk ATA WDC WD400BB-32CL 05.0 /dev/sdb
[1:0:1:0] cd/dvd JLMS DVD-ROM XJ-HD166 DD05 /dev/sr0

# echo "scsi add-single-device 1 0 0 0" > /proc/scsi/scsi

# lsscsi
[0:0:0:0] disk ATA IC35L040AVVA07-0 VA2O /dev/sda
[0:0:1:0] disk ATA WDC WD400BB-32CL 05.0 /dev/sdb
[1:0:0:0] disk ATA QUANTUM FIREBALL A1Y. /dev/sdd
[1:0:1:0] cd/dvd JLMS DVD-ROM XJ-HD166 DD05 /dev/sr0

Note that the removed device, originally known as /dev/sdc, was added back to the system, but as /dev/sdd. This highlights the potential risk associated with solely relying on arbitrary kernel-assigned device file names.
3.4 sysfs /sys/class/scsi_host/ (2.6 kernel)

The 2.6 kernel provides the /sys (sysfs) interface for interacting and managing system devices. In the case of SCSI devices, the /sys/class/scsi_host/ interface can be used to dynamically rescan a hostadapter, as well as add or remove specific devices.

To rescan a hostadapter:
# echo '- - -' > /sys/class/scsi_host/host<H>/scan

where <H> refers to the hostadapter or the instance of hostadapter where multiple (of the same type) exist on the system

To remove a specific device:
# echo 1 > /sys/class/scsi_host/host<H>/device/target<H>:<B>:<T>/<H>:<B>:<T>:<L>/delete

where <H> <B> <T> <L> refers to Host, Bus, Target and Lun

To add a specific device:
# echo "<B> <T> <L>" > /sys/class/scsi_host/host<H>/scan

where <H> <B> <T> <L> refers to Host, Bus, Target and Lun

Like the /proc/scsi/scsi interface, the /sys/class/scsi_host/ interface similarly allows for all filesytems, volumes and arrays, except those immediately involved in specific device removal, to remain online and mounted. Again, this method carries a high level of risk and requires a strong knowledge of the system and all storage layers/devices involved in the I/O path.

Where Fiber Channel (FC) Host Bus Adapters (HBA) are used, separate procfs and/or sysfs entries are created in various locations depending on Operating System and driver type and version used. In such cases, FC HBA driver level re-scan should precede SCSI Bus rescan. For example, for QLogic (qla2xxx):


Enterprise Linux 4:
# echo "scsi-qlascan" >> /proc/scsi/qla2xxx/<H>
# echo "scsi add-single-device <H> <B> <T> <L>" > /proc/scsi/scsi


Enterprise Linux 5:
# echo 1 > /sys/class/fc_host/host<H>/issue_lip
# echo '- - -' > /sys/class/scsi_host/host<H>/scan


The following example illustrates (non-FC HBA) SCSI hostadapter rescan, then removal and addition of a device:
# echo '- - -' > /sys/class/scsi_host/host1/scan



# lsscsi
[0:0:0:0] disk ATA IC35L040AVVA07-0 VA2O /dev/sda
[0:0:1:0] disk ATA WDC WD400BB-32CL 05.0 /dev/sdb
[1:0:0:0] disk ATA QUANTUM FIREBALL A1Y. /dev/sdc
[1:0:1:0] cd/dvd JLMS DVD-ROM XJ-HD166 DD05 /dev/sr0

[root@toxic ~]# echo 1 > /sys/class/scsi_host/host1/device/target1:0:0/1:0:0:0/delete

# lsscsi
[0:0:0:0] disk ATA IC35L040AVVA07-0 VA2O /dev/sda
[0:0:1:0] disk ATA WDC WD400BB-32CL 05.0 /dev/sdb
[1:0:1:0] cd/dvd JLMS DVD-ROM XJ-HD166 DD05 /dev/sr0

[root@toxic /]# echo '0 0 0' > /sys/class/scsi_host/host1/scan

# lsscsi
[0:0:0:0] disk ATA IC35L040AVVA07-0 VA2O /dev/sda
[0:0:1:0] disk ATA WDC WD400BB-32CL 05.0 /dev/sdb
[1:0:0:0] disk ATA QUANTUM FIREBALL A1Y. /dev/sdd
[1:0:1:0] cd/dvd JLMS DVD-ROM XJ-HD166 DD05 /dev/sr0

Once again, note that the name of the re-added device (/dev/sdd) differs to it’s original name (/dev/sdc).

The entries and names beneath /sys/class/scsi_host/ may vary depending on the operating system, kernel version and type of devices in use on the system. For example, if using iSCSI devices, additional directory entry session exists:
# lsscsi
[0:0:0:0] disk ATA WDC WD1600JS-75N 10.0 /dev/sda
[2:0:0:0] disk IET VIRTUAL-DISK 0 /dev/sdb
[3:0:0:0] disk IET VIRTUAL-DISK 0 /dev/sdc
[7:0:0:0] disk IET VIRTUAL-DISK 0 /dev/sdd
[10:0:0:0] disk IET VIRTUAL-DISK 0 /dev/sde



# ls -ld /sys/class/scsi_host/host*/device/session*/target*/[0-9]*
drwxr-xr-x 3 root root 0 Aug 7 22:35 /sys/class/scsi_host/host10/device/session8/target10:0:0/10:0:0:0
drwxr-xr-x 3 root root 0 Aug 7 22:35 /sys/class/scsi_host/host2/device/session0/target2:0:0/2:0:0:0
drwxr-xr-x 3 root root 0 Aug 7 22:35 /sys/class/scsi_host/host3/device/session1/target3:0:0/3:0:0:0
drwxr-xr-x 3 root root 0 Aug 7 22:35 /sys/class/scsi_host/host7/device/session5/target7:0:0/7:0:0:0


3.5 Host Adapter Vendor Supplied Scripts

Some hostadapter vendors supply their own scripts that can be used to scan, add and remove devices. These scripts may be used in favour of manual device interaction via native kernel interfaces. The scripts should, however, be thoroughly tested before reliance in production. Naturally, where provided by a third-party vendor, any issues arising from their use should be referred to the originating supplier.

Examples of vendor supplied scripts include:
ql-dynamic-tgt-lun-disc.sh (QLogic)
rescan-scsi-bus.sh (QLogic)
qlun_disc.sh (QLogic)
lun_scan (Emulex)
hp_rescan (HP)
proprietary and custom others

Contact your hostadapter vendor for latest available and recommended scripts.
4. Removing a Multipath Device by Example

Let’s look at a more complex, yet typical scenario involving multipathing (device-mapper-multipath).
In this instance, explicitly white-listed iSCSI-served partitioned target devices (LUNs) are multipathed on the initiator using user-defined names; ocr1, voting1, etc.
# dmsetup ls | sort
ocr1 (253, 5)
ocr1p1 (253, 9)
ocr2 (253, 6)
ocr2p1 (253, 10)
ocr3 (253, 7)
ocr3p1 (253, 11)
voting1 (253, 0)
voting1p1 (253, 3)
voting2 (253, 1)
voting2p1 (253, 4)
voting3 (253, 2)
voting3p1 (253, 8)



# multipath -ll
ocr3 (149455400000000000000000001000000ca0200000d000000) dm-7 IET,VIRTUAL-DISK
[size=980M][features=0][hwhandler=0]
\_ round-robin 0 [prio=0][active]
\_ 1:0:0:10 sdn 8:208 [active][ready]
\_ round-robin 0 [prio=0][enabled]
\_ 1:0:0:11 sdo 8:224 [active][ready]
ocr2 (149455400000000000000000001000000ed0200000d000000) dm-6 IET,VIRTUAL-DISK
[size=980M][features=0][hwhandler=0]
\_ round-robin 0 [prio=0][active]
\_ 1:0:0:8 sdl 8:176 [active][ready]
\_ round-robin 0 [prio=0][enabled]
\_ 1:0:0:9 sdm 8:192 [active][ready]
ocr1 (149455400000000000000000001000000e80200000d000000) dm-5 IET,VIRTUAL-DISK
[size=980M][features=0][hwhandler=0]
\_ round-robin 0 [prio=0][active]
\_ 1:0:0:6 sdj 8:144 [active][ready]
\_ round-robin 0 [prio=0][enabled]
\_ 1:0:0:7 sdk 8:160 [active][ready]
voting3 (149455400000000000000000001000000e30200000d000000) dm-2 IET,VIRTUAL-DISK
[size=965M][features=0][hwhandler=0]
\_ round-robin 0 [prio=0][active]
\_ 1:0:0:4 sdh 8:112 [active][ready]
\_ round-robin 0 [prio=0][enabled]
\_ 1:0:0:5 sdi 8:128 [active][ready]
voting2 (149455400000000000000000001000000de0200000d000000) dm-1 IET,VIRTUAL-DISK
[size=965M][features=0][hwhandler=0]
\_ round-robin 0 [prio=0][active]
\_ 1:0:0:2 sdf 8:80 [active][ready]
\_ round-robin 0 [prio=0][enabled]
\_ 1:0:0:3 sdg 8:96 [active][ready]
voting1 (149455400000000000000000001000000d90200000d000000) dm-0 IET,VIRTUAL-DISK
[size=965M][features=0][hwhandler=0]
\_ round-robin 0 [prio=0][active]
\_ 1:0:0:1 sde 8:64 [active][ready]
\_ round-robin 0 [prio=0][enabled]
\_ 1:0:0:0 sdd 8:48 [active][ready]

# cat /proc/partitions
major minor #blocks name

8 0 6291456 sda
8 1 5735173 sda1
8 2 554242 sda2
8 16 2097152 sdb
8 17 2096451 sdb1
8 32 2097152 sdc
8 33 2096451 sdc1
8 48 987966 sdd
8 49 987681 sdd1
8 64 987966 sde
8 65 987681 sde1
8 80 987966 sdf
8 81 987681 sdf1
8 96 987966 sdg
8 97 987681 sdg1
8 112 987966 sdh
8 113 987681 sdh1
8 128 987966 sdi
8 129 987681 sdi1
8 144 1004031 sdj
8 145 1003873 sdj1
8 160 1004031 sdk
8 161 1003873 sdk1
8 176 1004031 sdl
8 177 1003873 sdl1
8 192 1004031 sdm
8 193 1003873 sdm1
8 208 1004031 sdn
8 209 1003873 sdn1
8 224 1004031 sdo
8 225 1003873 sdo1
253 0 987966 dm-0
253 1 987966 dm-1
253 2 987966 dm-2
253 3 987681 dm-3
253 4 987681 dm-4
253 5 1004031 dm-5
253 6 1004031 dm-6
253 7 1004031 dm-7
253 8 987681 dm-8
253 9 1003873 dm-9
253 10 1003873 dm-10
253 11 1003873 dm-11

Below, unused multipath device ocr3 is dynamically removed from the system, as are its associated underlying devices. The devices were verified to no longer be in use or required by any program or service before their removal.

Note, whether the /sbin/multipath or /sbin/dmsetup command is used, the result is the same. However, when using the dmsetup command to remove partitioned multipathed devices, the multipath aliases for all of its partitions must first be removed before the multipath alias of the device itself can be removed, otherwise the command fails with a ‘device or resource busy error’ message. When using the multipath command to remove partitioned devices, removal of the multipath alias of the device will automatically remove all multipath aliases for all of its partitions.
# multipath -ll ocr3
ocr3(149455400000000000000000001000000ca0200000d000000) dm-7 IET,VIRTUAL-DISK
[size=980M][features=0][hwhandler=0]
\_ round-robin 0 [prio=0][active]
\_ 1:0:0:10 sdn 8:208 [active][ready]
\_ round-robin 0 [prio=0][enabled]
\_ 1:0:0:11 sdo 8:224 [active][ready]



# dmsetup ls | sort
ocr1 (253, 5)
ocr1p1 (253, 9)
ocr2 (253, 6)
ocr2p1 (253, 10)
ocr3 (253, 7)
ocr3p1 (253, 11)
voting1 (253, 0)
voting1p1 (253, 3)
voting2 (253, 1)
voting2p1 (253, 4)
voting3 (253, 2)
voting3p1 (253,

# cat /proc/partitions | grep -e 'sdo\|sdn\|dm-7\|dm-11'
8 208 1004031 sdn
8 209 1003873 sdn1
8 224 1004031 sdo
8 225 1003873 sdo1
253 7 1004031 dm-7
253 11 1003873 dm-11

# multipath -f ocr3
OR
# dmsetup remove ocr3p1
# dmsetup remove ocr3

# multipath -ll ocr3
#

# dmsetup ls | sort
ocr1 (253, 5)
ocr1p1 (253, 9)
ocr2 (253, 6)
ocr2p1 (253, 10)
voting1 (253, 0)
voting1p1 (253, 3)
voting2 (253, 1)
voting2p1 (253, 4)
voting3 (253, 2)
voting3p1 (253,

# cat /proc/partitions | grep -e 'sdo\|sdn\|dm-7\|dm-11'
8 208 1004031 sdn
8 209 1003873 sdn1
8 224 1004031 sdo
8 225 1003873 sdo1

# echo 1 > /sys/class/scsi_host/host1/device/session0/target1:0:0/1:0:0:10/delete
# echo 1 > /sys/class/scsi_host/host1/device/session0/target1:0:0/1:0:0:11/delete

# cat /proc/partitions | grep -e 'sdo\|sdn\|dm-7\|dm-11'
#


Note that the device-mapper devices previously associated with multipath device ocr3 (/dev/dm-7, /dev/dm-11) are removed, however the underlying device paths (/dev/sdn, /dev/sdo) remain until explicitly removed from the system.

Redhat Linux – How to dynamically add LUN’s to Qlogic HBA


Redhat Linux – How to dynamically add LUN’s to Qlogic HBA


Dynamically adding LUN’s to Qlogic HBA on Linux:

1. Make sure that newly configured LUN’s are properly configured and mapped to correct HBA’s

2. If you have installed SANsurfer GUI/CLI, make sure newly added LUN’s are visible from these tools


3. For each QLogic HBA installed in the system, do the following:

a) Determine the host ID (H) associated with the HBA. Each installed HBA has a numeric filename that is the host identifier.

# /bin/ls /proc/scsi/qla2300

b) Rescan for all the LUNs on all the ports.
H is the host identifier associated with HBA.

# /bin/echo scsi-qlascan > /proc/scsi/qla2300/H

c) Determine the target ID (T) associated with the new LUN.
This file lists the ID:LUN numbers recognized by the QLA driver. T is the
target ID value.

# /bin/cat /proc/scsi/qla2300/H

d) Add the LUN to HBA.
H is the host identifier associated with the HBA;
T is the target identifier obtained in Step c; and L is the LUN identifier.

# /bin/echo scsi add-single-device H 0 T L > /proc/scsi/scsi

4. Use the command “/sbin/fdisk -l” to verify if the newly added LUN is visible to the OS



5. Partition the disk attached from new lun ( procedure )

Find below example illustrating addition of a newly mapped T4 LUN on Red Hat Linux using QLA driver version 7.07.04

1) Determine host ID

# /bin/ls /proc/scsi/qla2300/2

2) Re-scan for LUN’s on both HBA’s

# /bin/echo scsi-qlascan > /proc/scsi/qla2300/2

3) Verify newly mapped LUN’s

# /bin/cat /proc/scsi/qla2300/2
QLogic PCI to Fibre Channel Host Adapter for QLA2342:
Firmware version: 3.03.19, Driver version 7.07.04
Entry address = f88ae060
HBA: QLA2312 , Serial# F05179
Request Queue = 0x377e0000, Response Queue = 0x377d0000
Request Queue count= 512, Response Queue count= 512
Total number of active commands = 0
Total number of interrupts = 35
Total number of active IP commands = 0
Total number of IOCBs (used/max) = (0/600)
Total number of queued commands = 0
Device queue depth = 0×20
Number of free request entries = 510
Number of mailbox timeouts = 0
Number of ISP aborts = 0
Number of loop resyncs = 2
Number of retries for empty slots = 0
Number of reqs in pending_q= 0, retry_q= 0, done_q= 0, scsi_retry_q= 0
Host adapter:loop state= <READY>, flags= 0×820813
Dpc flags = 0×0
MBX flags = 0×0
SRB Free Count = 4096
Link down Timeout = 000
Port down retry = 030
Login retry count = 030
Commands retried with dropped frame(s) = 0
Configured characteristic impedence: 50 ohms
Configured data rate: 1-2 Gb/sec auto-negotiate
SCSI Device Information:
scsi-qla0-adapter-node=200100e08b275bb5;
scsi-qla0-adapter-port=210100e08b275bb5;
scsi-qla0-target-0=20030003ba27cfa2;

SCSI LUN Information:
(Id:Lun) * – indicates lun is not registered with the OS.
( 0: 0): Total reqs 1, Pending reqs 0, flags 0×0*, 0:0:81,
( 0:15): Total reqs 0, Pending reqs 0, flags 0×0*, 0:0:81,

Note “*” in the above outputs, which indicates LUN as not registered
with OS, hence not visible to OS.



4) Register the new LUN’s with OS

# /bin/echo scsi add-single-device 2 0 0 15 > /proc/scsi/scsi

5) verify from OS using “fdisk -l”

# /sbin/fdisk -l

Disk /dev/sda: 36.4 GB, 36420075008 bytes
255 heads, 63 sectors/track, 4427 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 4173 33415200 83 Linux
/dev/sda3 4174 4427 2040255 82 Linux swap

Disk /dev/sdb: 5372 MB, 5372116992 bytes
255 heads, 63 sectors/track, 653 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 653 5245191 83 Linux

In the above output ‘sdb’ is the new LUN, which was partitioned earlier.
Twitter Bird Gadget