linux磁盘概念

发布时间:2022-06-22 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了linux磁盘概念脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

linux磁盘概念

1、磁盘层次结构详细说明--物理结构

1) 磁盘的外部结构: 看的见摸得到的结构

组成部分 a 磁盘主轴 决定磁盘转速(rpm-round PEr minute) 家用磁盘转速 7200 rpm 5400 rpm 企业磁盘转速 15k rpm 10k rpm b 磁盘盘片 用于存储数据 c 磁盘磁头 用于读取数据 d 磁盘接口 用于连接主板 用于连接阵列卡

2)磁盘的内部结构: 看不见的结构信息

组成部分: a 磁盘(disk b 磁头(Head) 作用说明:用来写入和读取数据的 特点说明:盘面数量等于磁头数量 工作原理:采用径向运动读写数据 c 磁道(Track) 作用说明:用来存储用户数据 特点说明:由多个同心组成

存储计数:最外面同心圆为0磁道 工作原理:磁盘默认按照磁道寻找数据 ​ 重点原理:磁头径向运动为机械运动(寻道) 性能小于固态硬盘(芯片) ​ 原理特点:磁头机械运动较慢 d 扇区(Sector) 作用说明:用来存储用户数据 特点说明:磁盘存储最小单位 存储计数:默认磁盘扇区从1扇区开始,扇区大小为512字节 系统存储最小单位是block e 柱面(Cylinder) 作用说明:用来存储用户数据

特点说明:不同盘面上相同的磁道组成(圆柱体) 工作原理:磁盘默认按照柱面进行读写 重点原理:磁头之间的切换为子切换 原理特点:磁头电子切换较快 f 单元块(UnITs) 作用说明:用来存储用户数据 特点说明:表示单个柱面大小

2、磁盘层次结构详细说明--磁盘阵列raid

阵列有什么用? 1) 提高磁盘存储效率 2) 提高磁盘存储安全 3) 提高磁盘存储容量 阵列的配置方法: raid 0 存储数据效率高 存储安全性低 raid 1 存储数据效率低 存储安全性高

raid 5 存储数据效率较高 存储安全性较高 说明: 至少有3块磁盘 raid5阵列中只能最多坏一块磁盘 损耗一块磁盘 的容量 300G 300G 300G --> raid5 --> 600G LVM 实现分区可以弹性缩融 和 扩容

3、磁盘层次结构详细说明--磁盘分区方法

1)预备知识:

a 系统启动引导记录-- mbr引导记录 用于引导磁盘空间小于2T gpt引导记录 用于引导磁盘空间大于2T

b 分区方式 情况一: 可以划分4个主分区 /dev/sda /dev/sda1 .. sda4 mount /dev/sda1 /mnt 情况二: 可以划分3个主分区 /dev/sda /dev/sda1 .. sda3 可以划分1个扩展分区 扩展分区无法直接使用 需要在扩展分区基础上划分逻辑分区: /dev/sda5 /dev/sda6 ...

2)分区实际操作

情况一: 磁盘分区实践--磁盘小于2T(Fdisk /dev/sdb)

 

第一个里程: 准备磁盘环境 准备了一块新的10G硬盘

第二个里程: 在系统中检查是否识别到了新的硬盘 检查是否有新的磁盘存储文件

 [root@oldboyedu ~]# ll /dev/sdb brw-rw----. 1 root disk 8, 16 APR 28 08:54 /dev/sdb

第三个里程: 对磁盘进行分区处理(fdisk-- 进行分区处理 查看分区信息) fdisk -l --- 查看分区信息

 [root@oldboyedu ~]# 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 0x6c918c6d. ​ Command (m for help):   --可以对磁盘进行分区了 Command action d   delete a partition  *****     删除分区          g   create a new empty GPT partition table     创建一个新的空的GPT分区表(可以对大于2T磁盘进行分区)      l   list known partition types     列出可以分区的类型???      m   print this menu     输出帮助菜单      n   add a new partition  *****     新建增加一个分区      p   print the partition table  *****     输出分区的结果信息      q   quit without saving changes      不保存退出      t   change a partition's System id     改变分区的系统id==改变分区类型(LVM 增加swap分区大小)      u   change display/entry units     改变分区的方式  是否按照扇区进行划分      w   write table to disk and exit  *****     将分区的信息写入分区表并退出==保存分区信息并退出

