momo's Blog.

使用快照备份迁移lvm

字数统计: 643阅读时长: 3 min
2022/06/20 Share

前言

云计算时代,很少使用LVM了, 大部分的云商的磁盘也支持热扩容。

基本上没有使用过lvm, 所以记录一下。

操作步骤

使用快照, 备份磁盘

使用云商功能创建即可

创建虚拟机,并将快照挂载到虚拟机实例

如题

恢复LVM

  1. 进入机器以后, 可以看到。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    root@lvm-restore-test:~# df -h
    Filesystem Size Used Avail Use% Mounted on
    udev 2.0G 0 2.0G 0% /dev
    tmpfs 394M 376K 393M 1% /run
    /dev/sda1 30G 1.7G 27G 6% /
    tmpfs 2.0G 0 2.0G 0% /dev/shm
    tmpfs 5.0M 0 5.0M 0% /run/lock
    /dev/sda15 124M 5.9M 118M 5% /boot/efi
    tmpfs 394M 0 394M 0% /run/user/0
  2. 查看硬盘

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
root@lvm-restore-test:~# fdisk -l
Disk /dev/sdb: 2 TiB, 2199023255552 bytes, 4294967296 sectors
Disk model: PersistentDisk
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: C453DB50-FA6A-4A68-8714-A36F54DEE02E

Device Start End Sectors Size Type
/dev/sdb1 2048 4294965247 4294963200 2T Linux LVM


Disk /dev/sda: 30 GiB, 32212254720 bytes, 62914560 sectors
Disk model: PersistentDisk
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 4D4AC699-86B2-C145-B35C-3BF615766DE4

Device Start End Sectors Size Type
/dev/sda1 262144 62912512 62650369 29.9G Linux filesystem
/dev/sda14 2048 8191 6144 3M BIOS boot
/dev/sda15 8192 262143 253952 124M EFI System

Partition table entries are not in disk order.
  1. 查看lvm
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    root@lvm-restore-test:~# pvdisplay
    --- Physical volume ---
    PV Name /dev/sdb1
    VG Name vg0
    PV Size <2.00 TiB / not usable 2.00 MiB
    Allocatable yes (but full)
    PE Size 4.00 MiB
    Total PE 524287
    Free PE 0
    Allocated PE 524287
    PV UUID 1utwKu-hhdD-38fo-dwpQ-vsP4-iFGC-bYP2UD

    root@lvm-restore-test:~# vgdisplay
    --- Volume group ---
    VG Name vg0
    System ID
    Format lvm2
    Metadata Areas 1
    Metadata Sequence No 2
    VG Access read/write
    VG Status resizable
    MAX LV 0
    Cur LV 1
    Open LV 0
    Max PV 0
    Cur PV 1
    Act PV 1
    VG Size <2.00 TiB
    PE Size 4.00 MiB
    Total PE 524287
    Alloc PE / Size 524287 / <2.00 TiB
    Free PE / Size 0 / 0
    VG UUID sJdUeZ-KIfz-YLLg-0p0Y-f23A-rmK0-zZpb8t

    root@lvm-restore-test:~# lvdisplay
    --- Logical volume ---
    LV Path /dev/vg0/data
    LV Name data
    VG Name vg0
    LV UUID nkzPK7-bcG7-Lud0-IUts-l9ER-Gdx6-L9FjGl
    LV Write Access read/write
    LV Creation host, time smash-os-gcpsg-openstreetmap-001, 2022-06-08 12:39:47 +0000
    LV Status NOT available
    LV Size <2.00 TiB
    Current LE 524287
    Segments 1
    Allocation inherit
    Read ahead sectors auto

可以看到未激活的状态

1
2
root@lvm-restore-test:~# lvscan
inactive '/dev/vg0/data' [<2.00 TiB] inherit

激活vg

使用 vgchange -ay 参数激活vg

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
root@lvm-restore-test:~# vgchange -ay vg0
1 logical volume(s) in volume group "vg0" now active
root@lvm-restore-test:~# lvdisplay
--- Logical volume ---
LV Path /dev/vg0/data
LV Name data
VG Name vg0
LV UUID nkzPK7-bcG7-Lud0-IUts-l9ER-Gdx6-L9FjGl
LV Write Access read/write
LV Creation host, time smash-os-gcpsg-openstreetmap-001, 2022-06-08 12:39:47 +0000
LV Status available
# open 0
LV Size <2.00 TiB
Current LE 524287
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 254:0

参考

  1. migrate-lvm-or-volume-group-to-new-linux
  2. cluster_logical_volume_manager
CATALOG
  1. 1. 前言
  2. 2. 操作步骤
    1. 2.1. 使用快照, 备份磁盘
    2. 2.2. 创建虚拟机,并将快照挂载到虚拟机实例
    3. 2.3. 恢复LVM
      1. 2.3.1. 激活vg
  3. 3. 参考