如何在linux系统中增加一块硬盘,并且格式化它呢:

我是使用VMware-workstation-full-7.1.0-261024.exe来做实验的。
(1)
使用VMware-workstation 给虚拟机增加一块硬盘,如下图所示:
图片
(2)然后在 /dev中查看新硬盘的名称,如我的名称是“sdb
然后给硬盘分区:

[root@localhost dev]# fdisk /dev/sdb

 

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

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): p

 

Disk /dev/sdb: 42.9 GB, 42949672960 bytes

255 heads, 63 sectors/track, 5221 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

   Device Boot      Start         End      Blocks   Id  System

 

Command (m for help): d

No partition is defined yet!

 

Command (m for help): n

Command action

   e   extended

   p   primary partition (1-4)

e

Partition number (1-4): 1

First cylinder (1-5221, default 1):

Using default value 1

Last cylinder or +size or +sizeM or +sizeK (1-5221, default 5221):

Using default value 5221

 

Command (m for help): n

Command action

   l   logical (5 or over)

   p   primary partition (1-4)

l

First cylinder (1-5221, default 1):

Using default value 1

Last cylinder or +size or +sizeM or +sizeK (1-5221, default 5221): 2500

 

Command (m for help): n

Command action

   l   logical (5 or over)

   p   primary partition (1-4)

l

First cylinder (2501-5221, default 2501):

Using default value 2501

Last cylinder or +size or +sizeM or +sizeK (2501-5221, default 5221):

Using default value 5221

 

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.

[root@localhost dev]# fdisk /dev/sdb

 

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

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): p

 

Disk /dev/sdb: 42.9 GB, 42949672960 bytes

255 heads, 63 sectors/track, 5221 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1               1        5221    41937651    5  Extended

/dev/sdb5               1        2500    20081187   83  Linux

/dev/sdb6            2501        5221    21856401   83  Linux

 

Command (m for help):

(3)我分了三个分区,如上,分别是sdb1,sdb5,sdb6.然后是对其进行格式化。
例如我先对sdb5进行格式化:

[root@localhost ~]# mkfs.ext3 /dev/sdb5

mke2fs 1.39 (29-May-2006)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

2513280 inodes, 5020296 blocks

251014 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=0

154 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,

        4096000

 

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.

分区完成!


(4)修改分区表

 

vim  /etc/fstab

在最后加上一行:

/dev/sdb5                /sdb_one               ext3    defaults        0 0

使用标签:

LABEL=/sdb5_label_hw          /sdb_one          ext3    defaults        0 0

 

(5)为分区设置标签

 

e2label /dev/sdb5 /sdb5_label_hw

 

注意:设置完成之后,最好reboot,否则使用mount进行挂载的时候,无法显示其中的内容,必须先进入文件夹,然后再退出,才能看到。

查看挂载情况,运行df -l