Heim  >  Artikel  >  Computer-Tutorials  >  Grundlegende Schritte zum Erstellen einer LVM-Erweiterung

Grundlegende Schritte zum Erstellen einer LVM-Erweiterung

WBOY
WBOYnach vorne
2024-02-19 20:18:55879Durchsuche

Verwenden Sie den Befehl df -Th, um Festplatteninformationen anzuzeigen. Sie können sehen, dass die aktuelle Kapazität des logischen LVM-Volumes 38 GB beträgt

[root@Z ~]# df -TH
文件系统类型容量已用可用 已用% 挂载点
/dev/mapper/centos-root xfs38G2.4G 36G7% /
devtmpfsdevtmpfs1.1G 01.1G0% /dev
tmpfs tmpfs 1.1G 01.1G0% /dev/shm
tmpfs tmpfs 1.1G 10M1.1G1% /run
tmpfs tmpfs 1.1G 01.1G0% /sys/fs/cgroup
/dev/sda1 xfs 1.1G139M925M 14% /boot
tmpfs tmpfs 208M 0208M0% /run/user/0

Sehen Sie sich die Festplattenpartition an. Sie können sehen, dass die SDA-Festplatte 64 GB groß ist und die SDA2-Partition unten in 40 GB unterteilt ist
[root@Z ~]# fdisk -l

磁盘 /dev/sda:64.4 GB, 64424509440 字节,125829120 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000b05f5

 设备 BootStart EndBlocks IdSystem
/dev/sda1 *2048 2099199 1048576 83Linux
/dev/sda2 20992008388607940893440 8eLinux LVM


磁盘 /dev/mapper/centos-root:37.7 GB, 37706792960 字节,73646080 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节


磁盘 /dev/mapper/centos-swap:4160 MB, 4160749568 字节,8126464 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节

Erstellen Sie eine neue Festplattenpartition sda3

[root@Z ~]# fdisk /dev/sda
欢迎使用 fdisk (util-linux 2.23.2)。

更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。


命令(输入 m 获取帮助):p (p是查看当前分区)

磁盘 /dev/sda:64.4 GB, 64424509440 字节,125829120 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000b05f5

 设备 BootStart EndBlocks IdSystem
/dev/sda1 *2048 2099199 1048576 83Linux
/dev/sda2 20992008388607940893440 8eLinux LVM




命令(输入 m 获取帮助):n(n是新建分区)
Partition type:
 p primary (2 primary, 0 extended, 2 free)
 e extended
Select (default p): (回车默认选择p主分区)
Using default response p
分区号 (3,4,默认 3): (回车默认3)
起始 扇区 (83886080-125829119,默认为 83886080):
将使用默认值 83886080
Last 扇区, +扇区 or +size{K,M,G} (83886080-125829119,默认为 125829119):+19G(这里给新建分区19G)
分区 3 已设置为 Linux 类型,大小设为 19 GiB

命令(输入 m 获取帮助):t(指定类型)
分区号 (1-3,默认 3):(要指定的分区号,刚刚默认3,这里也默认3)
Hex 代码(输入 L 列出所有代码):8e (8e代表LVM)
已将分区“Linux”的类型更改为“Linux LVM”

命令(输入 m 获取帮助):w(w保存)
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
正在同步磁盘。




### 注意:###
保存后,最后几行提示设备资源忙,这时同步不了磁盘
需要重启服务器或者执行partprobe,我这里是执行的命令,如果这里不做操作的话,下面格式化磁盘的时候会报错!!!

Partitionen anzeigen und Partitionen formatieren

[root@Z ~]# fdisk -l

磁盘 /dev/sda:64.4 GB, 64424509440 字节,125829120 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000b05f5

 设备 BootStart EndBlocks IdSystem
/dev/sda1 *2048 2099199 1048576 83Linux
/dev/sda2 20992008388607940893440 8eLinux LVM
/dev/sda383886080 12373196719922944 8eLinux LVM

磁盘 /dev/mapper/centos-root:37.7 GB, 37706792960 字节,73646080 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节




### 格式化分区 ###
[root@Z ~]# mkfs.xfs -f /dev/sda3
meta-data=/dev/sda3isize=512agcount=4, agsize=1245184 blks
 = sectsz=512 attr=2, projid32bit=1
 = crc=1finobt=0, sparse=0
data = bsize=4096 blocks=4980736, imaxpct=25
 = sunit=0swidth=0 blks
naming =version 2bsize=4096 ascii-ci=0 ftype=1
log=internal log bsize=4096 blocks=2560, version=2
 = sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0




