先把需要挂载的硬盘正确连接到电脑上,查看 BIOS,确保开机自检时,BIOS 能够检测并识别出新连接的硬盘,然后再进行下面的操作。


[root@Linux ~]# 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           1275     10241406      83     Linux

/dev/sda2            1276         2349     8626905        83     Linux

/dev/sda3            2350         2610     2096482+      82     Linux swap / Solaris


Disk /dev/sdb: 21.4 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes


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




[root@Linux ~]# fdisk /dev/sdb        //根据提示,对新硬盘进行分区操作

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

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)


//这一步可以不做,就是可以通过输入 h 查看帮助信息

Command (m for help): h  

h: unknown command

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            //输入 n,新建分区

Command action

   e   extended                    //新建逻辑分区

   p   primary partition (1-4)     //新建主分区

p                                             //输入 p,建立主分区

Partition number (1-4): 1            //一共可以分4个主分区,输入 1,建立第一个主分区

First cylinder (1-2610, default 1): //选择该分区的起始磁盘数,如无特殊需求强烈建议选择默认,也就是默认用1 来分区(直接按回车)

Using default value 1

Last cylinder or +size or +sizeM or +sizeK (1-2610, default 2610): //定义该分区的大小,如果按默认(直接回车),就是使用全部可用存储空间;如果要分成一个 1G 的空间,输入 +1024m 即可

Using default value 2610


Command (m for help): w       //写入分区信息,其实就是保存分区信息

The partition table has been altered!


Calling ioctl() to re-read partition table.

Syncing disks.



[root@Linux ~]# 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           1275     10241406     83     Linux

/dev/sda2            1276         2349     8626905      83     Linux

/dev/sda3            2350         2610     2096482+    82     Linux swap / Solaris


Disk /dev/sdb: 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/sdb1               1            2610    20964793+     83    Linux     //划线部分,就是分区,格式化时要写正确



[root@Linux ~]# mkfs -t ext3 -c /dev/sdb1    //对分区使用 ext3 格式化,如果建立了多个分区,显示 /dev/sdb2、/dev/sdb3 等,以此类推,重复输入这条命令,就可以进行其它分区的格式化操作了。因为新硬盘加了-c参数,要先检测磁盘坏道,因此,这个过程全有些长,需要耐心等待……

mke2fs 1.39 (29-May-2006)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

2621440 inodes, 5241198 blocks

262059 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=0

160 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, 2654208, 

        4096000


Checking for bad blocks (read-only test): done                                

Writing inode tables: done                            

Creating journal (32768 blocks): done

Writing superblocks and filesystem accounting information: done


This filesystem will be automatically checked every 25 mounts or

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



[root@Linux ~]# 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           1275     10241406     83     Linux

/dev/sda2            1276         2349     8626905       83     Linux

/dev/sda3            2350         2610     2096482+     82     Linux swap / Solaris


Disk /dev/sdb: 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/sdb1               1            2610    20964793+    83    Linux



[root@Linux ~]# mkdir /dir                         //新建挂载目录



[root@Linux ~]# mount /dev/sdb1 /dir            //挂载这块新硬盘



[root@Linux ~]# df -hl                                     //查看分区大小是否和我们预定的一样

Filesystem(文件系统)  Size(容量)  Used(已用) Avail(可用) Use%(已用%)  Mounted on(挂载点)                     

/dev/sda1                     9.5G           3.8G          5.2G           43%                 /

/dev/sda2                     8.0G           361M          7.3G           5%                   /linux

tmpfs                         506M          0              506M           0%             /dev/shm

/dev/sdb1                     20G            173M          19G            1%                   /dir    //最后这一行是新硬盘的相关信息



[root@Linux ~]# vi /etc/fstab    //编辑 /etc/fstab 文件,设置系统启动后自动挂载硬盘,最后一行为添加的相关内容

LABEL=//                       ext3         defaults                     1 1

LABEL=/web/linux               ext3         defaults                     1 2

tmpfs         /dev/shm         tmpfs        defaults                      0 0

devpts        /dev/pts         devpts       gid=5,mode=620                0 0

sysfs        /sys                 sysfs        defaults                     0 0

