linux逻辑卷管理(LVM)

1. 逻辑卷(LVM)的原理

  LVM(Logical Volume Manager)逻辑卷管理 是在物理磁盘和文件系统的之间添加一个逻辑层,通过对底层物理磁盘的封装,以逻辑卷的方式呈现给上层应用,通过对逻辑卷的操作来管理底层物理磁盘

2. LVM 中的基本术语

 物理存储介质(The physical media): 可以使整个磁盘、磁盘分区、RAID阵列、SAN磁盘,这些设备必须初始化为LVM物理卷,才可以与LVM 结合使用

 物理卷PV(Physical Volume):LVM基本的存储逻辑块,包含了物理介质没有的LVM相关的管理参数

 卷组VG(Volume Group):由一个或多个PV组成

 逻辑卷LV(Logical Volume):LV是建立在VG上,VG可以把部分磁盘空间给LV,也可以把全部的磁盘空间给LV,可以在LV上创建文件系统

 PE(Physical extent):PV可以分配的最小存储单位

 LE(Logical extent):LV中可以分配的最小存储单位,在同一个卷组中,LE与PE大小相同

lvm常用的命令
功能          PV管理命令     VG管理命令      LV管理命令
scan 扫描       pvscan        vgscan        lvscan
create 创建      pvcreate    vgcreate       lvcreate
display显示      pvdisplay   vgdisplay     lvdisplay
remove 移除      pvremove      vgremove       lvremove
extend 扩展                vgextend       lvextend
reduce减少                 vgreduce       lvreduce
查看卷名    简单对应卷信息的查看    扫描相关的所有的对应卷    详细对应卷信息的查看
物理卷        pvs            pvscan           pvdisplay
卷组         vgs            vgscan           vgdisplay
逻辑卷        lvs            lvscan           lvdisplay

 

3.LVM的优点

 1.使用VG对多个物理磁盘空间进行整合,变成一个大磁盘

 2.使用LVM可以跨越多个磁盘分区,动态的调整逻辑卷的大小,扩容、缩减、删除

 3.可以调整基于LVM上创建的文件系统的大小

 4.可以创建快照,来备份文件系统

4.创建LVM

  步骤:

  创建PV——>创建VG——>创建LV——>格式化LV成文件系统——>挂载LV

  先通过fdisk切割出磁盘分区

查看系统上的磁盘
[root@test01 Desktop]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda
8:0 0 20G 0 disk ├─sda1 8:1 0 300M 0 part /boot ├─sda2 8:2 0 14.7G 0 part │ └─rhel-rootlv 253:0 0 14.7G 0 lvm / ├─sda3 8:3 0 2G 0 part [SWAP] ├─sda4 8:4 0 1K 0 part └─sda5 8:5 0 300M 0 part ==>这是我新建的一个分区

 创建PV:

创建PV:
[root@test01 Desktop]# pvcreate /dev/sda5 Physical volume "/dev/sda5" successfully created
扫描PV [root@test01 Desktop]# pvscan PV
/dev/sda2 VG rhel lvm2 [14.64 GiB / 0 free] PV /dev/sda5 lvm2 [300.00 MiB] 显示PV的详细信息,后面不接PV名,会显示所有的PV信息 [root@test01 Desktop]# pvdisplay /dev/sda5 "/dev/sda5" is a new physical volume of "300.00 MiB" --- NEW Physical volume --- PV Name /dev/sda5 VG Name PV Size 300.00 MiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID YQbqqb-V3Wl-ot8s-SUR5-rsQL-oqdw-7fdzHa

创建VG:

创建VG
[root@test01 Desktop]# vgcreate -s 16m testvg /dev/sda5 Volume group "testvg" successfully created
-s:是为了指定VG的PE的大小为16m,testvg是VG的名字,/dev/sda5是成为PV的磁盘分区设备名,多个磁盘可以写成/dev/sda{5,6,7}; 扫描VG [root@test01 Desktop]# vgscan Reading all physical volumes. This may take a
while... Found volume group "rhel" using metadata type lvm2 Found volume group "testvg" using metadata type lvm2 显示VG的详细信息,若后面不接VG名,会显示系统上所有VG的信息 [root@test01 Desktop]# vgdisplay testvg --- Volume group --- VG Name testvg System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 1 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 1 Act PV 1 VG Size 288.00 MiB PE Size 16.00 MiB ==>PE大小:16m Total PE 18 Alloc PE / Size 0 / 0 Free PE / Size 18 / 288.00 MiB VG UUID eaUhl0-LvkR-Ebou-BXHa-ZnIb-DEza-qFZYbO

