8月11日上課 邏輯卷管理

1、邏輯卷簡要說明

將設(shè)備指定為物理卷
用一個或者多個物理卷來創(chuàng)建一個卷組
物理卷是用固定大小的物理區(qū)域(Physical Extent沸久,PE)來定義的
在物理卷上創(chuàng)建的邏輯卷是由物理區(qū)域(PE)組成
可以在邏輯卷上創(chuàng)建文件系統(tǒng)


Paste_Image.png

2、創(chuàng)建邏輯卷

[root@centos7 ~]#pvcreate /dev/sdb /dev/sdc1   ---創(chuàng)建物理卷
  Physical volume "/dev/sdb" successfully created.
  Physical volume "/dev/sdc1" successfully created.
[root@centos7 ~]#pvs  ---查看
  PV         VG Fmt  Attr PSize  PFree 
  /dev/sdb      lvm2 ---  20.00g 20.00g
  /dev/sdc1     lvm2 ---  15.00g 15.00g
[root@centos7 ~]#pvdisplay  ---詳細(xì)查看
  "/dev/sdb" is a new physical volume of "20.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb
  VG Name               
  PV Size               20.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               72dJR7-GCfL-GOHH-Tg9a-IIbl-EgTD-YLrRGz
  "/dev/sdc1" is a new physical volume of "15.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdc1
  VG Name               
  PV Size               15.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               j8i7QQ-sSR2-bsJn-UlJj-a1jY-Ubum-KRYgWx
[root@centos7 ~]#vgcreate vg0 /dev/sd{b,c1} ----創(chuàng)建卷組,可以用-s選項指定PE的大小
  Volume group "vg0" successfully created
[root@centos7 ~]#pvdisplay  ---創(chuàng)建完卷組后再來看物理卷
  --- Physical volume ---
  PV Name               /dev/sdb
  VG Name               vg0   ---卷組名
  PV Size               20.00 GiB / not usable 4.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB  ---PE大小
  Total PE              5119  ---PE個數(shù)邏輯卷蜻懦,分邏輯卷時是把PE分給
  Free PE               5119
  Allocated PE          0
  PV UUID               72dJR7-GCfL-GOHH-Tg9a-IIbl-EgTD-YLrRGz
  --- Physical volume ---
  PV Name               /dev/sdc1
  VG Name               vg0
  PV Size               15.00 GiB / not usable 4.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              3839
  Free PE               3839
  Allocated PE          0
  PV UUID               j8i7QQ-sSR2-bsJn-UlJj-a1jY-Ubum-KRYgWx
[root@centos7 ~]#vgs  ---查看卷組
  VG  #PV #LV #SN Attr   VSize  VFree 
  vg0   2   0   0 wz--n- 34.99g 34.99g
[root@centos7 ~]#vgdisplay ---詳細(xì)查看
  --- Volume group ---
  VG Name               vg0
  System ID             
  Format                lvm2
  Metadata Areas        2
  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                2
  Act PV                2
  VG Size               34.99 GiB
  PE Size               4.00 MiB
  Total PE              8958
  Alloc PE / Size       0 / 0   
  Free  PE / Size       8958 / 34.99 GiB
  VG UUID               HMIGkc-kO3K-sd6j-YuPc-i6ez-IOqY-KIReKJ
   [root@centos7 ~]#lvcreate -n lv0 -L 15G vg0   ---創(chuàng)建邏輯卷
  Logical volume "lv0" created.
[root@centos7 ~]#lvs  ---查看邏輯卷
  LV   VG  Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv0  vg0 -wi-a----- 15.00g                                                    
[root@centos7 ~]#lvdisplay ---詳細(xì)查看
  --- Logical volume ---
  LV Path                /dev/vg0/lv0
  LV Name                lv0
  VG Name                vg0
  LV UUID                HH3DXN-bMUd-ebeu-89Vs-ifnw-XYE5-aEBotX
  LV Write Access        read/write
  LV Creation host, time centos7.magedu.com, 2017-08-12 11:49:32 +0800
  LV Status              available
  # open                 0
  LV Size                15.00 GiB
  Current LE             3840
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
[root@centos7 ~]#ll /dev/vg0/lv0  ---可以看到邏輯卷的設(shè)備名為一個軟連接
lrwxrwxrwx. 1 root root 7 Aug 12 11:49 /dev/vg0/lv0 -> ../dm-0
[root@centos7 ~]#lvcreate -n lv1 -L 10G vg0  ---再創(chuàng)建一個邏輯卷
  Logical volume "lv1" created.
