CSA复习11

一.1.
系统中添加一块硬盘,虚拟机处于关闭状态
CSA复习11
2.如何识别系统中的设备

/dev/vdb:

v表示虚拟,virtual

[root@server8 ~]# df

df查看挂载情况

[root@server8 ~]# df -h 2的n次方
[root@server8 ~]# df -H 10的n次方

显示单位,h和H计算方式不同

[root@server8 ~]# lsblk 

查看设备使用情况

[root@server8 ~]# blkid 
/dev/vda1: UUID="658e2a5d-acb6-45e5-ba91-a974e37a6c68" TYPE="xfs" PARTUUID="6c106e59-01"
/dev/vda2: UUID="4ZojnM-GEf8-cYun-5Kf8-ZPbV-dtrY-nLEth0" TYPE="LVM2_member" PARTUUID="6c106e59-02"
/dev/mapper/rhel-root: UUID="77027b45-bfe1-48fe-9d6b-840c2b506266" TYPE="xfs"
/dev/mapper/rhel-swap: UUID="a0e0133b-52a3-4773-8d5f-e1c140b30408" TYPE="swap"

查看系统设备的ID

[root@server8 ~]# cat /proc/partitions 
major minor  #blocks  name

 252        0   15728640 vda
 252        1    1048576 vda1
 252        2   14679040 vda2
 252       16    5242880 vdb
 253        0   13103104 dm-0
 253        1    1572864 dm-1

查看系统识别设备

[root@server8 ~]# fdisk -l
Disk /dev/vda: 15 GiB, 16106127360 bytes, 31457280 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: 0x6c106e59

Device     Boot   Start      End  Sectors Size Id Type
/dev/vda1  *       2048  2099199  2097152   1G 83 Linux
/dev/vda2       2099200 31457279 29358080  14G 8e Linux LVM


Disk /dev/vdb: 5 GiB, 5368709120 bytes, 10485760 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 /dev/mapper/rhel-root: 12.5 GiB, 13417578496 bytes, 26206208 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 /dev/mapper/rhel-swap: 1.5 GiB, 1610612736 bytes, 3145728 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

查看真实的设备情况用此命令
3.设备的挂载

umount
mount

卸载和挂载
当处于挂载点时,不可以卸载,因为设备正忙

[root@server8 ~]# fuser -vm /mnt/

查看设备上运行的程序

[root@server8 ~]# fuser -kvm /mnt/

此命令可以结束设备上绝大多数程序

[root@server8 ~]# mount -o ro /dev/vda1 /mnt/

只读挂载
直接在shell中输入mount就可以看到所有的挂载信息

[root@server8 ~]# mount -o remount,rw /mnt

重新挂载mnt目录的设备并可以读写

4.磁盘分区
MBR
主分区和扩展分区,扩展分区包含逻辑分区
GPT,有一个efi分区,剩下的都是efi管理的分区,没有主分区,所有分区都可以是主分区

[root@server8 ~]# fdisk /dev/vdb

进入磁盘
CSA复习11按m
CSA复习11默认是DOS
CSA复习11
也可以调整成GPT类型

CSA复习11
n新建,p主分区,e拓展分区
当出现四个主分区时,即使磁盘还有容量也要将一个主分区调整成为子分区

CSA复习11删除分区用d
会提示删除第几个分区
GPT分区:

Command (m for help): g
Created a new GPT disklabel (GUID: 6E35D32B-9265-DA4B-BCF9-6EBEA47F45EE).

Command (m for help): p
Disk /dev/vdb: 5 GiB, 5368709120 bytes, 10485760 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: gpt
Disk identifier: 6E35D32B-9265-DA4B-BCF9-6EBEA47F45EE
Command (m for help): n    
Partition number (2-128, default 2): 
First sector (206848-10485726, default 206848): 
Last sector, +sectors or +size{K,M,G,T,P} (206848-10485726, default 10485726): +100M

Created a new partition 2 of type 'Linux filesystem' and of size 100 MiB.

Command (m for help): p
Disk /dev/vdb: 5 GiB, 5368709120 bytes, 10485760 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: gpt
Disk identifier: 6E35D32B-9265-DA4B-BCF9-6EBEA47F45EE

Device      Start    End Sectors  Size Type
/dev/vdb1    2048 206847  204800  100M Linux filesystem
/dev/vdb2  206848 411647  204800  100M Linux filesystem
[root@server8 ~]# udevadm settle 

同步分区表到系统
CSA复习11可以看到划分的分区已经产生,如果不想要了怎么做?

[root@server8 ~]# fdisk /dev/vdb

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.


Command (m for help): d
Partition number (1,2, default 2): 1

Partition 1 has been deleted.

Command (m for help): d
Selected partition 2
Partition 2 has been deleted.

当删除设备时一定确保设备在系统中未被使用

[root@server8 ~]# dd if=/dev/zero of=/dev/vdb bs=1M count=1
1+0 records in
1+0 records out
1048576 bytes (1.0 MB, 1.0 MiB) copied, 0.00212607 s, 493 MB/s

完整的清理分区
如何用命令建立分区?

[root@server8 ~]# parted /dev/vdb mklabel msdos
Information: You may need to update /etc/fstab.

命令建立一个dos分区

[root@server8 ~]# parted /dev/vdb mklabel gpt
Warning: The existing disk label on /dev/vdb will be destroyed and all data on
this disk will be lost. Do you want to continue?
Yes/No? yes                                                               
Information: You may need to update /etc/fstab.
[root@server8 ~]# parted /dev/vdb mkpart primary 1 100
[root@server8 ~]# parted /dev/vdb mkpart primary 101 200

开始划分分区的方式就是这样,后一个不能根前一个数字重合
,下一个就是201-300
删除怎么删除?

[root@server8 ~]# parted /dev/vdb rm 2
Information: You may need to update /etc/fstab.

[root@server8 ~]# parted /dev/vdb rm 1
Information: You may need to update /etc/fstab.

删除分区
这是非交互式使用命令来删除分区
5.格式化设备并且自动挂载及fstab文件处理
新设备不能挂载,需要格式化

[root@server8 ~]# mount /dev/vdb1 /mnt/
mount: /mnt: wrong fs type, bad option, bad superblock on /dev/vdb1, missing codepage or helper program, or other error.

如何格式化?

[root@server8 ~]# mkfs.xfs /dev/vdb1
meta-data=/dev/vdb1              isize=512    agcount=4, agsize=6400 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1
data     =                       bsize=4096   blocks=25600, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=1368, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

如果原本设备有数据,在最后加参数-f强制格式化

[root@server8 ~]# mount /dev/vdb1 /mnt/
[root@server8 ~]# df
Filesystem            1K-blocks    Used Available Use% Mounted on
devtmpfs                 906112       0    906112   0% /dev
tmpfs                    935136       0    935136   0% /dev/shm
tmpfs                    935136   17612    917524   2% /run
tmpfs                    935136       0    935136   0% /sys/fs/cgroup
/dev/mapper/rhel-root  13092864 4825336   8267528  37% /
/dev/vda1               1038336  233980    804356  23% /boot
tmpfs                    187024    1180    185844   1% /run/user/42
tmpfs                    187024       4    187020   1% /run/user/0
/dev/vdb1                 96928    6068     90860   7% /mnt
/dev/vdb1: UUID="2a86168c-345d-412f-984b-5333dcd3c2b2" TYPE="xfs" PARTUUID="fd00c604-01"

此时设备id也有了
这是临时挂载,当重启系统以后就没有了,如何永久挂载?

[root@server8 ~]# vim /etc/fstab 

CSA复习11设备 挂载点 文件系统类型 挂载参数 是否备份 是否检测

[root@server8 ~]# mount -a

让刚才执行的生效
重启测试一下,df

/dev/vdb1                 96928    6068     90860   7% /mnt

开机自动挂载了
如果不理解各个参数,输入man 5 fstab
当文件内容书写有问题,会导致系统启动失败,一定要注意

上一篇:什么时候用mini_batch或者batch梯度下降法


下一篇:linux直接IO代码演示