Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2323261
  • 博文数量: 535
  • 博客积分: 8689
  • 博客等级: 中将
  • 技术积分: 7066
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-26 10:00
文章分类

全部博文(535)

文章存档

2024年(4)

2023年(4)

2022年(16)

2014年(90)

2013年(76)

2012年(125)

2011年(184)

2010年(37)

分类: LINUX

2011-05-04 16:15:59




VMware添加虚拟硬盘
2009-10-27 13:46
场景:VMware安装linux的时候默认分配的空间是4GB,可能会不够,这个时候可以通过增加一块虚拟硬盘,将/usr或其他内容拷贝过去解决这个问题:

创建虚拟硬盘
1、关闭VM中正在运行的虚拟系统;
2、在虚拟系统名称上点右键->Virtual Machine Settings;
3、在Hardware页点“Add”->Add a hard disk->Create a new virtual disk->SCSI(recommended)->分配空间大小->OK;
4、可以看见Hardware中出现了一块新的硬盘Hard Disk 2。

对虚拟硬盘进行分区和格式化
-------------------------------------------------------------------------------
## 查看目前系统上有几块硬盘
[root@zhou-desktop ~]# fdisk -l

Disk /dev/hda: 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/hda1   *         132        1305     9430155   83 Linux
/dev/hda2               1         131     1052226   82 Linux swap / Solaris

Partition table entries are not in disk order

Disk /dev/hdb: 10.7 GB, 10737418240 bytes
15 heads, 63 sectors/track, 22192 cylinders
Units = cylinders of 945 * 512 = 483840 bytes

Disk /dev/hdb doesn't contain a valid partition table
-------------------------------------------------------------------------------
对/dev/hdb分区进行分区
[root@zhou-desktop ~]# fdisk /dev/hdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.


The number of cylinders for this disk is set to 22192.
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)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

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): p       ## 打印出目前该硬盘下的分区列表

Disk /dev/hdb: 10.7 GB, 10737418240 bytes
15 heads, 63 sectors/track, 22192 cylinders
Units = cylinders of 945 * 512 = 483840 bytes

   Device Boot      Start         End      Blocks   Id System

Command (m for help): n       ## 增加一个分区
Command action
   e   extended
   p   primary partition (1-4)
p                           ## 通常选择主分区,所以这里选p
Partition number (1-4): 1   ## 第一个分区,选1;第二个分区,选2,依次类推
First cylinder (1-22192, default 1): ## 默认值,回车
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-22192, default 22192):
## 如果要分区10G,这里可以直接输入:+10240M,因为这里要全部使用硬盘空间,则用默认
Using default value 22192

Command (m for help): p

Disk /dev/hdb: 10.7 GB, 10737418240 bytes
15 heads, 63 sectors/track, 22192 cylinders
Units = cylinders of 945 * 512 = 483840 bytes

   Device Boot      Start         End      Blocks   Id System
/dev/hdb1               1       22192    10485688+ 83 Linux

## 第一个分区已经分好了,接下来把这个分区写入硬盘,用w
Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

## 下面的工作就是对该硬盘进行格式,格式化成ext3
[root@zhou-desktop ~]# mkfs.ext3 /dev/hdb1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
1310720 inodes, 2621422 blocks
131071 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2684354560
80 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Writing inode tables: done                          
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 37 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
## 检查一下,是否已经格式好
[root@zhou-desktop ~]# fdisk -l

Disk /dev/hda: 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/hda1   *         132        1305     9430155   83 Linux
/dev/hda2               1         131     1052226   82 Linux swap / Solaris

Partition table entries are not in disk order

Disk /dev/hdb: 10.7 GB, 10737418240 bytes
15 heads, 63 sectors/track, 22192 cylinders
Units = cylinders of 945 * 512 = 483840 bytes

   Device Boot      Start         End      Blocks   Id System
/dev/hdb1               1       22192    10485688+ 83 Linux
[root@zhou-desktop ~]#

## 挂载虚拟硬盘
把/dev/hdb1挂载到/mnt/ext下
[root@zhou-desktop ~]# mount /dev/hdb1 /mnt/ext

## 重启系统之后,再挂载看是否成功
[root@zhou-desktop mnt]# df -lh
文件系统              容量 已用 可用 已用% 挂载点
/dev/hda1             8.8G 2.7G 5.6G 33% /
tmpfs                 252M     0 252M   0% /dev/shm
/dev/hdb1             9.9G 151M 9.2G   2% /mnt/ext

## 转移数据
1、/usr中的全部数据
2、清空usr目录:
   # rm -r /usr
   # mkdir /usr
3、卸载刚才挂上的虚拟硬盘,重新将它挂载到usr目录:
   # umount /mnt/ext
   # mount /dev/hdb1 /usr
4、 ## 用vi修改/etc/fstab,使系统启动就可以自动挂载
   # vim /etc/fstab
   在内容中加上一行:
   /dev/sdb1                /usr                     ext3     defaults         1 2

5、Ok,重新启动之后,可以查看现在的硬盘使用情况了:
[root@zhou-desktop mnt]# df -lh
文件系统              容量 已用 可用 已用% 挂载点
/dev/hda1             8.8G 2.7G 5.6G 33% /
tmpfs                 252M     0 252M   0% /dev/shm
/dev/hdb1             9.9G 151M 9.2G   2% /usr





阅读(1319) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~