[root@centos7 ~]#lvdisplay ---此時有兩個邏輯卷
  --- Logical volume ---
  LV Path                /dev/vg0/lv0
  LV Name                lv0
  VG Name                vg0
  LV UUID                HH3DXN-bMUd-ebeu-89Vs-ifnw-XYE5-aEBotX
  LV Write Access        read/write
  LV Creation host, time centos7.magedu.com, 2017-08-12 11:49:32 +0800
  LV Status              available
  # open                 0
  LV Size                15.00 GiB
  Current LE             3840
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
   
  --- Logical volume ---
  LV Path                /dev/vg0/lv1
  LV Name                lv1
  VG Name                vg0
  LV UUID                RAIOfB-sJ1U-0wGj-FPjn-53SZ-rBeE-AvsvBp
  LV Write Access        read/write
  LV Creation host, time centos7.magedu.com, 2017-08-12 12:00:14 +0800
  LV Status              available
  # open                 0
  LV Size                10.00 GiB
  Current LE             2560
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1
[root@centos7 ~]#mkfs.ext4 /dev/vg0/lv0  ---創(chuàng)建文件系統(tǒng)
[root@centos7 ~]#mkdir /mnt/lv0
[root@centos7 ~]#mount /dev/vg0/lv0 /mnt/lv0/  ---掛載
[root@centos7 ~]#df
Filesystem          1K-blocks     Used Available Use% Mounted on
/dev/sda2            52403200 15338660  37064540  30% /
devtmpfs               485268        0    485268   0% /dev
tmpfs                  499980       88    499892   1% /dev/shm
tmpfs                  499980    13544    486436   3% /run
tmpfs                  499980        0    499980   0% /sys/fs/cgroup
/dev/sda3            52403200   540228  51862972   2% /app
/dev/sda1             1038336   172284    866052  17% /boot
tmpfs                  100000       16     99984   1% /run/user/0
/dev/sr0              8086368  8086368         0 100% /run/media/root/CentOS 7 x86_64
/dev/mapper/vg0-lv0  15350728    40984  14506928   1% /mnt/lv0

總結(jié):創(chuàng)建邏輯卷的過程是在磁盤或者分區(qū)上先創(chuàng)建物理卷姨夹,如果是分區(qū)纤垂,創(chuàng)建分區(qū)時要指定id號為LVM,之后再創(chuàng)建卷組磷账,通過卷組再創(chuàng)建邏輯卷峭沦,因為邏輯卷是通過卷組創(chuàng)建的,所以卷組中創(chuàng)建了PE
逃糟,默認(rèn)PE大小為4MiB吼鱼,用它來指定邏輯卷的最小塊的單位,在創(chuàng)建卷組時可以通過-s來指定PE的大小來指定邏輯卷中塊的大小绰咽,在沒有創(chuàng)建卷組時物理卷中的PE是沒有的蛉抓,創(chuàng)建之后物理卷中才能看到。

3剃诅、擴(kuò)展邏輯卷

[root@centos7 app]#vgdisplay ---首先要看卷組里是否有剩余空間
  --- Volume group ---
  VG Name               vg0
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               1
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               34.99 GiB
  PE Size               4.00 MiB
  Total PE              8958
  Alloc PE / Size       6400 / 25.00 GiB
  Free  PE / Size       2558 / 9.99 GiB  ----卷組剩下空間
  VG UUID               HMIGkc-kO3K-sd6j-YuPc-i6ez-IOqY-KIReKJ
 ①沒有剩余空間
  [root@centos7 app]#pvcreate /dev/sdc2
WARNING: dos signature detected on /dev/sdc2 at offset 510. Wipe it? [y/n]: y
  Wiping dos signature on /dev/sdc2.
  Physical volume "/dev/sdc2" successfully created.  ---創(chuàng)建物理卷
[root@centos7 app]#vgextend vg0 /dev/sdc2  ---擴(kuò)展卷組巷送,將物理卷加到卷組里
  Volume group "vg0" successfully extended
[root@centos7 app]#vgdisplay 
  --- Volume group ---
  VG Name               vg0
  System ID             
  Format                lvm2
  Metadata Areas        3
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               1
  Max PV                0
  Cur PV                3
  Act PV                3
  VG Size               54.99 GiB
  PE Size               4.00 MiB
  Total PE              14077
  Alloc PE / Size       6400 / 25.00 GiB
  Free  PE / Size       7677 / 29.99 GiB  ---卷組的空間擴(kuò)大
  VG UUID               HMIGkc-kO3K-sd6j-YuPc-i6ez-IOqY-KIReKJ
   [root@centos7 app]#lvs
  LV   VG  Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv0  vg0 -wi-ao---- 15.00g                                                    
  lv1  vg0 -wi-a----- 10.00g                                                    
[root@centos7 app]#lvextend -L 20g /dev/vg0/lv0  ---擴(kuò)展邏輯卷到20G
  Size of logical volume vg0/lv0 changed from 15.00 GiB (3840 extents) to 20.00 GiB (5120 extents).
  Logical volume vg0/lv0 successfully resized.
[root@centos7 app]#lvs
  LV   VG  Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv0  vg0 -wi-ao---- 20.00g                                                    
  lv1  vg0 -wi-a----- 10.00g       