创建LV:

创建LV:
方法一:-L:指定LV的大小为200M,-n:指定LV的名字为testlv ,最后指定的VG的名字
[root@test01 Desktop]# lvcreate -L 200M -n testlv testvg Rounding up size to full physical extent 208.00 MiB Logical volume "testlv" created 方法二:-l(小写的L):通过指定PE的个数来指定LV的大小,上面我们的设定PE是16M,这里指定10个单位的PE,则LV大小是160M [root@test01 Desktop]# lvcreate -l 10 -n testlv testvg 扫描LV [root@test01 Desktop]# lvscan ACTIVE '/dev/rhel/rootlv' [14.64 GiB] inherit ACTIVE '/dev/testvg/testlv' [208.00 MiB] inherit 显示LV的详细信息,后面接的LV名得用绝对路径表示,不然报错找不到 [root@test01 Desktop]# lvdisplay testlv Volume group "testlv" not found Skipping volume group testlv [root@test01 Desktop]# lvdisplay /dev/testvg/testlv --- Logical volume --- LV Path /dev/testvg/testlv LV Name testlv VG Name testvg LV UUID VpC2SC-qpos-mCWn-F44a-RE6e-XVcu-LUK1j2 LV Write Access read/write LV Creation host, time test01, 2018-12-17 14:54:58 +0800 LV Status available # open 0 LV Size 208.00 MiB Current LE 13 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:1

格式化逻辑卷

格式化为ext4文件系统,也可以使用mkfs -t ext4
[root@test01 Desktop]# mkfs.ext4 /dev/testvg/testlv mke2fs 1.42.9 (28-Dec-2013) Filesystem label= OS type: Linux Block size=1024 (log=0) Fragment size=1024 (log=0) Stride=0 blocks, Stripe width=0 blocks 53248 inodes, 212992 blocks 10649 blocks (5.00%) reserved for the super user First data block=1 Maximum filesystem blocks=33816576 26 block groups 8192 blocks per group, 8192 fragments per group 2048 inodes per group Superblock backups stored on blocks: 8193, 24577, 40961, 57345, 73729, 204801 Allocating group tables: done Writing inode tables: done Creating journal (4096 blocks): done Writing superblocks and filesystem accounting information: done

挂载

[root@test01 Desktop]# mkdir /mnt/test
[root@test01 Desktop]# mount /dev/testvg/testlv /mnt/test
[root@test01 Desktop]# df -Th
Filesystem                Type      Size  Used Avail Use% Mounted on
/dev/mapper/rhel-rootlv   xfs        15G  4.3G   11G  30% /
devtmpfs                  devtmpfs  481M     0  481M   0% /dev
tmpfs                     tmpfs     490M  140K  490M   1% /dev/shm
tmpfs                     tmpfs     490M  7.1M  483M   2% /run
tmpfs                     tmpfs     490M     0  490M   0% /sys/fs/cgroup
/dev/sr0                  iso9660   3.5G  3.5G     0 100% /mnt/cdrom
/dev/sda1                 xfs       297M  109M  189M  37% /boot
/dev/mapper/testvg-testlv ext4      198M  1.8M  182M   1% /mnt/test
永久挂载,编辑/etc/fstab文件最后一行编辑
[root@test01 Desktop]# vim /etc/fstab
/dev/testvg/testlv /mnt/test ext4 defaults 0 0

5.LVM扩容,文件系统扩容,可以在线扩容

  步骤:

    1.vgdispaly查看VG的磁盘空间————>2.空间足够,直接 lvresize 增加LV空间容量————>3.调整文件系统大小,ext文件系统使用 resize2fs,xfs文件系统使用xfs_growfs

    若空间不够,则需要1.先创建新的PV——>2.VG扩容,使用 vgextend ——>3.再给LV扩容——>4.再调整文件系统

  先通过vgdisplay 命令查看该VG是否还有空余的空间,若剩余空间可以满足需求则直接调整LV的大小,再调整文件系统的大小,如若无法满足则需要新建一个PV,加入到VG中

