1. 添加一块小于2TB的磁盘进行使用,步骤如下:

[root@yinwucheng ~]# lsblk
sda      8:0    0   40G  0 disk 
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0    1G  0 part [SWAP]
└─sda3   8:3    0   38G  0 part /
sdb      8:16   0  300G  0 disk 
sdc      8:32   0  300G  0 disk 
sr0     11:0    1  4.3G  0 rom  
[root@yinwucheng ~]# 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 0x271d3013.

Command (m for help): m
Command action
   a   toggle a bootable flag               #切换分区启动标记
   b   edit bsd disklabel                   #编辑sdb磁盘标签
   c   toggle the dos compatibility flag    #切换dos兼容模式
   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     #创建新的Sun磁盘标签
   t   change a partitions system id       #修改分区ID,可以通过l查看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)
   e   extended      #扩展分区
Select (default p): p      #选择创建主分区
Partition number (1-4, default 1):      #默认创建第一个主分区
First sector (2048-629145599, default 2048):     #默认扇区-->回车即可
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-629145599, default 629145599): +150G    #分配150G
Partition 1 of type Linux and of size 150 GiB is set


Command (m for help): n     #新建分区
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): e    #创建扩展分区
Partition number (2-4, default 2): 
First sector (314574848-629145599, default 314574848): 
Using default value 314574848
Last sector, +sectors or +size{K,M,G} (314574848-629145599, default 629145599):    #剩余容量都给到扩展分区
Using default value 629145599
Partition 2 of type Extended and of size 150 GiB is set


Command (m for help): n   #新建分区
Partition type:
   p   primary (1 primary, 1 extended, 2 free)
   l   logical (numbered from 5)
Select (default p): l     #创建逻辑分区
Adding logical partition 5
First sector (314576896-629145599, default 314576896): 
Using default value 314576896
Last sector, +sectors or +size{K,M,G} (314576896-629145599, default 629145599): +50G     #分配50G容量
Partition 5 of type Linux and of size 50 GiB is set


Command (m for help): p    #查看创建的分区

Disk /dev/sdb: 322.1 GB, 322122547200 bytes, 629145600 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 label type: dos
Disk identifier: 0x271d3013

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048   314574847   157286400   83  Linux
/dev/sdb2       314574848   629145599   157285376    5  Extended
/dev/sdb5       314576896   419434495    52428800   83  Linux

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

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

[root@yinwucheng ~]# fdisk /dev/sdb -l |grep type   
Disk label type: dos

#安装parted, 刷新内核立即生效,无需重启
[root@yinwucheng ~]# yum install parted -y 
[root@yinwucheng ~]# partprobe /dev/sdb


 -b  设定数据区块占用空间大小,目前支持1024、2048、4096 bytes每个块。
 -t  用来指定什么类型的文件系统,可以是ext4, xfs
 -i  设定inode的大小
 -N  设定inode数量,防止Inode数量不够导致磁盘不足

[root@yinwucheng ~]# mkfs.ext4 /dev/sdb
mke2fs 1.42.9 (28-Dec-2013)
/dev/sdb is entire device, not just one partition!
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
19660800 inodes, 78643200 blocks
3932160 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2227175424
2400 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000, 7962624, 11239424, 20480000, 23887872, 71663616

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done  

[root@yinwucheng ~]# mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1              isize=512    agcount=4, agsize=9830400 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=39321600, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=19200, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0






[root@yinwucheng ~]# yum install gdisk -y

[root@yinwucheng ~]# gdisk /dev/sdc
GPT fdisk (gdisk) version 0.8.10

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

Creating new GPT entries.

Command (? for help): n
Partition number (1-128, default 1): 
First sector (34-629145566, default = 2048) or {+-}size{KMGTP}: 
Last sector (2048-629145566, default = 629145566) or {+-}size{KMGTP}: +500M
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): 
Changed type of partition to 'Linux filesystem'

