硬盘类型

1、SATA民用:不支持热插拔;
2、SCSI、SAS企业用:支持热插拔;

MBR分区方案

此方案最多支持4个主分区,在linux可以将第4个主分区设置为扩展分区(扩展分区只是表示分区范围,并不是实际的分区,无意义),在扩展分区下建立逻辑分区最多15个分区;2T以上硬盘不在支持MBR。

GPT分区方案

默认支持128个分区;可以解决MBR大小的限制;
GPT提供分区表信息冗余;主GPT在头,副本备份在尾;

fdisk管理MBR分区磁盘

1、硬盘分区表建立

#fdisk -l  //显示磁盘信息
#fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xdebdcc37.

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
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   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  //新建
Partition type:
   p   primary (0 primary, 0 extended, 4 free) //新建sdb第二块磁盘的主分区
   e   extended //新建扩展分区
Select (default p): p
Partition number (1-4, default 1): //默认编号1
First sector (2048-4194303, default 2048): //默认起始扇区
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-4194303, default 4194303): +1G   //新建1g主分区
Partition 1 of type Linux and of size 1 GiB is set

#partprobe /dev/sdb  //刷新硬盘分区表
#ls /dev/sdb<tab>  //列出分区表

2、分区格式化
制作文件系统格式,格式化后产生唯一uuid;

#mkfs.xfs /dev/sdb1  //格式化为xfs
#blkid /dev/sdb1  //获取sdb1的uuid

3、硬盘分区自动挂载(持久化)

#blkid /dev/sdb1 >> /etc/fstab //将uuid写入 fstab
#vim /etc/fstab
uuid=" "  /mnt/xfs(挂载点) xfs(类型) default 0(不检查) 0(不备份)
#mkdir /mnt/xfs //建立挂载点目录
#mount -a //重新获取挂载点 
#df -h //查看挂载点
// umount /dev/sda1 取消挂载

gdisk管理GPT分区

#gdisk /dev/sdb
GPT fdisk (gdisk) version 0.8.6

Partition table scan:
  MBR: not present
  BSD: not present
  APM: not present
  GPT: not present

Creating new GPT entries.

Command (? for help): ?
b   back up GPT data to a file
c   change a partition's name
d   delete a partition
i   show detailed information on a partition
l   list known partition types
n   add a new partition
o   create a new empty GUID partition table (GPT)
p   print the partition table
q   quit without saving changes
r   recovery and transformation options (experts only)
s   sort partitions
t   change a partition's type code
v   verify disk
w   write table to disk and exit
x   extra functionality (experts only)
?   print this menu

管理交换空间

交换空间可与linux内核内存配合使用的磁盘区域;补充系统的RAM,合成虚拟内存。

1、新建交换分区
#fdisk /dev/vdb 
n l +500M
#partprobe /dev/vdb
2、交换分区格式化
#mkswap /dev/vdb6
3、交换分区持久化挂载
#blkid /dev/vdb6 >> /etc/fstab
#vim /etc/fstab
uuid=" "  swap swap default 0 0
//或者 /dev/vdb6 swap swap defaults 0 0
#swapon -a //开启swap -s查看
#swapoff /dev/vdb6 //停止 删除fstab 删除分区

磁盘配额

为特定用户限制使用磁盘空间;
以下为格式ext的设置。

#vim /etc/fstab
uuid=" " ext4 default,usrquota 0 0
#mount -o remount /dev/vdb1  //重新加载
#quotacheck -cuf /dev/vdb1 /mnt/ext //强制生成用户数据库
#quotaon /dev/vdb1  //开启
#edquota -u wode  //设置用户的空间大小
#chmod o+w ext/  
(wode)#cd /mnt/ext
#dd if=/etc/zero of=aaa bs=1k count=10  //测试命令

RAID磁盘冗余阵列

解决磁盘损坏,数据无法写入和丢失;
软RAID:os内核提供cpu运算;
硬RAID(企业):自带阵列卡(cpu、内存)、有接口接硬盘;

RAID命令配置

软RAID5(利用软件mdadm):新建三块磁盘

#mdadm --create /dev/md0 --level=5 --raid-devices=3 /dev/vdb{6,7,8} //3个磁盘设置为raid5
#mkfs.xfs /dev/md0 //3磁盘格式化为xfs
#blkid /dev/md0 >> /etc/fstab
#vim /etc/fstab 
uuid=  xfs  /mnt/raid default 0 0  //设置挂载点
#mkdir /mnt/raid
#mount -a
#mdadm --detail --scan > /etc/mdadm.conf //生成配置文件
#mdadm --detail /dev/md0 //查看状态
测试
#mdadm /dev/md0 --set-faulty /dev/vdb7
#mdadm /dev/md0 --remove (--add)/dev/vdb7