一、破坏mbr分区表并修复
#备份MBR分区表
[root@centos7 ~]# dd if=/dev/sda of=/data/dpt.img bs=1 count=64 skip=446
[root@centos7 ~]# scp /data/dpt.img 192.168.150.128:
#破坏MBR分区表
[root@centos7 ~]# dd if=/dev/zero of=/dev/sda bs=1 count=64 seek=446
#重启,无法启动,提示error:no such partion. Entering rescue mode... grub rescue
#从光盘启动,选择troubleshooting,在选择rescue a centos system,进去后选择1再回车或者3 skip to shell都可以。
#配置网络
sh-4.2# ifconfig ens33 192.168.150.129/24
sh-4.2# scp 192.168.150.128:/root/dpt.img .
#恢复MBR分区表
sh-4.2# dd if=dpt.img of=/dev/sda bs=1 count=64 seek=446
#重启测试
二、总结RAID的各个级别及其组合方式和性能的不同。
| RAID级别 |
可用空间 |
容错能力 |
最少磁盘数量 |
读写性能 |
| RAID-0 |
N*min(S1,S2,...) |
无 |
2(2+) |
读写性能提升 |
| RAID-1 |
1*min(S1,S2,...) |
有冗余 |
2(2N) |
读性能提升、写性能下降 |
| RAID-5 |
(N-1)*min(S1,S2,...) |
有容错能力,最多允许坏一块磁盘 |
3(3+) |
读写性能提升 |
| RAID-6 |
(N-2)*min(S1,S2,...) |
有容错能力,最多允许坏两块磁盘 |
4(4+) |
读写性能提升 |
| RAID-10 |
N*min(S1,S2,...)/2 |
有容错能力,每组镜像最多只能坏一块磁盘 |
4(4+) |
读写性能提升 |
| RAID-01 |
N*min(S1,S2,...)/2 |
有容错能力,每组镜像最多只能坏一块磁盘 |
4(4+) |
读写性能提升 |
| RAID-50 |
|
有容错能力,每组镜像最多只能坏一块磁盘 |
6(6+) |
读写性能提升 |
| JBOD |
sum(S1,S2,...) |
无 |
|
多块磁盘空间合并成连续空间使用 |
三、创建一个2G的文件系统,块大小为2048byte,预留1%可用空间,文件系统 ext4,卷标为TEST,要求此分区开机后自动挂载至/test目录,且默认有acl挂载选项
#生成一个2G的文件
[root@centos7 ~]# dd if=/dev/zero of=file1.img bs=1M count=2048
#创建文件系统
[root@centos7 ~]# mkfs.ext4 -b 2048 -m 1 -L "TEST" file1.img
mke2fs 1.42.9 (28-Dec-2013)
file1.img is not a block special device.
Proceed anyway? (y,n) y
Discarding device blocks: done
Filesystem label=TEST
OS type: Linux
Block size=2048 (log=1)
Fragment size=2048 (log=1)
Stride=0 blocks, Stripe width=0 blocks
131072 inodes, 1048576 blocks
10485 blocks (1.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=269484032
64 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
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
[root@centos7 ~]# file file1.img
file1.img: Linux rev 1.0 ext4 filesystem data, UUID=4a818ff8-7e10-4057-9bff-ce31b29c82c5, volume name "TEST" (extents) (64bit) (huge files)
#创建目录并设置自动挂载
[root@centos7 ~]# mkdir /test
[root@centos7 ~]# echo "/root/file1.img /test ext4 acl 0 0" >> /etc/fstab
[root@centos7 ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Sun Feb 28 10:36:15 2021
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos_centos7-root / xfs defaults 0 0
UUID=63e345b0-a313-47cc-8cee-36bf03b83289 /boot xfs defaults 0 0
/dev/mapper/centos_centos7-data /data xfs defaults 0 0
/dev/mapper/centos_centos7-swap swap swap defaults 0 0
/root/file1.img /test ext4 acl 0 0
[root@centos7 ~]# 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 154G 0 part
├─centos_centos7-root 253:0 0 100G 0 lvm /
├─centos_centos7-swap 253:1 0 4G 0 lvm [SWAP]
└─centos_centos7-data 253:2 0 50G 0 lvm /data
sr0 11:0 1 918M 0 rom
loop0 7:0 0 2G 0 loop /test
四、创建一个至少有两个PV组成的大小为20G的名为testvg的VG;要求PE大小 为16MB, 而后在卷组中创建大小为5G的逻辑卷testlv;挂载至/users目录
#添加两块硬盘分别是15G和10G,并用命令扫描出新加的硬盘
[root@centos7 ~]# echo "- - -" > /sys/class/scsi_host/host0/scan
[root@centos7 ~]# 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 154G 0 part
├─centos_centos7-root 253:0 0 100G 0 lvm /
├─centos_centos7-swap 253:1 0 4G 0 lvm [SWAP]
└─centos_centos7-data 253:2 0 50G 0 lvm /data
sdb 8:16 0 15G 0 disk
sdc 8:32 0 10G 0 disk
sr0 11:0 1 918M 0 rom
loop0 7:0 0 2G 0 loop /test
#准备用sdb15G和sdc中分一个5G的分区出来组成PV
[root@centos7 ~]# echo -e 'n\np\n\n\n+5G\nw\n' | fdisk /dev/sdc
#安装lvm2工具
[root@centos7 ~]# yum -y install lvm2
#创建pv
[root@centos7 ~]# pvcreate /dev/sdb /dev/sdc1
Physical volume "/dev/sdb" successfully created.
Physical volume "/dev/sdc1" successfully created.
[root@centos7 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 centos_centos7 lvm2 a-- 154.00g 0
/dev/sdb lvm2 --- 15.00g 15.00g
/dev/sdc1 lvm2 --- 5.00g 5.00g
#创建指定PE大小为16M的testvg
[root@centos7 ~]# vgcreate -s 16 testvg /dev/sdb /dev/sdc1
Volume group "testvg" successfully created
[root@centos7 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos_centos7 1 3 0 wz--n- 154.00g 0
testvg 2 0 0 wz--n- <19.97g <19.97g
[root@centos7 ~]# vgdisplay
--- Volume group ---
VG Name testvg
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 2
Act PV 2
VG Size <19.97 GiB
PE Size 16.00 MiB
Total PE 1278
Alloc PE / Size 0 / 0
Free PE / Size 1278 / <19.97 GiB
VG UUID dCF8i9-JXSG-1wYK-nEWC-gFlJ-X3Mk-rnGZBW
--- Volume group ---
VG Name centos_centos7
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 1
Act PV 1
VG Size 154.00 GiB
PE Size 4.00 MiB
Total PE 39424
Alloc PE / Size 39424 / 154.00 GiB
Free PE / Size 0 / 0
VG UUID yn3zID-XfO9-kAXT-iuUH-MM0S-LORr-Q5j9zc
#创建大小为5G的逻辑卷testlv
[root@centos7 ~]# lvcreate -n testlv -L 5G testvg
Logical volume "testlv" created.
[root@centos7 ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
data centos_centos7 -wi-ao---- 50.00g
root centos_centos7 -wi-ao---- 100.00g
swap centos_centos7 -wi-ao---- 4.00g
testlv testvg -wi-a----- 5.00g
# 在lv上创建文件系统
[root@centos7 ~]# mkfs.ext4 /dev/testvg/testlv
#创建目录并做相应的挂载
[root@centos7 ~]# mkdir /users
[root@centos7 ~]# mount /dev/testvg/testlv /users
[root@centos7 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos_centos7-root 100G 2.0G 98G 2% /
devtmpfs 898M 0 898M 0% /dev
tmpfs 910M 0 910M 0% /dev/shm
tmpfs 910M 9.6M 901M 2% /run
tmpfs 910M 0 910M 0% /sys/fs/cgroup
/dev/loop0 2.0G 9.1M 1.9G 1% /test
/dev/sda1 1014M 146M 869M 15% /boot
/dev/mapper/centos_centos7-data 50G 33M 50G 1% /data
tmpfs 182M 0 182M 0% /run/user/0
/dev/mapper/testvg-testlv 4.8G 20M 4.6G 1% /users