Wednesday, September 19, 2012

Detect increased new size of existing LUN in RHEL by rescanning FC port without reboot

If the usual command :

echo “- - -“ > /sys/class/scsi_host/hostX/scan

doesn’t work for FC target, you can try this:

echo 1 > /sys/devices/{PCI-DEVICE-ID} /rescan 

The path is the device path to the FC target,which may have multiple paths. The scsi-rescan(rescan-scsi-bus.sh) tool in sg3_utils worked great for new LUN but it couldn’t detect the new size of existing LUN neither. The following procedure was tested in RHEL 6.3.



#Find the PCI ID of your device
>lspci | grep -i qlogic
15:00.0 Fibre Channel: QLogic Corp. ISP2532-based 8Gb Fibre Channel to PCI Express HBA (rev 02)
1a:00.0 Fibre Channel: QLogic Corp. ISP2532-based 8Gb Fibre Channel to PCI Express HBA (rev 02)
#Find the file rescan in /sys/devices by filtering PCI ids found above
>find /sys/devices  -name rescan  | egrep '15:00|1a:00'
/sys/devices/pci0000:00/0000:00:03.0/0000:15:00.0/rescan
/sys/devices/pci0000:00/0000:00:03.0/0000:15:00.0/host1/rport-1:0-0/target1:0:0/1:0:0:0/rescan
/sys/devices/pci0000:00/0000:00:03.0/0000:15:00.0/host1/rport-1:0-1/target1:0:1/1:0:1:0/rescan
/sys/devices/pci0000:00/0000:00:07.0/0000:1a:00.0/rescan
/sys/devices/pci0000:00/0000:00:07.0/0000:1a:00.0/host2/rport-2:0-0/target2:0:0/2:0:0:0/rescan
/sys/devices/pci0000:00/0000:00:07.0/0000:1a:00.0/host2/rport-2:0-1/target2:0:1/2:0:1:0/rescan
#kick off rescan by updating rescan file in each port
echo 1 > /sys/devices/pci0000:00/0000:00:03.0/0000:15:00.0/host1/rport-1:0-0/target1:0:0/1:0:0:0/rescan
echo 1 > /sys/devices/pci0000:00/0000:00:03.0/0000:15:00.0/host1/rport-1:0-1/target1:0:1/1:0:1:0/rescan
echo 1 > /sys/devices/pci0000:00/0000:00:07.0/0000:1a:00.0/host2/rport-2:0-0/target2:0:0/2:0:0:0/rescan
echo 1 > /sys/devices/pci0000:00/0000:00:07.0/0000:1a:00.0/host2/rport-2:0-1/target2:0:1/2:0:1:0/rescan
# messages log  file show that  the new size was detected.
>tail -f /var/log/messages
Sep 19 09:56:10 server1 kernel: sd 1:0:1:0: [sdc] 12884901888 512-byte logical blocks: (6.59 TB/6.00 TiB)
Sep 19 09:56:10 server1 kernel: sdc: detected capacity change from 5497558138880 to 6597069766656
Sep 19 10:05:57 server1 kernel: sd 1:0:0:0: [sdb] 15032385536 512-byte logical blocks: (7.69 TB/7.00 TiB)
Sep 19 10:05:57 server1 kernel: sdb: detected capacity change from 6597069766656 to 7696581394432
Sep 19 10:05:57 server1 kernel: sd 1:0:1:0: [sdc] 15032385536 512-byte logical blocks: (7.69 TB/7.00 TiB)
Sep 19 10:05:57 server1 kernel: sdc: detected capacity change from 6597069766656 to 7696581394432
Sep 19 10:05:57 server1 kernel: sd 2:0:0:0: [sdd] 15032385536 512-byte logical blocks: (7.69 TB/7.00 TiB)
Sep 19 10:05:57 server1 kernel: sdd: detected capacity change from 6597069766656 to 7696581394432
Sep 19 10:05:58 server1 kernel: sd 2:0:1:0: [sde] 15032385536 512-byte logical blocks: (7.69 TB/7.00 TiB)
Sep 19 10:05:58 server1 kernel: sde: detected capacity change from 6597069766656 to 7696581394432

Monday, September 3, 2012

Create GPT partition for LVM using parted tool

Traditional MBR(MSDOS) disk label has limitation of 2^32 (2TiB) in capacity and 15 in partition numbers(including logical partitions), while GUID Partition Table (GPT) supports 2^64 KiB (2 ZiB) and 128 partitions by default.

In Linux, fdisk doesn’t support GPT, parted is the common built-in tool for GPT.

#mpathb is the disk name is in FC SAN with multipath enabled in my test env
>parted  /dev/mapper/mpathb
(parted) mklabel gpt
(parted) mkpart primary ext4 1024kb 2tb
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel?
#This warning indicates the start position of the partition may not aligned with physical sector of the #hard disk. It is very important for harddisk of hardware raid, the start position must be n*stripe size.
#see also: http://honglus.blogspot.com.au/2009/08/align-partitions-on-stripe-boundary-for.html
#It may also hold true for single hard disk, because even a single harddisk has sector size of 2K,4K #nowadays .
#To fix the issue, just change the unit from SI to IEC 60027-2 standard
# k- stands for kilo, meaning 1,000 in Metric(SI) Prefix
# ki- stands for kilobinary ("kibi-"), meaning 1,024 in IEC 60027-2 standard
(parted) help unit
  unit UNIT                                set the default unit to UNIT
        UNIT is one of: s, B, kB, MB, GB, TB, compact, cyl, chs, %, kiB, MiB, GiB, TiB
(parted) mkpart primary ext4 1024KiB 8TiB
#the values are accepted without any warning
(parted) print
..
Number  Start   End     Size    File system  Name     Flags
 1      1049kB  8796GB  8796GB               primary
#1049KB is shown, because the default unit is KB, we change it to KiB
(parted) unit KiB
(parted) print
..
Number  Start    End            Size           File system  Name     Flags
 1      1024kiB  8589934592kiB  8589933568kiB               primary 
#set  LVM flag
#GPT has  reserved GUID for different partitions e.g LVM= E6D6D379-F507-44C2-A23C-238F2A3DF928
#
(parted) set 1 lvm on
(parted) p
Model: Linux device-mapper (multipath) (dm)
Disk /dev/mapper/mpathb: 19527106560kiB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number  Start    End            Size           File system  Name     Flags
 1      1024kiB  8589934592kiB  8589933568kiB               primary  lvm
#create LVM physical volume as usual.
>pvcreate /dev/mapper/mpathb1