Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1222711
  • 博文数量: 322
  • 博客积分: 10010
  • 博客等级: 上将
  • 技术积分: 3276
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-17 09:21
文章分类

全部博文(322)

文章存档

2010年(155)

2009年(167)

我的朋友

分类: LINUX

2010-01-03 19:29:56

1、先将虚拟机Power Off,在Virtual Machine Setting对话框里点击左下角的“Add”,选择“Hard Disk”,之后选择“Create a new virtual disk”,分配容量,其他默认配置就可以了。

2、启动虚拟机系统,用root登陆,利用 # ls /dev/sd*  的命令可以看到最后有一个sdb 或sdc(如果是添加的第三块硬盘会是sdc),它没有sdb1和sdb2或sdc1和sdc2之类的设备文件,说明系统检查出来了这块硬盘但还没有分区格式化。这样就是上一步添加的硬盘。

在命令行用fdisk -l查看是否识别了新硬盘,如果添加的是IDE硬盘,就应该看到hdb,如果是SCSI硬盘,看到的就应该是sdb。

Disk /dev/sdc: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000

Disk /dev/sdc doesn't contain a valid partition table

因为我之前已经加过一块硬盘了,所以这里显示sdc。

3、使用fdisk /dev/sdc,

然后输入类似如下的参数:
n (add a new partition)
p (建立主分区)     1(第一个分区)     1(第一个柱面)    1024(最后一个柱面)   
w (保存)

选择好这些选项中选择“w”,即将分区表写入硬盘并退出,这时再用fdisk -l查看就会发现:

Disk /dev/sdc: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x5404b953

Device Boot Start End Blocks Id System

4、用mkfs命令将其格式化,mkfs.ext3  /dev/sdc1

5、建立一个要把新硬盘mount到得目录,比如建立一个 /work

再用mount命令将其挂载,mount -t ext3 /dev/sdc1 /work

6、最后,修改/etc/fstab文件,把要mount的新硬盘追加到后面,如下:

vi /etc/fstab

/dev/sdb1 /work ext3    rw,user,auto,exec 1 2

/dev/sdc1 /work         defaults 1 2

defaults == rw, suid, dev, exec, auto, nouser, and async.

==================================================================

附录:/etc/fstab文件解析

1. fstab文件的作用
文件/etc/fstab存放的是系统中的文件系统信息。当正确的设置了该文件,则可以通过"mount /directoryname"命令来加载一个文件系统,每种文件系统都对应一个独立的行,每行中的字段都有空格或tab键分开。同时fsck、mount、umount的等命令都利用该程序。


2. fstab文件格式
下面是/etc/fatab文件的一个示例行:
fs_spec fs_file fs_type fs_options fs_dump fs_pass
/dev/hda1 / ext2 defaults 1 1
fs_spec - 该字段定义希望加载的文件系统所在的设备或远程文件系统,对于一般的本地块设备情况来说:IDE设备一般描述为/dev/hdaXN,X是IDE设备通道(a, b, or c),N代表分区号;SCSI设备一描述为/dev/sdaXN。对于NFS情况,格式一般为:,例如:`knuth.aeb.nl:/。

对于procfs,使用`proc来定义。
fs_file - 该字段描述希望的文件系统加载的目录点,对于swap设备,该字段为none;对于加载目录名包含空格的情况,用40来表示空格。
fs_type - 定义了该设备上的文件系统,一般常见的文件类型为ext2 (Linux设备的常用文件类型)、vfat(Windows系统的fat32格式)、NTFS、iso9600等。
fs_options - 指定加载该设备的文件系统是需要使用的特定参数选项,多个参数是由逗号分隔开来。