[root@centos7 app]#df -h
Filesystem           Size  Used Avail Use% Mounted on
/dev/sda2             50G   15G   36G  30% /
devtmpfs             474M     0  474M   0% /dev
tmpfs                489M   88K  489M   1% /dev/shm
tmpfs                489M   14M  476M   3% /run
tmpfs                489M     0  489M   0% /sys/fs/cgroup
/dev/sda3             50G  1.1G   49G   3% /app
/dev/sda1           1014M  169M  846M  17% /boot
tmpfs                 98M   16K   98M   1% /run/user/0
/dev/sr0             7.8G  7.8G     0 100% /run/media/root/CentOS 7 x86_64
/dev/mapper/vg0-lv0   15G  541M   14G   4% /mnt/lv0   ---此時文件系統(tǒng)顯示的大小還是15G,說明文件系統(tǒng)沒有同步
如果是xfs文件系統(tǒng):xfs_growfs /mnt/lv0
[root@centos7 app]#resize2fs /dev/vg0/lv0 20G  ---讓文件系統(tǒng)同步
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/vg0/lv0 is mounted on /mnt/lv0; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 3
The filesystem on /dev/vg0/lv0 is now 5242880 blocks long.
[root@centos7 app]#df -hT
Filesystem          Type      Size  Used Avail Use% Mounted on
/dev/sda2           xfs        50G   15G   36G  30% /
devtmpfs            devtmpfs  474M     0  474M   0% /dev
tmpfs               tmpfs     489M   88K  489M   1% /dev/shm
tmpfs               tmpfs     489M   14M  476M   3% /run
tmpfs               tmpfs     489M     0  489M   0% /sys/fs/cgroup
/dev/sda3           xfs        50G  1.1G   49G   3% /app
/dev/sda1           xfs      1014M  169M  846M  17% /boot
tmpfs               tmpfs      98M   16K   98M   1% /run/user/0
/dev/sr0            iso9660   7.8G  7.8G     0 100% /run/media/root/CentOS 7 x86_64
/dev/mapper/vg0-lv0 ext4       20G  544M   19G   3% /mnt/lv0  ---已經(jīng)同步
②有剩余空間
[root@centos7 app]#mkfs.xfs /dev/vg0/lv1  ---對邏輯卷lv1創(chuàng)建文件系統(tǒng)
[root@centos7 app]#mount /dev/vg0/lv1 /mnt/lv1  ---掛載
[root@centos7 app]#df -h
Filesystem           Size  Used Avail Use% Mounted on
/dev/sda2             50G   15G   36G  30% /
devtmpfs             474M     0  474M   0% /dev
tmpfs                489M   88K  489M   1% /dev/shm
tmpfs                489M   14M  476M   3% /run
tmpfs                489M     0  489M   0% /sys/fs/cgroup
/dev/sda3             50G  1.1G   49G   3% /app
/dev/sda1           1014M  169M  846M  17% /boot
tmpfs                 98M   16K   98M   1% /run/user/0
/dev/sr0             7.8G  7.8G     0 100% /run/media/root/CentOS 7 x86_64
/dev/mapper/vg0-lv0   20G  544M   19G   3% /mnt/lv0
/dev/mapper/vg0-lv1   10G   33M   10G   1% /mnt/lv1
[root@centos7 app]#lvs
  LV   VG  Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv0  vg0 -wi-ao---- 20.00g                                                    
  lv1  vg0 -wi-ao---- 10.00g                                                    
[root@centos7 app]#lvextend -r -L +5G /dev/vg0/lv1 ---將lv1邏輯卷增加5G矛辕,-r選項可以實現(xiàn)自動同步文件系統(tǒng)笑跛。
  Size of logical volume vg0/lv1 changed from 10.00 GiB (2560 extents) to 15.00 GiB (3840 extents).
  Logical volume vg0/lv1 successfully resized.
meta-data=/dev/mapper/vg0-lv1    isize=512    agcount=4, agsize=655360 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=2621440, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 2621440 to 3932160
[root@centos7 app]#lvs
  LV   VG  Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv0  vg0 -wi-ao---- 20.00g                                                    
  lv1  vg0 -wi-ao---- 15.00g      ---已增加
[root@centos7 app]#df -h ---我們看到已經(jīng)自動同步文件系統(tǒng)
Filesystem           Size  Used Avail Use% Mounted on
/dev/sda2             50G   15G   36G  30% /
devtmpfs             474M     0  474M   0% /dev
tmpfs                489M   88K  489M   1% /dev/shm
tmpfs                489M   14M  476M   3% /run
tmpfs                489M     0  489M   0% /sys/fs/cgroup
/dev/sda3             50G  1.1G   49G   3% /app
/dev/sda1           1014M  169M  846M  17% /boot
tmpfs                 98M   16K   98M   1% /run/user/0
/dev/sr0             7.8G  7.8G     0 100% /run/media/root/CentOS 7 x86_64
/dev/mapper/vg0-lv0   20G  544M   19G   3% /mnt/lv0
/dev/mapper/vg0-lv1   15G   33M   15G   1% /mnt/lv1

4付魔、縮減邏輯卷

只有邏輯卷是ext4文件系統(tǒng)的才能縮減邏輯卷,生產(chǎn)中一般不會縮減邏輯卷,有可能會破壞數(shù)據(jù)

