第七周作业

如题所述

第1个回答  2022-06-17
1、破坏mbr表并修复
#备份MBR分区表
[root@centos8 ~]#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.000147747 s, 433 kB/s
[root@centos8 ~]#scp /data/dpt.img 10.0.0.102:/data/
The authenticity of host '10.0.0.101 (10.0.0.101)' can't be established.
ECDSA key fingerprint is SHA256:tLe8oiREqQLendzAnl1I3ydeXtXXSYaWogXpP8pfifI.
ECDSA key fingerprint is MD5:9b:12:ea:fa:0d:6f:79:b8:ef:77:b8:74:51:91:c3:9a.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.0.0.101' (ECDSA) to the list of known hosts.
[email protected]'s password:
Permission denied, please try again.
[email protected]'s password:
dpt.img 100% 64 141.3KB/s 00:00
#破坏MBR分区表
[root@centos8 ~]#dd if=/dev/zero of=/dev/sda bs=1 count=64 seek=446
#无法启动
[root@centos8 ~]#reboot
#用光盘启动,进入rescue mode,选第3项skip to shell
#配置网络(注意本机的网卡名称)
#ifconfig ens33 10.0.0.8/24

#ip a a 10.0.0.8/24 dev/ens33
#复制备份的分区表
#scp 10.0.0.102:/root/dpt.img .
#恢复MBR分区表
#dd if=dpt.img of=/dev/sda bs=1 seek=446
#退出
#exit

2、总结RAID的各个级别及其组合方式和性能的不同
①RAID级别有:
RAID 0:读写性能提升,无容错能力
RAID 1:有容错能力,读写性能对比RAID 0略有不足
RAID 5:读写能力提升,有容错能力,允许最多一块磁盘损坏
RAID 6:读写能力提升,有容错能力,允许最多两块磁盘损坏

②RAID的组合方式和性能的不同
RAID 10:先保护磁盘资料(有容错能力),然后再增加磁盘的读写能力,每组磁盘只能坏一块
RAID 01:先增加磁盘的读写能力,后保护磁盘资料
RAID 50:先实现RAID 5(在同时提升读写能力和有容错能力的情况下),后组成RAID 0(再次提升读写的能力)

3、创建一个2G的文件系统,块大小为2048byte,预留1%的可用空间,文件系统 ext4,卷标TEST,要求此分区开机后自动挂载到/test目录,且默认又acl的挂载选项
①添加一个硬盘(这里为/dev/sdb)

②创建2G的分区
[root@centos7 ~]# 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 0x62a1ab10.
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): 1
First sector (2048-10485759, default 2048): 2048
Last sector, +sectors or +size{K,M,G} (2048-10485759, default 10485759): +2G
Partition 1 of type Linux and of size 2 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

③创建新分区的文件系统,,文件系统为,设置块大小为2048byte,预留1%的可用空间,卷标为TEST
[root@centos7 ~]# mkfs.ext4 /dev/sdb1 -L TEST -m 1 -b 2048
mke2fs 1.42.9 (28-Dec-2013)
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

④将新分区挂载到/etc/fstab中,使新分区可以开机自动挂载在/test目录下,且默认为acl选项
[root@centos7 ~]# mkdir /test
[root@centos7 ~]# blkid /dev/sdb1
/dev/sdb1: LABEL="TEST" UUID="904260ac-58bb-4a3e-8673-a29fb65e6d25" TYPE="ext4"
[root@centos7 ~]# vim /etc/fstab
(在后面添加这一行)
UUID=904260ac-58bb-4a3e-8673-a29fb65e6d25 /test ext4 acl 0 0
[root@centos7 ~]# mount -a

⑤结果验证
[root@centos7 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 100G 0 disk
├─sda1 8:1 0 200M 0 part /boot
├─sda2 8:2 0 1.5G 0 part [SWAP]
└─sda3 8:3 0 98.3G 0 part /
sdb 8:16 0 5G 0 disk
└─sdb1 8:17 0 2G 0 part /test
sr0 11:0 1 4.2G 0 rom

4、创建一个至少有两个PV组成的大小为20G的名为testvg的VG;要求PE大小为16M,而后在卷组中创建大小为5G的逻辑卷testlv;挂载至/users目录
①虚拟机添加2块10G的硬盘

②获取新添加的两个硬盘的信息
[root@centos7 ~]# echo "- - -" > /sys/class/scsi_host/host0/scan

[root@centos7 ~]# echo "- - -" > /sys/class/scsi_host/host1/scan

[root@centos7 ~]# echo "- - -" > /sys/class/scsi_host/host2/scan
[root@centos7 ~]# lsblk (sdd和sde为新加的硬盘)
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 100G 0 disk
├─sda1 8:1 0 200M 0 part /boot
├─sda2 8:2 0 1.5G 0 part [SWAP]
└─sda3 8:3 0 98.3G 0 part /
sdb 8:16 0 25G 0 disk
sdc 8:32 0 5G 0 disk
└─sdc1 8:33 0 2G 0 part /test
sdd 8:48 0 10G 0 disk
sde 8:64 0 10G 0 disk
sr0 11:0 1 4.2G 0 rom
③将两块新硬盘进行分区
[root@centos7 ~]# 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 0x1e65e9c2.

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): 1
First sector (2048-20971519, default 2048): 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519):
Using default value 20971519
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): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): p

Disk /dev/sdc: 10.7 GB, 10737418240 bytes, 20971520 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: 0x1e65e9c2

Device Boot Start End Blocks Id System
/dev/sdc1 2048 20971519 10484736 8e Linux LVM

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

[root@centos7 ~]# 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 0x8673f6e2.

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): 1
First sector (2048-20971519, default 2048): 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519):
Using default value 20971519
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): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): p

Disk /dev/sdd: 10.7 GB, 10737418240 bytes, 20971520 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: 0x8673f6e2

Device Boot Start End Blocks Id System
/dev/sdd1 2048 20971519 10484736 8e Linux LVM

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
注意:要修改为逻辑卷分区

④安装相关工具
[root@centos7 ~]# yum install -y lvm2

⑤创建物理卷
[root@centos7 ~]# pvcreate /dev/sdc1
Physical volume "/dev/sdc1" successfully created.
[root@centos7 ~]# pvcreate /dev/sdd1
Physical volume "/dev/sdd1" successfully created.
(查看物理卷)
[root@centos7 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdc1 lvm2 --- <10.00g <10.00g
/dev/sdd1 lvm2 --- <10.00g <10.00g

⑥创建卷组
[root@centos7 ~]# vgcreate -s 16M testvg /dev/sdc1 /dev/sdd1
Volume group "testvg" successfully created
[root@centos7 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
testvg 2 0 0 wz--n- <19.97g <19.97g

⑦创建逻辑卷
[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
testlv testvg -wi-a----- 5.00g

⑧创建文件系统
[root@centos7 ~]# mkfs.xfs /dev/testvg/testlv
meta-data=/dev/testvg/testlv isize=512 agcount=4, agsize=327680 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=1310720, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0

⑨挂载到/users目录
[root@centos7 ~]# mkdir /users
[root@centos7 ~]# mount /dev/testvg/testlv /users
[root@centos7 ~]# mount | grep users
/dev/mapper/testvg-testlv on /users type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
相似回答