How to do Online Storage Migration in Unix/Linux

Storage migration is the day to day activity of every Linux/Unix system administrator. In IT production environment we have to move data from one LUN (logical unit number) to another very safely without any downtime or less downtime and without corrupting the data. In this tutorial we will show you how you can safely and easily do online storage migration in your Linux/UNIX server whether it is physical server or virtual.

 
How to do Online Storage Migration Linux
 

Generally in Unix environment storage migration is mainly done on physical servers where new LUN’s are assigned from SAN and old SAN storage LUN’s are given back to them. Storage migration involves assigning of new storage LUN’s, scanning them, moving data from old storage to new ones and then removing the old LUNs and giving them back. 🙂

 

Steps to do Online Storage Migration in Linux/UNIX

 

1. The first step for storage migration is the availability of new LUN’s where you want to migrate your data from old storage device. Once the storage is assigned from SAN team, you can do online SCAN. Please refer to below article for reference. You can use same article for physical servers also.

 

Recommended Article: Adding Storage to VM Host without Reboot

 

In physical servers after following instruction in above article, just use multipath command and you will able to see your new storage LUN’s.

# multipath
# multipath -ll

For a particular multipath device you can run below command.

[root@local ~]# multipath -list  mpath0
mpath0 (000000000000192601761530123456789) dm-6 EMC,SYMMETRIX
[size=52G][features=1 queue_if_no_path][hwhandler=0][rw]
\_ round-robin 0 [prio=0][active]
 \_ 3:0:0:0 sda        8:0   [active][undef]
 \_ 3:0:1:0 sdb        8:16  [active][undef]
 \_ 5:0:0:0 sdc        8:32  [active][undef]
 \_ 5:0:1:0 sdd        8:48  [active][undef]

 

2. Once you have scan your new LUN’s, you can create physical volumes (PV’s) from them and then you can extend your volume group (VG) or create new VG. Use below commands to do this.

#  pvcreate /dev/mapper/mpath0
#  pvcreate /dev/mapper/mpath1

or

pvcreate /dev/mapper/mpath{0..1}

#  vgextend vg1 /dev/mapper/mpath0
#  vgextend vg1 /dev/mapper/mpath1

Recommended Article: 5 Basic Storage Certifications for IT Administrators

 

3. Once your VG’s or VG are extended, you can migrate your data to new physical volumes which you have just created on new storage LUN’s. You can use pvmove command for this. You can do one to one mapping of physical volume or you can also move data of one logical volume at a time.

For moving data or physical extents from one pv to another use below command syntax.

Syntax:

# pvmove old-pv new-pv

Example:

# pvmove /dev/sdc1 /dev/sdd1
# pvmove /dev/mapper/mapth0 /dev/mapper/mpath2

You can also perform same task only to extents belonging to the single Logical Volume. Use below command line for that.

Syntax:

# pvmove -v -n lv-name old-pv new-pv

Example:

# pvmove -v -n lv1 /dev/sdb1 /dev/sdc1
# pvmove -v -n lv2 /dev/mapper/mapth0 /dev/mapper/mpath2

Note: Please do PV move from one device to another only when there is less production impact. Else we will suggest to move data from logical volumes one be one using “-n” switch.

While performing above storage migration, keep in mind that your load average and CPU utilization will also go high so be prepare for it.

 

4. Once all your data is moved from old physical volume to new one. You can remove old PV from your volume group using vgreduce command and then do PV remove.

Syntax:

# vgreduce vg-name pv-name
# pvremove pv-name

Refer our article on safely removing VMDK from Linux server in virtual environment. For physical server you can follow below steps.

If you have multipath device then after following above steps you will have to first remove there mapping. So use below command for each multipath device.

# multipath -f 

Example:

multipath -f mpath0

Now to flush any outstanding I/O to all paths to the device

# blockdev --flushbufs 

Example:

blockdev --flushbufs /dev/sdb 
blockdev --flushbufs /dev/mapper/sdb

Now you will have to remove block device which are mapped with multipath device as below.

echo 1 > /sys/block/sd*/device/delete

Example:

echo 1 > /sys/block/sda/device/delete
echo 1 > /sys/block/sdb/device/delete
echo 1 > /sys/block/sdc/device/delete
echo 1 > /sys/block/sdd/device/delete

After you have remove your block device, you can handover LUN’s to your storage team and asked them to reclaim them. This was a simple tutorial on how to do online storage migration in Linux/Unix servers. Do let us know if you face any issue with storage migration activity. You can mail us, like us on Facebook and comment for your query.

4 Comments

  1. J.R.Einhorn June 7, 2016
    • ST June 7, 2016
  2. Abhay February 21, 2017
    • ST February 21, 2017

Add Comment

wordpress hit counter