增加虚拟机linux硬盘容量方法有好几种
先记录我使用过的一种方法:
1、 关闭虚拟机里面的linux系统
2、 在vmware 软件的VM->Settings 选中harddisk 选中右侧的utlities 下面有expand选项。
3、 对弹出的对话框输入你要扩展到的硬盘容量(包括原有的容量)。
4、 成功后重新启动linux系统。
5、 以root用户登录对文件系统进行操作(以下默认使用root用户)。
6、[root@wangwei wangwei]# fdisk-l
Disk /dev/sda: 107.4 GB,107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000ca91a
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not endon cylinder boundary.
/dev/sda2 26 6527 52223296 8e Linux LVM
Disk /dev/dm-0: 52.4 GB, 52399439872 bytes
255 heads, 63 sectors/track, 6370 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000
Disk /dev/dm-0 doesn't contain a valid partition table
Disk /dev/dm-1: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000
Disk /dev/dm-1 doesn't contain a valid partition table
由以上的数据可以看出整个/dev/sda 有100G容量,共分区/dev/sda1 和 /dev/sda2 也就是你扩展前的容量。我以前是50G的(我从50G扩大到100G)。
7、 对/dev/sda 进行分区,操作如下:
[root@wangweiwangwei]# fdisk /dev/sda
The number ofcylinders for this disk is set to 13054.
There is nothingwrong with that, but this is larger than 1024,
and could incertain setups cause problems with:
1) software thatruns at boot time (e.g., old versions of LILO)
2) booting andpartitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m forhelp): n
Command action
e extended
p primary partition (1-4)
p
Partition number(1-4): 4
First cylinder(6528-13054, default 6528):
Using defaultvalue 6528
Last cylinder,+cylinders or +size{K,M,G} (6528-13054, default 13054):
Using defaultvalue 13054
Command (m for help): w
The partitiontable 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 stilluses the old table. The new table will be used at
the next rebootor after you run partprobe(8) or kpartx(8)
Syncing disks.
8、做到这里表示分区完成了,但是内核并没有识别到,可以选择重启,也可以选择使用命令partprobe 强制内核对分区重新读取。
我选择重启,重启后继续以root登录。
查看分区信息:[root@wangweiwangwei]# fdisk -l
Disk /dev/sda: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
Disk identifier: 0x000ca91a
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinderboundary.
/dev/sda2 26 6527 52223296 8e Linux LVM
/dev/sda4 6528 13054 52428127+ 83 Linux
新分区已经在了,下面进行格式化和挂载。
8、对新分区/dev/sda4格式化:[root@wangwei wangwei]# mkfs -t ext3 /dev/sda4
9、挂载:挂载的时候要注意了。最好不要挂载在有数据的目录,可以新建一个空目录来挂载。
我挂载在/opt目录下。
[root@wangwei wangwei]# mount /dev/sda4 /opt/
10、修改系统fstab文件。
[root@wangweiopt]# vi /etc/fstab
在最末尾处增加一行:
/dev/sda4 /opt ext3 defaults 0 0
到此就完成了,可重启查看文件系统分区信息 :df -h