[root@test01 Desktop]# vgdisplay testvg 
  --- Volume group ---
  VG Name               testvg
  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               288.00 MiB
  PE Size               16.00 MiB
  Total PE              18
  Alloc PE / Size       13 / 208.00 MiB
  Free  PE / Size       5 / 80.00 MiB  ==> 还有5个PE,80M的空间
  VG UUID               eaUhl0-LvkR-Ebou-BXHa-ZnIb-DEza-qFZYbO

第一种情况:通过VG剩余的空间扩容

调整LVM的大小为250M,-L:250M
[root@test01 Desktop]# lvresize -L 250M /dev/testvg/testlv Rounding size to boundary between physical extents: 256.00 MiB Extending logical volume testlv to 256.00 MiB Logical volume testlv successfully resized [root@test01 Desktop]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/rhel-rootlv 15G 4.3G 11G 30% / devtmpfs 481M 0 481M 0% /dev tmpfs 490M 140K 490M 1% /dev/shm tmpfs 490M 7.1M 483M 2% /run tmpfs 490M 0 490M 0% /sys/fs/cgroup /dev/sr0 3.5G 3.5G 0 100% /mnt/cdrom /dev/sda1 297M 109M 189M 37% /boot /dev/mapper/testvg-testlv 198M 1.8M 182M 1% /mnt/test ==>文件系统并未变化
该调整文件系统大小 [root@test01 Desktop]# resize2fs
/dev/testvg/testlv
resize2fs
1.42.9 (28-Dec-2013) Filesystem at /dev/testvg/testlv is mounted on /mnt/test; on-line resizing required old_desc_blocks = 2, new_desc_blocks = 2 The filesystem on /dev/testvg/testlv is now 262144 blocks long. [root@test01 Desktop]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/rhel-rootlv 15G 4.3G 11G 30% / devtmpfs 481M 0 481M 0% /dev tmpfs 490M 140K 490M 1% /dev/shm tmpfs 490M 7.1M 483M 2% /run tmpfs 490M 0 490M 0% /sys/fs/cgroup /dev/sr0 3.5G 3.5G 0 100% /mnt/cdrom /dev/sda1 297M 109M 189M 37% /boot /dev/mapper/testvg-testlv 244M 2.1M 226M 1% /mnt/test ==>文件系统大小已变更 [root@test01 Desktop]# lvscan ACTIVE '/dev/rhel/rootlv' [14.64 GiB] inherit ACTIVE '/dev/testvg/testlv' [256.00 MiB] inherit

第二种情况:新建一个PV加入到VG中

[root@test01 Desktop]# lsblk
NAME              MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                 8:0    0   20G  0 disk 
├─sda1              8:1    0  300M  0 part /boot
├─sda2              8:2    0 14.7G  0 part 
│ └─rhel-rootlv   253:0    0 14.7G  0 lvm  /
├─sda3              8:3    0    2G  0 part [SWAP]
├─sda4              8:4    0    1K  0 part 
├─sda5              8:5    0  300M  0 part 
│ └─testvg-testlv 253:1    0  256M  0 lvm  /mnt/test
└─sda6              8:6    0  300M  0 part  ==>新加的分区
新建一个PV
[root@test01 Desktop]# pvcreate /dev/sda6 Physical volume "/dev/sda6" successfully created
把新建的PV加入到VG中 [root@test01 Desktop]# vgextend testvg
/dev/sda6 Volume group "testvg" successfully extended [root@test01 Desktop]# vgs testvg VG #PV #LV #SN Attr VSize VFree testvg 2 1 0 wz--n- 576.00m 320.00m [root@test01 Desktop]# vgdisplay testvg --- Volume group --- VG Name testvg System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 4 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 1 Max PV 0 Cur PV 2 Act PV 2 VG Size 576.00 MiB PE Size 16.00 MiB Total PE 36 Alloc PE / Size 16 / 256.00 MiB Free PE / Size 20 / 320.00 MiB ==>剩余的空间为320M VG UUID eaUhl0-LvkR-Ebou-BXHa-ZnIb-DEza-qFZYbO
LV扩容
[root@test01 Desktop]# lvresize -L 480M /dev/testvg/testlv Extending logical volume testlv to 480.00 MiB Logical volume testlv successfully resized [root@test01 Desktop]# lvscan ACTIVE '/dev/rhel/rootlv' [14.64 GiB] inherit ACTIVE '/dev/testvg/testlv' [480.00 MiB] inherit

