第七周作业

1.1破坏mbr表并修复

##1. 添加一块实验用磁盘:/dev/sdb
[root@bogon ~]# fdisk /dev/sdb

Welcome to fdisk (util-linux 2.32.1).
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.
Created a new DOS disklabel with disk identifier 0x440d52d3.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p):

Using default response p.
Partition number (1-4, default 1):
First sector (2048-10485759, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-10485759, default 10485759):

Created a new partition 1 of type 'Linux' and of size 5 GiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

[root@bogon ~]#
[root@bogon ~]#
[root@bogon ~]# partprobe /dev/sdb
[root@bogon ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.45.6 (20-Mar-2020)
Creating filesystem with 1310464 4k blocks and 327680 inodes
Filesystem UUID: ce994dfa-b43a-41ef-a867-de489f359f14
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@bogon ~]# lsblk /dev/sdb
NAME   MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb      8:16   0   5G  0 disk
└─sdb1   8:17   0   5G  0 part
[root@bogon ~]#


## 用hexdump -C /dev/sdb -n 512查看分区表前512字节
通过修改分区表修改如图的64个字节来达到破坏效果
[root@bogon ~]# hexdump -C /dev/sdb -n 512
00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001b0  00 00 00 00 00 00 00 00  95 2e a5 86 00 00 00 20  |............... |
000001c0  21 00 83 b4 a8 8c 00 08  00 00 00 f8 9f 00 00 00  |!...............|
000001d0  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
[root@bogon ~]#

# #备份 /dev/sdb mrb分区表:
[root@bogon software]# dd if=/dev/sdb of=/root/mbr-bak.img bs=1 count=64 skip=446
64+0 records in
64+0 records out
64 bytes copied, 0.000591286 s, 108 kB/s
[root@bogon software]# ls -lh
-rw-r--r--   1 root root   64 Jan 10 22:05 mbr-bak.img
[root@bogon software]#

## 破坏/dev/sdb mbr 分区表
[root@bogon software]# dd if=/dev/zero of=/dev/sdb bs=1 count=64 seek=446
64+0 records in
64+0 records out
64 bytes copied, 0.000855001 s, 74.9 kB/s
[root@bogon software]#
## 破坏分区表前:
[root@bogon ~]# lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda           8:0    0   20G  0 disk
├─sda1        8:1    0    1G  0 part /boot
└─sda2        8:2    0   19G  0 part
  └─cl-root 253:0    0   19G  0 lvm  /
sdb           8:16   0    5G  0 disk
└─sdb1        8:17   0    5G  0 part
sr0          11:0    1  1.6G  0 rom

## 破坏分区表后:
[root@bogon software]# lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda           8:0    0   20G  0 disk
├─sda1        8:1    0    1G  0 part /boot
└─sda2        8:2    0   19G  0 part
  └─cl-root 253:0    0   19G  0 lvm  /
sdb           8:16   0    5G  0 disk
sr0          11:0    1  1.6G  0 rom

## 如果是根分区所在磁盘
#无法重新启动
[root@bogon software]#reboot

1.2修复/dev/sdb mbr分区表:

用光盘启动,进入rescue mode
先确保鼠标在VMware界面里
重启进入进度条时,按一次Esc键


image.png

image.png
image.png

image.png

使用备份的mbr 表恢复:


image.png

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

Level Description Min number of drives
RAID0 缺点:没有数据冗余。
优点:性能提升(写入和读取速度)
最小磁盘数: 2
RAID1 优点:容错和简单的数据恢复。提高了读取性能
缺点:可用容量较低。每兆字节的成本更高(达到所需容量所需的驱动器数量的两倍)
最小磁盘数: 2
RAID5 优点:容错和IO性能提升(低于RAID 0
缺点:由于奇偶校验开销导致服务器执行大量写操作,性能降低
最小磁盘数: 3
RAID6 优点:比RAID 5更高的冗余。提高了读取性能。
缺点:由于奇偶校验开销,服务器执行大量写操作会降低性能
最小磁盘数: 4
RAID10 优点:性能非常高。容错
缺点:可用容量较低/成本较高。有限的可扩展性
最小磁盘数: 4

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

## 热添加磁盘
[root@bogon ~]# ls /sys/class/scsi_host/ # 查看主机scsi 总线号
host0  host1  host2
[root@bogon ~]# lsblk 
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda           8:0    0   20G  0 disk
├─sda1        8:1    0    1G  0 part /boot
└─sda2        8:2    0   19G  0 part
  └─cl-root 253:0    0   19G  0 lvm  /
sdb           8:16   0    5G  0 disk
└─sdb1        8:17   0    5G  0 part
sr0          11:0    1  1.6G  0 rom
[root@bogon ~]#
[root@bogon ~]# echo "- - -" > /sys/class/scsi_host/host0/scan
[root@bogon ~]# echo "- - -" > /sys/class/scsi_host/host1/scan
[root@bogon ~]# echo "- - -" > /sys/class/scsi_host/host2/scan
[root@bogon ~]# lsblk            ## 成功热添加 sdc
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda           8:0    0   20G  0 disk
├─sda1        8:1    0    1G  0 part /boot
└─sda2        8:2    0   19G  0 part
  └─cl-root 253:0    0   19G  0 lvm  /
sdb           8:16   0    5G  0 disk
└─sdb1        8:17   0    5G  0 part
sdc           8:32   0    2G  0 disk
sr0          11:0    1  1.6G  0 rom
[root@bogon ~]#

[root@bogon ~]# fdisk /dev/sdc

Welcome to fdisk (util-linux 2.32.1).
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.
Created a new DOS disklabel with disk identifier 0xa00230c2.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p):