开始分区:

a 规划分4个主分区 每个分区1G

分区操作过程

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

分区操作检查:

 Command (m for help): p Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x3069F1dd ​    Device 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     8390655     1048576   83  Linux ​ Command (m for help): n If you want to create more than four partitions, you must replace a primary partition with an extended partition first.

b 规划分3个主分区 1个扩展分区 每个主分区1G 剩余都给扩展分区

删除分区

 Command (m for help): d    Partition number (1-4, default 4): 1 Partition 1 is deleted

创建逻辑分区

 Command (m for help): p ​ Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x3069f1dd ​    Device 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   有了扩展分区才能逻辑分区 ​ Command (m for help): n All primary partitions are in use Adding logical partition 5 First sector (6295552-20971519, default 6295552):  Using default value 6295552 Last sector, +sectors or +size{K,M,G} (6295552-20971519, default 20971519): +1G Partition 5 of type Linux and of size 1 GiB is set ​ Command (m for help): p Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x3069f1dd ​    Device 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     8392703     1048576   83  Linux ​ ###   

第四个里程: 保存退出,让系统可以加载识别分区信息 让系统可以加载识别分区文件 [root@HGG ~]# partprobe /dev/sdb

格式化分区

[root@HGG /]# mkfs.xfs /dev/sdb1

情况二: 磁盘分区实践--磁盘大于2T(parted /dev/sdc)

第一个里程: 准备磁盘环境 虚拟主机中添加一块3T硬盘

第二个里程: 使用parted命令进行分区

parted /dev/sdc

 mklabel,mktable LABEL-tYPE               create a new disklabel (partition table)                                          创建一个分区表 (默认为mbr)                                           print [devices|free|list,all|NUMBER]     display the partition table, available devices, free space, all found                                          partitions, or a particular partition                                          显示分区信息                                           mkpart PART-TYPE [FS-TYPE] START END     make a partition                                          创建一个分区                                            quit                                     exit program                                          退出分区状态                                           rm NUMBER                                delete partition NUMBER                                          删除分区 

 

分区方法:

 [root@HGG ~]# parted /dev/sdc ​ GNU Parted 3.1 Using /dev/sdc Welcome to GNU Parted! Type 'help' to view a list of commands. ​ (parted) mklabel gpt  --创建分区表 ​ Warning: The existing disk label on /dev/sdc will be destroyed and all data on this disk will be lost. Do you want to continue? Yes/No? yes  ​ (parted) print    --查看分区信息 ​ Model: VMware, VMware Virtual S (scsi) Disk /dev/sdc: 3221GB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags:  ​ Number  Start  End  Size  File system  Name  Flags ​ (parted) mkpart primary 0  2100G        --创建分区 ​ Warning: The resulting partition is not properly aligned for best performance. Ignore/Cancel? Ignore                                                      (parted) print Model: VMware, VMware Virtual S (scsi) Disk /dev/sdc: 3221GB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags:  ​ Number  Start   End     Size    File system  Name     Flags  1      17.4kB  2100GB  2100GB               primary  (parted) q             --退出分区,分区操作会自动保存

 

第三个里程: 加载磁盘分区 partprobe /dev/sdc

第四里程:格式化分区

mkfs.xfs /dev/sdc1

4、磁盘层次结构--格式化操作(mkfs.xfs)

mkfs.xfs /dev/sdb1 mkfs -t xfs /dev/sdb2

创建文件系统: 磁盘分区存储数据的方式 xfs centos7 格式效率较高 数据存储效率提升(数据库服务器)

[root@oldboyedu /]# mkfs.xfs /dev/sdb2meta-data=/dev/sdb2              isize=512    agcount=4, agsize=65536 blks         =                       sectsz=512   attr=2, projid32bit=1         =                       crc=1        finoBT=0, sparse=0data     =                       bsize=4096   blocks=262144, imaxpct=25         =                       sunit=0      swidth=0 blksnaming   =version 2              bsize=4096   ascii-ci=0 ftype=1log      =internal log           bsize=4096   blocks=2560, version=2         =                       sectsz=512   sunit=0 blks, lazy-count=1realtime =none                   extsz=4096   blocks=0, rtextents=0

 

