查看挂载根目录是否为逻辑卷(系统默认挂载根目录方式:逻辑卷)
[root@hadoop2 cloudera-manager]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_hadoop2-lv_root
18G 17G 0 100% /
tmpfs 932M 4.0K 932M 1% /dev/shm
/dev/sda1 477M 42M 411M 10% /boot
如果是 /dev/mapper/... 表示逻辑卷,/dev/sda*:直接挂载物理盘
步骤:
1.在虚拟机关机的情况下,点击需要扩容的虚拟机设置

点击右下角扩展:填写的数字需要比现在的磁盘大小要大;


2.开启虚拟机,查看磁盘大小 与扩容前大小不一致说明扩容成功
[root@hadoop2 ~]# fdisk -l
Disk /dev/sda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 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: 0x0001f66e
Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 2611 20458496 8e Linux LVM
/dev/sda3 2611 3916 10483750 83 Linux
3.使用fdisk /dev/sda, 创建新分区。
注意:不同操作系统的磁盘命名方式不同,有些是/dev/sda。具体使用方式参考第三步中fdisk -l首行显示Disk。如笔者在该系统中首行显示为Disk /dev/sda: 53.7 GB, 53687091200 bytes ,故使用命令fdisk /dev/sda)
[root@hadoop2 ~]# fdisk /dev/sda
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): m --查看所有命令
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help): n --新建分区
Command action
e extended
p primary partition (1-4)
p --创建独立分区
Selected partition 4
First cylinder (3917-6527, default 3917): --回车默认
Using default value 3917
Last cylinder, +cylinders or +size{K,M,G} (3917-6527, default 6527): --回车默认
Using default value 6527
Command (m for help): t --改变分区编号
Partition number (1-4): 4 --不要和已有的编号重复
Hex code (type L to list codes): 8e --分区的类型
Changed system type of partition 4 to 8e (Linux LVM)
Command (m for help): p --显示分区信息
Disk /dev/sda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 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: 0x0001f66e
Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 2611 20458496 8e Linux LVM
/dev/sda3 2611 3916 10483750 83 Linux
/dev/sda4 3917 6527 20972857+ 8e Linux LVM
Command (m for help): w ---保存信息
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: 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)
Syncing disks.
4.reboot命令重启虚拟机查看分区,多了sda4
[root@hadoop2 ~]# fdisk -l
Disk /dev/sda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 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: 0x0001f66e
Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 2611 20458496 8e Linux LVM
/dev/sda3 2611 3916 10483750 83 Linux
/dev/sda4 3917 6527 20972857+ 8e Linux LVM
正式开始扩容
1. pvcreate命令 用于将物理硬盘分区初始化为物理卷,以便LVM使用。
#pvcreate /dev/sda4 --分区为新增分区名称
[root@hadoop2 ~]# pvcreate /dev/sda4
Physical volume "/dev/sda4" successfully created
查看新建的物理卷和大小
[root@hadoop2 ~]# vgdisplay
--- Volume group ---
VG Name vg_hadoop2
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 5
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 29.50 GiB
PE Size 4.00 MiB
Total PE 7553
Alloc PE / Size 7553 / 29.50 GiB
Free PE / Size 0 / 0
VG UUID MVOZ8z-qRjX-csiA-X4hI-JXwD-Wph1-E6sScZ
2.vgextend命令 用于动态扩展LVM卷组,它通过向卷组中添加物理卷来增加卷组的容量。LVM卷组中的物理卷可以在使用
# vgextend vg_hadoop2 /dev/sda4 -- 填写查询的物理卷名称 新增分区
[root@hadoop2 ~]# vgextend vg_hadoop2 /dev/sda4
Volume group "vg_hadoop2" successfully extended
3. 增加lv_root的大小,增加20G
# lvextend -L +20G /dev/mapper/vg_hadoop2-lv_root
[root@hadoop2 ~]# lvextend -L +20G /dev/mapper/vg_hadoop2-lv_root
Size of logical volume vg_hadoop2/lv_root changed from 27.50 GiB (7041 extents) to 47.50 GiB (12161 extents).
Logical volume lv_root successfully resized.
4. 重新识别大小, xfs_qrowfs 是centos7的命令,在centos6.X中是resize2fs
# resize2fs /dev/mapper/vg_hadoop2-lv_root
root@hadoop2 ~]# resize2fs /dev/mapper/vg_hadoop2-lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/vg_hadoop2-lv_root is mounted on /; on-line resizing required
old desc_blocks = 2, new_desc_blocks = 3
Performing an on-line resize of /dev/mapper/vg_hadoop2-lv_root to 12452864 (4k) blocks.
The filesystem on /dev/mapper/vg_hadoop2-lv_root is now 12452864 blocks long.
5. 查看扩容后的大小
[root@hadoop2 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_hadoop2-lv_root
47G 23G 23G 50% /
tmpfs 932M 80K 932M 1% /dev/shm
/dev/sda1 477M 42M 411M 10% /boot
/dev/sr0 3.7G 3.7G 0 100% /media/CentOS_6.9_Final
参考博客:
https://blog.youkuaiyun.com/max229max/article/details/80356250
本文介绍了在Linux环境下如何扩展根目录的磁盘空间,特别是针对逻辑卷的情况。步骤包括虚拟机扩容、创建新分区、使用fdisk、pvcreate、vgextend、lvextend和resize2fs命令来逐步增加卷组和根目录的大小,以适应系统需求。
5201

被折叠的 条评论
为什么被折叠?