Using default response p.
Partition number (1-4, default 1):
First sector (2048-10485759, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-10485759, default 10485759): +2G

Created a new partition 1 of type 'Linux' and of size 2 GiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

[root@bogon ~]# mkfs.ext4 -t ext4 -b 2048 -L TEST -m 1  /dev/sdc1  ##格式化
mke2fs 1.45.6 (20-Mar-2020)
Creating filesystem with 1048576 2k blocks and 131072 inodes
Filesystem UUID: d4822e63-ea0f-4e37-9d9c-2bd7ed120980
Superblock backups stored on blocks:
        16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816

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

[root@bogon ~]# blkid /dev/sdb1
/dev/sdb1: UUID="ce994dfa-b43a-41ef-a867-de489f359f14" TYPE="ext4" PARTUUID="440d52d3-01"
[root@bogon ~]#
[root@bogon /]# cat /etc/fstab |grep acl
UUID=0e342325-5312-444f-ad7a-6f6237bfac47 /test ext4    acl             0 0
[root@bogon /]#
[root@bogon /]# dumpe2fs -h /dev/sdc1
dumpe2fs 1.45.6 (20-Mar-2020)
Filesystem volume name:   TEST
Last mounted on:          
Filesystem UUID:          d4822e63-ea0f-4e37-9d9c-2bd7ed120980
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype extent 64bit flex_bg sparse_super large_file huge_file dir_nlink extra_isize metadata_csum
Filesystem flags:         signed_directory_hash
Default mount options:    user_xattr acl
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              131072
Block count:              1048576
Reserved block count:     10485
Free blocks:              1011035
Free inodes:              131061
First block:              0
Block size:               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:       Mon Jan 11 00:13:41 2021
Last mount time:          n/a
Last write time:          Mon Jan 11 00:13:41 2021
Mount count:              0
Maximum mount count:      -1
Last checked:             Mon Jan 11 00:13:41 2021
Check interval:           0 ()
Lifetime writes:          1058 kB
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:               256
Required extra isize:     32
Desired extra isize:      32
Journal inode:            8
Default directory hash:   half_md4
Directory Hash Seed:      03893215-8699-427e-9856-8ccb079b3099
Journal backup:           inode blocks
Checksum type:            crc32c
Checksum:                 0x1c68f744
Journal features:         (none)
Journal size:             32M
Journal length:           16384
Journal sequence:         0x00000001
Journal start:            0

[root@bogon /]#

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

[root@bogon ~]# vgcreate -s 16m testvg /dev/sdb1 /dev/sdc1 ## 创建VG
WARNING: ext4 signature detected on /dev/sdb1 at offset 1080. Wipe it? [y/n]: y
  Wiping ext4 signature on /dev/sdb1.
WARNING: ext4 signature detected on /dev/sdc1 at offset 1080. Wipe it? [y/n]: y
  Wiping ext4 signature on /dev/sdc1.
  Physical volume "/dev/sdb1" successfully created.
  Physical volume "/dev/sdc1" successfully created.
  Volume group "testvg" successfully created
[root@bogon ~]# 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               <6.97 GiB
  PE Size               16.00 MiB
  Total PE              446
  Alloc PE / Size       0 / 0
  Free  PE / Size       446 / <6.97 GiB
  VG UUID               U8E23g-ljdX-X1Ga-aDkd-7ouo-wby9-Rg424D
[root@bogon ~]# lvcreate -L 5G -n testlv testvg  ## 创建lv
  Logical volume "testlv" created.
[root@bogon ~]# mkfs.ext4 /dev/testvg/testlv   ##格式化lv 为ext4格式
mke2fs 1.45.6 (20-Mar-2020)
Creating filesystem with 1310720 4k blocks and 327680 inodes
Filesystem UUID: 76031543-4f71-4730-a8f1-88494b6aa290
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@bogon ~]# mkdir /users
[root@bogon ~]# mount /dev/testvg/testlv  /users    ## 挂载lv 到文件夹

[root@bogon ~]# lsblk
NAME              MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                 8:0    0   20G  0 disk
├─sda1              8:1    0    1G  0 part /boot
└─sda2              8:2    0   19G  0 part
  └─cl-root       253:0    0   19G  0 lvm  /
sdb                 8:16   0    5G  0 disk
└─sdb1              8:17   0    5G  0 part
  └─testvg-testlv 253:1    0    5G  0 lvm  /users
sdc                 8:32   0    5G  0 disk
└─sdc1              8:33   0    2G  0 part
  └─testvg-testlv 253:1    0    5G  0 lvm  /users
sr0                11:0    1  1.6G  0 rom
[root@bogon ~]#

你可能感兴趣的:(第七周作业)