掛載已有資料的LVM磁碟

ippondo發表於2024-09-11

客戶的centos虛擬機器無法進入系統,但裡面的資料很重要,所以新建一個centos虛擬機器來掛載故障虛擬機器的lvm磁碟

1.新建虛擬機器後先開機進系統,然後再掛載舊磁碟

2.用fdisk -l 檢視磁碟情況,能識別到舊磁碟sdb

[root@localhost ~]# fdisk -l

Disk /dev/sda: 536.9 GB, 536870912000 bytes, 1048576000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000c5f9d

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200  1048575999   523238400   8e  Linux LVM

Disk /dev/mapper/centos-root: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-swap: 8455 MB, 8455716864 bytes, 16515072 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-home: 473.6 GB, 473645973504 bytes, 925089792 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/sdb: 536.9 GB, 536870912000 bytes, 1048576000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000b090b

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *        2048     2099199     1048576   83  Linux
/dev/sdb2         2099200  1048575999   523238400   8e  Linux LVM

3.掃出sdb上的vg卷,發現新系統的VG卷和舊磁碟的VG卷是同名的

[root@localhost ~]# vgscan
  Reading volume groups from cache.
  Found volume group "centos" using metadata type lvm2
  Found volume group "centos" using metadata type lvm2

4.vgdisplay檢視vg uuid,因為VG卷名相同,所以只能用VG UUID來更改卷名,隨意更改一個vg卷名,以作區分

[root@localhost ~]# vgdisplay
  --- Volume group ---
  VG Name               centos
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <499.00 GiB
  PE Size               4.00 MiB
  Total PE              127743
  Alloc PE / Size       127742 / 498.99 GiB
  Free  PE / Size       1 / 4.00 MiB
  VG UUID               dEgXW8-PsYd-1t6H-JNu5-sgcg-2K3l-EwXMtc

  --- Volume group ---
  VG Name               centos
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <499.00 GiB
  PE Size               4.00 MiB
  Total PE              127743
  Alloc PE / Size       127742 / 498.99 GiB
  Free  PE / Size       1 / 4.00 MiB
  VG UUID               YIk6Ds-MsxE-mwek-1x3S-uzdT-lxUo-VFxnGs

[root@localhost ~]# vgrename YIk6Ds-MsxE-mwek-1x3S-uzdT-lxUo-VFxnGs vg01
  Processing VG centos because of matching UUID YIk6Ds-MsxE-mwek-1x3S-uzdT-lxUo-VFxnGs
  Volume group "YIk6Ds-MsxE-mwek-1x3S-uzdT-lxUo-VFxnGs" successfully renamed to "vg01"

5.掃出未啟用的那個lvm,並啟用,可以看到我剛才改的卷是新系統的卷,所以我現在需要啟用舊磁碟上的卷

[root@localhost ~]# lvscan
  inactive          '/dev/centos/swap' [<7.88 GiB] inherit
  inactive          '/dev/centos/home' [<441.12 GiB] inherit
  inactive          '/dev/centos/root' [50.00 GiB] inherit
  ACTIVE            '/dev/vg01/swap' [<7.88 GiB] inherit
  ACTIVE            '/dev/vg01/home' [<441.12 GiB] inherit
  ACTIVE            '/dev/vg01/root' [50.00 GiB] inherit
  
[root@localhost ~]# vgchange -ay /dev/centos
  3 logical volume(s) in volume group "centos" now active

6.新建一個掛載點並掛載舊磁碟的卷,讓軟體方copy資料,根據網上的資料,需要掛載的是、/dev/centos/root這個目錄,據說掛載home會有問題

[root@localhost ~]# mkdir /mnt/olddisk

[root@localhost ~]# mount /dev/centos/root /mnt/olddisk

相關文章