[root@centos7 lv0]#df -T  --這里我們縮減lv0邏輯卷
Filesystem          Type     1K-blocks     Used Available Use% Mounted on
/dev/sda2           xfs       52403200 15338912  37064288  30% /
devtmpfs            devtmpfs    485268        0    485268   0% /dev
tmpfs               tmpfs       499980       88    499892   1% /dev/shm
tmpfs               tmpfs       499980    13548    486432   3% /run
tmpfs               tmpfs       499980        0    499980   0% /sys/fs/cgroup
/dev/sda3           xfs       52403200  1052228  51350972   3% /app
/dev/sda1           xfs        1038336   172284    866052  17% /boot
tmpfs               tmpfs       100000       16     99984   1% /run/user/0
/dev/sr0            iso9660    8086368  8086368         0 100% /run/media/root/CentOS 7 x86_64
/dev/mapper/vg0-lv0 ext4      20511312   557040  18931260   3% /mnt/lv0
/dev/mapper/vg0-lv1 xfs       15718400    71272  15647128   1% /mnt/lv1
[root@centos7 lv0]#umount /mnt/lv0   ---第一步取消掛載
[root@centos7 ~]#fsck -f /dev/vg0/lv0   ---第二步檢查文件系統(tǒng)
fsck from util-linux 2.23.2
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/mapper/vg0-lv0: 12/1310720 files (0.0% non-contiguous), 126323/5242880 blocks
[root@centos7 ~]#resize2fs /dev/vg0/lv0 18G   ---第三步縮減文件系統(tǒng)到18G
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/vg0/lv0 to 4718592 (4k) blocks.
The filesystem on /dev/vg0/lv0 is now 4718592 blocks long.
[root@centos7 ~]#lvreduce -L 18G /dev/vg0/lv0   ---第四步縮減邏輯卷到18G
  WARNING: Reducing active logical volume to 18.00 GiB.
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce vg0/lv0? [y/n]: y
  Size of logical volume vg0/lv0 changed from 20.00 GiB (5120 extents) to 18.00 GiB (4608 extents).
  Logical volume vg0/lv0 successfully resized.
[root@centos7 ~]#lvs
  LV   VG  Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv0  vg0 -wi-ao---- 18.00g      ---已經(jīng)縮減                                            
  lv1  vg0 -wi-ao---- 15.00g     
 [root@centos7 ~]#mount -a
[root@centos7 ~]#df -Th
Filesystem          Type      Size  Used Avail Use% Mounted on
/dev/sda2           xfs        50G   15G   36G  30% /
devtmpfs            devtmpfs  474M     0  474M   0% /dev
tmpfs               tmpfs     489M   88K  489M   1% /dev/shm
tmpfs               tmpfs     489M   20M  469M   4% /run
tmpfs               tmpfs     489M     0  489M   0% /sys/fs/cgroup
/dev/sda3           xfs        50G  1.1G   49G   3% /app
/dev/sda1           xfs      1014M  169M  846M  17% /boot
tmpfs               tmpfs      98M   16K   98M   1% /run/user/0
/dev/sr0            iso9660   7.8G  7.8G     0 100% /run/media/root/CentOS 7 x86_64
/dev/mapper/vg0-lv1 xfs        15G   70M   15G   1% /mnt/lv1
/dev/mapper/vg0-lv0 ext4       18G   45M   17G   1% /mnt/lv0

總結(jié):縮減邏輯卷的過程中是先取消掛載飞蹂,這一步很重要几苍,不要忘記,然后檢查文件系統(tǒng)陈哑,縮減文件系統(tǒng)妻坝,縮減邏輯卷,要按照這個過程一步步的來惊窖。

5刽宪、遷移卷組

[root@centos6 ~]#umount /mnt/lv0/  ---第一步取消掛載
[root@centos6 ~]#df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda2       50264772 4786024  42918748  11% /
tmpfs             502056      76    501980   1% /dev/shm
/dev/sda3       40185208  561020  37576188   2% /app
/dev/sda1         991512   34904    905408   4% /boot
/dev/sr0         6049912 6049912         0 100% /media/CDROM
[root@centos6 ~]#vgrename vg0 newvg0  ---第二步為了和其他卷組的名字沖突,重新定義卷組和邏輯卷的名字
  Volume group "vg0" successfully renamed to "newvg0"
[root@centos6 ~]#lvrename /dev/newvg0/lv0 newlv0   ---邏輯卷的名字改不改都可以界酒,卷組的名字變了圣拄,邏輯卷的名字也跟著變了
  Renamed "lv0" to "newlv0" in volume group "newvg0"
[root@centos6 ~]#vgchange -an newvg0    ---第三步把卷組設(shè)為非活動狀態(tài)
  0 logical volume(s) in volume group "newvg0" now active
[root@centos6 ~]#lvdisplay 
  --- Logical volume ---
  LV Path                /dev/newvg0/newlv0
  LV Name                newlv0
  VG Name                newvg0
  LV UUID                ua7BV0-2Zem-qtzq-Zeiv-DaM4-hA4K-2UKux0
  LV Write Access        read/write
  LV Creation host, time centos6.magedu.com, 2017-08-09 16:46:39 +0800
  LV Status              NOT available   ---查看已經(jīng)處于不活動狀態(tài)
  LV Size                8.00 GiB
  Current LE             2048
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  [root@centos6 ~]#vgexport newvg0
  Volume group "newvg0" successfully exported  ---第四步導(dǎo)出卷組
