day 18 磁盘

磁盘的基本结构

盘片:
磁道: 负责存储数据
扇区: 512字节 数据是存储在哪个磁道哪个扇区
柱面:

磁盘的接口

IDE out

Scsi out

SATA III 6Gbps/s 750MB/s 1T 400 100MB/s

SAS 8Gbps/s 1000MB/s 1T 4500

SSD 纯电子 抗摔

m.2

接口类型

SATA 几乎所有主板都兼容, 便宜 性能差
PCI-E 需要看主板是否兼容, 贵, 性能高

传输通道

PCI-E AHCI
NVMe

磁盘的名词

容量 MB GB TB PB EB .............
转速 SATA3 ==7200 SAS 15000 (非常之高) 磁盘阵列RAID
尺寸 3.5 2.5 1.8
IOPS Input/Output 输入输出

image.png
磁盘再硬盘上的命名方式

磁盘的命名规则 [a-z] aa-zz

image.png

磁盘基本分区fdisk

1.物理机添加硬盘 或虚拟机添加硬盘
image.png
列出指定外围设备的分区表状况

fdisk -l
显示主分区 扩展分区 逻辑分区

[root@zhaoshuang ~]#fdisk -l
Disk /dev/sda: 21.5 GB, 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
Disk label type: dos
Disk identifier: 0x000ae534
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      411647      204800   83  Linux
/dev/sda2          411648     4507647     2048000   82  Linux swap / Solaris
/dev/sda3         4507648    41943039    18717696   83  Linux

Disk /dev/sdb: 53.7 GB, 53687091200 bytes, 104857600 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: 0x5072bb0a

2.编辑挂载的硬盘/dev/sdb 进入分区模式

[root@zhaoshuang ~]#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.

Command (m for help): 
image.png
1. fdsi创建主分区

n 新建分区
p 主分区
e 扩展分区
分配大小50M

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):              #默认创建的第一个分区
First sector (2048-104857599, default 2048):    #默认扇区回车
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-104857599, default 104857599): +50M   #分配的大小 :50M
Partition 1 of type Linux and of size 50 MiB is set
2. fdsik 创建扩展分区
Command (m for help): n                               # 新建分区
Partition type:
   p   primary (1 primary, 0 extended, 3 free)        #创建主分区
   e   extended                                       #创建扩展分区
Select (default p): e                                #选择创建扩展分区
Partition number (2-4, default 2):                   #默认创建的第二个分区
First sector (104448-104857599, default 104448):     #默认扇区回车 
Using default value 104448
Last sector, +sectors or +size{K,M,G} (104448-104857599, default 104857599):   #剩余空间都给了扩展分区 回车
Using default value 104857599
Partition 2 of type Extended and of size 50 GiB is set
3. fdisk 创建逻辑分区
Command (m for help): n                               # 新建分区
Partition type:
   p   primary (1 primary, 1 extended, 2 free)        #创建主分区
   l   logical (numbered from 5)                      #创建逻辑分区
Select (default p): l                                #选择创建逻辑分区
Adding logical partition 5
First sector (106496-104857599, default 106496):      #默认扇区回车 
Using default value 106496
Last sector, +sectors or +size{K,M,G} (106496-104857599, default 104857599): +100M  #分配大小:+50M
Partition 5 of type Linux and of size 100 MiB is set
4. fdsik 查看分区情况 并保存
Command (m for help): p                       #查看分区情况

Disk /dev/sdb: 53.7 GB, 53687091200 bytes, 104857600 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: 0x5072bb0a

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048      104447       51200   83  Linux
/dev/sdb2          104448   104857599    52376576    5  Extended
/dev/sdb5          106496      311295      102400   83  Linux

Command (m for help): w                           #保存并退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@zhaoshuang ~]#
检查分区方式,刷新内核立即生效

partprobe

#检查磁盘是否是MBR分区方式
[root@zhaoshuang ~]#fdisk /dev/sdb -l |grep type
Disk label type: dos
#如未安装parted,则安装parted,后刷新内核立即生效,无需重启
[root@zhaoshuang ~]#yum -y install parted
[root@zhaoshuang ~]#partprobe /dev/sdb
使用mkfs 对磁盘进行格式化

-f 强制格式化
强制格式化 : mkfs -t xfs /dev/sdb1

[root@zhaoshuang ~]#mkfs -t xfs  /dev/sdb1
meta-data=/dev/sdb1              isize=512    agcount=2, agsize=6400 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=12800, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=855, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
挂载硬盘
[root@zhaoshuang ~]#mount /dev/sdb1 /data/sdb1/
[root@zhaoshuang ~]#df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        18G  6.8G   12G  38% /
devtmpfs        476M     0  476M   0% /dev
tmpfs           487M     0  487M   0% /dev/shm
tmpfs           487M  7.6M  479M   2% /run
tmpfs           487M     0  487M   0% /sys/fs/cgroup
/dev/sda1       197M  105M   93M  54% /boot
tmpfs            98M     0   98M   0% /run/user/0
/dev/sdb1        47M  2.7M   45M   6% /data/sdb1
永久挂载

/dev/sdb1 /data/sdb1 xfs defaults 0 0
/dev/sdb5 /data/sdb5 xfs defaults 0 0

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

# /etc/fstab
# Created by anaconda on Mon Jun 10 21:22:24 2019
# 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
UUID=1b609b66-5a99-4c6b-8798-2eb5a7a27338 /boot                   xfs     defaults        0 0
UUID=73ee8622-75e1-478c-aee0-d377ef9e4a15 swap                    swap    defaults        0 0
/dev/sdb1    /data/sdb1                    xfs defaults      0 0
/dev/sdb5    /data/sdb5                    xfs defaults      0 0

你可能感兴趣的:(day 18 磁盘)