Day18 磁盘管理 (一)

2019-08-19  本文已影响0人  梦幻新阳

1.磁盘的基本概念

      永久存储数据的存储器。

2.磁盘的基本结构

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

3.磁盘的预备知识

磁盘的接口
IDE      out
Scsi     out
SATA III    6Gbps/s    750MB/s    1T   400 100MB/s
SAS 8Gbps/s   1000MB/s   1T    4500
SSD    纯电子 抗摔
msata    out
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 输入输出
顺序读写
随机读写

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

8.192.png

5.磁盘基本分区Fdisk

磁盘基本分区步骤

1.添加磁盘
2.给磁盘分区 fdisk fdisk /dev/sdb
3.使用mkfs对磁盘进行格式化 mkfs -t xfs /dev/sdb6
4.挂载 mount mount /dev/sdb6 /data_6/
1.添加磁盘
8.193.png
1.添加磁盘
[root@kelongyi ~]# ll /dev/sd*
brw-rw----. 1 root disk 8,  0 Aug 19 14:03 /dev/sda
brw-rw----. 1 root disk 8,  1 Aug 19 14:03 /dev/sda1
brw-rw----. 1 root disk 8,  2 Aug 19 14:03 /dev/sda2
brw-rw----. 1 root disk 8,  3 Aug 19 14:03 /dev/sda3
brw-rw----. 1 root disk 8, 16 Aug 19 14:03 /dev/sdb
brw-rw----. 1 root disk 8, 32 Aug 19 14:03 /dev/sdc
                      
[root@kelongyi ~]# 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    1G  0 part [SWAP]
└─sda3   8:3    0   38G  0 part /
sdb      8:16   0    1T  0 disk 
sdc      8:32   0    4T  0 disk 
sr0     11:0    1  4.3G  0 rom 
2.给磁盘分区 fdisk fdisk /dev/sdb
[root@kelongyi ~]# 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    1G  0 part [SWAP]
└─sda3   8:3    0   38G  0 part /
sdb      8:16   0    1T  0 disk 
sdc      8:32   0    4T  0 disk 
sr0     11:0    1  4.3G  0 rom  

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

Command (m for help): m                    m进入命令帮助        
Command action
   a   toggle a bootable flag              切换可引导标志                
   b   edit bsd disklabel                  编辑BSD磁盘标签
   c   toggle the dos compatibility flag   切换DOS兼容性标志
   d   delete a partition                   删除分区
   g   create a new empty GPT partition table   创建新的空GPT分区表
   G   create an IRIX (SGI) partition table     创建IRIX(SGI)分区表
   l   list known partition types           列出已知分区类型
   m   print this menu                      打印这个菜单
   n   add a new partition                  添加新分区
   o   create a new empty DOS partition table  创建新的空DOS分区表
   p   print the partition table             打印分区表
   q   quit without saving changes           不保存更改就退出
   s   create a new empty Sun disklabel      创建新的空Sun磁盘标签
   t   change a partition's system id        更改分区的系统ID
   u   change display/entry units            更改显示/输入单位
   v   verify the partition table            验证分区表
   w   write table to disk and exit          将表写入磁盘并退出(保存退出)
   x   extra functionality (experts only)    额外功能(仅限专家)

(1)创建主分区

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-2147483647, default 2048):       默认
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-214748364
7, default 2147483647): +10G                      给10G    
Partition 1 of type Linux and of size 10 GiB is set

Command (m for help): p                     打印                         

Disk /dev/sdb: 1099.5 GB, 1099511627776 bytes, 2147483648 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: 0xf6ae0826

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    20973567    10485760   83  Linux

(2)创建拓展分区

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 (20973568-2147483647, default 20973568): 默认
Using default value 20973568
Last sector, +sectors or +size{K,M,G} (20973568-2147483647, default 21474
83647):                               全给
Using default value 2147483647
Partition 2 of type Extended and of size 1014 GiB is set

(3)创建逻辑分区

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 (20975616-2147483647, default 20975616): 
Using default value 20975616       默认
Last sector, +sectors or +size{K,M,G} (20975616-2147483647, default 21474
83647): +10G                  给10G
Partition 5 of type Linux and of size 10 GiB is set

Command (m for help): p        打印查看                                
 
Disk /dev/sdb: 1099.5 GB, 1099511627776 bytes, 2147483648 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: 0xf6ae0826

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    20973567    10485760   83  Linux
/dev/sdb2        20973568  2147483647  1063255040    5  Extended
/dev/sdb5        20975616    41947135    10485760   83  Linux

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

Calling ioctl() to re-read partition table.
Syncing disks.
[root@kelongyi ~]# 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    1G  0 part [SWAP]
└─sda3   8:3    0   38G  0 part /
sdb      8:16   0    1T  0 disk 
├─sdb1   8:17   0   10G  0 part 
├─sdb2   8:18   0    1K  0 part 
└─sdb5   8:21   0   10G  0 part 
sdc      8:32   0    4T  0 disk 
sr0     11:0    1  4.3G  0 rom 