halt   ---第五步關(guān)機(jī),將硬盤裝入centos7
[root@centos7 ~]#echo '- - -'> /sys/class/scsi_host/host0/scan  ---激活一下硬盤
[root@centos7 ~]#lsblk
NAME              MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                 8:0    0  200G  0 disk 
├─sda1              8:1    0    1G  0 part /boot
├─sda2              8:2    0   50G  0 part /
├─sda3              8:3    0   50G  0 part /app
├─sda4              8:4    0  512B  0 part 
└─sda5              8:5    0    2G  0 part [SWAP]
sdb                 8:16   0   20G  0 disk 
└─vg0-lv0         253:0    0   18G  0 lvm  /mnt/lv0
sdc                 8:32   0  150G  0 disk 
├─sdc1              8:33   0   15G  0 part 
│ └─vg0-lv1       253:1    0   15G  0 lvm  /mnt/lv1
└─sdc2              8:34   0   20G  0 part 
  └─vg0-lv1       253:1    0   15G  0 lvm  /mnt/lv1
sdd                 8:48   0  120G  0 disk 
sde                 8:64   0   60G  0 disk   ---可以看到這個磁盤了
├─sde1              8:65   0    5G  0 part 
│ └─newvg0-newlv0 253:2    0    8G  0 lvm  
└─sde2              8:66   0    5G  0 part 
  └─newvg0-newlv0 253:2    0    8G  0 lvm  
sr0                11:0    1  7.7G  0 rom  /run/media/root/CentOS 7 x86_64
[root@centos7 ~]#pvscan ---第六步可以看到新的卷組處于導(dǎo)出狀態(tài)
  PV /dev/sdb    VG vg0             lvm2 [20.00 GiB / 2.00 GiB free]
  PV /dev/sdc1   VG vg0             lvm2 [15.00 GiB / 4.00 MiB free]
  PV /dev/sdc2   VG vg0             lvm2 [20.00 GiB / 19.99 GiB free]
  PV /dev/sde1    is in exported VG newvg0 [5.01 GiB / 0    free]
  PV /dev/sde2    is in exported VG newvg0 [5.01 GiB / 2.02 GiB free]
  Total: 5 [65.00 GiB] / in use: 5 [65.00 GiB] / in no VG: 0 [0   ]
root@centos7 ~]#vgimport newvg0 ---第七步導(dǎo)入卷組
  Volume group "newvg0" successfully imported
root@centos7 ~]#vgchange -ay newvg0   ---第八步激活卷組
  1 logical volume(s) in volume group "newvg0" now active
[root@centos7 ~]#mkdir /mnt/newlv0
[root@centos7 ~]#mount /dev/newvg0/newlv0 /mnt/newlv0/
[root@centos7 ~]#df
Filesystem                1K-blocks     Used Available Use% Mounted on
/dev/sda2                  52403200 15341732  37061468  30% /
devtmpfs                     485268        0    485268   0% /dev
tmpfs                        499980      128    499852   1% /dev/shm
tmpfs                        499980    19816    480164   4% /run
tmpfs                        499980        0    499980   0% /sys/fs/cgroup
/dev/sda3                  52403200  1052228  51350972   3% /app
/dev/sda1                   1038336   172284    866052  17% /boot
tmpfs                        100000       20     99980   1% /run/user/0
/dev/sr0                    8086368  8086368         0 100% /run/media/root/CentOS 7 x86_64
/dev/mapper/vg0-lv1        15718400    71272  15647128   1% /mnt/lv1
/dev/mapper/vg0-lv0        18447056    45084  17441872   1% /mnt/lv0
/dev/mapper/newvg0-newlv0   8125880   530424   7159644   7% /mnt/newlv0
[root@centos7 ~]#cd /mnt/newlv0/
[root@centos7 newlv0]#ls
f1  lost+found
可以看到文件沒有丟失

6毁欣、從邏輯卷中刪除正在使用的物理分區(qū)(硬盤)

[root@centos7 ~]#vgdisplay   ---先看一下卷組
  --- Volume group ---
  VG Name               vg0
  System ID             
  Format                lvm2
  Metadata Areas        3
  Metadata Sequence No  10
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               1
  Max PV                0
  Cur PV                3
  Act PV                3
  VG Size               54.99 GiB
  PE Size               4.00 MiB
  Total PE              14077
  Alloc PE / Size       8448 / 33.00 GiB
  Free  PE / Size       5629 / 21.99 GiB  ---卷組的剩余空間是否滿足將硬盤或分期的空間轉(zhuǎn)移到其他物理卷
  VG UUID               HMIGkc-kO3K-sd6j-YuPc-i6ez-IOqY-KIReKJ
