溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Linux中的LVM增加容量與刪除卷的方法介紹

發(fā)布時(shí)間:2021-08-06 18:41:55 來(lái)源:億速云 閱讀:180 作者:chen 欄目:系統(tǒng)運(yùn)維

這篇文章主要講解了“Linux中的LVM增加容量與刪除卷的方法介紹”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來(lái)研究和學(xué)習(xí)“Linux中的LVM增加容量與刪除卷的方法介紹”吧!

放大LV容量涉及到LVM管理中的命令lvresize,我們先創(chuàng)建一個(gè)卷組VG VolGroup02,它建立在磁盤/dev/sdc (大小為8G)上。創(chuàng)建邏輯卷LV時(shí),我們故意只使用了一小部分。具體情況如下所示

代碼如下:


[root@localhost ~]# vgdisplay
 --- Volume group ---
 VG Name               VolGroup02
 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               7.97 GiB
 PE Size               32.00 MiB
 Total PE              255
 Alloc PE / Size       0 / 0  
 Free  PE / Size       255 / 7.97 GiB
 VG UUID               SETgjx-dobd-Uayt-AWgN-HKID-hsYe-tEotIS
[root@localhost ~]# lvcreate -L7.97 -n LogVol00 VolGroup02
 Rounding up size to full physical extent 32.00 MiB
 Logical volume "LogVol00" created
[root@localhost ~]# mkfs -t ext4 /dev/VolGroup02/LogVol00
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
8192 inodes, 32768 blocks
1638 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=33554432
4 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
       8193, 24577

Writing inode tables: done                            
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 23 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@localhost ~]# cd /
[root@localhost /]# mkdir /u01
[root@localhost /]# mount /dev/VolGroup02/LogVol00 /u01
[root@localhost /]# vi /etc/fstab

#
# /etc/fstab
# Created by anaconda on Mon Aug 17 15:08:21 2015
#
# 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=3440ad55-6486-45ed-876f-e942b08013bf /                       ext4    defaults        1 1
UUID=d3abb655-db70-4c42-967d-57c421abfda0 /boot                   ext4    defaults        1 2
UUID=660624ff-335d-42ca-b779-f130a80d9da8 /home                   ext4    defaults        1 2
UUID=6f534bf0-e486-4937-84ae-ed1221cf34f1 swap                    swap    defaults        0 0
/dev/VolGroup02/LogVol00                  /u01                    ext4    defaults        1 1
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0



Linux中的LVM增加容量與刪除卷的方法介紹
此時(shí),我們要放大文件系統(tǒng)/u01的大小,那么就需要使用到lvresize 放大LV容量

代碼如下:


[root@localhost ~]# lvscan
 ACTIVE            '/dev/VolGroup02/LogVol00' [32.00 MiB] inherit
[root@localhost ~]# lvdisplay /dev/VolGroup02/LogVol00
 --- Logical volume ---
 LV Path                /dev/VolGroup02/LogVol00
 LV Name                LogVol00
 VG Name                VolGroup02
 LV UUID                OCHwx1-EL9P-6C5J-RNuz-2Xu5-4215-H3xt5s
 LV Write Access        read/write
 LV Creation host, time localhost.localdomain, 2015-09-01 10:50:10 +0800
 LV Status              available
 # open                 1
 LV Size                32.00 MiB
 Current LE             1
 Segments               1
 Allocation             inherit
 Read ahead sectors     auto
 - currently set to     256
 Block device           253:0
 
[root@localhost ~]# lvresize -L +7.89G /dev/VolGroup02/LogVol00
 Rounding size to boundary between physical extents: 7.91 GiB
 Size of logical volume VolGroup02/LogVol00 changed from 32.00 MiB (1 extents) to 7.94 GiB (254 extents).
 Logical volume LogVol00 successfully resized


Linux中的LVM增加容量與刪除卷的方法介紹

代碼如下:


[root@localhost ~]# resize2fs -p /dev/VolGroup02/LogVol00
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/VolGroup02/LogVol00 is mounted on /u01; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 32
Performing an on-line resize of /dev/VolGroup02/LogVol00 to 8323072 (1k) blocks.
The filesystem on /dev/VolGroup02/LogVol00 is now 8323072 blocks long.