3.使用mkfs对磁盘进行格式化 mkfs -t xfs /dev/sdb1

[root@kelongyi ~]# mkfs -t xfs /dev/sdb1         格式化sdb1
meta-data=/dev/sdb1              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@kelongyi ~]# mkfs -t xfs /dev/sdb5         格式化sdb5
meta-data=/dev/sdb5              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@kelongyi ~]# ls /dev/sd*             查看
/dev/sda   /dev/sda2  /dev/sdb   /dev/sdb2  /dev/sdc
/dev/sda1  /dev/sda3  /dev/sdb1  /dev/sdb5

4.挂载 mount mount /dev/sdb1 /data_1/

[root@kelongyi ~]# mkdir /data_1
[root@kelongyi ~]# mkdir /data_5
[root@kelongyi ~]# mount /dev/sdb1 /data_1/        挂载
[root@kelongyi ~]# mount /dev/sdb5 /data_5/
[root@kelongyi ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        38G  2.3G   36G   6% /
devtmpfs        980M     0  980M   0% /dev
tmpfs           991M     0  991M   0% /dev/shm
tmpfs           991M  9.5M  981M   1% /run
tmpfs           991M     0  991M   0% /sys/fs/cgroup
/dev/sda1      1014M  127M  888M  13% /boot
tmpfs           199M     0  199M   0% /run/user/0
/dev/sdb1        10G   33M   10G   1% /data_1
/dev/sdb5        10G   33M   10G   1% /data_5
[root@kelongyi ~]# cd /data_1/
[root@kelongyi data_1]# touch file1
[root@kelongyi data_1]# touch file2
[root@kelongyi data_1]# cd /data_5/
[root@kelongyi data_5]# touch file3
[root@kelongyi data_5]# touch file4
[root@kelongyi data_5]# cd

再次进行分区

[root@kelongyi ~]# 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): p                             打印分区

Disk /dev/sdb: 1099.5 GB, 1099511627776 bytes, 2147483648 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: 0xf6ae0826

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    20973567    10485760   83  Linux
/dev/sdb2        20973568  2147483647  1063255040    5  Extended
/dev/sdb5        20975616    41947135    10485760   83  Linux

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 6
First sector (41949184-2147483647, default 41949184): 
Using default value 41949184                        默认
Last sector, +sectors or +size{K,M,G} (41949184-2147483647, default 2147483647): 
Using default value 2147483647                      全给
Partition 6 of type Linux and of size 1004 GiB is set

Command (m for help): p                          打印分区

Disk /dev/sdb: 1099.5 GB, 1099511627776 bytes, 2147483648 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: 0xf6ae0826

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    20973567    10485760   83  Linux
/dev/sdb2        20973568  2147483647  1063255040    5  Extended
/dev/sdb5        20975616    41947135    10485760   83  Linux
/dev/sdb6        41949184  2147483647  1052767232   83  Linux

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

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

[root@kelongyi ~]# part
parted     partprobe  partx      
[root@kelongyi ~]# partprobe                    刷新
Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.
[root@kelongyi ~]# mkfs -t xfs /dev/sdb6      格式化
meta-data=/dev/sdb6              isize=512    agcount=4, agsize=65797952 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=263191808, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=128511, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@kelongyi ~]# mkdir /data_6                挂载
[root@kelongyi ~]# mount /dev/sdb6  /data_6/
[root@kelongyi ~]# df -h                         查看
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        38G  2.3G   36G   6% /
devtmpfs        980M     0  980M   0% /dev
tmpfs           991M     0  991M   0% /dev/shm
tmpfs           991M  9.5M  981M   1% /run
tmpfs           991M     0  991M   0% /sys/fs/cgroup
/dev/sda1      1014M  127M  888M  13% /boot
tmpfs           199M     0  199M   0% /run/user/0
/dev/sdb1        10G   33M   10G   1% /data_1
/dev/sdb5        10G   33M   10G   1% /data_5
/dev/sdb6      1004G   33M 1004G   1% /data_6
[root@kelongyi ~]# 
主分区 扩展分区 逻辑分区
MBR: 只能分配4个主分区 如果足够使用就行
MBR: 分配7个分区,怎么办? 3主分区 1扩展分区(4个逻辑分区) 2主
分区 1扩展分区(5个逻辑分区) 1主分区 1扩展分区6个逻辑分区)
(500G 格式化 挂载 -->/data )
系统盘 / ----> /dev/sda
数据盘 /data ----> /dev/sdb
数据盘 /so----> /dev/sdc

5.磁盘的基本分区Gdisk
6.磁盘挂载方式Mount
7.虚拟磁盘介绍SWAP
8.磁盘阵列 RAID
9.模拟磁盘阵列 --->软件实现
上一篇下一篇

猜你喜欢

热点阅读