[root@centos7 ~]#pvdisplay   ---這里我們可以把/dev/sdc2分區(qū)中已經(jīng)分配出去的2個PE轉(zhuǎn)移到其他物理卷
  --- Physical volume ---
  PV Name               /dev/sdb
  VG Name               vg0
  PV Size               20.00 GiB / not usable 4.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              5119
  Free PE               511
  Allocated PE          4608
  PV UUID               72dJR7-GCfL-GOHH-Tg9a-IIbl-EgTD-YLrRGz
   
  --- Physical volume ---
  PV Name               /dev/sdc1
  VG Name               vg0
  PV Size               15.00 GiB / not usable 4.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              3839
  Free PE               1
  Allocated PE          3838
  PV UUID               j8i7QQ-sSR2-bsJn-UlJj-a1jY-Ubum-KRYgWx
   
  --- Physical volume ---
  PV Name               /dev/sdc2
  VG Name               vg0
  PV Size               20.00 GiB / not usable 4.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              5119
  Free PE               5117
  Allocated PE          2
  PV UUID               DTnJdv-pV0n-p8Dz-Ku8b-gtQv-hNDI-A56LPK
[root@centos7 ~]#pvmove /dev/sdc2  ---移動/dev/sdc2中已經(jīng)分配的PE空間給其他物理卷
  /dev/sdc2: Moved: 100.00%
[root@centos7 ~]#pvdisplay 
  --- Physical volume ---
  PV Name               /dev/sdb
  VG Name               vg0
  PV Size               20.00 GiB / not usable 4.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              5119
  Free PE               509
  Allocated PE          4610
  PV UUID               72dJR7-GCfL-GOHH-Tg9a-IIbl-EgTD-YLrRGz
   
  --- Physical volume ---
  PV Name               /dev/sdc1
  VG Name               vg0
  PV Size               15.00 GiB / not usable 4.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              3839
  Free PE               1
  Allocated PE          3838
  PV UUID               j8i7QQ-sSR2-bsJn-UlJj-a1jY-Ubum-KRYgWx
   
  --- Physical volume ---
  PV Name               /dev/sdc2
  VG Name               vg0
  PV Size               20.00 GiB / not usable 4.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              5119
  Free PE               5119
  Allocated PE          0    ---此時/dev/sdc2分區(qū)一個PE也沒有分配給邏輯卷
  PV UUID               DTnJdv-pV0n-p8Dz-Ku8b-gtQv-hNDI-A56LPK
[root@centos7 ~]#vgreduce vg0 /dev/sdc2  ---縮減卷組
  Removed "/dev/sdc2" from volume group "vg0"
[root@centos7 ~]#pvdisplay 
  --- Physical volume ---
  PV Name               /dev/sdb
  VG Name               vg0
  PV Size               20.00 GiB / not usable 4.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              5119
  Free PE               509
  Allocated PE          4610
  PV UUID               72dJR7-GCfL-GOHH-Tg9a-IIbl-EgTD-YLrRGz
   
  --- Physical volume ---
  PV Name               /dev/sdc1
  VG Name               vg0
  PV Size               15.00 GiB / not usable 4.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              3839
  Free PE               1
  Allocated PE          3838
  PV UUID               j8i7QQ-sSR2-bsJn-UlJj-a1jY-Ubum-KRYgWx
   
  "/dev/sdc2" is a new physical volume of "20.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdc2
  VG Name                        ---可以看到已經(jīng)移除庇谆,不屬于任何卷組
  PV Size               20.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               DTnJdv-pV0n-p8Dz-Ku8b-gtQv-hNDI-A56LPK
[root@centos7 ~]#pvremove /dev/sdc2  ---刪除物理卷
  Labels on physical volume "/dev/sdc2" successfully wiped.
[root@centos7 ~]#pvdisplay 
  --- Physical volume ---
  PV Name               /dev/sdb
  VG Name               vg0
  PV Size               20.00 GiB / not usable 4.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              5119
  Free PE               509
  Allocated PE          4610
  PV UUID               72dJR7-GCfL-GOHH-Tg9a-IIbl-EgTD-YLrRGz
   
  --- Physical volume ---
  PV Name               /dev/sdc1
  VG Name               vg0
  PV Size               15.00 GiB / not usable 4.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              3839
  Free PE               1
  Allocated PE          3838
  PV UUID               j8i7QQ-sSR2-bsJn-UlJj-a1jY-Ubum-KRYgWx
  之后就可以將這個分區(qū)刪除

7、邏輯卷快照管理

邏輯卷的快照就相當(dāng)于在同一個卷組中再創(chuàng)建一個邏輯卷快照的空間凭疮,這個空間的大小要保證修改的文件能夠存入饭耳,剛開始時邏輯卷的快照里沒有數(shù)據(jù),只是一個空間执解,當(dāng)在邏輯卷中修改一個文件時寞肖,會把一個文件的原始狀態(tài)推送到這個快照空間中保存起來。

[root@centos7 lv0]#lvcreate -L 500M -s -n lv0-snapshot -p r /dev/vg0/lv0   ---對邏輯卷lv0創(chuàng)建一個500M的快照材鹦,-L指定大小逝淹,-s指定是快照耕姊,-n指定名字桶唐,-p指定是只讀
  Using default stripesize 64.00 KiB.
  Logical volume "lv0-snapshot" created.