对于大多数系统使用"defaults"就可以满足需要。其他常见的选项包括:
选项 含义
ro 以只读模式加载该文件系统
sync 不对该设备的写操作进行缓冲处理,这可以防止在非正常关机时情况下破坏文件系统,但是却降低了计算机速度
user 允许普通用户加载该文件系统
quota 强制在该文件系统上进行磁盘定额限制
noauto 不再使用mount -a命令(例如系统启动时)加载该文件系统
fs_dump - 该选项被"dump"命令使用来检查一个文件系统应该以多快频率进行转储,若不需要转储就设置该字段为0
fs_pass - 该字段被fsck命令用来决定在启动时需要被扫描的文件系统的顺序,根文件系统"/"对应该字段的值应该为1,其他文件系统应该为2。若该文件系统无需在启动时扫描则设置该字段为0


3. 示例文件
# /etc/fstab
/dev/hda9 swap swap defaults 0 0
/dev/hda1 / ext2 defaults 1 1
/dev/hda5 /home ext2 defaults 1 1
/dev/hda6 /usr ext2 defaults 1 1
/dev/hda7 /usr/local ext2 defaults 1 1
/dev/hda8 /var ext2 defaults 1 1
/dev/hdb /cdrom iso9660 noauto,user 0 0
none /proc proc defaults 0 0
none /dev/pts devpts gid=5,mode=620 0 0

=======================================================================

 具体操作例子如下:
 
I’ve been using
VMWare
for a while now and I always get asked some common questions about it.
One of those is how to add a new virtual disk to a Linux virtual
machine. So in response to that, here are the steps to adding a new
SCSI based virtual disk to a CentOS Linux virtual machine. The steps
for adding a disk to a 视窗系统 machine is very much the same except you
would use the Disk Management utility from the Control Panel.
Step 1: Open virtual machine settings
Select your virtual machine, as you can see from the photo I selected
the Infrastructure virtual machine. Next press the “Edit virtual
machine settings’ to open the Virtual Machine Settings dialog.

Step 2: Add new hardware
From the “Virtual Machine Settings” dialog select the “Add…” button at
the bottom of the screen. From this dialog you can also modify how much
memory you dedicate to the machine when it boots.

Step 4: Select new hard disk
From this screen we can see the many types of hardware we can add to a
virtual machine. You can emulate just about any piece of hardware that
one can expect in a modern operating system. It definitely makes
testing with different configurations and devices much easier. For our
example we want to select “Hard Disk” and then select the “Next >”
button.

Step 5: Create the virtual disk
In the next screen we see the three options for adding a new disk. We
can “Create a new virtual disk”, this will create a brand new disk on
the guest operating system. The second option, “Use an existing virtual
disk”, allows you to mount a disk from another virtual machine. I like
to do this with my “source” drive. I have one virtual disk that I’ve
made that has all the Oracle and Linux CDs on it, that way I can just
mount it to the machine I need when I have to do a new install instead
of copying the binaries I need across disks, its definitely a big time
saver. The last option is to “Use a physical disk”, this allows you to
mount a local physical disk to the operating system. This option is
akin to NFS mounting a drive to a virtual machine. To add a new disk we
select the “Create a new virtual disk” option and select the “Next
>” button.

Step 6: Select type of disk
Next we want to select the type of disk. I’ve been using VMWare for a
long time and agree that the recommended Virtual Disk Type should be
SCSI. I don’t know why, but I’ve had much better success with the SCSI
virtual disks than the IDE ones. So in this step we want to select
“SCSI (Recommended)” and the “Next >” button.

Step 7: Set disk size and options
Now we want to set the size of the disk we are creating. One of the
nice features of VMWare is that you don’t have to allocate all of the
disk when you create it. So if you create a 40 GB disk it doesn’t have
to take it all right away, the disk will grow as your virtual machine
needs it. I will say this is a big performance hit you take when the
disk has to extend, but for most applications its OK. Also, I will warn
that if the virtual disk grows and there is no physical disk left on
the host operating system you will see a catastrophic failure and in
most cases both the host and guest operating systems lock up and become
unusable. (Don’t say I didn’t warn you) Lastly, you can split the files
into 2GB sizes, while this isn’t necessary, it just makes all the disks
much easier to manage and move around. For this step we want to set our
disk size (12 GB in this case), I chose not to allocate the disk space
right now (the machine has a 300 GB drive and has only 20 GB on it) and
Split disk into 2 GB files.

