Linux中VMware虚拟机增加磁盘空间的扩容操作[图文]

来源:互联网 发布:长沙联通网络好不好 编辑:程序博客网 时间:2024/05/16 02:14

用VMwareware虚拟机安装的Red Hat Enterprise Linux系统剩余空间不足,造成软件无法正常安装。如果重新装一遍系统就需要重新配置好开发环境和软件的安装配置。通过上网搜集的资料,结合自己的实践,总结了如下扩大硬盘空间的详细步骤,希望对大家有帮助。

(1)打开VMware,选择Edit Virtual mache settings,Utilities下拉框中找到Expand如下图

Linux中VMware虚拟机增加磁盘空间的扩容操作[图文]

(2)将磁盘空间扩大到50G,点击Expand即可,随后进入一个较长的Expand过程,完成后这是新的空间已经增加,但linux环境下还不可见。

Linux中VMware虚拟机增加磁盘空间的扩容操作[图文]

(3)启动VMware环境下的Linux操作系统,添加新分区,需要root账号身份。

3.1 【fdisk -l】 最大分区为/dev/sda3,说明新创建的分区将会是sda4

3.2 输入【fdisk /dev/sda】

3.2.1命令行提示下输入【m】

3.2.2输入命令【n】添加新分区。

3.2.3输入命令【p】创建主分区。

3.2.4输入【回车】,选择默认大小,这样不浪费空间

3.2.5输入【回车】,选择默认的start cylinder。

3.2.6输入【w】,保持修改

3.3 输入【reboot】 重启linux,必须reboot,否则/dev/sda4无法格式化。

3.4 这时在/dev/目录下,才能看到了新的分区比如/dev/sda4

3.5 【mkfs.ext2 /dev/sda4】格式化

3.6 在根目录下创建disk4目录

3.7 【mount /dev/sda4 /disk4/】将分区mount到/disk4/上

3.8  在vim修改/etc/fstab文件,加入【/dev/sda4   /disk4 ext2 defaults 0 0】一行,并保存,实现开机自动mount。

至此,新增加的磁盘空间容量,即可在disk4上体现,并且重新开机自动mount该分区,追加磁盘空间的工作完毕。

如果当前磁盘无容可阔,可以用增加磁盘的方法,在VMware主界面,选择 【VMware】下拉菜单,选择【Settings】,用【Add】方式增加一块磁盘,后面的操作类似,不再重复。


分区的过程正常:

[root@db1 /]# fdisk -l

 

Disk /dev/sda: 21.4 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 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         650     5116702+  83  Linux

/dev/sda3             651         841     1534207+  82  Linux swap / Solaris

[root@db1 /]# fdisk /dev/sda

 

The number of cylinders for this disk is set to 2610.

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

Command action

   e   extended

   p   primary partition (1-4)

p

Selected partition 4

First cylinder (842-2610, default 842):

Using default value 842

Last cylinder or +size or +sizeM or +sizeK (842-2610, default 2610):

Using default value 2610

 

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.

Syncing disks.

 

再次查看,分区已经划好:

[root@db1 /]# fdisk -l

 

Disk /dev/sda: 21.4 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 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         650     5116702+  83  Linux

/dev/sda3             651         841     1534207+  82  Linux swap / Solaris

/dev/sda4             842        2610    14209492+  83  Linux

 

但是格式化的时候,报错:

[root@db1 /]# mkfs -t ext3 /dev/sda4

mke2fs 1.39 (29-May-2006)

Could not stat /dev/sda4 --- No such file or directory

 

The device apparently does not exist; did you specify it correctly?

 

 

解决方法:执行下partprobe 命令

 

       partprobe包含在parted的rpm软件包中。partprobe可以修改kernel中分区表,使kernel重新读取分区表。 因此,使用该命令就可以创建分区并且在不重新启动机器的情况下系统能够识别这些分区

 

查看是否安装该命令:

[root@db1 dev]# rpm -q parted

parted-1.8.1-23.el5

 

我们执行一下该命令:

[root@db1 dev]# partprobe

Warning: Unable to open /dev/hdc read-write (Read-only file system).  /dev/hdc has been opened read-only.

 

然后在格式化,就ok了:

[root@db1 dev]# mkfs -t ext3 /dev/sda4

mke2fs 1.39 (29-May-2006)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

1778880 inodes, 3552373 blocks

177618 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=3640655872

109 block groups

32768 blocks per group, 32768 fragments per group

16320 inodes per group

Superblock backups stored on blocks:

        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208

 

Writing inode tables: done                           

Creating journal (32768 blocks): done

Writing superblocks and filesystem accounting information: done

 

This filesystem will be automatically checked every 38 mounts or

180 days, whichever comes first.  Use tune2fs -c or -i to override.


转自:http://www.linuxidc.com/Linux/2011-02/32083.htm

0 0
原创粉丝点击