不执行"注意"命令或不重启设备,格式化时报找不到设备:
[root@Z ~]# mkfs.xfs-f/dev/sda3
/dev/sda3: 没有那个文件或目录

Konvertieren Sie die Partition in ein physisches Volume und verwenden Sie den Befehl pvdisplay, um die Informationen zum physischen Volume anzuzeigen: pvdisplay

### 转换物理卷 ###
[root@Z ~]# pvcreate /dev/sda3
 WARNING: xfs signature detected on /dev/sda3 at offset 0. Wipe it? [y/n]: y
Wiping xfs signature on /dev/sda3.
Physical volume "/dev/sda3" successfully created.




### 查看物理卷 ###
 [root@Z ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name centos
PV Size <39.00 GiB / not usable 3.00 MiB
Allocatable yes 
PE Size 4.00 MiB
Total PE9983
Free PE 1
Allocated PE9982
PV UUID v5DSQS-Cumb-xtyK-BWsx-ayfS-T0iT-FC3rbE
 
"/dev/sda3" is a new physical volume of "19.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sda3
VG Name 
PV Size 19.00 GiB
Allocatable NO
PE Size 0 
Total PE0
Free PE 0
Allocated PE0
PV UUID Xkbr0u-Ce9h-jvqW-JSZr-nwxY-qYNo-OSqqWm

Mit vgdisplay sehe ich, dass die Gesamtkapazität Alloc PE 38,9 beträgt und die frei zuweisbare Kapazität weg ist

[root@Z ~]# vgdisplay
--- Volume group ---
VG Name centos
System ID 
Formatlvm2
Metadata Areas1
Metadata Sequence No3
VG Access read/write
VG Status resizable
MAX LV0
Cur LV2
Open LV 2
Max PV0
Cur PV1
Act PV1
VG Size <39.00 GiB
PE Size 4.00 MiB
Total PE9983
Alloc PE / Size 9982 / 38.99 GiB
FreePE / Size 1 / 4.00 MiB
VG UUID hTO0Fm-c4q8-yboo-cSig-XLcK-CXo7-JoTInz

Fügen Sie das gerade initialisierte physische Volume zum physischen Volume der primären Partition hinzu: vgextend centos(vg name) /dev/sda3 Überprüfen Sie nach dem Hinzufügen vgdisplay und Sie können sehen, dass die frei zuweisbare Kapazität 19G beträgt

[root@Z ~]# vgextend centos /dev/sda3
Volume group "centos" successfully extended

[root@Z ~]# vgdisplay
--- Volume group ---
VG Name centos
System ID 
Formatlvm2
Metadata Areas2
Metadata Sequence No4
VG Access read/write
VG Status resizable
MAX LV0
Cur LV2
Open LV 2
Max PV0
Cur PV2
Act PV2
VG Size 57.99 GiB
PE Size 4.00 MiB
Total PE14846
Alloc PE / Size 9982 / 38.99 GiB
FreePE / Size 4864 / 19.00 GiB
VG UUID hTO0Fm-c4q8-yboo-cSig-XLcK-CXo7-JoTInz

LVM-Informationen zum logischen Volume anzeigen: lvdisplay, hauptsächlich LV-Pfad und LV-Größe anzeigen

[root@Z ~]# lvdisplay
--- Logical volume ---
LV Path/dev/centos/swap
LV Nameswap
VG Namecentos
LV UUIDvfUMhU-5XVp-s4uB-lVs3-436b-29Vh-StDsYb
LV Write Accessread/write
LV Creation host, time localhost, 2022-03-30 16:58:54 +0800
LV Statusavailable
# open 2
LV Size<3.88 GiB
Current LE 992
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
 
--- Logical volume ---
LV Path/dev/centos/root
LV Nameroot
VG Namecentos
LV UUID4KsFu6-jk8H-WsUa-1RVM-2DUq-gyPE-Nb6Rcx
LV Write Accessread/write
LV Creation host, time localhost, 2022-03-30 16:58:54 +0800
LV Statusavailable
# open 1
LV Size<35.12 GiB
Current LE 8990
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0

Verwenden Sie den Befehl lvextend, um die Partition zu erweitern: lvextend -l +4864 /dev/centos/root. Überprüfen Sie nach der Erweiterung die LV-Größe mit lvdisplay. Die Größe 4864 ist: die ID-Nummer von Free PE. centos/root mit dem Befehl vgdisplay und es ist: LV-Pfad über den Befehl lvdisplay anzeigen

[root@Z ~]# lvextend -l +4864 /dev/centos/root
Size of logical volume centos/root changed from <35.12 GiB (8990 extents) to <54.12 GiB (13854 extents).
Logical volume centos/root successfully resized.



[root@Z ~]# lvdisplay
--- Logical volume ---
LV Path/dev/centos/swap
LV Nameswap
VG Namecentos
LV UUIDvfUMhU-5XVp-s4uB-lVs3-436b-29Vh-StDsYb
LV Write Accessread/write
LV Creation host, time localhost, 2022-03-30 16:58:54 +0800
LV Statusavailable
# open 2
LV Size<3.88 GiB
Current LE 992
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
 
--- Logical volume ---
LV Path/dev/centos/root
LV Nameroot
VG Namecentos
LV UUID4KsFu6-jk8H-WsUa-1RVM-2DUq-gyPE-Nb6Rcx
LV Write Accessread/write
LV Creation host, time localhost, 2022-03-30 16:58:54 +0800
LV Statusavailable
# open 1
LV Size<54.12 GiB
Current LE 13854
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0

Mount: xfs_growfs /dev/centos/root; Wenn der Festplattentyp xfs ist, verwenden Sie: xfs_frowfs-Befehl. Wenn der Festplattentyp ext4 ist, verwenden Sie: resize2fs-Befehl [resize2fs /dev/centos/root]

[root@Z ~]# xfs_growfs /dev/centos/root
meta-data=/dev/mapper/centos-root isize=512agcount=4, agsize=2301440 blks
 = sectsz=512 attr=2, projid32bit=1
 = crc=1finobt=0 spinodes=0
data = bsize=4096 blocks=9205760, imaxpct=25
 = sunit=0swidth=0 blks
naming =version 2bsize=4096 ascii-ci=0 ftype=1
log=internal bsize=4096 blocks=4495, version=2
 = sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 9205760 to 14186496

df -TH Festplatteninformationen anzeigen, die Erweiterung wurde abgeschlossen

[root@Z ~]# df -TH
文件系统类型容量已用可用 已用% 挂载点
/dev/mapper/centos-root xfs59G2.4G 56G5% /
devtmpfsdevtmpfs1.1G 01.1G0% /dev
tmpfs tmpfs 1.1G 01.1G0% /dev/shm
tmpfs tmpfs 1.1G 10M1.1G1% /run
tmpfs tmpfs 1.1G 01.1G0% /sys/fs/cgroup
/dev/sda1 xfs 1.1G139M925M 14% /boot
tmpfs tmpfs 208M 0208M0% /run/user/0

Zusammenfassung des LVM-ArbeitsprinzipsGrundlegende Schritte zum Erstellen einer LVM-Erweiterung

Erstellen Sie zunächst die Partition gemäß dem LVM-Format in ein PV (physisches Volume), fügen Sie das physische Volume zur Volume-Gruppe (VG) hinzu und trennen Sie dann das LV (logisches Volume) durch das logische Volume, um eine Partitionserweiterung zu erreichen LVM zur Erweiterung Tatsächlich wird das abgetrennte logische Volume auf die Root-Partition erweitert.

Zusammenfassung der Schritte zur Verwendung von LVM zur Kapazitätserweiterung

Bereiten Sie eine neue Festplatte mit Partitionen vor → ändern Sie den Festplattentyp auf 8e → erstellen Sie ein logisches Volume (PV) (verwenden Sie die neu hinzugefügte Festplattenpartition als physisches Volume) → erstellen Sie eine Volume-Gruppe (VG) → erstellen Sie ein logisches Volume (LV) → Logische Volumes formatieren und mounten → Kapazitätserweiterung erreichen

Einfach ausgedrückt:

PV: 是物理的磁盘分区
VG: LVM中的物理的磁盘分区,也就是PV,必须加入VG,可以将VG理解为一个仓库或者是几个大的硬盘
LV: 从VG中划分的逻辑分区

Übersicht der Schritte

#把硬盘分区创建成pv
pvresize /dev/sdb1 (新分区)
#把创建成pv的分区 加入vg
vgextend centos/dev/sdb1(新分区)
# 给vg中的/dev/centos/home 扩容
lvextend -L +500G /dev/centos/home
#调整XFS文件系统以利用新增的空间。使用xfs_growfs命令来调整XFS文件系统的大小
xfs_growfs /dev/centos/home(xfs)
#调整文件系统大小以利用新增的空间。如果逻辑卷上运行的是ext2、ext3或ext4文件系统,可以使用resize2fs命令调整文件系统大小
 resize2fs /dev/centos/home(ext4)

Das obige ist der detaillierte Inhalt vonGrundlegende Schritte zum Erstellen einer LVM-Erweiterung. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Stellungnahme:
Dieser Artikel ist reproduziert unter:mryunwei.com. Bei Verstößen wenden Sie sich bitte an admin@php.cn löschen