5、磁盘层次结构--磁盘挂载应用(mount)

挂载分区:

[root@HGG ~]# mkdir mount01[root@HGG ~]# mkdir mount02[root@HGG ~]# mount /dev/sdb1 /mount01[root@HGG /]# mount /dev/sdb2 /mount02

检查确认:

[root@HGG /]# DF -h/dev/sdb1       2.0G   33M  2.0G   2% /mount01/dev/sdb2       2.0G   33M  2.0G   2% /mount02

如何实现开机自动挂载: 方法一: 将挂载命令放入 vim /etc/rc.local

[root@oldboyedu /]# tail -2 /etc/rc.local mount /dev/sdb1 /mount01mount /dev/sdb2 /mount02[root@oldboyedu /]#chmod +x /etc/rc.d/rc.local  --给文件加上执行权限

系统开机加载rc.local流程: 加载/etc/rc.local --> /etc/rc.d/rc.local --> 以绝对路径方式执行 /etc/rc.d/rc.local chmod +x /etc/rc.d/rc.local

方法二: 在vim /etc/fstab文件中进行设置

blkid 查看磁盘uid

UUID=e2fc8646-2b36-47cc-a35a-8c13208f4d0b /          xfs                 defaults            0             0UUID=34fc45ba-c38c-42bc-a120-90f9d5dd2382 /boot      xfs                 defaults            0             0UUID=62100743-6f8a-4f83-a37d-e2088c4830e2 swap       swap                defaults            0             0挂载磁盘文件(存储设备)                   挂载点     指定文件系统类型   挂载的参数    是否备份磁盘  是否检查磁盘 

mount 挂载的磁盘文件 挂载点

[root@oldboyedu ~]# vim etc/fstab/dev/sdb1                                 /mount01                xfs     defaults        0 0UUID=144738ff-0da3-4162-b574-40af379cbe9e /mount02                xfs     defaults        0 0

6、企业磁盘常见问题:

1) 磁盘满的情况 No space left on device

a 存储的数据过多了(block)

查看方式:df -h

模拟磁盘空间不足 dd if=/dev/zero of=/tmp/oldboy.txt bs=10M count=100 block存储空间不足了 解决方式: 1、 删除没用的数据 2、找出大的没用的数据 find / -type f -size +xxx du -sh /etc/sysconfig/network-scripts/*|sort -h

	 	补充: 按照数值排序命令
   [root@oldboyedu mount01]# cat num.txt |sort -n   # 1   # 10   # 11   # 12   # 2   # 3   # 6   # 9   [root@oldboyedu mount01]# cat num.txt |sort -n -k2   # 1   # 2   # 3   # 6   # 9   # 10   # 11   # 12

 

b 存储的数据过多了(inode)

查看方式:df -i

	  inode存储空间不足了: 出现了大量小文件	   

7、如何调整swap分区大小

第一个历程: 将磁盘分出一部分空间给swap分区使用 dd if=/dev/zero of=/tmp/1G bs=100M count=10

第二个历程: 将指定磁盘空间作为swap空间使用

mkswap /tmp/1G

[root@oldboyedu tmp]# mkswap /tmp/1G Setting up swapspace version 1, size = 1023996 KiBno label, UUID=6dd70684-dec2-48CF-8fd9-f311548bbb4f

第三个历程: 加载使用swap空间

swapon /tmp/1G

[root@oldboyedu tmp]# swapon /tmp/1G swapon: /tmp/1G: insecure permissions 0644, 0600 suggested.[root@oldboyedu tmp]# free -h              total        used        free      shared  buff/cache   availableMem:           1.9G        225M        575M        9.6M        1.2G        1.5GSwap:          2.0G          0B        2.0G[root@oldboyedu tmp]# swapoff /tmp/1G --取消swap空间[root@oldboyedu tmp]# free -h              total        used        free      shared  buff/cache   availableMem:           1.9G        224M        576M        9.6M        1.2G        1.5GSwap:          1.0G          0B        1.0G[root@oldboyedu tmp]# rm /tmp/1G -f

 

脚本宝典总结

以上是脚本宝典为你收集整理的linux磁盘概念全部内容,希望文章能够帮你解决linux磁盘概念所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。