Monday 18 November 2013

LVM export and import: Move a VG to another machine or group

vgexport & vgimport are not necessary to move drives from one system from another.

It is an admin policy tool to prevent access to volumes in the time it takes to move them.

 Exporting Volume Group

1. unmount the file system

First make sure no users are accessing files on active volume, then unmount it

# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              25G  4.9G   19G  21% /
tmpfs                 593M     0  593M   0% /dev/shm
/dev/mapper/vg--ctechz-lvm--ctechz
                      664M  542M   90M  86% /lvm-ctechz

# umount /lvm-ctechz/

# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              25G  4.9G   19G  21% /
tmpfs                 593M     0  593M   0% /dev/shm

2. Mark the Volume Group inactive

Marks the volume group inactive removes it from the kernal and prevents any further activity on it.

# vgchange -an vg-ctechz(VG name)
0 logical volume(s) in volume group "vg-ctechz" now active

3. Export the VG

It is now necessor to export the Volume Group, this prevents it from being accessed on the "old"host system and prepares it to be removed.

# vgexport vg-ctechz(vg name)
  Volume group "vg-ctechz" successfully exported

when the machine is next shut down, the disk can be unplgged and then connected to its new machine.

 Import the Volume Group(VG)

When plugged into new system it becomes /dev/sdb or what ever depends so an initial pvscan shows:

1. # pvscan
PV /dev/sda3 is in exported VG vg-ctechz[580.00MB/0 free]
PV /dev/sda4 is in exported VG vg-ctechz[484.00MB/312.00MB free]
PV /dev/sda5 is in exported VG vg-ctechz[288.00MB/288.00MB free]
 Total: 3 [1.32 GB] / in use: 3 [1.32 GB] / in no VG: 0[0]

2. We can now import the Volume Group (which also activates it) and mount the fle system.

If you are importing on an LVM2 system run,

# vgimport vg-ctechz
Volume group "vg-ctechz" successfully imported

If you are importing on an LVM1 system, add the pvs that needed to import

# vgimport vg-ctechz /dev/sda3 /dev/sda4 /dev/sda5

3. Activate the Volume Group

You must activate the volume group before you can access it

# vgchange -ay vg-ctechz
1 logical volume(s) in volume group "vg-ctechz" now active

Now mount the file system
# mount /dev/vg-ctechz/lvm-ctechz /LVM-import/

# mount
/dev/sda1 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
/dev/mapper/vg--ctechz-lvm--ctechz on /LVM-import type ext3 (rw)
[root@localhost ~]#

[root@localhost ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              25G  4.9G   19G  21% /
tmpfs                 593M     0  593M   0% /dev/shm
/dev/mapper/vg--ctechz-lvm--ctechz
                      664M  542M   90M  86% /LVM-import

 Using Vgscan

# pvs

  PV         VG        Fmt  Attr PSize   PFree
  /dev/sda3  vg-ctechz lvm2 ax-  580.00M 0
  /dev/sda4  vg-ctechz lvm2 ax-  484.00M 312.00M
  /dev/sda5  vg-ctechz lvm2 ax-  288.00M 288.00M

# pvs shows in which all disk attached to vg

# vgscan
Reading all physical volumes.  This may take a while...
Found exported volume group "vg-ctechz" using metadata type lvm2

# vgimport vg-ctechz
Volume group "vg-ctechz" successfully imported

# vgchange -ay vg-ctechz
1 logical volume(s) in volume group "vg-ctechz" now active

# mkdir /LVM-vgscan
# mount /dev/vg-ctechz/lvm-ctechz /LVM-vgscan

# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              25G  4.9G   19G  21% /
tmpfs                 593M     0  593M   0% /dev/shm
/dev/mapper/vg--ctechz-lvm--ctechz
                      664M  542M   90M  86% /LVM-vgscan

# mount
/dev/sda1 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
/dev/mapper/vg--ctechz-lvm--ctechz on /LVM-vgscan type ext3 (rw)

VG Scan is using when we are not exporting the vg. ie, first umount the Logical Volume and take the disk and attach it to some other disk, and then do the # vgscan

it will detect the volume group from the disk and mount it in the new system.

1 comment: