概念:
RAID ( Redundant Array of Independent Disks )即独立磁盘冗余阵列,简称为「磁盘阵列」,其实就是用多个独立的磁盘组成在一起形成一个大的磁盘系统,从而实现比单块磁盘更好的存储性能和更高的可靠性。
种类:
Raid 0:至少需要两块硬盘,磁盘越多,读写速度越快,没有冗余。
Raid 1:只能用两块硬盘,两块硬盘的数据互为镜像(写慢,读快),一块磁盘冗余。
Raid 5:至少需要3块硬盘,一块磁盘冗余。它是最通行的配置方式。具有奇偶校验的数据恢复功能的数据存贮方式。奇偶校验数据块分布于阵列里的各个硬盘中。
Raid 6:至少需要4块硬盘,2块磁盘冗余,硬盘的总数大于等于4即可。
Raid 10:至少需要4块硬盘,冗余一半的硬盘数量,但是硬盘的总数必须是大于或等于4的偶数(相当于每两块硬盘做一个Raid0,然后把各个Raid0做成一个Raid1)。
Raid 50:至少需要6块硬盘,磁盘的冗余相当于每三个硬盘做了一个Raid5,然后,每个Raid5又组合成了Raid0(Raid5中有一个硬盘冗余,即使坏了也不会破坏Raid0),所以,Raid50的磁盘的 冗余硬盘数量=磁盘总数÷3 。
Raid 60:至少需要8块硬盘
RAID0 是一种非常简单的的方式,它将多块磁盘组合在一起形成一个大容量的存储。当我们要写数据的时候,会将数据分为N份,以独立的方式实现N块磁盘的读写,那么这N份数据会同时并发的写到磁盘中,因此执行性能非常的高。RAID0 的读写性能理论上是单块磁盘的N倍(仅限理论,因为实际中磁盘的寻址时间也是性能占用的大头)
但RAID0的问题是,它并不提供数据校验或冗余备份,因此一旦某块磁盘损坏了,数据就直接丢失,无法恢复了。因此RAID0就不可能用于高要求的业务中,但可以用在对可靠性要求不高,对读写性能要求高的场景中。
显示
命令查看
[root@localhost ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 199G 0 part ├─centos-root 253:0 0 50G 0 lvm / ├─centos-swap 253:1 0 7.9G 0 lvm [SWAP] └─centos-home 253:2 0 141.1G 0 lvm sdb 8:16 0 50G 0 disk sdc 8:32 0 50G 0 disk sdd 8:48 0 50G 0 disk sde 8:64 0 50G 0 disk sr0 11:0 1 4.2G 0 rom
下载mdadm命令
#检索 [root@localhost ~]# yum provides *bin/mdadm Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.cqu.edu.cn * extras: mirrors.cqu.edu.cn * updates: mirrors.cqu.edu.cn base | 3.6 kB 00:00:00 extras | 2.9 kB 00:00:00 updates | 2.9 kB 00:00:00 updates/7/x86_64/primary_db | 20 MB 00:00:07 mdadm-4.1-6.el7.x86_64 : The mdadm program controls Linux md devices (software RAID arrays) Repo : base Matched from: Filename : /usr/sbin/mdadm updates/7/x86_64/filelists_db | 11 MB 00:00:04 mdadm-4.1-7.el7_9.x86_64 : The mdadm program controls Linux md devices (software RAID arrays) Repo : updates Matched from: Filename : /usr/sbin/mdadm mdadm-4.1-8.el7_9.x86_64 : The mdadm program controls Linux md devices (software RAID arrays) Repo : updates Matched from: Filename : /usr/sbin/mdadm mdadm-4.1-9.el7_9.x86_64 : The mdadm program controls Linux md devices (software RAID arrays) Repo : updates Matched from: Filename : /usr/sbin/mdadm #安装 [root@localhost ~]# yum -y install mdadm Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.cqu.edu.cn * extras: mirrors.cqu.edu.cn * updates: mirrors.cqu.edu.cn Resolving Dependencies --> Running transaction check ---> Package mdadm.x86_64 0:4.1-9.el7_9 will be installed --> Processing Dependency: libreport-filesystem for package: mdadm-4.1-9.el7_9.x86_64 --> Running transaction check ......
用两块磁盘创建raid 0
[root@localhost ~]# mdadm --create /dev/md0 --level 0 --raid-device 2 /dev/sd{b,c} mdadm: Fail to create md0 when using /sys/module/md_mod/parameters/new_array, fallback to creation via node mdadm: Defaulting to version 1.2 metadata mdadm: array /dev/md0 started. [root@localhost ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 199G 0 part ├─centos-root 253:0 0 50G 0 lvm / ├─centos-swap 253:1 0 7.9G 0 lvm [SWAP] └─centos-home 253:2 0 141.1G 0 lvm sdb 8:16 0 50G 0 disk └─md0 9:0 0 100G 0 raid0 sdc 8:32 0 50G 0 disk └─md0 9:0 0 100G 0 raid0 sdd 8:48 0 50G 0 disk sde 8:64 0 50G 0 disk sr0 11:0 1 4.2G 0 rom
格式化md0,并挂载
#格式化 [root@localhost ~]# mkfs.xfs /dev/md0 meta-data=/dev/md0 isize=512 agcount=16, agsize=1637248 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=26195968, imaxpct=25 = sunit=128 swidth=256 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=12792, version=2 = sectsz=512 sunit=8 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 #挂载 [root@localhost ~]# mkdir /raid0 [root@localhost ~]# mount /dev/md0 /raid0 [root@localhost ~]# df -hT Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/centos-root xfs 50G 14G 37G 28% / devtmpfs devtmpfs 3.8G 0 3.8G 0% /dev tmpfs tmpfs 3.9G 0 3.9G 0% /dev/shm tmpfs tmpfs 3.9G 12M 3.8G 1% /run tmpfs tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup /dev/sda1 xfs 1014M 142M 873M 14% /boot tmpfs tmpfs 781M 0 781M 0% /run/user/0 /dev/md0 xfs 100G 33M 100G 1% /raid0
添加到开机自启动配置文件里面
[root@localhost ~]# blkid /dev/md0 /dev/md0: UUID="cc930653-5ab7-43a0-87e4-6906c3d1bd98" TYPE="xfs" [root@localhost ~]# vi /etc/fstab /dev/mapper/centos-root / xfs defaults 0 0 UUID=60defebd-6b85-43da-b5ce-1977bac72048 /boot xfs defaults 0 0 #/dev/mapper/centos-home /home xfs defaults 0 0 /dev/mapper/centos-swap swap swap defaults 0 0 UUID=cc930653-5ab7-43a0-87e4-6906c3d1bd98 /raid0 xfs defaults 0 0
RAID1 是磁盘阵列中单位成本最高的一种方式。因为它的原理是在往磁盘写数据的时候,将同一份数据无差别的写两份到磁盘,分别写到工作磁盘和镜像磁盘,那么它的实际空间使用率只有50%了,两块磁盘当做一块用,这是一种比较昂贵的方案。
RAID1其实与RAID0效果刚好相反。RAID1 这种写双份的做法,就给数据做了一个冗余备份。这样的话,任何一块磁盘损坏了,都可以再基于另外一块磁盘去恢复数据,数据的可靠性非常强,但性能就没那么好了。
两块磁盘创建raid 1
[root@localhost ~]# mdadm --create /dev/md1 --level 1 --raid-device 2 /dev/sd{e,f} mdadm: Note: this array has metadata at the start and may not be suitable as a boot device. If you plan to store '/boot' on this device please ensure that your boot-loader understands md/v1.x metadata, or use --metadata=0.90 mdadm: cannot open /dev/sdf: No such file or directory [root@localhost ~]# mdadm --create /dev/md1 --level 1 --raid-device 2 /dev/sd{d,e} mdadm: Note: this array has metadata at the start and may not be suitable as a boot device. If you plan to store '/boot' on this device please ensure that your boot-loader understands md/v1.x metadata, or use --metadata=0.90 Continue creating array? y mdadm: Fail to create md1 when using /sys/module/md_mod/parameters/new_array, fallback to creation via node mdadm: Defaulting to version 1.2 metadata mdadm: array /dev/md1 started.
查看,并格式化挂载
#查看 [root@localhost ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 199G 0 part ├─centos-root 253:0 0 50G 0 lvm / ├─centos-swap 253:1 0 7.9G 0 lvm [SWAP] └─centos-home 253:2 0 141.1G 0 lvm sdb 8:16 0 50G 0 disk └─md0 9:0 0 100G 0 raid0 sdc 8:32 0 50G 0 disk └─md0 9:0 0 100G 0 raid0 sdd 8:48 0 50G 0 disk └─md1 9:1 0 50G 0 raid1 sde 8:64 0 50G 0 disk └─md1 9:1 0 50G 0 raid1 sr0 11:0 1 4.2G 0 rom #格式化 [root@localhost ~]# mkfs.xfs /dev/md1 meta-data=/dev/md1 isize=512 agcount=4, agsize=3274688 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=13098752, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=6395, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 #挂载 [root@localhost ~]# mkdir /raid1 [root@localhost ~]# mount /dev/md1 /raid1 [root@localhost ~]# df -hT Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/centos-root xfs 50G 14G 37G 28% / devtmpfs devtmpfs 3.8G 0 3.8G 0% /dev tmpfs tmpfs 3.9G 0 3.9G 0% /dev/shm tmpfs tmpfs 3.9G 12M 3.8G 1% /run tmpfs tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup /dev/sda1 xfs 1014M 142M 873M 14% /boot tmpfs tmpfs 781M 0 781M 0% /run/user/0 /dev/md1 xfs 50G 33M 50G 1% /raid1
添加到开机自启动配置文件里
[root@localhost ~]# umount /raid1 [root@localhost ~]# blkid /dev/md1 /dev/md1: UUID="401222a9-5c23-47cb-936a-aa03101cbb1a" TYPE="xfs" [root@localhost ~]# vi /etc/fstab /dev/mapper/centos-root / xfs defaults 0 0 UUID=60defebd-6b85-43da-b5ce-1977bac72048 /boot xfs defaults 0 0 #/dev/mapper/centos-home /home xfs defaults 0 0 /dev/mapper/centos-swap swap swap defaults 0 0 UUID=401222a9-5c23-47cb-936a-aa03101cbb1a /raid1 xfs defaults 0 0
RAID 5是目前用的最多的一种方式。因为 RAID5 是一种将 存储性能、数据安全、存储成本 兼顾的一种方案。RAID5模式中,不再需要用单独的磁盘写校验码了。它把校验码信息分布到各个磁盘上。例如,总共有N块磁盘,那么会将要写入的数据分成N份,并发的写入到N块磁盘中,同时还将数据的校验码信息也写入到这N块磁盘中(数据与对应的校验码信息必须得分开存储在不同的磁盘上)。一旦某一块磁盘损坏了,就可以用剩下的数据和对应的奇偶校验码信息去恢复损坏的数据。
RAID5校验位算法原理:P = D1 xor D2 xor D3 … xor Dn (D1,D2,D3 … Dn为数据块,P为校验,xor为异或运算)
RAID5的方式,最少需要三块磁盘来组建磁盘阵列,允许最多同时坏一块磁盘。如果有两块磁盘同时损坏了,那数据就无法恢复了。
显示
查看
[root@localhost ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 199G 0 part ├─centos-root 253:0 0 50G 0 lvm / ├─centos-swap 253:1 0 7.9G 0 lvm [SWAP] └─centos-home 253:2 0 141.1G 0 lvm sdb 8:16 0 20G 0 disk sdc 8:32 0 20G 0 disk sdd 8:48 0 20G 0 disk
创建raid 5
[root@localhost ~]# mdadm --create /dev/md5 --raid-device 3 /dev/sd{b,c,d} mdadm: a RAID level is needed to create an array. [root@localhost ~]# mdadm --create /dev/md5 --level 5 --raid-device 3 /dev/sd{b,c,d} mdadm: Fail to create md5 when using /sys/module/md_mod/parameters/new_array, fallback to creation via node mdadm: Defaulting to version 1.2 metadata mdadm: array /dev/md5 started. [root@localhost ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 199G 0 part ├─centos-root 253:0 0 50G 0 lvm / ├─centos-swap 253:1 0 7.9G 0 lvm [SWAP] └─centos-home 253:2 0 141.1G 0 lvm sdb 8:16 0 20G 0 disk └─md5 9:5 0 40G 0 raid5 sdc 8:32 0 20G 0 disk └─md5 9:5 0 40G 0 raid5 sdd 8:48 0 20G 0 disk └─md5 9:5 0 40G 0 raid5
格式化挂载
#格式化 [root@localhost ~]# mkfs.xfs /dev/md5 meta-data=/dev/md5 isize=512 agcount=16, agsize=654720 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=10475520, imaxpct=25 = sunit=128 swidth=256 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=5120, version=2 = sectsz=512 sunit=8 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 #挂载 [root@localhost ~]# df -hT Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/centos-root xfs 50G 14G 37G 28% / devtmpfs devtmpfs 3.8G 0 3.8G 0% /dev tmpfs tmpfs 3.9G 0 3.9G 0% /dev/shm tmpfs tmpfs 3.9G 12M 3.8G 1% /run tmpfs tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup /dev/sda1 xfs 1014M 142M 873M 14% /boot tmpfs tmpfs 781M 0 781M 0% /run/user/0 /dev/md5 xfs 40G 33M 40G 1% /raid5
添加到开机自启动配置文件里
[root@localhost ~]# blkid /dev/md5 /dev/md5: UUID="0d4231a6-6c05-4c89-a489-671cf062c966" TYPE="xfs" [root@localhost ~]# vi /etc/fstab /dev/mapper/centos-root / xfs defaults 0 0 UUID=60defebd-6b85-43da-b5ce-1977bac72048 /boot xfs defaults 0 0 #/dev/mapper/centos-home /home xfs defaults 0 0 /dev/mapper/centos-swap swap swap defaults 0 0 UUID=0d4231a6-6c05-4c89-a489-671cf062c966 /raid5 xfs defaults 0 0
RAID10兼备了RAID1和RAID0的有优点。首先基于RAID1模式将磁盘分为2份,当要写入数据的时候,将所有的数据在两份磁盘上同时写入,相当于写了双份数据,起到了数据保障的作用。且在每一份磁盘上又会基于RAID0技术讲数据分为N份并发的读写,这样也保障了数据的效率。
但也可以看出RAID10模式是有一半的磁盘空间用于存储冗余数据的,浪费的很严重,因此用的也不是很多。
显示
查看
[root@localhost ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 199G 0 part ├─centos-root 253:0 0 50G 0 lvm / ├─centos-swap 253:1 0 7.9G 0 lvm [SWAP] └─centos-home 253:2 0 141.1G 0 lvm sdb 8:16 0 100G 0 disk sdc 8:32 0 100G 0 disk sdd 8:48 0 100G 0 disk sde 8:64 0 100G 0 disk sr0 11:0 1 4.2G 0 rom
创建raid 10
[root@localhost ~]# mdadm --create /dev/md10 --level 10 --raid-device 4 /dev/sd{b,c,d,e} mdadm: Fail to create md10 when using /sys/module/md_mod/parameters/new_array, fallback to creation via node mdadm: Defaulting to version 1.2 metadata mdadm: array /dev/md10 started. [root@localhost ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 199G 0 part ├─centos-root 253:0 0 50G 0 lvm / ├─centos-swap 253:1 0 7.9G 0 lvm [SWAP] └─centos-home 253:2 0 141.1G 0 lvm sdb 8:16 0 100G 0 disk └─md10 9:10 0 199.9G 0 raid10 sdc 8:32 0 100G 0 disk └─md10 9:10 0 199.9G 0 raid10 sdd 8:48 0 100G 0 disk └─md10 9:10 0 199.9G 0 raid10 sde 8:64 0 100G 0 disk └─md10 9:10 0 199.9G 0 raid10 sr0 11:0 1 4.2G 0 rom
磁盘格式化并挂载
#格式化 [root@localhost ~]# mkfs.xfs /dev/md10 meta-data=/dev/md10 isize=512 agcount=16, agsize=3274624 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=52393984, imaxpct=25 = sunit=128 swidth=256 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=25584, version=2 = sectsz=512 sunit=8 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 #挂载 [root@localhost ~]# mkdir /raid10 [root@localhost ~]# mount /dev/md10 /raid10 [root@localhost ~]# df -hT Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/centos-root xfs 50G 14G 37G 28% / devtmpfs devtmpfs 3.8G 0 3.8G 0% /dev tmpfs tmpfs 3.9G 0 3.9G 0% /dev/shm tmpfs tmpfs 3.9G 12M 3.8G 1% /run tmpfs tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup /dev/sda1 xfs 1014M 142M 873M 14% /boot tmpfs tmpfs 781M 0 781M 0% /run/user/0 /dev/md10 xfs 200G 33M 200G 1% /raid10
添加到开机自启动配置文件里
[root@localhost ~]# blkid /dev/md10 /dev/md10: UUID="c57bbd24-efc0-4521-a4d7-a870f012c430" TYPE="xfs" [root@localhost ~]# vi /etc/fstab /dev/mapper/centos-root / xfs defaults 0 0 UUID=60defebd-6b85-43da-b5ce-1977bac72048 /boot xfs defaults 0 0 #/dev/mapper/centos-home /home xfs defaults 0 0 /dev/mapper/centos-swap swap swap defaults 0 0 UUID=c57bbd24-efc0-4521-a4d7-a870f012c430 /raid10 xfs defaults 0 0
命令:
[root@localhost ~]# fdisk -l Disk /dev/sdb: 2147.5 GB, 2147483648000 bytes, 4194304000 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 /dev/sda: 214.7 GB, 214748364800 bytes, 419430400 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: 0x00097353 Device Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 419430399 208665600 8e Linux LVM Disk /dev/mapper/centos-root: 53.7 GB, 53687091200 bytes, 104857600 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 /dev/mapper/centos-swap: 8455 MB, 8455716864 bytes, 16515072 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 /dev/mapper/centos-home: 151.5 GB, 151523426304 bytes, 295944192 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
内容为1个primary分区,1个exetended分区,3个logical分区
#创建主分区 Command (m for help): p Disk /dev/sdb: 2147.5 GB, 2147483648000 bytes, 4194304000 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: 0xb65bdaed Device Boot Start End Blocks Id System Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): Using default response p Partition number (1-4, default 1): First sector (2048-4194303999, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-4194303999, default 4194303999): +10G Partition 1 of type Linux and of size 10 GiB is set Command (m for help): p Disk /dev/sdb: 2147.5 GB, 2147483648000 bytes, 4194304000 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: 0xb65bdaed Device Boot Start End Blocks Id System /dev/sdb1 2048 20973567 10485760 83 Linux #创建扩展分区 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 (20973568-4194303999, default 20973568): Using default value 20973568 Last sector, +sectors or +size{K,M,G} (20973568-4194303999, default 4194303999): Using default value 4194303999 Partition 2 of type Extended and of size 2 TiB is set Command (m for help): p Disk /dev/sdb: 2147.5 GB, 2147483648000 bytes, 4194304000 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: 0xb65bdaed Device Boot Start End Blocks Id System /dev/sdb1 2048 20973567 10485760 83 Linux /dev/sdb2 20973568 4194303999 2086665216 5 Extended #创建3个逻辑分区 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 (20975616-4194303999, default 20975616): Using default value 20975616 Last sector, +sectors or +size{K,M,G} (20975616-4194303999, default 4194303999): +20G Partition 5 of type Linux and of size 20 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 6 First sector (62920704-4194303999, default 62920704): Using default value 62920704 Last sector, +sectors or +size{K,M,G} (62920704-4194303999, default 4194303999): +30G Partition 6 of type Linux and of size 30 GiB is set Command (m for help): p Disk /dev/sdb: 2147.5 GB, 2147483648000 bytes, 4194304000 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: 0x10285311 Device Boot Start End Blocks Id System /dev/sdb1 2048 20973567 10485760 83 Linux /dev/sdb2 20973568 4194303999 2086665216 5 Extended /dev/sdb5 20975616 62918655 20971520 83 Linux /dev/sdb6 62920704 125835263 31457280 83 Linux 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 7 First sector (125837312-4194303999, default 125837312): Using default value 125837312 Last sector, +sectors or +size{K,M,G} (125837312-4194303999, default 4194303999): +50G Partition 7 of type Linux and of size 50 GiB is set Command (m for help): p Disk /dev/sdb: 2147.5 GB, 2147483648000 bytes, 4194304000 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: 0x10285311 Device Boot Start End Blocks Id System /dev/sdb1 2048 20973567 10485760 83 Linux /dev/sdb2 20973568 4194303999 2086665216 5 Extended /dev/sdb5 20975616 62918655 20971520 83 Linux /dev/sdb6 62920704 125835263 31457280 83 Linux /dev/sdb7 125837312 230694911 52428800 83 Linux
命令:
#w保存退出 Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. #刷新磁盘 [root@localhost ~]# partprobe Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only.
查看
[root@localhost ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 199G 0 part ├─centos-root 253:0 0 50G 0 lvm / ├─centos-swap 253:1 0 7.9G 0 lvm [SWAP] └─centos-home 253:2 0 141.1G 0 lvm sdb 8:16 0 2T 0 disk ├─sdb1 8:17 0 10G 0 part ├─sdb2 8:18 0 1K 0 part ├─sdb5 8:21 0 20G 0 part ├─sdb6 8:22 0 30G 0 part └─sdb7 8:23 0 50G 0 part sr0 11:0 1 4.2G 0 rom [root@localhost ~]# fdisk -l Disk /dev/sdb: 2147.5 GB, 2147483648000 bytes, 4194304000 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: 0xe4f035bc Device Boot Start End Blocks Id System /dev/sdb1 2048 20973567 10485760 83 Linux /dev/sdb2 20973568 4194303999 2086665216 5 Extended /dev/sdb5 20975616 62918655 20971520 83 Linux /dev/sdb6 62920704 125835263 31457280 83 Linux /dev/sdb7 125837312 230694911 52428800 83 Linux
命令:
#设置/dev/sdb6的文件格式为xfs [root@localhost ~]# mkfs.xfs /dev/sdb6 meta-data=/dev/sdb6 isize=512 agcount=4, agsize=1966080 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=7864320, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=3840, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 #将sdb6挂载到mnt文件夹 [root@localhost ~]# mount /dev/sdb6 /mnt [root@localhost ~]# df -hT Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/centos-root xfs 50G 14G 37G 28% / devtmpfs devtmpfs 3.8G 0 3.8G 0% /dev tmpfs tmpfs 3.9G 0 3.9G 0% /dev/shm tmpfs tmpfs 3.9G 12M 3.8G 1% /run tmpfs tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup /dev/sda1 xfs 1014M 142M 873M 14% /boot tmpfs tmpfs 781M 0 781M 0% /run/user/0 /dev/sdb6 xfs 30G 33M 30G 1% /mnt #配置开机自启动挂载 [root@localhost ~]# blkid /dev/sdb6 /dev/sdb6: UUID="57eb7bba-cc7a-4f6c-99bf-bccb067d266f" TYPE="xfs" [root@localhost ~]# vi /etc/fstab /dev/mapper/centos-root / xfs defaults 0 0 UUID=60defebd-6b85-43da-b5ce-1977bac72048 /boot xfs defaults 0 0 #/dev/mapper/centos-home /home xfs defaults 0 0 /dev/mapper/centos-swap swap swap defaults 0 0 UUID="57eb7bba-cc7a-4f6c-99bf-bccb067d266f" /mnt xfs defaults 0 0
更改磁盘id为swap
#更改/dev/sdb7的id为82 [root@localhost ~]# fdisk /dev/sdb Command (m for help): t Partition number (1,2,5-7, default 7): 7 Hex code (type L to list all codes): 82 Changed type of partition 'Linux' to 'Linux swap / Solaris' Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) Syncing disks. [root@localhost ~]# partprobe Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only. [root@localhost ~]# fdisk -l Disk /dev/sdb: 2147.5 GB, 2147483648000 bytes, 4194304000 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: 0xe4f035bc Device Boot Start End Blocks Id System /dev/sdb1 2048 20973567 10485760 83 Linux /dev/sdb2 20973568 4194303999 2086665216 5 Extended /dev/sdb5 20975616 62918655 20971520 83 Linux /dev/sdb6 62920704 125835263 31457280 83 Linux /dev/sdb7 125837312 230694911 52428800 82 Linux swap / Solaris
格式化
[root@localhost ~]# mkswap /dev/sdb7 Setting up swapspace version 1, size = 52428796 KiB no label, UUID=a48e154b-4da3-4771-9e09-8a357aa6049b
挂载到swap分区
#查看swap分区有7G [root@localhost ~]# free -h total used free shared buff/cache available Mem: 7.6G 181M 7.2G 11M 295M 7.2G Swap: 7.9G 0B 7.9G #添加/dev/sdb7后 [root@localhost ~]# swapon /dev/sdb7 [root@localhost ~]# free -h total used free shared buff/cache available Mem: 7.6G 221M 7.1G 11M 295M 7.1G Swap: 57G 0B 57G
实现自动挂载
[root@localhost ~]# blkid /dev/sdb7 /dev/sdb7: UUID="6c77c8f6-9b57-4def-9885-d92a45b7abe4" TYPE="swap" [root@localhost ~]# vi /etc/fstab /dev/mapper/centos-root / xfs defaults 0 0 UUID=60defebd-6b85-43da-b5ce-1977bac72048 /boot xfs defaults 0 0 #/dev/mapper/centos-home /home xfs defaults 0 0 /dev/mapper/centos-swap swap swap defaults 0 0 UUID="6c77c8f6-9b57-4def-9885-d92a45b7abe4" swap swap defaults 0 0