下面介绍怎样将一块新硬盘分区、格式化、挂载到系统,如适合你请继续阅读。服务器上已经有两块硬盘,所以硬盘为sdc,后面就不做说明了,至于不知道sdc怎么回事的人,先去问问百度大哥再回来接着看。 公司内网的服务器硬盘空间不足,将新买来的150G硬盘挂载并设置成samba的共享目录,关于samba请参考此文章

1、# fdisk -l      查看当前磁盘信息,就会发现最下面显示新加入的硬盘不是有效分区,如下:
Disk /dev/sdc: 1500.3 GB, 1500301910016 bytes
255 heads, 63 sectors/track, 182401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdc doesn't contain a valid partition table
2、# fdisk /dev/sdc      对新硬盘分区,并根据提示进一步操作
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 182401.
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): h      输入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为主分区,e为逻辑分区
Partition number (1-4): 1      由于是新盘我们输入1来分第一个主分区,共可以分4个主分区
First cylinder (1-182401, default 1):      选择该分区的起始磁盘数,如无特殊需求强烈建议选择默认,也就是1来分区(直接按回车)
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-182401, default 182401):      定义该分区的大小,如果按默认(按回车)即是使用全部可用存储额,如分一个1G的空间,输入+1024m
Using default value 182401
Command (m for help): w      写入分区
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
3、# fdisk -l      可以找到我们刚才分的一个分区,内容如下:
Disk /dev/sdc: 1500.3 GB, 1500301910016 bytes
255 heads, 63 sectors/track, 182401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot      Start         End      Blocks   Id System
/dev/sdc1               1      182401 1465136001   83 Linux
//个人环境加入删除相关操作
fdisk 对硬盘及分区的操作,进入fdisk 对硬盘操作阶段

  我们可以对硬盘进行分区操作,前提是您把fdisk -l 弄明白了;通过fdisk -l ,我们能找出机器中所有硬盘个数及设备名称;比如上面的例子,我们会看到两个设备一个是/dev/hda ,另一个是/dev/sda ;

  fdisk 操作硬盘的命令格式如下:

  [root@localhost beinan]# fdisk 设备

  比如我们通过 fdisk -l 得知 /dev/hda 或者 /dev/sda设备;我们如果想再添加或者删除一些分区,可以用

  [root@localhost beinan]# fdisk /dev/hda

  或

  [root@localhost beinan]# fdisk /dev/sda

  注 在以后的例子中,我们要以 /dev/sda设备为例,来讲解如何用fdisk 来操作添加、删除分区等动作;

  1、fdisk 的说明;

  当我们通过 fdisk 设备,进入相应设备的操作时,会发现有如下的提示;以 fdisk /dev/sda 设备为例,以下同;

[root@localhost beinan]# fdisk /dev/sda
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 注:l是列出分区类型,以供我们设置相应分区的类型;
m print this menu 注:m 是列出帮助信息;
n add a new partition 注:添加一个分区;
o create a new empty DOS partition table
p print the partition table 注:p列出分区表;
q quit without saving changes 注:不保存退出;
s create a new empty Sun disklabel
t change a partition's system id 注:t 改变分区类型;
u change display/entry units
v verify the partition table
w write table to disk and exit 注:把分区表写入硬盘并退出;
x extra functionality (experts only) 注:扩展应用,专家功能;

  其实我们常用的只有注有中文的,其它的功能我们不常用(呵,主要是我不会用,否则早会卖弄一下了);x扩展功能,也不是常用的;一般的情况下只要懂得 d l m p q t w 就行了;

  下面以实例操作来详述,没有例子没有办法就,新手也看不懂;

  2、列出当前操作硬盘的分区情况,用p

Command (m for help): p
Disk /dev/sda: 1035 MB, 1035730944 bytes
256 heads, 63 sectors/track, 125 cylinders
Units = cylinders of 16128 * 512 = 8257536 bytes
Device Boot Start End Blocks Id System
/dev/sda1 1 25 201568+ c W95 FAT32 (LBA)
/dev/sda2 26 125 806400 5 Extended
/dev/sda5 26 50 201568+ 83 Linux
/dev/sda6 51 76 200781 83 Linux

  3、通过fdisk的d指令来删除一个分区

Command (m for help): p 注:列出分区情况;
Disk /dev/sda: 1035 MB, 1035730944 bytes
256 heads, 63 sectors/track, 125 cylinders
Units = cylinders of 16128 * 512 = 8257536 bytes
Device Boot Start End Blocks Id System
/dev/sda1 1 25 201568+ c W95 FAT32 (LBA)
/dev/sda2 26 125 806400 5 Extended
/dev/sda5 26 50 201568+ 83 Linux
/dev/sda6 51 76 200781 83 Linux
Command (m for help): d 注:执行删除分区指定;
Partition number (1-6): 6 注:我想删除 sda6 ,就在这里输入 6 ;
Command (m for help): p 注:再查看一下硬盘分区情况,看是否删除了?
Disk /dev/sda: 1035 MB, 1035730944 bytes
256 heads, 63 sectors/track, 125 cylinders
Units = cylinders of 16128 * 512 = 8257536 bytes
Device Boot Start End Blocks Id System
/dev/sda1 1 25 201568+ c W95 FAT32 (LBA)
/dev/sda2 26 125 806400 5 Extended
/dev/sda5 26 50 201568+ 83 Linux
Command (m for help):

  警告:删除分区时要小心,请看好分区的序号,如果您删除了扩展分区,扩展分区之下的逻辑分区都会删除;所以操作时一定要小心;如果知道自己操作错了,请不要惊慌,用q不保存退出;切记切记!!!!在分区操作错了之时,千万不要输入w保存退出!!!
//个人环境删除操作结束
4、# mkfs -t ext3 -c /dev/sdc1      对分区使用ext3格式化,如多个分区sdc2等以此类推,因为新硬盘加了-c参数要先检测磁盘坏道,此过程万分漫长(150G),等待。。。
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
183156736 inodes, 366284000 blocks
18314200 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
11179 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, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
        102400000, 214990848
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 22 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

5、# mkdir /var/samba      新建挂载目录
6、# mount /dev/sdc1 /var/samba      挂载新硬盘

7、# df -hl      查看分区大小是否和我们预定的一样:
文件系统               容量   已用 可用 已用% 挂载点
/dev/sda7             9.5G 3.2G 5.9G 35% /
/dev/sda6             9.5G 151M 8.9G   2% /tmp
/dev/sda5              19G 3.6G   15G 20% /usr
/dev/sda3              19G 719M   18G   4% /home
/dev/sda2             230G   23G 196G 11% /var
/dev/sda1              99M   25M   69M 27% /boot
/dev/sdb1             233G 156G   78G 67% /var/samba2
tmpfs                1008M     0 1008M   0% /dev/shm
/dev/sdc1             1.4T 198M 1.3T   1% /var/samba      此行为新硬盘

8、# vi /etc/fstab      设置系统自动挂载硬盘,加入一行:
/dev/sdc1               /var/samba2             ext3    defaults        0 0
9、重启服务器,用步骤7检查一下,一切正常挂载完成,祝好运~