It is quite easy to move a whole volume group to another system if, for example, a user department acquires a new server. To do this we use the vgexport and vgimport commands.
Unmount the file system
Mark the volume group inactive
Export the volume group
Import the volume group
Activate the volume group
Mount the file system
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--nagavg-lvm--naga 664M 542M 90M 86% /lvm-naga
# umount /lvm-naga
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-nagavg(VG name)
logical volume(s) in volume group "vg-naga" 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-nagavg(vg name)
Volume group "vg-nagavg" 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-nagavg[580.00MB/0 free]
PV /dev/sda4 is in exported VG vg-nagavg[484.00MB/312.00MB free]
PV /dev/sda5 is in exported VG vg-nagavg[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-nagavg
Volume group "vg-nagavg" successfully imported
If you are importing on an LVM1 system, add the pvs that needed to import
# vgimport vg-nagavg/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-nagavg
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--nagavg-lvm--naga on /LVM-import type ext3 (rw)
[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--nagavg-lvm--naga 664M 542M 90M 86% /LVM-import
Using Vgscan
# pvs
PV VG Fmt Attr PSize PFree
/dev/sda3 vg-nagavg lvm2 ax- 580.00M 0
/dev/sda4 vg-nagavg lvm2 ax- 484.00M 312.00M
/dev/sda5 vg-nagavg 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-nagavg" using metadata type lvm2
# vgimport vg-naagavg
Volume group "vg-nagavg" successfully imported
# vgchange -ay vg-nagavg
1 logical volume(s) in volume group "vg-nagavg" 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--naga-lvm--nagavg 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--nagavg-lvm--naga 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.
Wednesday, June 15, 2016
LVM export and import: How to move a VG to another Machine or Group
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment