Friday, 23 September 2011

HOWTO---> Disk and File system Modification with multipath devices


HOWTO: Disk and File system Modification with multipath devices

This document shows how to add disk to a partition, extend and reduce file systems and finally how to remove disk devices.


Adding Disk devices


To dynamically add disk devices to a running Linux system requires the following steps

1.      List the current mpath devices (so you will know which ones have been added)

            multipath –l

2.      Get the list of host adapters

            ls /sys/class/scsi_host

            This will return a list of host adapters e.g. host0

3.      For each host adapter perform a scan

            echo “- - -“ > /sys/class/scsi_host/<host adapter>/scan

            e.g.  echo “- - -“ > /sys/class/scsi_host/host0/scan

4.      Rescan the multipath configuration for changes

multipath

5.      List the mpath devices to ensure they’ve been added

multipath -l




Adding a new device to a volume group


Once a new device has been added it needs to be added to a volume group to be used by LVM. This is accomplished as follows

1.      Format the device for LVM usage

pvcreate <device>

e.g. pvcreate /dev/mapper/mpath3

2.      Add the device to a volume group

vgextend <volume group> <device>

e.g. vgextend appvg /dev/mapper/mpath3



Extending a File System


The following steps are required to extend a file system.

The following assumes that there is enough space available in the disk group/volumes.

1.      Get the logical volume device for the file system to be extended using the df command e.g.

            df -h /opt

            Returns

       Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/rootvg-optlv
                             1.3G   34M  1.2G   3% /opt

            The logical volume device name is highlighted in blue

2.      Increase the size of the logical volume

            lvextend -L+<size><Units> <device name> [<disk>]

Where Units is expressed as K, M, G or T. The command will automatically round up to the nearest multiple of  PE Size (can be found using vgdisplay).
            One or more <disk> devices can be specified, but this is optional. Full path to
the devices is required e.g. /dev/sdb

            More advanced options are also available e.g. stripe size, specifying specific          physical extents can also be used.

3.      Increase the size of the file system

            resize2fs <logical volume device>

            This will resize the file system to the size of the logical volume.




Reducing a File System


Reducing a file system cannot be carried out while the file system is active. The resize is a 2 stage process. First to reduce the size of the file system and second to the logical volume. There are no safeguards for the second phase of this operation i.e. the system will let you reduce the logical volume to less than the size of the file system.

1.      Get the logical volume device for the file system to be reduced, and the size in Mbytes using the following df command

df --block-size=1M <file system>

            e.g.
           
            df--block-size=1M  /opt

            Returns

Filesystem           1M-blocks      Used Available Use% Mounted on
/dev/mapper/rootvg-optlv
                          1240        34      1142   3% /opt

            The logical volume device name is highlighted in blue and the size in Mbytes
            is highlighted in red

2.      Unmount the file system

umount <file system>

3.      Check the file system (required before reducing)

            e2fsck -f <device>

4.      Reduce the size of the file system

You need to know the final size of the file system to resize it i.e. you cannot specify a size to reduce by.

resize2fs <file system> <size>M

Different units can be used, but to ensure we have exact sizings (for reducing the logical volumes), then Mbytes is a good Unit to use.

To ensure the correct reduction the following command could be used

resize2fs <file system> $((<current size>-<amount>))M

Where <current size> is the size in Mbytes from the previous df command
            <amount> is the reduction require in Mbytes

e.g.

resize2fs /opt $((1240-200))M

6.      Reduce the size of the logical volume

lvreduce -L-<size><Unit> <device>

Where <size> is the amount to reduce the logical volume by
<Unit> is K, M, G , T, P or E
<device> is the path to the logical volume device
           
            e.g.

                        lvreduce -L-200M /dev/mapper/rootvg-optlv

7.      Re mount the file system

mount <file system>



Increasing a current LUN


It’s possible to increase a LUN, or VMware backing device, and then use the additional space within the Linux partition.

1.      Check the current LUN size

multipath –l <device>

e.g.  multipath -l mpath1

2.      Resize the LUN (performed by storage)

3.      Re read the device map for each path of the device (as specified by multipath –l <mpath>)

echo 1 > /sys/block/<device>/device/rescan

e.g. 

multipath –l mpath1
mpath1 (3600508b4000ce20c0000a00008ca0000) dm-1 HP,HSV450
[size=140G][features=1 queue_if_no_path][hwhandler=0][rw]
\_ round-robin 0 [prio=0][active]
 \_ 0:0:1:2 sde 8:64  [active][undef]
 \_ 0:0:2:2 sdh 8:112 [active][undef]
\_ round-robin 0 [prio=0][enabled]
 \_ 0:0:0:2 sdb 8:16  [active][undef]
 \_ 1:0:0:2 sdk 8:160 [active][undef]

echo 1 > /sys/block/sde/device/rescan
echo 1 > /sys/block/sdh/device/rescan
echo 1 > /sys/block/sdb/device/rescan
echo 1 > /sys/block/sdk/device/rescan

4.      Rescan the multipath configuration by running multipath without any parameters

multipath

5.      Check the device has increased in size

multipath –l <mpath device>





Removing a multipath device


The following process can be followed to remove a multipath device from a Linux system.

NB. This process assumes that the device is has no active partitions and is not part of a volume group

1.      List the path devices for the multipath device

multipath –l <multipath device>

e.g. multipath –l mpath3
mpath3 (3600508b4000ce20c0000a000091a0000) dm-26 HP,HSV450
[size=20G][features=1 queue_if_no_path][hwhandler=0][rw]
\_ round-robin 0 [prio=0][active]
 \_ 0:0:0:4 sds 65:32  [active][undef]
 \_ 1:0:0:4 sdv 65:80  [active][undef]
\_ round-robin 0 [prio=0][enabled]
 \_ 0:0:1:4 sdt 65:48  [active][undef]
 \_ 0:0:2:4 sdu 65:64  [active][undef]

2.      Remove each of the path device files from /dev

rm /dev/<disk>
rm /dev/disk/by-path/<device>

            Where <device> is the disk device for each path e.g. in the above example the
            disk devices are sds, sdv, sdt & sdu

3.      Delete the disk devices for each of the paths

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

            Where <device> is the disk device e.g. sdb

4.      Remove the multipath device from the configuration

dmsetup remove <device>

Where <device> is the multipath device e.g. mpath3