[root@centos7 lv0]#mkdir /mnt/lv0-snapshot
[root@centos7 lv0]#mount /dev/vg0/lv0-snapshot /mnt/lv0-snapshot/  ---掛載快照
mount: /dev/mapper/vg0-lv0--snapshot is write-protected, mounting read-only
[root@centos7 lv0]#df
Filesystem                    1K-blocks     Used Available Use% Mounted on
/dev/sda2                      52403200 15341232  37061968  30% /
devtmpfs                         918932        0    918932   0% /dev
tmpfs                            933644       88    933556   1% /dev/shm
tmpfs                            933644     9260    924384   1% /run
tmpfs                            933644        0    933644   0% /sys/fs/cgroup
/dev/sda3                      52403200  1052228  51350972   3% /app
/dev/mapper/vg0-lv0            18447056    45084  17441872   1% /mnt/lv0
/dev/sda1                       1038336   172284    866052  17% /boot
tmpfs                            186732       12    186720   1% /run/user/0
/dev/sr0                        8086368  8086368         0 100% /run/media/root/CentOS 7 x86_64
/dev/mapper/vg0-lv0--snapshot  18447056    45084  17441872   1% /mnt/lv0-snapshot
[root@centos7 lv0-snapshot]#cd /mnt/lv0  ---進(jìn)入原來的lv0邏輯卷目錄
[root@centos7 lv0]#ls
fstab  lost+found
[root@centos7 lv0]#vim fstab ---修改一下文件內(nèi)容
  1 UUID=e7e1738b-58ae-49d3-9f7e-c62988ead392 /                       xfs     defaults
           0 0
  2 UUID=348930fe-f95e-40e6-90ff-83c66b3f2e9a /app                    xfs     defaults
           0 0
  3 UUID=dfbab032-681e-4e34-a16e-2f5e1eda5f32 /boot                   xfs     defaults
           0 0
  4 UUID=6145ae5c-6ebd-4655-a52f-e90f9b5a9e58 swap                    swap    defaults
           0 0
                                                                          
"fstab" 4L, 376C written
[root@centos7 lv0]#
[root@centos7 lv0]#
[root@centos7 lv0]#
[root@centos7 lv0]#
[root@centos7 lv0]#cat fstab ---修改之后的內(nèi)容
UUID=e7e1738b-58ae-49d3-9f7e-c62988ead392 /                       xfs     defaults        0 0
UUID=348930fe-f95e-40e6-90ff-83c66b3f2e9a /app                    xfs     defaults        0 0
UUID=dfbab032-681e-4e34-a16e-2f5e1eda5f32 /boot                   xfs     defaults        0 0
UUID=6145ae5c-6ebd-4655-a52f-e90f9b5a9e58 swap                    swap    defaults        0 0
[root@centos7 lv0]#
   0 0
[root@centos7 lv0]#cd /mnt/lv0-snapshot/  ---進(jìn)入快照的目錄
[root@centos7 lv0-snapshot]#ls 
fstab  lost+found
[root@centos7 lv0-snapshot]#cat fstab ---可以看到已經(jīng)將原始的內(nèi)容保存到其中

#
# /etc/fstab
# Created by anaconda on Fri Jul 14 11:16:04 2017
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=e7e1738b-58ae-49d3-9f7e-c62988ead392 /                       xfs     defaults        0 0
UUID=348930fe-f95e-40e6-90ff-83c66b3f2e9a /app                    xfs     defaults        0 0
UUID=dfbab032-681e-4e34-a16e-2f5e1eda5f32 /boot                   xfs     defaults        0 0
UUID=6145ae5c-6ebd-4655-a52f-e90f9b5a9e58 swap                    swap    defaults        0 0
[root@centos6 ~]#lvconvert --merge /dev/vg0/lv0-snapshot ---恢復(fù)快照
  Merging of volume vg0/lv0-snapshot started.
  lv1: Merged: 100.00%
[root@centos6 lv1]#cd /mnt/lv0
[root@centos6 lv1]#ls
etc  fstab
[root@centos6 lv0]#cat fstab ---可以看到文件又恢復(fù)到原來的狀態(tài),沒有丟失
總結(jié):在恢復(fù)快照之前一定要先取消掛載茉兰,包括邏輯卷的掛載和快照的掛載都要取消尤泽,否則無法恢復(fù)快照。這個是在練習(xí)中經(jīng)常出現(xiàn)的錯誤规脸。
#
# /etc/fstab
# Created by anaconda on Fri Jul 14 11:16:04 2017
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=e7e1738b-58ae-49d3-9f7e-c62988ead392 /                       xfs     defaults        0 0
UUID=348930fe-f95e-40e6-90ff-83c66b3f2e9a /app                    xfs     defaults        0 0
UUID=dfbab032-681e-4e34-a16e-2f5e1eda5f32 /boot                   xfs     defaults        0 0
UUID=6145ae5c-6ebd-4655-a52f-e90f9b5a9e58 swap                    swap    defaults        0 0

UUID=fca04a06-6e33-41bb-8902-cc89b908ae22    /mnt/lv0             ext4     defaults       0  0 

總結(jié):在修改邏輯卷上的文件時會將原文件數(shù)據(jù)推送至快照中坯约,在生產(chǎn)中一般不會使用快照。因為這樣會影響服務(wù)器的性能莫鸭。相當(dāng)于在修改的時候會把原數(shù)據(jù)輸出到快照闹丐。