proc         /proc                proc         defaults                     0 0

LABEL=SWAP-sda3         swap                swap       defaults                      0 0

/dev/sdb1    /dir                   ext3         defaults                      1 2

"/etc/fstab" 8L, 571C written



[root@Linux ~]# df -h                //再次查看硬盘信息,最后一行为新添加的硬盘信息

Filesystem            Size       Used      Avail       Use%     Mounted on

/dev/sda1              9.5G      3.8G       5.2G       43%      /

/dev/sda2              8.0G      361M      7.3G       5%        /linux

tmpfs                     506M     0             506M      0%       /dev/shm

/dev/sdb1             20G       173M      19G        1%        /dir



[root@Linux ~]# reboot             //重新启动系统


[root@Linux ~]# df -h                //查看硬盘信息;同时,检查我们添加硬盘、挂载硬盘、系统启动后自动挂载硬盘这一系列的操作是否正确,如果出现了最后一行,则我们的操作就是正确的

Filesystem            Size       Used      Avail       Use%     Mounted on

/dev/sda1              9.5G      3.8G       5.2G       43%      /

/dev/sda2              8.0G      361M      7.3G       5%        /linux

tmpfs                     506M     0             506M      0%       /dev/shm

/dev/sdb1             20G       173M      19G        1%        /dir



//================   以下命令与注释,是上面的精简版  ================//


[root@Linux ~]# fdisk -l   //查看当前磁盘信息,就会发现最下面显示新加入的硬盘不是有效分区,如下:


[root@Linux ~]# fdisk /dev/sdb        //根据提示,对新硬盘进行分区操作


//这一步可以不做,就是可以通过输入 h 查看帮助信息

Command (m for help): h  


//这一步是必须做的

Command (m for help): n        //输入 n,新建分区

Command action

   e   extended                         //新建逻辑分区

   p   primary partition (1-4)     //新建主分区

p                                             //输入 p,建立主分区

Partition number (1-4): 1        //一共可以分4个主分区,输入 1,建立第一个主分区

First cylinder (1-2610, default 1): //选择该分区的起始磁盘数,如无特殊需求强烈建议选择默认,也就是默认用1 来分区(直接按回车)

Using default value 1

Last cylinder or +size or +sizeM or +sizeK (1-2610, default 2610): //定义该分区的大小,如果按默认(直接回车),就是使用全部可用存储空间;如果要分成一个 1G 的空间,输入 +1024m 即可

Using default value 2610


Command (m for help): w       //写入分区信息,其实就是保存分区信息


[root@Linux ~]# fdisk -l            //查看刚刚分成的分区,内容如下,注意最后一行的信息:

/dev/sdb1               1            2610    20964793+     83    Linux     //划线部分,就是分区,格式化时要写正确


[root@Linux ~]# mkfs -t ext3 -c /dev/sdb1    //对分区使用 ext3 格式化,如果建立了多个分区,显示 /dev/sdb2、/dev/sdb3 等,以此类推,重复输入这条命令,就可以进行其它分区的格式化操作了。因为新硬盘加了-c参数,要先检测磁盘坏道,因此,这个过程全有些长,需要耐心等待……


[root@Linux ~]# fdisk -l                    //再次查看硬盘信息


[root@Linux ~]# mkdir /dir                         //新建挂载目录


[root@Linux ~]# mount /dev/sdb1 /dir        //挂载这块新硬盘


[root@Linux ~]# df -hl                                     //查看分区大小是否和我们预定的一样

/dev/sdb1                     20G            173M          19G            1%                   /dir    //最后这一行是新硬盘的相关信息


[root@Linux ~]# vi /etc/fstab    //编辑 /etc/fstab 文件,设置系统启动后自动挂载硬盘,最后一行为添加的相关内容


[root@Linux ~]# df -h                //再次查看硬盘信息,最后一行为新添加的硬盘信息


[root@Linux ~]# reboot             //重新启动系统


[root@Linux ~]# df -h                //查看硬盘信息;同时,检查我们添加硬盘、挂载硬盘、系统启动后自动挂载硬盘这一系列的操作是否正确,如果出现了最后一行,则我们的操作就是正确的