VMware增加Linux磁盘空间,通过LVM调整.

调整磁盘大小

首先在VM中扩展/增加磁盘

image

查看增加了容量的磁盘

~$  fdisk -l

**Disk /dev/sda: 10.7 GB**, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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         391     3036285   8e  Linux LVM

创建新分区

进入分区界面,输入’n’创建新分区

~$  fdisk /dev/sda

The number of cylinders for this disk is set to 1305.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n
输入p选择primary partition
Command action
e   extended
p   primary partition (1-4)
  p
因为我们已经有两个分区了,所以输入3
Partition number (1-4): 3
输入起始与结束位置
First cylinder (392-1305, default 392): <enter>
Using default value 392
Last cylinder or +size or +sizeM or +sizeK (392-1305, default 1305): <enter>
Using default value 1305
设置分区类型
Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): 8e
Changed system type of partition 3 to 8e (Linux LVM)
输入w 保存配置
Command (m for help): w
此时fdisk提示你需要重启才有效.我们可以尝试以下命令防止重启
~$ partprobe -s
如果上面的命令没效果,尝试以下命令
partx -v -a /dev/sda
此时再用fdisk –l 就可以看到新建的磁盘了
~$  fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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         391     3036285   8e  Linux LVM
/dev/sda3             392        1305     7341705   8e  Linux LVM

使用LVM扩展分区

创建LVM的物理卷

~$  pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created
查看LVM组名
~$  vgdisplay
--- Volume group ---
VG Name               VolGroup00
...
扩展这个组
~$  vgextend VolGroup00 /dev/sda3
Volume group "VolGroup00" successfully extended
通过pvscan命令我们可以看到我们刚添加的未使用的空间
~$  pvscan
PV /dev/sda2   VG VolGroup00   lvm2 [2.88 GB / 0    free]
PV /dev/sda3   VG VolGroup00   lvm2 [7.00 GB / 7.00 GB free]
Total: 2 [9.88 GB] / in use: 2 [9.88 GB] / in no VG: 0 [0   ]
增加逻辑卷
~$  lvextend /dev/VolGroup00/LogVol00 /dev/sda3
Extending logical volume LogVol00 to 9.38 GB
Logical volume LogVol00 successfully resized
最后执行resize2fs调整分区即可
~$  resize2fs /dev/VolGroup00/LogVol00
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line resizing required
Performing an on-line resize of /dev/VolGroup00/LogVol00 to 2457600 (4k) blocks.
The filesystem on /dev/VolGroup00/LogVol00 is now 2457600 blocks long.

参考

Increase A VMware Disk Size (VMDK) Formatted As Linux LVM without rebooting

打赏支持:支付宝/微信。如果你觉得我的文章对你有所帮助,可以打赏我哟。