linux邏輯卷管理(LVM)

1. 邏輯卷(LVM)的原理node

  LVM(Logical Volume Manager)邏輯卷管理 是在物理磁盤和文件系統的之間添加一個邏輯層,經過對底層物理磁盤的封裝,以邏輯卷的方式呈現給上層應用,經過對邏輯卷的操做來管理底層物理磁盤linux

2. LVM 中的基本術語vim

 物理存儲介質(The physical media): 可使整個磁盤、磁盤分區、RAID陣列、SAN磁盤,這些設備必須初始化爲LVM物理卷,才能夠與LVM 結合使用app

 物理卷PV(Physical Volume):LVM基本的存儲邏輯塊,包含了物理介質沒有的LVM相關的管理參數ide

 卷組VG(Volume Group):由一個或多個PV組成ui

 邏輯卷LV(Logical Volume):LV是創建在VG上,VG能夠把部分磁盤空間給LV,也能夠把所有的磁盤空間給LV,能夠在LV上建立文件系統spa

 PE(Physical extent):PV能夠分配的最小存儲單位code

 LE(Logical extent):LV中能夠分配的最小存儲單位,在同一個卷組中,LE與PE大小相同orm

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的優勢blog

 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'
相關文章
相關標籤/搜索