Tuesday, February 28, 2012

Dont remove a LUN cleanly!!! (LVM)

Recently I've added some FC LUNs and created LVM partitions on top of that in my RHEL 5 Box. Later on we had to delete the LUNs in our SAN and recreate them. I deleted the LUNs from our SAN before clean them up in the system! later on when I wanted to remove the volume groups:

UPDATE: if you haven't removed the LUNs from SAN and just deleted the LUNS
with echo 1>/sys/block//device/delete without deleteing the related
volume group, vgs command will hangs. To fix that you need to delete the
mpaths with dmsetup remove /dev/mpath/mpath and rescan the luns with
echo "- - -" > /sys/class/scsi_host/host#n/scan. It brings up sanity to
the system! (at least for me)


# vgremove VG
/dev/VG/otestapps: read failed after 0 of 4096 at 4096: Input/output error
/dev/VG/odevlapps: read failed after 0 of 4096 at 106300375040: Input/output error
/dev/VG/odevlapps: read failed after 0 of 4096 at 106300432384: Input/output error
/dev/VG/odevlapps: read failed after 0 of 4096 at 0: Input/output error
..
Volume group "VG" not found

So, dmsetup comes to rescue (after you probably lost some pounds and pulling some hair!)

# dmsetup remove --force /dev/mpath/mpath41
# for i in `ls /dev/VG/LV-0*`;do dmsetup remove $i;done

# ls -l /dev/mapper/VG* (should be gone)
# ls -l /dev/VG/* (soft link to /dev/mapper/VG*)

I also had to remove the LUNs with this commands:

echo 1 > /sys/class/scsi_device/0\:0\:0\:0/device/delete
echo 1 > /sys/class/scsi_device/0\:0\:0\:1/device/delete
echo 1 > /sys/class/scsi_device/0\:0\:1\:0/device/delete
echo 1 > /sys/class/scsi_device/0\:0\:1\:1/device/delete

multipath -F


To prevent this issue, let's see what is the best practice recemmended by Redhat:

Procedure 1. Ensuring a Clean Device Removal
1. Close all users of the device and backup device data as needed.

2. Unmount any file systems that mounted the device.

3. Remove the device from any md and LVM volume using it. If the device is a member of an LVM Volume group, then it may be necessary to move data off the device using the pvmove command, then use the vgreduce command to remove the physical volume, and (optionally) pvremove to remove the LVM metadata from the disk.

4. If the device uses multipathing, run multipath -l and note all the paths to the device. Afterwards, remove the multipathed device using multipath -F device.

5. Run blockdev –flushbufs device to flush any outstanding I/O to all paths to the device. This is particularly important for raw devices, where there is no umount or vgreduce operation to cause an I/O flush.

6.Remove any reference to the device's path-based name, like /dev/sd, /dev/disk/by-path or the major:minor number, in applications, scripts, or utilities on the system. This is important in ensuring that different devices added in the future will not be mistaken for the current device.

7.Finally, remove each path to the device from the SCSI subsystem. To do so, use the command echo 1 > /sys/block/device-name/device/delete where device-name may be sde, for example.
Another variation of this operation is echo 1 > /sys/class/scsi_device/h:c:t:l/device/delete, where h is the HBA number, c is the channel on the HBA, t is the SCSI target ID, and l is the LUN


Ref: http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/5/html/Online_Storage_Reconfiguration_Guide/removing_devices.html

Wednesday, February 22, 2012

Resize a Lun (multipath) Linux

# multipath -ll mpath0

# for i in `multipath -ll mpath0 | grep sd | awk '{print $2}'`; do
> echo $i ; done
1:0:1:0
2:0:1:0
1:0:0:0
2:0:0:0

>>>> to reread the current (storage-based) size parameters of the devices

# for i in `multipath -ll mpath0 | grep sd | awk '{print $3}'`; \
do \
lockdev --rereadpt /dev/$i ;\
done

>>>> You can check with: blockdev –getsz /dev/$i


# multipathd -k"resize multipath mpath0"

# multipath -ll mpath0

# pvresize /dev/mapper/mpath0

# lvresize -L 50G /dev/VolGroup01/san1

# resize2fs /dev/VolGroup01/san1

# df


Ref:
http://blogs.utexas.edu/hcoyote/2009/11/12/resizing-a-linu-multipathd-san-lun/
http://run.tournament.org.il/hot-resize-multipath-disk-linux/
http://zenhat.org/2011/04/02/how-to-extend-lun-without-reboot-redhat/

Scan for New/Removed LUNs Linux (FC)

more /sys/class/scsi_host/host*/state

echo "- - -" > /sys/class/scsi_host/hostN/scan

# Re-scans


multipath -F && multipath

ls -ltra /dev/mapper


# Removing a LUN

umount /path/to/volume

multipath -l

multipath -F

lsof /dev/sdX

