1、创建一个10G分区,并格式为ext4文件系统;
(1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl;
创建分区
[root@localhost Desktop]# 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 0xd1fd27d7. 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-41943039, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +10G Partition 1 of type Linux and of size 10 GiB is set Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@localhost Desktop]# partx -a /dev/sdb partx: /dev/sdb: error adding partition 1
指定block大小,预留空间百分比及卷标
[root@localhost Desktop]# mke2fs -t ext4 -b 2048 -m 2 -L 'MYDATA' /dev/sdb1 mke2fs 1.42.9 (28-Dec-2013) Filesystem label=MYDATA OS type: Linux Block size=2048 (log=1) Fragment size=2048 (log=1) Stride=0 blocks, Stripe width=0 blocks 655360 inodes, 5242880 blocks 104857 blocks (2.00%) reserved for the super user First data block=0 Maximum filesystem blocks=273678336 320 block groups 16384 blocks per group, 16384 fragments per group 2048 inodes per group Superblock backups stored on blocks: 16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816, 1327104, 2048000, 3981312 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done
添加acl挂载属性
[root@localhost Desktop]# tune2fs -o acl /dev/sdb1 tune2fs 1.42.9 (28-Dec-2013)
(2) 挂载至/data/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳;
[root@localhost Desktop]# mkdir -p /data/mydata [root@localhost Desktop]# mount -o noexec,noatime /dev/sdb1 /data/mydata/
2、创建一个大小为1G的swap分区,并创建好文件系统,并启用之;
创建分区
[root@localhost Desktop]# 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. Command (m for help): n Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): p Partition number (2-4, default 2): First sector (20973568-41943039, default 20973568): Using default value 20973568 Last sector, +sectors or +size{K,M,G} (20973568-41943039, default 41943039): +1G Partition 2 of type Linux and of size 1 GiB is set 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 Desktop]# partx -a /dev/sdb partx: /dev/sdb: error adding partition 1
写入文件系统fstab
[root@localhost Desktop]# mkswap /dev/sdb2 Setting up swapspace version 1, size = 1048572 KiB no label, UUID=2f3ba372-bac4-4846-b833-636eb3d97303 [root@localhost Desktop]# vim /etc/fstab [root@localhost Desktop]# cat /etc/fstab | grep swap /dev/mapper/rhel-swap swap swap defaults 0 0 UUID=2f3ba372-bac4-4846-b833-636eb3d97303swapswap defaults0 0 [root@localhost Desktop]# mount -a
启用swap分区
[root@localhost Desktop]# swapon -a [root@localhost Desktop]# free -m total used free shared buffers cached Mem: 1826 868 958 9 1 283 -/+ buffers/cache: 583 1243 Swap: 3071 0 3071
3、写一个脚本
(1) 获取并列出当前系统上的所有磁盘设备;
(2) 显示每个磁盘设备上每个分区相关的空间使用信息;
#!/bin/bash echo "disk info:" fdisk -l /dev/[sh]d[a-z] echo echo "partition info:" for disk in $(fdisk -l | grep -o "^Disk /dev/[sh]d[a-z]" | cut -d' ' -f2); do echo $disk declare -i i=1 while [ $i -le $(fdisk -l $disk | grep "^/dev/[sh]d[a-z][0-9]" | wc -l) ]; do df -Th ${disk}${i} | tail -1 let i++ done echo done
4、总结RAID的各个级别及其组合方式和性能的不同;
RAID-0: 条带卷,strip
特点:读、写性能提升;无容错能力
可用空间:N*min(S1,S2,...)
最少磁盘数:2
RAID-1:镜像卷,mirror
优点:读性能提升、写性能略有下降;有冗余能力
可用空间:1*min(S1,S2,...)
最少磁盘数:2
RAID-5:
特点:读、写性能提升;有容错能力:1块磁盘
可用空间:(N-1)*min(S1,S2,...)
最少磁盘数:3
RAID-6:
特点:读、写性能提升;有容错能力:2块磁盘
可用空间:(N-2)*min(S1,S2,...)
最少磁盘数:4
混合类型
RAID-10:读、写性能提升;有容错能力:每组镜像最多只能坏1块
可用空间:N*min(S1,S2,...)/2
最少磁盘数:4
JBOD:Just a Bunch Of Disks
功能:将多块磁盘的空间合并一个大的连续空间使用
可用空间:sum(S1,S2,...)
5、创建一个大小为10G的RAID1,要求有一个空闲盘,而且CHUNK大小为128k;
[root@localhost Desktop]# 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 0xba3edeaa. 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-41943039, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +10G Partition 1 of type Linux and of size 10 GiB is set Command (m for help): t Selected partition 1 Hex code (type L to list all codes): fd Changed type of partition 'Linux' to 'Linux raid autodetect' Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@localhost Desktop]# fdisk /dev/sdc 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 0x2b6abd80. 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-41943039, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +10G Partition 1 of type Linux and of size 10 GiB is set Command (m for help): t Selected partition 1 Hex code (type L to list all codes): fd Changed type of partition 'Linux' to 'Linux raid autodetect' Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@localhost Desktop]# fdisk /dev/sdd 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 0xde9307db. 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-41943039, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +10G Partition 1 of type Linux and of size 10 GiB is set Command (m for help): t Selected partition 1 Hex code (type L to list all codes): fd Changed type of partition 'Linux' to 'Linux raid autodetect' Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@localhost Desktop]# partprobe [root@localhost Desktop]# mdadm -C /dev/md1 -a yes -c 128K -l 1 -n 2 -x 1 /dev/sdb1 /dev/sdc1 /dev/sdd1 [root@localhost Desktop]# mdadm -D /dev/md1 /dev/md1: Version : 1.2 Creation Time : Wed May 31 22:46:16 2017 Raid Level : raid1 Array Size : 10477440 (9.99 GiB 10.73 GB) Used Dev Size : 10477440 (9.99 GiB 10.73 GB) Raid Devices : 2 Total Devices : 3 Persistence : Superblock is persistent Update Time : Wed May 31 22:47:08 2017 State : active Active Devices : 2 Working Devices : 3 Failed Devices : 0 Spare Devices : 1 Name : localhost.localdomain:1 (local to host localhost.localdomain) UUID : d627c232:7ff80074:285fe4c7:6fc0a6bf Events : 18 Number Major Minor RaidDevice State 0 8 17 0 active sync /dev/sdb1 1 8 33 1 active sync /dev/sdc1 2 8 49 - spare /dev/sdd1
6、创建一个大小为4G的RAID5设备,chunk大小为256k,格式化ext4文件系统,要求可开机自动挂载至/backup目录,而且不更新访问时间戳,且支持acl功能;
[root@localhost Desktop]# 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. Command (m for help): n Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): p Partition number (2-4, default 2): First sector (20973568-41943039, default 20973568): Using default value 20973568 Last sector, +sectors or +size{K,M,G} (20973568-41943039, default 41943039): +4G Partition 2 of type Linux and of size 4 GiB is set Command (m for help): t Partition number (1,2, default 2): 2 Hex code (type L to list all codes): fd Changed type of partition 'Linux' to 'Linux raid autodetect' 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 Desktop]# fdisk /dev/sdc 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. Command (m for help): n Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): p Partition number (2-4, default 2): First sector (20973568-41943039, default 20973568): Using default value 20973568 Last sector, +sectors or +size{K,M,G} (20973568-41943039, default 41943039): +4G Partition 2 of type Linux and of size 4 GiB is set Command (m for help): t Partition number (1,2, default 2): 2 Hex code (type L to list all codes): fd Changed type of partition 'Linux' to 'Linux raid autodetect' 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 Desktop]# fdisk /dev/sdd 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. Command (m for help): n Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): p Partition number (2-4, default 2): First sector (20973568-41943039, default 20973568): Using default value 20973568 Last sector, +sectors or +size{K,M,G} (20973568-41943039, default 41943039): +4G Partition 2 of type Linux and of size 4 GiB is set Command (m for help): t Partition number (1,2, default 2): 2 Hex code (type L to list all codes): fd Changed type of partition 'Linux' to 'Linux raid autodetect' 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 Desktop]# partprobe [root@localhost Desktop]# mdadm -C /dev/md5 -a yes -c 256K -l 5 -n 3 /dev/sdb2 /dev/sdc2 /dev/sdd2 [root@localhost Desktop]# mdadm -D /dev/md5 /dev/md5: Version : 1.2 Creation Time : Wed May 31 23:23:25 2017 Raid Level : raid5 Array Size : 8384000 (8.00 GiB 8.59 GB) Used Dev Size : 4192000 (4.00 GiB 4.29 GB) Raid Devices : 3 Total Devices : 3 Persistence : Superblock is persistent Update Time : Wed May 31 23:23:46 2017 State : clean Active Devices : 3 Working Devices : 3 Failed Devices : 0 Spare Devices : 0 Layout : left-symmetric Chunk Size : 256K Name : localhost.localdomain:5 (local to host localhost.localdomain) UUID : 2dd21526:ded34170:a50dd479:4324cab9 Events : 20 Number Major Minor RaidDevice State 0 8 18 0 active sync /dev/sdb2 1 8 34 1 active sync /dev/sdc2 3 8 50 2 active sync /dev/sdd2 [root@localhost Desktop]# mke2fs -t ext4 /dev/md5 mke2fs 1.42.9 (28-Dec-2013) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=64 blocks, Stripe width=128 blocks 524288 inodes, 2096000 blocks 104800 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=2147483648 64 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 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done [root@localhost Desktop]# mkdir /backup [root@localhost Desktop]# vim /etc/fstab [root@localhost Desktop]# tail -1 /etc/fstab /dev/md5/backupext4defaults,acl,noatime 0 0 [root@localhost Desktop]# mount -a