调整文件系统大小 [root@test01 Desktop]# resize2fs
/dev/testvg/testlv resize2fs 1.42.9 (28-Dec-2013) Filesystem at /dev/testvg/testlv is mounted on /mnt/test; on-line resizing required old_desc_blocks = 2, new_desc_blocks = 4 The filesystem on /dev/testvg/testlv is now 491520 blocks long. [root@test01 Desktop]# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/rhel-rootlv xfs 15G 4.3G 11G 30% / devtmpfs devtmpfs 481M 0 481M 0% /dev tmpfs tmpfs 490M 140K 490M 1% /dev/shm tmpfs tmpfs 490M 7.1M 483M 2% /run tmpfs tmpfs 490M 0 490M 0% /sys/fs/cgroup /dev/sr0 iso9660 3.5G 3.5G 0 100% /mnt/cdrom /dev/sda1 xfs 297M 109M 189M 37% /boot /dev/mapper/testvg-testlv ext4 461M 2.3M 434M 1% /mnt/test ==>文件系统再一次变大

若是XFS文件系统,调整文件系统的命令则是

[root@test01 Desktop]# xfs_growfs /dev/testvg/testlv

6.LVM缩减,不支持在线缩减,必须先卸载文件系统

  步骤:

  卸载文件系统——>(e2fsck -f )检查文件系统——>调整文件系统大小——>调整LVM——>挂载文件系统

  卸载文件系统

[root@test01 Desktop]# umount /mnt/test/
[root@test01 Desktop]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/rhel-rootlv   15G  4.3G   11G  30% /
devtmpfs                 481M     0  481M   0% /dev
tmpfs                    490M  140K  490M   1% /dev/shm
tmpfs                    490M  7.1M  483M   2% /run
tmpfs                    490M     0  490M   0% /sys/fs/cgroup
/dev/sr0                 3.5G  3.5G     0 100% /mnt/cdrom
/dev/sda1                297M  109M  189M  37% /boot

  变更文件系统大小

[root@test01 Desktop]# resize2fs /dev/testvg/testlv 160M
resize2fs 1.42.9 (28-Dec-2013)
Please run 'e2fsck -f /dev/testvg/testlv' first.
得先强制检查一下文件系统,再调整文件系统大小
[root@test01 Desktop]# e2fsck -f /dev/testvg/testlv 
e2fsck 1.42.9 (28-Dec-2013)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/testvg/testlv: 11/122880 files (0.0% non-contiguous), 21922/491520 blocks
调整文件系统大小为160M [root@test01 Desktop]# resize2fs
/dev/testvg/testlv 160M resize2fs 1.42.9 (28-Dec-2013) Resizing the filesystem on /dev/testvg/testlv to 163840 (1k) blocks. The filesystem on /dev/testvg/testlv is now 163840 blocks long.

缩减LV

调整LVM的大小为160
[root@test01 Desktop]# lvresize -L 160M /dev/testvg/testlv WARNING: Reducing active logical volume to 160.00 MiB THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce testlv? [y/n]: y Reducing logical volume testlv to 160.00 MiB Logical volume testlv successfully resized [root@test01 Desktop]# lvscan ACTIVE '/dev/rhel/rootlv' [14.64 GiB] inherit ACTIVE '/dev/testvg/testlv' [160.00 MiB] inherit ==>testvg大小变为160M [root@test01 Desktop]# mount /dev/testvg/testlv /mnt/test [root@test01 Desktop]# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/rhel-rootlv xfs 15G 4.3G 11G 30% / devtmpfs devtmpfs 481M 0 481M 0% /dev tmpfs tmpfs 490M 140K 490M 1% /dev/shm tmpfs tmpfs 490M 7.1M 483M 2% /run tmpfs tmpfs 490M 0 490M 0% /sys/fs/cgroup /dev/sr0 iso9660 3.5G 3.5G 0 100% /mnt/cdrom /dev/sda1 xfs 297M 109M 189M 37% /boot /dev/mapper/testvg-testlv ext4 151M 1.6M 140M 2% /mnt/test ==>文件系统也变成160M了

 7.LVM系统快照

  快照就是把当前的系统信息记录下来,快照区LV与被快照区的LV必须在同一个VG上,当建立快照区LV时,系统会预留一个区域作为数据存放处,此时快照区无任何数据,快照区与系统区共享所有的PE数据,这时快照区的内容与文件系统是一样的;当系统区的数据有变化时,快照区则会备份变更之前的数据,其他未改变的数据还是处于共享状态,因此快照占用的容量很少

  若快照区给的空间已容纳不了变更的数据时,快照会失效