# Delete the drives.
# Do this for EACH drive

echo 1 > /sys/block/sdX/device/delete

# Unmap the volume on the SAN

multipath
multipath -l

Thursday, February 16, 2012

Migrating Data form one San to another

This is not an offical post, just to keep what I did, I hope I can add more later on!

I used both these weblogs and came up with a little bit better solution
to recreate the old VG on old san:

http://saharageeks.com/2011/07/26/migrated-data-using-lvm-mirroring/

http://codeworks.gnomedia.com/archives/2005/general/lvm_recovery/

http://storagemeat.blogspot.com/2010/07/migrating-volumes-with-linux-lvm.html

Old VG: /dev/loop0 and /dev/loop1
New VG: only /dev/loop5

888 dd if=/dev/zero of=LUN01 bs=4096 count=250000
889 dd if=/dev/zero of=LUN02 bs=4096 count=250000
890 dd if=/dev/zero of=LUN03 bs=4096 count=2500000

897 losetup /dev/loop0 LUN01
898 losetup /dev/loop1 LUN02
901 losetup /dev/loop5 LUN03

1031 pvcreate /dev/loop5
1032 pvcreate /dev/loop0
1033 pvcreate /dev/loop1

1034 vgcreate TestEMC /dev/loop0 /dev/loop1
1035 lvcreate -L 800M -n testLV01 TestEMC
1037 lvcreate -L 1100M -n testLV02 TestEMC
1041 lvcreate -l 13 -n testLV03 TestEMC
1042 vgs

1054 mkfs.ext2 /dev/mapper/TestEMC-testLV01
1055 mkfs.ext2 /dev/mapper/TestEMC-testLV02
1057 mkfs.ext2 /dev/mapper/TestEMC-testLV03

1059 mount /dev/mapper/TestEMC-testLV01 test1
1060 mount /dev/mapper/TestEMC-testLV02 test2
1066 mount /dev/mapper/TestEMC-testLV03 test3

1067 lvs
1068 vgs
1069 lvs -m
1070 lvdisplay -m

1071 cp /etc/lvm/backup/TestEMC .

1073 vgextend TestEMC /dev/loop5

1074 vgs

1075 lvconvert -m1 --corelog TestEMC/testLV01 /dev/loop5
1092 lvconvert -m1 --corelog TestEMC/testLV02 /dev/loop5
1093 lvconvert -m1 --corelog TestEMC/testLV03 /dev/loop5

1094 umount test1
1096 umount test2
1097 umount test3

1098 lvconvert -m0 TestEMC/testLV01 /dev/loop0 /dev/loop1
1099 lvconvert -m0 TestEMC/testLV02 /dev/loop0 /dev/loop1
1100 lvconvert -m0 TestEMC/testLV03 /dev/loop0 /dev/loop1

1101 vgsplit TestEMC OldTestEMC /dev/loop0 /dev/loop1
1102 cp /etc/lvm/backup/TestEMC ./OldTestEMC

1110 vi OldTestEMC

(I made a copy of TestEMC, named it OldTestEMC, and I changed the UUID for LVs and VG and the name of VG in OldTestEMC)

1111 vgcfgrestore -f OldTestEMC OldTestEMC
1112 vgs
1113 lvs -v

1118 mkdir test1old
1119 mkdir test2old
1120 mkdir test3old

1121 vgs

1125 vgchange -ay OldTestEMC

1126 mount /dev/mapper/OldTestEMC-testLV01 test1
1127 mount /dev/mapper/OldTestEMC-testLV02 test2
1128 mount /dev/mapper/OldTestEMC-testLV03 test3
1137 umount test1
1138 umount test2
1139 umount test3

1140 fsck /dev/mapper/OldTestEMC-testLV01
1141 fsck /dev/mapper/OldTestEMC-testLV03
1142 fsck /dev/mapper/OldTestEMC-testLV02

1143 mount /dev/mapper/OldTestEMC-testLV03 test3
1144 mount /dev/mapper/OldTestEMC-testLV03 test2
1145 mount /dev/mapper/OldTestEMC-testLV03 test1

Clean UP and destory the lab!

1155 lvremove TestEMC
1156 lvremove OldTestEMC (it will remove LVs one by one in this VG)

1159 umount test1
1160 umount /test/test1
1161 umount /test/test2
1162 umount /test/test3
1163 mount | grep test
1164 lvremove OldTestEMC
1178 vgchange -a n NetApp
1187 umount /dev/mapper/NetApp-orappl
1188 fuser /dev/mapper/NetApp-orappl
1190 umount /dev/mapper/NetApp-orappl
1194 losetup -d /dev/loop0
1195 losetup -d /dev/loop1
1196 losetup -d /dev/loop2
1197 losetup -d /dev/loop3
1198 losetup -d /dev/loop4
1199 losetup -d /dev/loop5
1200 losetup -a