8、刪除邏輯卷的步驟

從上往下刪除被因,跟創(chuàng)建的時候相反

[root@centos7 lv1]#lvdisplay 
  --- Logical volume ---
  LV Path                /dev/vg0/lv1
  LV Name                lv1
  VG Name                vg0
  LV UUID                RAIOfB-sJ1U-0wGj-FPjn-53SZ-rBeE-AvsvBp
  LV Write Access        read/write
  LV Creation host, time centos7.magedu.com, 2017-08-12 12:00:14 +0800
  LV Status              available
  # open                 1
  LV Size                15.00 GiB
  Current LE             3840
  Segments               3
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
[root@centos7 ~]#umount /mnt/lv1  ---先取消掛載
[root@centos7 ~]#lvremove /dev/vg0/lv1  ---刪除邏輯卷
Do you really want to remove active logical volume vg0/lv1? [y/n]: y
  Logical volume "lv1" successfully removed
[root@centos7 ~]#vgremove vg0
  Volume group "vg0" successfully removed
[root@centos7 ~]#pvs
  PV         VG Fmt  Attr PSize  PFree 
  /dev/sdb      lvm2 ---  20.00g 20.00g
  /dev/sdc1     lvm2 ---  15.00g 15.00g
[root@centos7 ~]#pvremove /dev/sd{b,c1}  ---刪除物理卷
  Labels on physical volume "/dev/sdb" successfully wiped.
  Labels on physical volume "/dev/sdc1" successfully wiped.
之后就可以刪除分區(qū)或者拔除硬盤了卿拴。
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末衫仑,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子堕花,更是在濱河造成了極大的恐慌文狱,老刑警劉巖,帶你破解...
    沈念sama閱讀 206,723評論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件缘挽,死亡現(xiàn)場離奇詭異瞄崇,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)壕曼,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,485評論 2 382
  • 文/潘曉璐 我一進(jìn)店門苏研,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人窝稿,你說我怎么就攤上這事楣富。” “怎么了伴榔?”我有些...
    開封第一講書人閱讀 152,998評論 0 344
  • 文/不壞的土叔 我叫張陵纹蝴,是天一觀的道長。 經(jīng)常有香客問我踪少,道長塘安,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 55,323評論 1 279
  • 正文 為了忘掉前任援奢,我火速辦了婚禮兼犯,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘集漾。我一直安慰自己切黔,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 64,355評論 5 374
  • 文/花漫 我一把揭開白布具篇。 她就那樣靜靜地躺著纬霞,像睡著了一般。 火紅的嫁衣襯著肌膚如雪驱显。 梳的紋絲不亂的頭發(fā)上诗芜,一...
    開封第一講書人閱讀 49,079評論 1 285
  • 那天,我揣著相機(jī)與錄音埃疫,去河邊找鬼伏恐。 笑死,一個胖子當(dāng)著我的面吹牛栓霜,可吹牛的內(nèi)容都是我干的翠桦。 我是一名探鬼主播,決...
    沈念sama閱讀 38,389評論 3 400
  • 文/蒼蘭香墨 我猛地睜開眼胳蛮,長吁一口氣:“原來是場噩夢啊……” “哼销凑!你這毒婦竟也來了愁铺?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 37,019評論 0 259
  • 序言:老撾萬榮一對情侶失蹤闻鉴,失蹤者是張志新(化名)和其女友劉穎茵乱,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體孟岛,經(jīng)...
    沈念sama閱讀 43,519評論 1 300
  • 正文 獨居荒郊野嶺守林人離奇死亡瓶竭,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 35,971評論 2 325
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了渠羞。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片斤贰。...
    茶點故事閱讀 38,100評論 1 333
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖次询,靈堂內(nèi)的尸體忽然破棺而出荧恍,到底是詐尸還是另有隱情,我是刑警寧澤屯吊,帶...
    沈念sama閱讀 33,738評論 4 324
  • 正文 年R本政府宣布送巡,位于F島的核電站,受9級特大地震影響盒卸,放射性物質(zhì)發(fā)生泄漏骗爆。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 39,293評論 3 307
  • 文/蒙蒙 一蔽介、第九天 我趴在偏房一處隱蔽的房頂上張望摘投。 院中可真熱鬧,春花似錦虹蓄、人聲如沸犀呼。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,289評論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽外臂。三九已至,卻和暖如春体箕,著一層夾襖步出監(jiān)牢的瞬間专钉,已是汗流浹背挑童。 一陣腳步聲響...
    開封第一講書人閱讀 31,517評論 1 262
  • 我被黑心中介騙來泰國打工累铅, 沒想到剛下飛機(jī)就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人站叼。 一個月前我還...
    沈念sama閱讀 45,547評論 2 354
  • 正文 我出身青樓娃兽,卻偏偏與公主長得像,于是被迫代替她去往敵國和親尽楔。 傳聞我的和親對象是個殘疾皇子投储,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 42,834評論 2 345

推薦閱讀更多精彩內(nèi)容