Step 8: Name the disk file
This is actually pretty simple in that you decide what you want to
physically call the disk and where to put it. .vmdk is the extension
for VMWare virtual disks. After we name the disk we can select the
“Finish” button which adds the disk to the virtual machine.

Step 9: Ensure new disk exists
So now we can see that the new disk has been added to the “Virtual
Machine Settings” within the selected virtual machine. From here the
disk acts just like it would if you added a new disk to a standalone
server. So we select the “OK” button to continue.

Step 10: Boot the virtual machine
From here we just start the virtual machine like we would normally,
either by selecting the button on the toolbar or selecting the “Start
this virtual machine” link.

Step 11: Virtual machine start up
The machine boots normally as it would any other time.

Step 12: Create the Partition
After we’ve logged in and accessed a terminal window as root (or
another user with root/sudo privs) we first want to run fdisk on the
newly created drive. In Linux the first SCSI drive is sda, the second
sdb, the third sdc, etc. since this was the second SCSI drive we added
to the system, the device is known as /dev/sdb
The first command we want to run is fdisk /dev/sdb (NOTE: Thanks to everyone that caught my typo here)
this utility works very much like the DOS utility of the old days and
allows you to create and manage partitions. To create a new partition
we enter the command n to create a new partition.  This is going to be a primary partition p, and the first partition number 1.
Because I want this disk to consume the full 12 GB I specified earlier
we start at the first cylinder and end it at the last cylinder. We then
want to write the partition table with the new partition we have just
created so we enter the command w which writes the new table and exits fdisk.

Step 13: Format the partition
Now that we’ve create the partition, we now want to format the first
with the new file system. I’ve decided to use ext3 filesystem for this
disk, ext3 provides all the features of the classic ext2 file system
plus journaling which helps to prevent disk corruption in the event of
an improper shutdown and speeds up the recovery process. For a good
overview of Linux standard file systems check out this article:

So, to format the new partition we enter the command mkfs -t ext3 /dev/sdb1.  This command makes a new files system with the type t ext3 on the /dev/sdb1 partition, this is the first partition on the sdb disk.

Step 14: Create the mount point
Determine where you want to add the new virtual disk you’ve created. I
like to create a partition specifically for all the software I install
after the basic Linux install called /software to do that we run mkdir /software,
just a simple make directory command. Once that is complete we then
want to mount the newly created partition. Because we haven’t added the
partition to the /etc/fstab yet we have to mount it manually.  To do that we run mount -t ext3 /dev/sdb1 /software.
To break down this command we run mount with the ext3 filesystem type,
the partition /dev/sdb1 to the directory /software. Pretty simple and
straight forward. To check that the partition is properly mounted we
run df -k which shows us the mounted partitions and the amount of available space.

Step 15: Open the fstab file
The fstab file holds all of the used disks and partitions, and
determines how they are supposed to be used by the operating system. So
we edit the file to add the newly created partition

Step 16: Modify the fstab for the new partition
After we open the fstab file in the previous step we add the following line:
/dev/sdb1                        /software                       ext3       defaults                  1   1
The first column is the partition name, the second is the default mount
point, the third is the filesystem type. The fourth is the mount
options, in this case I used default which mounts the drive rw, suid,
dev, exec, auto, nouser and asynchronous. The 5th and 6th options are
for the dump and fsck options. If dump is set to 1 the filesystem is
marked to be backed up, if you are going to have sensitive material on
the drive its a good idea to set it to 1. If fsck is set to greater
than 1, then the operating system uses the number to determine in what
order fsck should be run during start up. If it is set to 0 it will be
ignored such as in the case of a cdrom drive since its a solid state
disk. For more information on the fstab file check out this article:

Lastly, we write and quit the file with the :wq command.

So now that the fstab has been written the drive will be mounted and
unmounted when the machine is either started or shutdown. So there you
have it, the quick and dirty process for adding a brand new disk to a
virtual machine. Until next time…
阅读(2097) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~