VMware下Linux虚拟机增加磁盘空间
1、首先在虚拟机实例设置中,选择已有的harddisk,然后点击Utilities中的expand扩充硬盘空间。
比如:现在是15g,调整到16g,点击expand就扩充完成了。
这里也可以选择增加一个硬盘。
2、现在硬盘已经加了1g,下面需要到虚拟机里面将这1g空间挂载上,首先打开虚拟机
用root用户从终端登录,用命令 fdisk -l查看
Disk /dev/sdb: 17.1 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 1958 15727603+ 83 Linux
可以看到/dev/sdb 的大小已经是17gb了
如果是新加的硬盘,这里会新增一个 /dev/sdx x从a开始增加
3、使用fdisk /dev/sdb 进入菜单项
参数:m 列出菜单,p列出分区,n增加分区,w保存退出
操作如下:依次执行
[root@localhost ~]# fdisk /dev/sdb
The number of cylinders for this disk is set to 2088.
There is nothing wrong with that, but this is larger than1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions ofLILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2FDISK)
列出现有的分区
Command (m for help): p
Disk /dev/sdb: 17.1 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 1958 15727603+ 83 Linux
增加分区sdb2
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (1959-2088, default1959):
Using default value 1959
Last cylinder or +size or +sizeM or +sizeK (1959-2088, default2088):
Using default value 2088
列出分区,发现增加了sdb2
Command (m for help): p
Disk /dev/sdb: 17.1 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 1958 15727603+ 83 Linux
/dev/sdb2 1959 2088 1044225 83 Linux
保存并退出
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:设备或资源忙.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
You have new mail in /var/spool/mail/root
4、重启机器,继续后面的工作
[root@localhost ~]# reboot
5、重启机器后进入root用户
操作如下:
挂载前的分区情况
[root@localhost ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda6 17G 15G 755M 96% /
/dev/sda3 4.8G 213M 4.3G 5% /var
/dev/sda2 5.7G 2.8G 2.7G 51% /home
/dev/sda1 494M 16M 453M 4% /boot
tmpfs 710M 0 710M 0%/dev/shm
/dev/sdb1 15G 3.5G 11G 25% /home/software
.host:/ 30G 16G 14G 54%/mnt/hgfs
/dev/hdc 2.9G 2.9G 0 100% /media/RHEL_5.5 i386DVD
格式化分区
[root@localhost ~]# mkfs.ext3 /dev/sdb2
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
130560 inodes, 261056 blocks
13052 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
16320 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information:done
This filesystem will be automatically checked every 23 mountsor
180 days, whichever comes first. Use tune2fs-c or -i to override.
创建/test目录并挂载新的分区到这上面
[root@localhost ~]# mkdir /test
[root@localhost ~]# mount /dev/sdb2 /test
挂载后的分区情况
[root@localhost ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda6 17G 15G 755M 96% /
/dev/sda3 4.8G 213M 4.3G 5% /var
/dev/sda2 5.7G 2.8G 2.7G 51% /home
/dev/sda1 494M 16M 453M 4% /boot
tmpfs 710M 0 710M 0%/dev/shm
.host:/ 30G 16G 14G 54%/mnt/hgfs
/dev/hdc 2.9G 2.9G 0 100% /media/RHEL_5.5 i386DVD
/dev/sdb1 15G 3.5G 11G 25% /home/software
/dev/sdb2 1004M 18M 936M 2% /test
[root@localhost ~]#
6、设置开机自动加载
[root@localhost ~]# vi /etc/fstab
在文件最后添加下列语句:
/dev/sdb2 /test ext3 defaults 0 0
然后保存重启即可