[root@localhost ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2              27G  6.0G   20G  24% /
tmpfs                 5.9G     0  5.9G   0% /dev/shm
/dev/sda1             477M   32M  420M   8% /boot
/dev/sdb1              99G   60M   94G   1% /home
/dev/mapper/VolGroup02-LogVol00
                     7.7G  2.7M  7.3G   1% /u01


Linux中的LVM增加容量與刪除卷的方法介紹
如果我們此時(shí)在虛擬機(jī)上將磁盤從8G擴(kuò)展為10G,那么要如何利用擴(kuò)展的磁盤空間呢?
Linux中的LVM增加容量與刪除卷的方法介紹

代碼如下:


[root@localhost u01]# fdisk -l

Disk /dev/sda: 42.9 GB, 42949672960 bytes
64 heads, 32 sectors/track, 40960 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000462cf

  Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           2         501      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2             502       28672    28847104   83  Linux
Partition 2 does not end on cylinder boundary.
/dev/sda3           28673       40960    12582912   82  Linux swap / Solaris
Partition 3 does not end on cylinder boundary.

Disk /dev/sdc: 8589 MB, 8589934592 bytes
64 heads, 32 sectors/track, 8192 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x98c391fe

  Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1        8192     8388592   83  Linux

Disk /dev/sdb: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0002488e

  Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1       13055   104856576   83  Linux

Disk /dev/mapper/VolGroup02-LogVol00: 33 MB, 33554432 bytes
255 heads, 63 sectors/track, 4 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Linux中的LVM增加容量與刪除卷的方法介紹
重啟過(guò)后才能看到/dev/sdc的空間變化情況。
Linux中的LVM增加容量與刪除卷的方法介紹

刪除物理卷
刪除卷LVM管理中的命令vgreduce, pvremove:

   vgreduce:通過(guò)刪除LVM卷組中的物理卷來(lái)減少卷組容量。注意:不能刪除LVM卷組中剩余的最后一個(gè)物理卷

   pvremove: 用于刪除一個(gè)存在的物理卷。使用pvremove指令刪除物理卷時(shí),它將LVM分區(qū)上的物理卷信息刪除,使其不再被視為一個(gè)物理卷。

在刪除物理卷PV之前,必須將服務(wù)器的分區(qū)信息、卷組信息、物理卷信息、邏輯卷信息都掌握清楚,避免出現(xiàn)失誤或誤操作。

代碼如下:


[root@localhost ~]# fdisk -l

Disk /dev/sda: 128.8 GB, 128849018880 bytes
255 heads, 63 sectors/track, 15665 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

  Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14       10443    83778975   8e  Linux LVM
/dev/sda3           10444       15665    41945715   83  Linux
[root@localhost ~]# vgscan
 Reading all physical volumes.  This may take a while...
 Found volume group "VolGroup00" using metadata type lvm2
[root@localhost ~]# pvscan
 PV /dev/sda2   VG VolGroup00   lvm2 [79.88 GB / 0    free]
 PV /dev/sda3   VG VolGroup00   lvm2 [40.00 GB / 40.00 GB free]
 Total: 2 [119.88 GB] / in use: 2 [119.88 GB] / in no VG: 0 [0   ]
[root@localhost ~]# pvdisplay
 --- Physical volume ---
 PV Name               /dev/sda2
 VG Name               VolGroup00
 PV Size               79.90 GB / not usable 23.41 MB
 Allocatable           yes (but full)
 PE Size (KByte)       32768
 Total PE              2556
 Free PE               0
 Allocated PE          2556
 PV UUID               YGtB2J-ZKJr-mV62-NluQ-2DGy-vuUT-cCc1lo
 
 --- Physical volume ---
 PV Name               /dev/sda3
 VG Name               VolGroup00
 PV Size               40.00 GB / not usable 2.61 MB
 Allocatable           yes
 PE Size (KByte)       32768
 Total PE              1280
 Free PE               1280
 Allocated PE          0
 PV UUID               wsnv13-7j1H-SH8q-hl6k-HpNc-x4WU-gM7LzW
 
[root@localhost ~]# lvscan
 ACTIVE            '/dev/VolGroup00/LogVol00' [77.91 GB] inherit
 ACTIVE            '/dev/VolGroup00/LogVol01' [1.97 GB] inherit
[root@localhost ~]# lvs
 LV       VG         Attr   LSize  Origin Snap%  Move Log Copy%  Convert
 LogVol00 VolGroup00 -wi-ao 77.91G                                      
 LogVol01 VolGroup00 -wi-ao  1.97G    


vgreduce參數(shù):
-a:如果命令行中沒(méi)有指定要?jiǎng)h除的物理卷,則刪除所有的空物理卷;

--removemissing:刪除卷組中丟失的物理卷,使卷組恢復(fù)正常狀態(tài)。

代碼如下:


[root@localhost ~]# vgreduce VolGroup00 /dev/sda3
Removed "/dev/sda3" from volume group "VolGroup00"
[root@localhost ~]#


Linux中的LVM增加容量與刪除卷的方法介紹

代碼如下:


[root@localhost ~]# pvscan
 PV /dev/sda2   VG VolGroup00      lvm2 [79.88 GB / 0    free]
 PV /dev/sda3                      lvm2 [40.00 GB]
 Total: 2 [119.88 GB] / in use: 1 [79.88 GB] / in no VG: 1 [40.00 GB]
[root@localhost ~]# pvs
 PV         VG         Fmt  Attr PSize  PFree
 /dev/sda2  VolGroup00 lvm2 a-   79.88G     0
 /dev/sda3             lvm2 a-   40.00G 40.00G
[root@localhost ~]# pvremove /dev/sda3
 Labels on physical volume "/dev/sda3" successfully wiped
[root@localhost ~]# pvscan
 PV /dev/sda2   VG VolGroup00   lvm2 [79.88 GB / 0    free]
 Total: 1 [79.88 GB] / in use: 1 [79.88 GB] / in no VG: 0 [0   ]

感謝各位的閱讀,以上就是“Linux中的LVM增加容量與刪除卷的方法介紹”的內(nèi)容了,經(jīng)過(guò)本文的學(xué)習(xí)后,相信大家對(duì)Linux中的LVM增加容量與刪除卷的方法介紹這一問(wèn)題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI