0

This is my hard drive at first:

  1. /dev/sda1 100MB for bios_grub
  2. /dev/sda2/ 500MB for /boot
  3. /dev/sda3 800MB as physical volume for LVM2 myvg volume group.

I used parted to delete sda1, and sda2. After that recreated /sda1 (600MB) for /boot. Then used gdisk to update numbering /dev/sda. so now /dev/sda3 becomes /dev/sda2. The problem is that the when I run pvs I still get /dev/sda3 as physical voume for myvg.

How do I update this while keeping the data inside myvg intact?

2

For other people who would like to do the same, here are two recommendations:

  • If you can : Do not reorganize the numbers of your partitions, there is too much risk for a system in production. It does not matter that the numbering is not consecutive.
  • If you really need to do this : First unmount all lvm partitions belonging to the volume group. The physical volume names in pvs will be updated immediately.

In this case you have several solutions :

  • reboot the system once.
  • Disable the volume group, execute partprobe to inform the system about partition change, enable the volume group. (As suggest @rudimeier)
# vgchange -an myvg
# partprobe
# vgchange -ay myvg

Details below :


I reproduced what you did with the same tools. The disk name and size differ, /dev/sdb instead of /dev/sda.

Before removing the first partitions:

# fdisl -l /dev/sdb
[...]
Device       Start      End  Sectors Size Type
/dev/sdb1     2048  4196351  4194304   2G Linux filesystem
/dev/sdb2  4196352  8390655  4194304   2G Linux filesystem
/dev/sdb3  8390656 20971486 12580831   6G Linux LVM

# pvs
  PV         VG   Fmt  Attr PSize PFree
  /dev/sdb3  myvg lvm2 a--  6.00g 5.92g

After the deletion:

# fdisk -l /dev/sdb
[...]
Device       Start      End  Sectors Size Type
/dev/sdb3  8390656 20971486 12580831   6G Linux LVM

After creating a new partition 1:

# fdisk -l /dev/sdb
[...]
Device       Start      End  Sectors Size Type
/dev/sdb1     2048  8390655  8388608   4G Linux filesystem
/dev/sdb3  8390656 20971486 12580831   6G Linux LVM

After reorganizing the numbers (gdisk /dev/sdb + s):

# fdisk -l /dev/sdb
[...]
Device       Start      End  Sectors Size Type
/dev/sdb1     2048  8390655  8388608   4G Linux filesystem
/dev/sdb2  8390656 20971486 12580831   6G Linux LVM

But the pvs command show the wrong number

# pvs
  PV         VG   Fmt  Attr PSize PFree
  /dev/sdb3  myvg lvm2 a--  6.00g 5.92g

In this case LVM or some parts of the kernel always uses the old table.

After the reboot the new partition numbers were correctly taken into account by the system and by lvm.

# pvs
  PV         VG   Fmt  Attr PSize PFree
  /dev/sdb2  myvg lvm2 a--  6.00g 5.92g

I think this is safe for your data, if i'm not mistaken lvm use directly the uuid of disk. These commands are not supposed to change the uuid.

In any case this is certainly safer than changing the numbering of partitions;)

  • 1
    Instead of reboot you could just disable the PV (pvchange -yn /dev/sda3), re-read the partition table (partprobe /dev/sda) and enable the new PV. – rudimeier May 29 '17 at 15:28
  • Thank you for your comment, I think however you want to talk about disabling volume group (vgchange -an myvg) It should also work, I add it in the solution – Maximilien D May 29 '17 at 15:44
  • Ah you are right, there is no pvchange -an. But instead of vgchange -an it may be enough to only disable all the LVs which need /dev/sda3, lvchange -an .... – rudimeier May 29 '17 at 15:57
  • I was stuck because i did not use 'w' command in gdisk console to save the partition table. – biocyberman May 30 '17 at 19:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.