Command (? for help): p
Disk /dev/sdc: 629145600 sectors, 300.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 0FE3F4A5-FBC9-4515-8C25-F24BB0553830
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 629145566
Partitions will be aligned on 2048-sector boundaries
Total free space is 628121533 sectors (299.5 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048         1026047   500.0 MiB   8300  Linux filesystem

Command (? for help): w   #保存分区

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING

Do you want to proceed? (Y/N): Y
OK; writing new GUID partition table (GPT) to /dev/sdc.
The operation has completed successfully.

[root@yinwucheng ~]# fdisk /dev/sdc -l |grep type
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
Disk label type: gpt

#4.安装parted, 刷新内核立即生效,无需重启
[root@yinwucheng ~]# yum install parted -y 
[root@yinwucheng ~]# partprobe /dev/sdc


[root@yinwucheng ~]# mkfs.xfs /dev/sdc1


[root@yinwucheng ~]# mkdir /data2
[root@yinwucheng ~]# mount /dev/sdc1 /data2

PS: 类似我的商场没有门,那么就无法进入购买商品,此时通过mount命令可以创建一个入口。给超市安装一个门。如图:


      -a 挂载/etc/fstab中的配置文件
      -o 指定挂载参数
[root@yinwucheng ~]# mkdir /db1
[root@yinwucheng ~]# mount -t xfs /dev/sdb1 /db1/ 


#选项: -l 强制卸载

[root@yinwucheng ~]# umount /db1/

[root@yinwucheng ~]# umount /dev/sdb1


[root@yinwucheng ~]# blkid |grep 'sdb1'
/dev/sdb1: UUID="01353c25-0bde-49b6-a026-f805fc0de265" TYPE="xfs" 

#2.使用UUID挂载磁盘sdb1分区至于db1, 测试挂载
[root@yinwucheng ~]# mount UUID="01353c25-0bde-49b6-a026-f805fc0de265" /db1

[root@yinwucheng ~]# vim /etc/fstab    
UUID=01353c25-0bde-49b6-a026-f805fc0de265 /db1 xfs  defaults 0  0

#4.加载fstab配置文件, 同时检测语法是否有错误
[root@yinwucheng ~]# mount -a


要挂载的设备 挂载点(入口) 文件系统类型 挂载参数 是否备份 是否检查
/dev/sdb1 /db1 xfs defaults 0 0


参数 含义
async/sync 是否为同步方式运行。默认async
user/nouser 是否允许普通用户使用mount命令挂载。默认nouser
exec/noexe 是否允许可执行文件执行。默认exec
suid/nosuid 是否允许存在suid属性的文件。默认suid
auto/noauto 执行mount -a 命令时,此文件系统是否被主动挂载。默认auto
rw/ro 是否以只读或者读写模式进行挂载。默认rw
default 具有rw,suid,dev,exec,auto,nouser,async等默认参数的设定


选项 含义
0 代表不做备份
1 代表要每天进行备份操作
2 代表不定日期的进行备份操作


选项 含义
0 不要检验磁盘是否有坏道
1 检验
2 校验 (当1级别检验完成之后进行2级别检验)

PS: 当物理内存不够时会随机kill占用内存的进程,从而产生oom,临时使用swap可以解决。


[root@yinwucheng ~]# fdisk /dev/sdc   ##大小分1G
[root@yinwucheng ~]# mkswap /dev/sdc2   ##格式化为swap
Setting up swapspace version 1, size = 1048572 KiB
no label, UUID=f31cae8d-7bc8-4950-985f-94682b1a3718


[root@yinwucheng ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:           3931         109        3489          11         332        3574
Swap:          1023           0        1023

[root@yinwucheng ~]# swapon /dev/sdc2
[root@yinwucheng ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:           3931         110        3488          11         332        3574
Swap:          2047           0        2047

[root@yinwucheng ~]# swapon -a     ##代表激活所有的swap

[root@yinwucheng ~]# swapoff /dev/sdc2
[root@yinwucheng ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:           3931         110        3489          11         332        3574
Swap:          1023           0        1023
[root@yinwucheng ~]# swapoff -a    ##代表关闭所有的swap


[root@yinwucheng ~]# swapon -s
Filename				Type		Size	Used	Priority
/dev/sda2                              	partition	1048572	0	-2
/dev/sdc2                              	partition	1048572	0	-3


[root@yinwucheng ~]# dd if=/dev/zero of=/opt/swap_file bs=1M count=500
[root@yinwucheng ~]# chmod 0600 /opt/swap_file
[root@yinwucheng ~]# mkswap -f /opt/swap_file 
[root@yinwucheng ~]# swapon /opt/swap_file
[root@yinwucheng ~]# free -m

RAID 0 1 5