第20天作业
作业:
1.完成思维导图,注意!一定是要在理解的基础上做,而不是单纯的复制粘贴。
2.笔记里的分区实验全部练习一遍以上。
3.完成练习题

练习题:
1.机械硬盘和固态硬盘都怕啥

机械硬盘怕震动

固态硬盘怕突然断电

2.请描述以下设备表示的意思
/dev/sda 第一块硬盘
/dev/sda1 第一块硬盘第一个分区
/dev/sdb2 第二块硬盘第二分区
/dev/sdc3 第三块硬盘第三个分区
/dev/sdd 第四块硬盘
3.请描述MBR分区和GPT分区的区别

MBR分区最多只能新建4个主分区

逻辑分区必须在拓展分区下

GPT可以新建128分区

拓展分区和逻辑分区

4.新增加一块10G大小的磁盘,创建MBR分区类型,3个主分区,2个逻辑分区,主分区每个1G大小,逻辑分区一个2G大小,最后一个使用所有空间。

[root@centos7-100 ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   40G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   39G  0 part 
  ├─centos-root 253:0    0   37G  0 lvm  /
  └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
sdb               8:16   0   10G  0 disk 
├─sdb1            8:17   0    1G  0 part 
├─sdb2            8:18   0    1G  0 part 
├─sdb3            8:19   0    1G  0 part 
├─sdb4            8:20   0    1K  0 part 
├─sdb5            8:21   0    2G  0 part 
└─sdb6            8:22   0    5G  0 part 
sr0              11:0    1  4.5G  0 rom  
[root@centos7-100 ~]# fdisk -l /dev/sdb

磁盘 /dev/sdb:10.7 GB, 10737418240 字节,20971520 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0xbba70158

   设备 Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     2099199     1048576   83  Linux
/dev/sdb2         2099200     4196351     1048576   83  Linux
/dev/sdb3         4196352     6293503     1048576   83  Linux
/dev/sdb4         6293504    20971519     7339008    5  Extended
/dev/sdb5         6295552    10489855     2097152   83  Linux
/dev/sdb6        10491904    20971519     5239808   83  Linux
[root@centos7-100 ~]# 

最后一个是5G

5.删除刚才创建的MBR分区,创建GPT分区类型,创建三个分区,前两个分区使用1G大小,最后一个分区使用所有空间。

[root@centos7-100 ~]# gdisk -l /dev/sdb
GPT fdisk (gdisk) version 0.8.10

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.
Disk /dev/sdb: 20971520 sectors, 10.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 882ED297-F140-46D8-98D1-21E2991231FC
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 20971486
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048         2099199   1024.0 MiB  8300  Linux filesystem
   2         2099200         4196351   1024.0 MiB  8300  Linux filesystem
   3         4196352        20971486   8.0 GiB     8300  Linux filesystem

[root@centos7-100 ~]# blkid
/dev/sda1: UUID="28a58b70-76c6-4a21-b99b-a51da96040d0" TYPE="xfs" 
/dev/sda2: UUID="DKpBKF-m84h-seOs-b6F1-c6uM-N7hU-Jh2Dxb" TYPE="LVM2_member" 
/dev/sr0: UUID="2020-04-22-00-54-00-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos" 
/dev/mapper/centos-root: UUID="05924dd2-f8c9-48d1-a49b-88aeae6f7edf" TYPE="xfs" 
/dev/mapper/centos-swap: UUID="9408f906-1ce9-494a-9774-a6f827d52b85" TYPE="swap" 
/dev/sdb1: PARTLABEL="Linux filesystem" PARTUUID="cdce1d17-72dd-4421-a823-fdd896c4301e" 
/dev/sdb2: PARTLABEL="Linux filesystem" PARTUUID="5e3ad103-aaae-4586-aeb3-f6554ea60a3d" 
/dev/sdb3: PARTLABEL="Linux filesystem" PARTUUID="fd6641c9-3d9c-4251-9e83-f954b9b2ad00" 

[root@centos7-100 ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   40G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   39G  0 part 
  ├─centos-root 253:0    0   37G  0 lvm  /
  └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
sdb               8:16   0   10G  0 disk 
├─sdb1            8:17   0    1G  0 part 
├─sdb2            8:18   0    1G  0 part 
└─sdb3            8:19   0    8G  0 part 
sr0              11:0    1  4.5G  0 rom  
[root@centos7-100 ~]# 

6.删除刚才创建的GPT分区,使用parted交互式和免交互式分别创建2个分区的文件系统

[root@centos7-100 ~]# parted /dev/sdb
GNU Parted 3.1
使用 /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p                                                                
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start  End  Size  File system  Name  标志

(parted) rm 1
错误: 分区不存在。
(parted) mkpart
分区名称?  []? 1                                                         
文件系统类型?  [ext2]? xfs                                               
起始点? 0                                                                
结束点? 1000                                                             
警告: The resulting partition is not properly aligned for best performance.
忽略/Ignore/放弃/Cancel? Ignore                                           
(parted) p                                                                
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name  标志
 1      17.4kB  1000MB  1000MB               1

(parted) mkpart                                                           
分区名称?  []? 2                                                         
文件系统类型?  [ext2]? xfs                                               
起始点? 1000                                                             
结束点? -1                                                               
(parted) p                                                                
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name  标志
 1      17.4kB  1000MB  1000MB               1
 2      1000MB  10.7GB  9736MB               2

(parted) q                                                                
信息: You may need to update /etc/fstab.

[root@centos7-100 ~]# parted /dev/sdb p                                   
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name  标志
 1      17.4kB  1000MB  1000MB               1
 2      1000MB  10.7GB  9736MB               2

[root@centos7-100 ~]# parted /dev/sdb rm 1
信息: You may need to update /etc/fstab.

[root@centos7-100 ~]# parted /dev/sdb p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name  标志
 2      1000MB  10.7GB  9736MB               2

[root@centos7-100 ~]# parted /dev/sdb rm 2
信息: You may need to update /etc/fstab.

[root@centos7-100 ~]# parted /dev/sdb p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start  End  Size  File system  Name  标志

[root@centos7-100 ~]# parted /dev/sdb mklabel gpt 
警告: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue?
是/Yes/否/No? yes                                                         
信息: You may need to update /etc/fstab.

[root@centos7-100 ~]# parted /dev/sdb p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start  End  Size  File system  Name  标志

[root@centos7-100 ~]# parted /dev/sdb mklabel xfs
parted: invalid token: xfs
新的磁盘标签类型? xfs
parted: invalid token: xfs
新的磁盘标签类型? y                                                      
parted: invalid token: y
新的磁盘标签类型?                                                        
新的磁盘标签类型? 1                                                      
parted: invalid token: 1
新的磁盘标签类型? q                                                      
parted: invalid token: q
新的磁盘标签类型? ^C                                                     
错误: 需要磁盘标签类型。
[root@centos7-100 ~]# parted /dev/sdb mklabel mklabel 1 0 10GB
parted: invalid token: mklabel
新的磁盘标签类型? ^C                                                     
错误: 需要磁盘标签类型。
[root@centos7-100 ~]# parted /dev/sdb mklabel  1 0 10GB            
parted: invalid token: 1
新的磁盘标签类型? ^C                                                     
错误: 需要磁盘标签类型。
[root@centos7-100 ~]# parted /dev/sdb mkpart 1  0 10GB                   
警告: The resulting partition is not properly aligned for best performance.
忽略/Ignore/放弃/Cancel? Ignore
信息: You may need to update /etc/fstab.

[root@centos7-100 ~]# parted /dev/sdb p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size     File system  Name  标志
 1      17.4kB  10.0GB  10000MB               1


7.请描述Windows和Linux下常见的文件系统

windows常见文件系统 fat32,ntfs

Linux常见文件系统xfs,ext4

8.删除刚才创建的分区,直接创建xfs文件系统使用整块磁盘

[root@centos7-100 ~]# mkfs.xfs /dev/sdb -f
meta-data=/dev/sdb               isize=512    agcount=4, agsize=655360 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=2621440, 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
[root@centos7-100 ~]# fdisk -l /dev/sdb

磁盘 /dev/sdb:10.7 GB, 10737418240 字节,20971520 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节

[root@centos7-100 ~]# blkid /dev/sdb
/dev/sdb: UUID="43e01880-9142-40c0-85bf-cad866a80029" TYPE="xfs" 
[root@centos7-100 ~]# 

查看挂载情况

[root@centos7-100 ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   40G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   39G  0 part 
  ├─centos-root 253:0    0   37G  0 lvm  /
  └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
sdb               8:16   0   10G  0 disk 
sr0              11:0    1  4.5G  0 rom  
[root@centos7-100 ~]# df -h 
文件系统                 容量  已用  可用 已用% 挂载点
devtmpfs                 475M     0  475M    0% /dev
tmpfs                    487M     0  487M    0% /dev/shm
tmpfs                    487M  7.7M  479M    2% /run
tmpfs                    487M     0  487M    0% /sys/fs/cgroup
/dev/mapper/centos-root   37G  2.5G   35G    7% /
/dev/sda1               1014M  147M  868M   15% /boot
tmpfs                     98M     0   98M    0% /run/user/0
[root@centos7-100 ~]# 

/dev/sdb 挂载到/data1并查看系统挂载情况

[root@centos7-100 ~]# mount /dev/sdb /data1
[root@centos7-100 ~]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
devtmpfs                 475M     0  475M    0% /dev
tmpfs                    487M     0  487M    0% /dev/shm
tmpfs                    487M  7.7M  479M    2% /run
tmpfs                    487M     0  487M    0% /sys/fs/cgroup
/dev/mapper/centos-root   37G  2.5G   35G    7% /
/dev/sda1               1014M  147M  868M   15% /boot
tmpfs                     98M     0   98M    0% /run/user/0
/dev/sdb                  10G   33M   10G    1% /data1
[root@centos7-100 ~]# 

9.将刚才格式化的文件系统挂载到/data目录下

取消/data1挂载,并查看挂载情况

[root@centos7-100 ~]# umount /data1
[root@centos7-100 ~]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
devtmpfs                 475M     0  475M    0% /dev
tmpfs                    487M     0  487M    0% /dev/shm
tmpfs                    487M  7.7M  479M    2% /run
tmpfs                    487M     0  487M    0% /sys/fs/cgroup
/dev/mapper/centos-root   37G  2.5G   35G    7% /
/dev/sda1               1014M  147M  868M   15% /boot
tmpfs                     98M     0   98M    0% /run/user/0
[root@centos7-100 ~]# 

挂载到/data目录下

[root@centos7-100 ~]# mount /dev/sdb /data
[root@centos7-100 ~]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
devtmpfs                 475M     0  475M    0% /dev
tmpfs                    487M     0  487M    0% /dev/shm
tmpfs                    487M  7.7M  479M    2% /run
tmpfs                    487M     0  487M    0% /sys/fs/cgroup
/dev/mapper/centos-root   37G  2.5G   35G    7% /
/dev/sda1               1014M  147M  868M   15% /boot
tmpfs                     98M     0   98M    0% /run/user/0
/dev/sdb                  10G   33M   10G    1% /data

10.实现开机自动挂载/data分区

查看/dev/sdb blkid信息

[root@centos7-100 ~]# blkid
/dev/sda1: UUID="28a58b70-76c6-4a21-b99b-a51da96040d0" TYPE="xfs" 
/dev/sda2: UUID="DKpBKF-m84h-seOs-b6F1-c6uM-N7hU-Jh2Dxb" TYPE="LVM2_member" 
/dev/sr0: UUID="2020-04-22-00-54-00-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos" 
/dev/mapper/centos-root: UUID="05924dd2-f8c9-48d1-a49b-88aeae6f7edf" TYPE="xfs" 
/dev/mapper/centos-swap: UUID="9408f906-1ce9-494a-9774-a6f827d52b85" TYPE="swap" 
/dev/sdb: UUID="43e01880-9142-40c0-85bf-cad866a80029" TYPE="xfs" 

复制/dev/sdb UUID 复制到vim /etc/fastab中加开机自启

[root@centos7-100 ~]# vim /etc/fstab 
[root@centos7-100 ~]# cat /etc/fstab 

#
# /etc/fstab
# Created by anaconda on Wed Sep 15 19:33:47 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-root /                       xfs     defaults        0 0
UUID=28a58b70-76c6-4a21-b99b-a51da96040d0 /boot                   xfs     defaults        0 0
/dev/mapper/centos-swap swap                    swap    defaults        0 0
UUID=d92f54b9-5c05-4558-8458-5969a4f53b68 /boot                   xfs     defaults        0 0
UUID=83979830-6227-41aa-8b0e-f5bec42a7b86 /boot                   xfs     defaults        0 0
UUID=43e01880-9142-40c0-85bf-cad866a80029 /data                   xfs     defaults        0 0
[root@centos7-100 ~]#