有时服务器需要添加新的硬盘,添加之后要经过分区、格式化、挂载才能使用,还要做开机自动挂载!

1.分区一般使用fdisk命令,参数-l:

#fdisk -l


Disk /dev/sda: 600.1 GB, 600127266816 bytes
255 heads, 63 sectors/track, 72961 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: 0x000862c9

Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 3851 30720000 83 Linux
/dev/sda3 3851 4373 4194304 82 Linux swap / Solaris

Disk /dev/sdd: 600.1 GB, 600127266816 bytes
255 heads, 63 sectors/track, 72961 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/sdb: 600.1 GB, 600127266816 bytes
255 heads, 63 sectors/track, 72961 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: 0x000862c9

Device Boot Start End Blocks Id System
/dev/sdb1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sdb2 26 3851 30720000 83 Linux
/dev/sdb3 3851 4373 4194304 82 Linux swap / Solaris

你可以看到有几块盘,大小,分区情况!

   找到你新加的硬盘,进行分区,命令还是fdisk:  

   以/dev/sdc为例;

#fdisk /dev/sdc


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,看下有哪些参数

按下p,打印已经分区好的信息

按下n,新建分区,然后选择开始分区的地方、结束分区的地方;再次按下p,看下分区信息,按下w,保存;按下q,退出!!!

记住:分好区可以按下w保存,如果分区错了,不要按下w,直接按下q,离开并且不会保存你刚刚进行的分区操作!

 

2.格式化分区

# mkfs.ext4  /dev/sdc1

等着就行,一般不会报错

 

3.挂载

先创建挂载点/目录

mkdir  /xmon/

 

直接挂载

mount  /dev/sdc1  /xmon

4.开机自动挂载  实现方式很多

     (1)#vim  /etc/fstab

     增加一行    /dev/sdc1      /xmon      ext4  defaults   0    0

     (2)写入/etc/rc/loacl文件

      /dev/sdc1      /xmon      ext4  defaults   0    0

等等,也可以写入其他开机会读取的配置文件或者是系统的环境变量!