1

I have been using VM linux (RHEL OS) on VMWare Server. As result , I want to attach virtual hard disk from one vm to another. How can I mount this to the new VM ? btw , I am using LVM for both VM linux.

OLD machine :

--- Physical volume ---

PV Name /dev/sdc -> VG Name u01_vg  -> LV Name u01_lv
PV Name /dev/sdd -> VG Name u01_vg  -> LV Name u01_lv

NEW machine :

--- Physical volume ---

PV Name /dev/sdb -> VG Name u01_vg  -> LV Name u01_lv
PV Name /dev/sdc -> VG Name u01_vg  -> LV Name u01_lv

I am thinking a workflow like below. Am I correct ? please correct me if I am wrong.

LVM Export and Import Workflow:

  • Due to use a duplicate volume group name. rename the volume group first on old machine

    • vgrename UUID New_VG_Name
    • vgchange -ay New_VG_Name
  • unmount the file system from OLD Virtual Linux/Unix Server

    • umount /mount-point/
    • vgchange -an New_VG_Name
    • vgexport New_VG_Name
    • when the machine is next shut down, the disk can be unplgged and then connected to its new machine.
  • move a whole volume group to another system

    • pvscan
    • vgimport New_VG_Name
    • vgchange -ay New_VG_Name
    • mkdir /olddata/
    • mount /dev/New_VG_Name/data_lv /olddata/

Thanks,

2
  • looks good to me, I am not sure you can safely vgrename while filesystem is mounted.
    – Archemar
    Oct 4, 2020 at 6:08
  • So what is the procedure for vgrename?
    – Cell-o
    Oct 4, 2020 at 6:22

1 Answer 1

3

In your scenario, the vgexport/vgimport is not really necessary, precisely because you already know the existing VG names in the new machine.

For renaming a VG on the old system, you'll most likely need to unmount and deactivate it first, and since there is no VG name conflict there, you don't have to use the VG UUID instead of the old VG name (although you can if you wish):

umount /mount-point/
vgchange -an Old_VG_Name
vgrename Old_VG_Name New_VG_Name
vgchange -ay New_VG_Name
<edit /etc/fstab to replace Old_VG_Name with New_VG_Name>
mount /mount-point

Before removing the disks:

<edit /etc/fstab to comment out/remove the line for the /mount-point/>
umount /mount-point/
vgchange -an Old_VG_Name   # technically the shutdown procedure would do this too

You could even hot-unplug the disks if you do this after deactivating the VG:

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

This tells the kernel to prepare for the imminent physical disconnection of those devices. (If you are using paravirtualized drivers in a VM, the virtualization host may send a warning message to the driver before hot-removal of a virtual disk, making this step unnecessary.)

Once the disks are moved to a new system, the normal system start-up procedure will in most distributions automatically execute the equivalents of pvscan and vgchange -ay, activating all non-conflicting VGs automatically by default. In that case, you'll only need to create a mount point directory, edit /etc/fstab and mount the volume:

mkdir /olddata
<edit /etc/fstab>
mount /olddata

What is the purpose of vgexport/vgimport then, you might ask? It is for the situation when you don't know if there will be a VG with the same name in the new system or not. When a VG is exported, the VG metadata on the disk is marked effectively "skip me", and so the VG will avoid the automatic activation step at system start-up, and all the LVM management commands will prefer the existing non-exported VG on the new system over the possibly-conflictingly-named new arrival, until the system administrator gets around to renaming & importing it. vgimport removes this mark. It does nothing else.

The above is true for Linux LVM version 2, which has existed since the beginning of the 2.6 kernel series. If you deal with 2.4.xx or older kernels, you might have LVM version 1, for which the vgexport/vgimport commands might have worked differently (I don't remember the details of those any more).

2
  • Wow thanks for your detailed help. btw , mount /dev/New_VG_Name/data_lv /olddata/ or mount /olddata Which of these should I use? Also , I can see mount /dev/New_VG_Name/data_lv /olddata/ or mount /dev/mapper/VG1-LV1. which one is right?
    – Cell-o
    Oct 4, 2020 at 7:07
  • 1
    If you have edited /etc/fstab, you can use just mount /olddata; if you have not done that yet, you need to use the long form. And the LV device name can be expressed as /dev/New_VG_Name/data_lvor /dev/mapper/New_VG_Name-data_lv; the latter is technically the current form, but the former is compatibility syntax for LVM version 1 (and similar to LVM on other unix systems) and it is still supported and often used too.
    – telcoM
    Oct 4, 2020 at 7:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .