环境准备
系统环境:EVE-PRO-VM-2.0.4-20
前期是使用ova导入安装,精简置备,40G虚拟磁盘容量。空间不足,尝试了很久,记录操作记录如下:
血泪教训:操作不当有可能引起数据丢失,需要提前备份数据!备份镜像!!备份lab!!!
1. 关机状态下编辑EVE虚拟机
将虚拟磁盘容量从40G扩展至200G,扩展完毕之后,会提示:磁盘已成功扩展,您必须从客户及操作系统内部对磁盘重新进行分区和扩展文件系统。
注意:无法扩展具有快照的虚机中的磁盘,必须删除快照!
2. EVE系统层面对磁盘重新分区
''' 操作之前 '''
root@eve-ng:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 3.9G 0 3.9G 0% /dev
tmpfs 799M 27M 773M 4% /run
/dev/mapper/eve--ng--vg-root 38G 17G 20G 46% / >>> 记住这个卷名称
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sda1 472M 83M 365M 19% /boot
root@eve-ng:~#
root@eve-ng:~#
建议备份 /etc/fstab ,之前遇到虚拟机重启后 eve--ng--vg-root 这个逻辑卷从 fstab 中消失。
''' 查看磁盘分区情况 '''
root@eve-ng:~# fdisk -l
......
Disk /dev/sda: 200 GiB, 214748364800 bytes, 419430400 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x3e3ca055
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 999423 997376 487M 83 Linux
/dev/sda2 1001470 83884031 82882562 39.5G 5 Extended
/dev/sda5 1001472 83884031 82882560 39.5G 8e Linux LVM
Disk /dev/mapper/eve--ng--vg-root: 38.6 GiB, 41406169088 bytes, 80871424 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/eve--ng--vg-swap_1: 980 MiB, 1027604480 bytes, 2007040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
root@eve-ng:~#
开始磁盘分区操作:
root@eve-ng:~# fdisk /dev/sda
Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): n >>> 创建新分区
Partition type
p primary (1 primary, 1 extended, 2 free)
l logical (numbered from 5)
Select (default p): p
Partition number (3,4, default 3): 3
First sector (999424-419430399, default 999424): 83884032 >>> sda3的First sector = sda2的end sector + 1
Last sector, +sectors or +size{K,M,G,T,P} (83884032-419430399, default 419430399):
Created a new partition 3 of type 'Linux' and of size 160 GiB.
''' 修改分区类型(与sda5保持一致,可选) '''
Command (m for help): t
Partition number (1-3,5, default 5): 3
Partition type (type L to list all types): 8e
Changed type of partition 'Linux' to 'Linux LVM'.
Command (m for help): p
Disk /dev/sda: 200 GiB, 214748364800 bytes, 419430400 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x3e3ca055
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 999423 997376 487M 83 Linux
/dev/sda2 1001470 83884031 82882562 39.5G 5 Extended
/dev/sda3 83884032 419430399 335546368 160G 8e Linux LVM
/dev/sda5 1001472 83884031 82882560 39.5G 8e Linux LVM
Partition table entries are not in disk order.
Command (m for help): w >>> 写入磁盘分区表
The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: Device or resource busy
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).
root@eve-ng:~#
此时可以进行选择,使用 fdisk 工具只是将分区信息写到磁盘,如果需要 mkfs 磁盘分区则需要重启系统,
而使用 partprobe 则可以使 kernel 重新读取分区信息,从而避免重启系统。
root@eve-ng:~# partprobe
3. 初始化物理卷(可选)
root@eve-ng:~# pvscan
PV /dev/sda5 VG eve-ng-vg lvm2 [39.52 GiB / 0 free]
Total: 1 [39.52 GiB] / in use: 1 [39.52 GiB] / in no VG: 0 [0 ]
root@eve-ng:~#
root@eve-ng:~# pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created
root@eve-ng:~#
root@eve-ng:~# pvscan
PV /dev/sda5 VG eve-ng-vg lvm2 [39.52 GiB / 0 free]
PV /dev/sda3 lvm2 [160.00 GiB]
Total: 2 [199.52 GiB] / in use: 1 [39.52 GiB] / in no VG: 1 [160.00 GiB]
root@eve-ng:~#
pvcreate命令 用于将物理硬盘分区初始化为物理卷,以便LVM使用。
4. 扩展逻辑卷空间
''' 操作之前查看当前卷组属性 '''
root@eve-ng:~# vgdisplay
--- Volume group ---
VG Name eve-ng-vg >>> 记录卷组名称
......
VG Size 39.52 GiB
......
VG UUID EvwUbc-nfsg-dHqA-znxB-U3gv-V782-Q8ZxkI
root@eve-ng:~#
''' 向卷组中添加物理卷 '''
root@eve-ng:~# vgextend eve-ng-vg /dev/sda3
Volume group "eve-ng-vg" successfully extended
root@eve-ng:~#
root@eve-ng:~# vgdisplay
--- Volume group ---
VG Name eve-ng-vg
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 199.52 GiB
PE Size 4.00 MiB
Total PE 51077
Alloc PE / Size 10117 / 39.52 GiB
Free PE / Size 40960 / 160.00 GiB
VG UUID EvwUbc-nfsg-dHqA-znxB-U3gv-V782-Q8ZxkI
root@eve-ng:~#
此时查看 pvscan ,不在 VG 中的物理卷空间为 0:
root@eve-ng:~# pvscan
PV /dev/sda5 VG eve-ng-vg lvm2 [39.52 GiB / 0 free]
PV /dev/sda3 VG eve-ng-vg lvm2 [160.00 GiB / 160.00 GiB free]
Total: 2 [199.52 GiB] / in use: 2 [199.52 GiB] / in no VG: 0 [0 ]
root@eve-ng:~#
接下来扩展逻辑卷空间:
''' 操作之前检查当前逻辑卷属性 '''
root@eve-ng:~# lvdisplay
--- Logical volume ---
LV Path /dev/eve-ng-vg/root >>> 记录LV Path
......
LV Size 38.56 GiB
......
--- Logical volume ---
LV Path /dev/eve-ng-vg/swap_1
......
root@eve-ng:~#
root@eve-ng:~#
root@eve-ng:~# lvextend -l +100%FREE /dev/eve-ng-vg/root
Size of logical volume eve-ng-vg/root changed from 38.56 GiB (9872 extents) to 198.56 GiB (50832 extents).
Logical volume root successfully resized.
root@eve-ng:~#
root@eve-ng:~# lvdisplay
--- Logical volume ---
LV Path /dev/eve-ng-vg/root
LV Name root
VG Name eve-ng-vg
LV UUID ktUpR0-VpqS-rJJv-a1FC-u6Gd-U8yN-2WYQ53
LV Write Access read/write
LV Creation host, time eve-ng, 2018-03-21 02:25:21 +0200
LV Status available
# open 1
LV Size 198.56 GiB
Current LE 50832
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
--- Logical volume ---
LV Path /dev/eve-ng-vg/swap_1
LV Name swap_1
VG Name eve-ng-vg
LV UUID oFbeHd-xHkl-cpe1-22Nx-xX73-xLJF-fJKrXK
LV Write Access read/write
LV Creation host, time eve-ng, 2018-03-21 02:25:21 +0200
LV Status available
# open 2
LV Size 980.00 MiB
Current LE 245
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
root@eve-ng:~#
最后执行 resize2fs 重新计算文件系统大小:
root@eve-ng:~# resize2fs /dev/eve-ng-vg/root
resize2fs 1.42.13 (17-May-2015)
Filesystem at /dev/eve-ng-vg/root is mounted on /; on-line resizing required
old_desc_blocks = 3, new_desc_blocks = 13
The filesystem on /dev/eve-ng-vg/root is now 52051968 (4k) blocks long.
root@eve-ng:~#
root@eve-ng:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 3.9G 0 3.9G 0% /dev
tmpfs 799M 27M 773M 4% /run
/dev/mapper/eve--ng--vg-root 196G 17G 171G 9% /
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sda1 472M 83M 365M 19% /boot
root@eve-ng:~#
2020年3月,删除之前博客内容,整理扩展LVM卷的内容,eve-ng操作技巧后面单独整理一篇
本文由 SHIYL 创作,采用 知识共享署名4.0 国际许可协议进行许可
本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名
最后编辑时间为: Mar 26, 2020 at 11:06 am