1、破坏mbr表并修复

##先做分区表备份
[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  100G  0 part /
├─sda3   8:3    0   50G  0 part /data
├─sda4   8:4    0    1K  0 part 
└─sda5   8:5    0    2G  0 part [SWAP]
sr0     11:0    1  4.5G  0 rom  
[root@centos7 ~]# dd if=/dev/sda of=/data/dpt.img bs=1 count=64 skip=446
64+0 records in
64+0 records out
64 bytes (64 B) copied, 0.000314256 s, 204 kB/s
[root@centos7 ~]# ll /data/dpt.img
-rw-r--r--. 1 root root 64 Feb 23 14:42 /data/dpt.img

##备份到远程主机
[root@centos7 ~]# scp /data/dpt.img 10.0.0.203:/data/
The authenticity of host '10.0.0.203 (10.0.0.203)' can't be established.
ECDSA key fingerprint is SHA256:rB9N78xM2IfAKqhHahltwZEBmHEMhToDY/caJDmuycs.
ECDSA key fingerprint is MD5:29:2c:59:55:59:c8:e9:b4:db:f1:09:ea:19:c2:47:bb.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.0.0.203' (ECDSA) to the list of known hosts.
root@10.0.0.203's password: 
dpt.img                                                               100%   64     5.2KB/s   00:00    
[root@centos8 ~]# ll /data/dpt.img
-rw-r--r--. 1 root root 64 Feb 23 14:49 /data/dpt.img


##破坏mbr分区表
[root@centos7 ~]# dd if=/dev/zero of=/dev/sda bs=1 count=64 seek=446
64+0 records in
64+0 records out
64 bytes (64 B) copied, 0.00024709 s, 259 kB/s

[root@centos7 ~]# hexdump -C -n 512 /dev/sda -v
00000000  eb 63 90 10 8e d0 bc 00  b0 b8 00 00 8e d8 8e c0  |.c..............|
00000010  fb be 00 7c bf 00 06 b9  00 02 f3 a4 ea 21 06 00  |...|.........!..|
00000020  00 be be 07 38 04 75 0b  83 c6 10 81 fe fe 07 75  |....8.u........u|
00000030  f3 eb 16 b4 02 b0 01 bb  00 7c b2 80 8a 74 01 8b  |.........|...t..|
00000040  4c 02 cd 13 ea 00 7c 00  00 eb fe 00 00 00 00 00  |L.....|.........|
00000050  00 00 00 00 00 00 00 00  00 00 00 80 01 00 00 00  |................|
00000060  00 00 00 00 ff fa 90 90  f6 c2 80 74 05 f6 c2 70  |...........t...p|
00000070  74 02 b2 80 ea 79 7c 00  00 31 c0 8e d8 8e d0 bc  |t....y|..1......|
00000080  00 20 fb a0 64 7c 3c ff  74 02 88 c2 52 be 05 7c  |. ..d|<.t...R..||
00000090  b4 41 bb aa 55 cd 13 5a  52 72 3d 81 fb 55 aa 75  |.A..U..ZRr=..U.u|
000000a0  37 83 e1 01 74 32 31 c0  89 44 04 40 88 44 ff 89  |7...t21..D.@.D..|
000000b0  44 02 c7 04 10 00 66 8b  1e 5c 7c 66 89 5c 08 66  |D.....f..\|f.\.f|
000000c0  8b 1e 60 7c 66 89 5c 0c  c7 44 06 00 70 b4 42 cd  |..`|f.\..D..p.B.|
000000d0  13 72 05 bb 00 70 eb 76  b4 08 cd 13 73 0d 5a 84  |.r...p.v....s.Z.|
000000e0  d2 0f 83 de 00 be 85 7d  e9 82 00 66 0f b6 c6 88  |.......}...f....|
000000f0  64 ff 40 66 89 44 04 0f  b6 d1 c1 e2 02 88 e8 88  |d.@f.D..........|
00000100  f4 40 89 44 08 0f b6 c2  c0 e8 02 66 89 04 66 a1  |.@.D.......f..f.|
00000110  60 7c 66 09 c0 75 4e 66  a1 5c 7c 66 31 d2 66 f7  |`|f..uNf.\|f1.f.|
00000120  34 88 d1 31 d2 66 f7 74  04 3b 44 08 7d 37 fe c1  |4..1.f.t.;D.}7..|
00000130  88 c5 30 c0 c1 e8 02 08  c1 88 d0 5a 88 c6 bb 00  |..0........Z....|
00000140  70 8e c3 31 db b8 01 02  cd 13 72 1e 8c c3 60 1e  |p..1......r...`.|
00000150  b9 00 01 8e db 31 f6 bf  00 80 8e c6 fc f3 a5 1f  |.....1..........|
00000160  61 ff 26 5a 7c be 80 7d  eb 03 be 8f 7d e8 34 00  |a.&Z|..}....}.4.|
00000170  be 94 7d e8 2e 00 cd 18  eb fe 47 52 55 42 20 00  |..}.......GRUB .|
00000180  47 65 6f 6d 00 48 61 72  64 20 44 69 73 6b 00 52  |Geom.Hard Disk.R|
00000190  65 61 64 00 20 45 72 72  6f 72 0d 0a 00 bb 01 00  |ead. Error......|
000001a0  b4 0e cd 10 ac 3c 00 75  f4 c3 00 00 00 00 00 00  |.....<.u........|
000001b0  00 00 00 00 00 00 00 00  b4 a5 03 00 00 00 00 00  |................|
000001c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............U.|
00000200

重置设备在救援模式下恢复

然后重新启动设备就OK了。

2、总结RAID的各个级别及其组合方式和性能的不同

1)RAID0特性:

读写性能提升;
可用空间,N*min;
无容错能力;
最小磁盘数2

2)RAID1特性:

读性能提升,写性能略有下降,同一份数据要存两份;
可用空间,n/2*min,磁盘总空间的一半;
有冗余能力;
最少磁盘数,2

3)RAID5特性:

读写性能提升;
可用空间,N-1*min;
有冗余能力;
最少磁盘数,3

4)RAID10特性:

读写性能提升;
可用空间,N*min/2;
有冗余能力,每组镜像最多只能坏一块;
最少磁盘数,4

3、创建一个2G的文件系统,块大小为2048byte,预留1%可用空间,文件系统 ext4,卷标为TEST,要求此分区开机后自动挂载至/test目录,且默认有acl挂载选项

##创建文件系统
[root@centos7 ~]# dd if=/dev/zero of=/disk.img bs=2M count=1024
1024+0 records in
1024+0 records out
2147483648 bytes (2.1 GB) copied, 36.1938 s, 59.3 MB/s
[root@centos7 ~]# du -sh /disk.img
2.0G	/disk.img

[root@centos7 ~]# mkfs.ext4 -b 2048 -m 1 -L TEST /disk.img
mke2fs 1.42.9 (28-Dec-2013)
/disk.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 ~]# blkid /disk.img
/disk.img: LABEL="TEST" UUID="347a6916-5318-49fa-ac00-14db874a0fbf" TYPE="ext4" 

##写入/etc/fstab文件,实现开机自动挂载
[root@centos7 ~]# vim /etc/fstab
[root@centos7 ~]# cat /etc/fstab
UUID=09e19907-d211-4ea5-9057-f90351aa5499 swap                    swap    defaults        0 0
/disk.img                                 /test                   ext4    loop,acl        0 0

[root@centos7 ~]# mkdir /test
[root@centos7 ~]# mount -a
[root@centos7 ~]# losetup -a
/dev/loop0: [2050]:367930 (/disk.img)
[root@centos7 ~]# lsblk -f
NAME   FSTYPE  LABEL           UUID                                 MOUNTPOINT
sda                                                                 
├─sda1 xfs                     4fa848f3-02f9-4814-8fdb-f41a6d59fc33 /boot
├─sda2 xfs                     81d93980-4fd1-4183-9a76-c707bccccc45 /
├─sda3 xfs                     2f8ce926-5155-4f92-8025-ecbf34a7aa40 /data
├─sda4                                                              
└─sda5 swap                    09e19907-d211-4ea5-9057-f90351aa5499 [SWAP]
sr0    iso9660 CentOS 7 x86_64 2020-04-22-00-54-00-00               
loop0  ext4    TEST            347a6916-5318-49fa-ac00-14db874a0fbf /test

[root@centos7 ~]# cp /etc/issue /test
[root@centos7 ~]# ll /test
total 18
-rw-r--r--. 1 root root    23 Mar  7 13:54 issue
drwx------. 2 root root 16384 Mar  7 13:39 lost+found

##重启设备之后再查看/test目录下的内容
[root@centos7 ~]# lsblk -f
NAME   FSTYPE  LABEL           UUID                                 MOUNTPOINT
sda                                                                 
├─sda1 xfs                     4fa848f3-02f9-4814-8fdb-f41a6d59fc33 /boot
├─sda2 xfs                     81d93980-4fd1-4183-9a76-c707bccccc45 /
├─sda3 xfs                     2f8ce926-5155-4f92-8025-ecbf34a7aa40 /data
├─sda4                                                              
└─sda5 swap                    09e19907-d211-4ea5-9057-f90351aa5499 [SWAP]
sr0    iso9660 CentOS 7 x86_64 2020-04-22-00-54-00-00               
loop0  ext4    TEST            347a6916-5318-49fa-ac00-14db874a0fbf /test
[root@centos7 ~]# ll /test
total 18
-rw-r--r--. 1 root root    23 Mar  7 13:54 issue
drwx------. 2 root root 16384 Mar  7 13:39 lost+found

[root@centos7 ~]# tune2fs -l /disk.img
tune2fs 1.42.9 (28-Dec-2013)
Filesystem volume name:   TEST      ##卷标TEST
Last mounted on:          /test
Filesystem UUID:          347a6916-5318-49fa-ac00-14db874a0fbf
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype needs_recovery extent 64bit flex_bg sparse_super huge_file uninit_bg dir_nlink extra_isize
Filesystem flags:         signed_directory_hash 
Default mount options:    user_xattr acl      ##acl功能
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              131072
Block count:              1048576
Reserved block count:     10485      ##预留1%的空间
Free blocks:              994650
Free inodes:              131060
First block:              0
Block size:               2048      ##块大小2048
Fragment size:            2048
Group descriptor size:    64
Reserved GDT blocks:      512
Blocks per group:         16384
Fragments per group:      16384
Inodes per group:         2048
Inode blocks per group:   256
Flex block group size:    16
Filesystem created:       Sun Mar  7 13:39:02 2021
Last mount time:          Sun Mar  7 13:57:17 2021
Last write time:          Sun Mar  7 13:57:17 2021
Mount count:              2
Maximum mount count:      -1
Last checked:             Sun Mar  7 13:39:02 2021
Check interval:           0 (<none>)
Lifetime writes:          65 MB
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:	          256
Required extra isize:     28
Desired extra isize:      28
Journal inode:            8
Default directory hash:   half_md4
Directory Hash Seed:      6a94c4cb-b9e4-42fc-ab1d-384eea4da9ca
Journal backup:           inode blocks

4、创建一个至少有两个PV组成的大小为20G的名为testvg的VG;要求PE大小 为16MB, 而后在卷组中创建大小为5G的逻辑卷testlv;挂载至/users目录

##1)创建物理卷
[root@centos8 ~]# 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  100G  0 part /
├─sda3   8:3    0    4G  0 part [SWAP]
├─sda4   8:4    0    1K  0 part 
└─sda5   8:5    0   50G  0 part /data
sdb      8:16   0   20G  0 disk 
└─sdb1   8:17   0   18G  0 part 
sdc      8:32   0    2G  0 disk 
sr0     11:0    1    7G  0 rom  

[root@centos8 ~]# pvcreate /dev/sdb1 /dev/sdc
  Physical volume "/dev/sdb1" successfully created.
  Physical volume "/dev/sdc" successfully created.
[root@centos8 ~]# pvs
  PV         VG Fmt  Attr PSize  PFree 
  /dev/sdb1     lvm2 ---  18.00g 18.00g
  /dev/sdc      lvm2 ---   2.00g  2.00g
[root@centos8 ~]# pvdisplay
  "/dev/sdb1" is a new physical volume of "18.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb1
  VG Name               
  PV Size               18.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               mIlED9-di5O-3xmZ-PjnF-GiLB-0nIW-4SPc6e
   
  "/dev/sdc" is a new physical volume of "2.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdc
  VG Name               
  PV Size               2.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               b57Zqu-bo6B-Rcdw-rZtW-4iMr-xqjC-qnZ8k5

##创建卷组
[root@centos8 ~]# vgcreate -s 16M testvg /dev/sdb1 /dev/sdc
  Volume group "testvg" successfully created
[root@centos8 ~]# vgs
  VG     #PV #LV #SN Attr   VSize   VFree  
  testvg   2   0   0 wz--n- <19.97g <19.97g
[root@centos8 ~]# 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               9GcXDK-KxPq-Cinx-Tgqk-hjw3-wdiK-c8gzXz

##创建逻辑卷
[root@centos8 ~]# lvcreate -n testlv -L 5G testvg
WARNING: xfs signature detected on /dev/testvg/testlv at offset 0. Wipe it? [y/n]: y
  Wiping xfs signature on /dev/testvg/testlv.
  Logical volume "testlv" created.
[root@centos8 ~]# lvs
  LV     VG     Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  testlv testvg -wi-a----- 5.00g                                                    
[root@centos8 ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/testvg/testlv
  LV Name                testlv
  VG Name                testvg
  LV UUID                6IriL2-lsW1-CiNc-40yD-SFL6-sH3J-on6f6O
  LV Write Access        read/write
  LV Creation host, time centos8.magedu.org, 2021-03-07 15:42:18 +0800
  LV Status              available
  # open                 0
  LV Size                5.00 GiB
  Current LE             320
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

##对逻辑卷创建文件系统
[root@centos8 ~]# ll /dev/testvg/testlv
lrwxrwxrwx. 1 root root 7 Mar  7 15:42 /dev/testvg/testlv -> ../dm-0
[root@centos8 ~]# mkfs.ext4 /dev/testvg/testlv
mke2fs 1.44.6 (5-Mar-2019)
Creating filesystem with 1310720 4k blocks and 327680 inodes
Filesystem UUID: 9062d0e8-3cab-473c-bca7-afc7b413145a
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736

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

[root@centos8 ~]# blkid
...
/dev/mapper/testvg-testlv: UUID="9062d0e8-3cab-473c-bca7-afc7b413145a" TYPE="ext4"

##挂载
[root@centos8 ~]# vim /etc/fstab
[root@centos8 ~]# cat /etc/fstab
...
UUID=9062d0e8-3cab-473c-bca7-afc7b413145a /users                  ext4    defaults        0 0

[root@centos8 ~]# mkdir /users
[root@centos8 ~]# mount -a
[root@centos8 ~]# mount
...
/dev/mapper/testvg-testlv on /users type ext4 (rw,relatime,seclabel)

[root@centos8 ~]# df -hT
Filesystem                Type      Size  Used Avail Use% Mounted on
devtmpfs                  devtmpfs  967M     0  967M   0% /dev
tmpfs                     tmpfs     983M     0  983M   0% /dev/shm
tmpfs                     tmpfs     983M  8.7M  974M   1% /run
tmpfs                     tmpfs     983M     0  983M   0% /sys/fs/cgroup
/dev/sda2                 xfs       100G  2.1G   98G   3% /
/dev/sda5                 xfs        50G  390M   50G   1% /data
/dev/sda1                 ext4      976M  112M  798M  13% /boot
tmpfs                     tmpfs     197M     0  197M   0% /run/user/0
/dev/mapper/testvg-testlv ext4      4.9G   20M  4.6G   1% /users