zoukankan      html  css  js  c++  java
  • 第七周作业

    1、破坏mbr表并修复

    备份MBR分区表

    [root@centos8 ~]#dd if=/dev/sda of=/data/dpt.img bs=1 count=64 skip=446
    [root@centos8 ~]#scp /data/dpt.img 10.0.0.102:
    

    破坏MBR分区表

    [root@centos8 ~]#dd if=/dev/zero of=/dev/sda bs=1 count=64 seek=446(把分区表都写成0)
    

    重启后无法启动系统

    [root@centos8 ~]#reboot
    

    用光盘启动,进入rescue mode,选第3项skip to shell
    配置网络

    #ifconfig ens160 10.0.0.8/24
    #ip a a 10.0.0.8/24 dev/ens160
    #scp 10.0.0.102:/root/dpt.img .
    

    恢复MBR分区表

    #dd if=dpt.img of=/dev/sda bs=1 seek=446
    #exit
    

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

    级别:多块磁盘组织在一起的工作方式有所不同
    RAID-0:条带卷,strip,无容错能力,最少2块磁盘,读写性能提升
    RAID-1:镜像卷,mirror,1/2空间,读性能提升,写性能略下降,最少2块磁盘
    RAID-4:多块数据盘异或运算值存于专用校验盘,磁盘利用率 n-1/n,有冗余,至少3块磁盘
    raid5 磁盘利用率 n-1/n 最少3块磁盘
    raid6 磁盘利用率 n-2/n 最少4块磁盘
    raid7 可以理解为一个独立存储计算机,自身带有操作系统和管理工具,可以独立运行,理论上性能最高的
    raid10 磁盘利用率 1/2,先两两组合成raid1,再把这2组raid1组成raid0,最少4块磁盘,每组镜像最多坏1个磁盘,系统失败的几率是1/3
    raid01 磁盘利用率 1/2,先两两组合成raid0,再把这2组raid0组成raid1,最少4块磁盘,系统失败几率是2/3.
    raid50 先做成raid5,再做成raid0
    JBOD:单纯的把几个硬盘组合成一个逻辑的大硬盘,没有其他作用。

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

    [root@centos8 ~]# fdisk -l /dev/sdb  #从/dev/sdb创建一个文件系统
    [root@centos7 ~]# mke2fs -t ext4 -b 2048 -L 'TEST' -m 1 /dev/sdb1  #创建卷标为TEST格式为ext4的预留1%可用空间的文件系统
    [root@centos7 ~]# blkid #查看新创建的文件系统的UUID
    [root@centos7 ~]# vim /etc/fstab   #写入fatab文件
    

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

    查看当期那硬盘信息

    [19:39:49 root@etcd3 ~]#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    4G  0 part 
    └─sda3   8:3    0  195G  0 part /
    sdb      8:16   0   20G  0 disk 
    sdc      8:32   0   20G  0 disk 
    sr0     11:0    1  7.7G  0 rom  
    

    开始编辑/devsdb,创建1个10G的分区

    [19:39:53 root@etcd3 ~]#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 0x1a14949a.
    
    Command (m for help): n
    Partition type
       p   primary (0 primary, 0 extended, 4 free)
       e   extended (container for logical partitions)
    Select (default p): p
    Partition number (1-4, default 1): 
    First sector (2048-41943039, default 2048): 
    Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039): +10G
    
    Created a new partition 1 of type 'Linux' and of size 10 GiB.
    
    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/sdb: 20 GiB, 21474836480 bytes, 41943040 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
    Disklabel type: dos
    Disk identifier: 0x1a14949a
    
    Device     Boot Start      End  Sectors Size Id Type
    /dev/sdb1        2048 20973567 20971520  10G 8e Linux LVM
    
    Command (m for help): w
    The partition table has been altered.
    Calling ioctl() to re-read partition table.
    Syncing disks.
    

    在/dev/sdc创建一个10G的分区

    [19:41:10 root@etcd3 ~]#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 0xbfcf6ce6.
    
    Command (m for help): n
    Partition type
       p   primary (0 primary, 0 extended, 4 free)
       e   extended (container for logical partitions)
    Select (default p): p
    Partition number (1-4, default 1): 
    First sector (2048-41943039, default 2048): 
    Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039): +10G
    
    Created a new partition 1 of type 'Linux' and of size 10 GiB.
    
    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: 20 GiB, 21474836480 bytes, 41943040 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
    Disklabel type: dos
    Disk identifier: 0xbfcf6ce6
    
    Device     Boot Start      End  Sectors Size Id Type
    /dev/sdc1        2048 20973567 20971520  10G 8e Linux LVM
    
    Command (m for help): w
    The partition table has been altered.
    Calling ioctl() to re-read partition table.
    Syncing disks.
    

    创建完成后继续查看分区信息

    [19:43:07 root@etcd3 ~]#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    4G  0 part 
    └─sda3   8:3    0  195G  0 part /
    sdb      8:16   0   20G  0 disk 
    └─sdb1   8:17   0   10G  0 part 
    sdc      8:32   0   20G  0 disk 
    └─sdc1   8:33   0   10G  0 part 
    sr0     11:0    1  7.7G  0 rom  
    

    在/dev/sdb1和/dev/sdc1上创建物理卷

    [19:43:25 root@etcd3 ~]#pvcreate /dev/sdb1
      Physical volume "/dev/sdb1" successfully created.
    [19:46:13 root@etcd3 ~]#pvcreate /dev/sdc1
      Physical volume "/dev/sdc1" successfully created.
    

    创建物理卷组,将上面的物理卷加入其中

    [19:46:17 root@etcd3 ~]#vgcreate -s 16M testvg /dev/sdb1 /dev/sdc1
      Volume group "testvg" successfully created
    [19:47:35 root@etcd3 ~]#vgs
      VG     #PV #LV #SN Attr   VSize   VFree  
      testvg   2   0   0 wz--n- <19.97g <19.97g
    

    在testvgz中创建大小为5G的逻辑卷

    [19:47:38 root@etcd3 ~]#lvcreate -n testlv -L 5G testvg
      Logical volume "testlv" created.
    [19:49:01 root@etcd3 ~]#lvs
      LV     VG     Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
      testlv testvg -wi-a----- 5.00g    
    

    创建文件系统

    [19:49:06 root@etcd3 ~]#mkfs.ext4 /dev/testvg/testlv 
    mke2fs 1.45.4 (23-Sep-2019)
    Creating filesystem with 1310720 4k blocks and 327680 inodes
    Filesystem UUID: a85dca48-8dc0-474e-81c9-dbe1d2476833
    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 
    

    查看新创建的逻辑卷的UUID

    [19:49:44 root@etcd3 ~]#blkid
    /dev/sda1: UUID="d748f17d-7af2-4187-a919-bcbdfc3267e3" TYPE="ext4" PARTUUID="67bc259b-01"
    /dev/sda2: UUID="5847e7d9-47ab-4d4a-8179-ffd024a2fa99" TYPE="swap" PARTUUID="67bc259b-02"
    /dev/sda3: UUID="642d007c-6670-4c6f-828f-054866c78a31" TYPE="xfs" PARTUUID="67bc259b-03"
    /dev/sr0: UUID="2020-06-08-22-08-25-00" LABEL="CentOS-8-2-2004-x86_64-dvd" TYPE="iso9660" PTUUID="545ce9a4" PTTYPE="dos"
    /dev/sdb1: UUID="zh2ivK-RPfl-7Zpe-tfvb-bVYa-ddcw-k3UHYf" TYPE="LVM2_member" PARTUUID="1a14949a-01"
    /dev/sdc1: UUID="Pfzulg-sKJr-FvKn-7ePE-ur0W-l25R-c7vnaM" TYPE="LVM2_member" PARTUUID="bfcf6ce6-01"
    /dev/mapper/testvg-testlv: UUID="a85dca48-8dc0-474e-81c9-dbe1d2476833" TYPE="ext4"
    

    创建users目录

    [19:51:58 root@etcd3 ~]#mkdir /users
    在/etc/fatab配置文件中添加UUID
    [19:52:28 root@etcd3 ~]#vim /etc/fstab 
    UUID=642d007c-6670-4c6f-828f-054866c78a31 /                       xfs     defaults        0 0
    UUID=d748f17d-7af2-4187-a919-bcbdfc3267e3 /boot                   ext4    defaults        1 2
    UUID=5847e7d9-47ab-4d4a-8179-ffd024a2fa99 swap                    swap    defaults        0 0
    UUID=a85dca48-8dc0-474e-81c9-dbe1d2476833 /users                  ext4     defaults        0  0           
    

    挂载

    [19:55:23 root@etcd3 ~]#mount -a
    

    查看

     [19:55:27 root@etcd3 ~]#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    4G  0 part 
    └─sda3              8:3    0  195G  0 part /
    sdb                 8:16   0   20G  0 disk 
    └─sdb1              8:17   0   10G  0 part 
      └─testvg-testlv 253:0    0    5G  0 lvm  /users
    sdc                 8:32   0   20G  0 disk 
    └─sdc1              8:33   0   10G  0 part 
    sr0                11:0    1  7.7G  0 rom  
    [19:55:32 root@etcd3 ~]#df -h
    Filesystem                 Size  Used Avail Use% Mounted on
    devtmpfs                   460M     0  460M   0% /dev
    tmpfs                      477M     0  477M   0% /dev/shm
    tmpfs                      477M  6.7M  470M   2% /run
    tmpfs                      477M     0  477M   0% /sys/fs/cgroup
    /dev/sda3                  195G  2.8G  193G   2% /
    /dev/sda1                  976M  118M  792M  13% /boot
    tmpfs                       96M     0   96M   0% /run/user/0
    /dev/mapper/testvg-testlv  4.9G   20M  4.6G   1% /users
    
  • 相关阅读:
    内联函数和宏
    python面向对象高级:@property
    python面向对象高级:__slots__
    Python哈希表的例子:dict、set
    python数据结构之哈希表
    python数据结构之队列
    python数据结构之堆栈
    python数据结构之链表
    分治法及其python实现例子
    查找算法:二分法查找及其python实现案例
  • 原文地址:https://www.cnblogs.com/qiaokaixin/p/14579042.html
Copyright © 2011-2022 走看看