添加一块硬盘后需要经过分区、格式化、挂载才可使用。

1、分区

(1)查看新的硬盘否添加进来

[root@localhost ~]# fdisk -l
Disk /dev/sdb: 4294 MB, 4294967296 bytes    //新的硬盘
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000a3ed1
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        1045     7875584   8e  Linux LVM
Disk /dev/mapper/VolGroup-lv_root: 6987 MB, 6987710464 bytes
255 heads, 63 sectors/track, 849 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/VolGroup-lv_swap: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

(2)对硬盘进行分区

[root@localhost ~]# fdisk /dev/sdb   //进行分区
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x240770df.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').
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): n
Command action
   e   extended   //建立扩展分区
   p   primary partition (1-4)  //建立主分区
p   //选择新建主分区
Partition number (1-4): 1  //指定第一个主分区
First cylinder (1-522, default 1):  //指定第一个扇区
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-522, default 522): +1G  //指定所建分区大小
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
e   //新建扩展分区
Partition number (1-4): 3
First cylinder (159-522, default 159):
Using default value 159
Last cylinder, +cylinders or +size{K,M,G} (159-522, default 522): +250M
Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l   //新建逻辑分区
First cylinder (159-191, default 159):
Using default value 159
Last cylinder, +cylinders or +size{K,M,G} (159-191, default 191): +100M
Command (m for help): p   //查看分区表
Disk /dev/sdb: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x240770df
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         132     1060258+  83  Linux
/dev/sdb2             133         158      208845   83  Linux
/dev/sdb3             159         191      265072+   5  Extended
/dev/sdb5             159         172      112423+  83  Linux
Command (m for help): w  //w保存退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

2、格式化

[root@localhost ~]# mkfs.ext4 /dev/sdb1  //格式化成ext4文件系统类型
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
66384 inodes, 265064 blocks
13253 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=272629760
9 block groups
32768 blocks per group, 32768 fragments per group
7376 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 22 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

3、挂载

[root@localhost ~]# mount /dev/sdb1 /guazai

设置自动挂载

[root@localhost lost+found]# vi /etc/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
mount /dev/sdb1 /guazai


[root@localhost lost+found]# vi /etc/fstab
/dev/sdb1               /guazai                 ext4    defaults        0 04