创建文件系统/dev/testvg/testlv的快照

先查看将被快照的lv的大小,便于设定快照区的大小
[root@test01 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/rhel-rootlv 15G 4.3G 11G 30% / devtmpfs 905M 0 905M 0% /dev tmpfs 914M 140K 914M 1% /dev/shm tmpfs 914M 8.9M 905M 1% /run tmpfs 914M 0 914M 0% /sys/fs/cgroup /dev/sr0 3.5G 3.5G 0 100% /mnt/cdrom /dev/mapper/testvg-testlv 151M 9.1M 132M 7% /mnt/test ==>才9.1M /dev/sda1 297M 109M 189M 37% /boot [root@test01 ~]# ls /mnt/test/ grub2 lost+found passwd shadow 创建快照 [root@test01 ~]# lvcreate -l 5 -s -n testlv_backup /dev/testvg/testlv Logical volume "testlv_backup" created
-l:给快照区的PE的个数
-s:就是代表快照的意思
-n:快照的名字
/dev/testvg/testlv:被快照的LV的名字

查看快照信息

[root@test01 ~]# lvdisplay /dev/testvg/testlv_backup 
  --- Logical volume ---
  LV Path                /dev/testvg/testlv_backup
  LV Name                testlv_backup
  VG Name                testvg
  LV UUID                1WuR1d-vpav-YQ9r-X8Rr-dpjW-ohTd-ffrebn
  LV Write Access        read/write
  LV Creation host, time test01, 2018-12-18 17:02:52 +0800
  LV snapshot status     active destination for testlv
  LV Status              available
  # open                 0
  LV Size                160.00 MiB ==>被快照的原LV的容量大小
  Current LE             10
  COW-table size         80.00 MiB  ==>快照区的容量
  COW-table LE           5      ==>快照区的PE个数
  Allocated to snapshot  0.01%   ==>快照的使用率,0.0.1%这是未使用
  Snapshot chunk size    4.00 KiB
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:2

挂载这个快照看下内容是不是和原LV一样

[root@test01 ~]# mkdir /mnt/lvback
[root@test01 ~]# mount /dev/testvg/testlv_backup /mnt/lvback/
[root@test01 ~]# ls /mnt/lvback/
grub2  lost+found  passwd  shadow
[root@test01 ~]# ls /mnt/test/
grub2  lost+found  passwd  shadow
[root@test01 ~]# ll /mnt/test/
total 21
drwxr-xr-x. 6 root root  1024 Dec  5 15:25 grub2
drwx------. 2 root root 12288 Dec 17 15:12 lost+found
-rw-r--r--. 1 root root  2100 Dec 18 16:58 passwd
----------. 1 root root  1224 Dec 18 16:58 shadow
[root@test01 ~]# ll /mnt/lvback/
total 21
drwxr-xr-x. 6 root root  1024 Dec  5 15:25 grub2
drwx------. 2 root root 12288 Dec 17 15:12 lost+found
-rw-r--r--. 1 root root  2100 Dec 18 16:58 passwd
----------. 1 root root  1224 Dec 18 16:58 shadow
大小、权限、属性完全一样
进入testlv的挂载目录,删除里面的grub2目录
[root@test01 ~]# cd /mnt/test/ [root@test01 test]# ls grub2 lost+found passwd shadow [root@test01 test]# rm -rf grub2

可见grub2目录已被删除 [root@test01 test]# ls lost
+found passwd shadow
但是快照LV中依然存在grub2目录,这就是快照的功能,保存被更改数据的原数据 [root@test01 test]# ll ..
/lvback/ total 21 drwxr-xr-x. 6 root root 1024 Dec 5 15:25 grub2 drwx------. 2 root root 12288 Dec 17 15:12 lost+found -rw-r--r--. 1 root root 2100 Dec 18 16:58 passwd ----------. 1 root root 1224 Dec 18 16:58 shadow [root@test01 test]# lvdisplay /dev/testvg/testlv_backup --- Logical volume --- LV Path /dev/testvg/testlv_backup LV Name testlv_backup VG Name testvg LV UUID 1WuR1d-vpav-YQ9r-X8Rr-dpjW-ohTd-ffrebn LV Write Access read/write LV Creation host, time test01, 2018-12-18 17:02:52 +0800 LV snapshot status active destination for testlv LV Status available # open 1 LV Size 160.00 MiB Current LE 10 COW-table size 80.00 MiB COW-table LE 5 Allocated to snapshot 0.15% ==>快照区的使用空间变化了,从之前的0.0.1%到0.15%,说明被删除的文件已被移动给到快照区了 Snapshot chunk size 4.00 KiB Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:2

 8. 利用快照备份数据,恢复数据

备份数据

创建备份目录
[root@test01 lvback]# mkdri /backup
进入快照LV挂载目录,备份所有数据 [root@test01 Desktop]# cd
/mnt/lvback/ [root@test01 lvback]# ls grub2 lost+found passwd shadow [root@test01 lvback]# tar -jcvf /backup/testlv.tar.bz2 * [root@test01 lvback]# ll /backup/ total 2536 -rw-r--r--. 1 root root 2594327 Dec 19 11:09 testlv.tar.bz2

恢复数据

卸载需恢复的文件系统
[root@test01 ~]# umount /mnt/test/
格式化
[root@test01 ~]# mkfs.ext4 /dev/testvg/testlv mke2fs 1.42.9 (28-Dec-2013) Filesystem label= OS type: Linux Block size=1024 (log=0) Fragment size=1024 (log=0) Stride=0 blocks, Stripe width=0 blocks 40960 inodes, 163840 blocks 8192 blocks (5.00%) reserved for the super user First data block=1 Maximum filesystem blocks=33816576 20 block groups 8192 blocks per group, 8192 fragments per group 2048 inodes per group Superblock backups stored on blocks: 8193, 24577, 40961, 57345, 73729 Allocating group tables: done Writing inode tables: done Creating journal (4096 blocks): done Writing superblocks and filesystem accounting information: done
重新挂载 [root@test01
~]# mount /dev/testvg/testlv /mnt/test/ [root@test01 ~]# cd /mnt/test/ [root@test01 test]# ls lost+found
把备份的数据解压到挂载目录下,可见数据已完全恢复,之前被删除的grub2目录也恢复了 [root@test01 test]# tar
-jxvf /backup/testlv.tar.bz2 -C . [root@test01 test]# ls grub2 lost+found passwd shadow

9.移除LVM

  步骤:

    卸载文件系统——>移除LV——>使VG不具备Active标志——>移除VG——>移除PV——>修改磁盘分区ID号

卸载文件系统
[root@test01 ~]# umount /mnt/test/
移除快照LV [root@test01 ~]# lvremove /dev/testvg/testlv_backup Do you really want to remove active logical volume testlv_backup? [y/n]: y Logical volume "testlv_backup" successfully removed
移除testlv [root@test01
~]# lvremove /dev/testvg/testlv Do you really want to remove active logical volume testlv? [y/n]: y Logical volume "testlv" successfully removed
让testvg不具有Active标志 [root@test01
~]# vgchange -a n testvg 0 logical volume(s) in volume group "testvg" now active
移除testvg [root@test01
~]# vgremove testvg Volume group "testvg" successfully removed
移除pv [root@test01
~]# pvremove /dev/sda{5,6} Labels on physical volume "/dev/sda5" successfully wiped Labels on physical volume "/dev/sda6" successfully wiped
修改磁盘分区ID号,使用t参数 [root@test01
~]# fdisk /dev/sda Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): t Partition number (1-6, default 6): Hex code (type L to list all codes): 83 Changed type of partition 'Linux LVM' to 'Linux' Command (m for help): t Partition number (1-6, default 6): 5 Hex code (type L to list all codes): 83 Changed type of partition 'Linux LVM' to 'Linux'

 

posted @ 2018-12-19 14:48  筱筱的小孩  阅读(616)  评论(0编辑  收藏  举报