需求:添加一块100M的硬盘并把它永久挂载到/data01上,写出详细的操作步骤

方法一:

[root@localhost ~]# fdisk -l |grep 'sdb'
Disk /dev/sdb: 106 MB, 106954752 bytes

[root@localhost ~]# fdisk -cu /dev/sdb
Command (m for help): m
Command action
  ……
   d   delete a partition
   l    list known partition types
   m   print this menu
   n   add a new partition
   p   print the partition table
   q   quit without saving changes
   w   write table to disk and exit
  

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p  
Partition number (1-4): 1
First sector (2048-208895, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-208895, default 208895): 
Using default value 208895

Command (m for help): p

Disk /dev/sdb: 106 MB, 106954752 bytes
64 heads, 32 sectors/track, 102 cylinders, total 208896 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x65338ab6

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048      208895      103424   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

#通知系统/dev/sdb硬盘的磁盘分区表变化了
[root@localhost ~]# partprobe /dev/sdb

[root@localhost ~]# mkfs.ext4 /dev/sdb1

#关闭磁盘分区的自动检查
[root@localhost ~]# tune2fs -c 0 -i 0 /dev/sdb1
注释:
-c 0 count   关闭每挂载多少次进行磁盘检查的功能
-i 0 interval 关闭每个180天进行磁盘检查功能


[root@localhost ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        19G  5.0G   14G  27% /
tmpfs           120M     0  120M   0% /dev/shm
/dev/sda1       190M   35M  145M  20% /boot
[root@localhost ~]# mkdir /data01
[root@localhost ~]# mount /dev/sdb1 /data01
[root@localhost ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        19G  5.0G   14G  27% /
tmpfs           120M     0  120M   0% /dev/shm
/dev/sda1       190M   35M  145M  20% /boot
/dev/sdb1        94M  1.6M   88M   2% /data01

[root@localhost ~]# vim /etc/fstab 
....
/dev/sdb1               /data01                 ext4    defaults        0 0

第一个0表示:关闭自动备份功能
第二个0表示:关闭磁盘自动检查功能

方法二: 使用parted 工具分区(可用于大于2T的数据盘分区),常用参数说明:

p[rint] 显示磁盘分区表信息 mklabel 创建磁盘分区表,可用的磁盘分区表为:gpt、msdos(mbr) mkpart 创建分区 rm 删除分区 q 退出不保存

parted /dev/sdb mklabel gpt y
parted /dev/sdb mkpart primary 0 -1 Ignore(全部容量默认给一个分区)
parted /dev/sdb p

partprobe /dev/sdb
mkfs.ext4 /dev/sdb1 
tune2fs -c 0 -i 0 /dev/sdb1
/bin/mount /dev/sdb1 /data01/
df -h
echo "/bin/mount /dev/sdb1 /data01/" >>/etc/rc.local 

步骤总结: 1.分区 2.通知系统/dev/sdb硬盘的磁盘分区表变化了格式化创建文件系统 3.格式化创建文件系统 4.关闭磁盘分区的自动检查 5.进行磁盘分区挂载 6.进行永久挂载(开机自动挂载)