最新要闻

广告

手机

iphone11大小尺寸是多少?苹果iPhone11和iPhone13的区别是什么?

iphone11大小尺寸是多少?苹果iPhone11和iPhone13的区别是什么?

警方通报辅警执法直播中被撞飞:犯罪嫌疑人已投案

警方通报辅警执法直播中被撞飞:犯罪嫌疑人已投案

家电

天天观点:Linux基础18 磁盘介绍, 结构, 磁盘分区Fdisk

来源:博客园

磁盘的基本概念

1.什么是磁盘?磁盘就像是森林,是所有硬式存储的统称,如最早出现的软盘,现在的硬盘,都是磁盘中的一部分。2.什么是软盘?磁盘开始指的是1.44MB的3.5英寸磁盘,这是很早时候的电脑储存盘,也叫软盘。软盘在如今已经很少被使用了,使用软盘需要安装软盘驱动。软盘容量小,容易损坏。随着数据的大量增长,软盘已经不满足日益所需的数据存储需求,如是,硬盘便被研发出来。3.什么是硬盘?硬盘就是计算机中的最大的存储装置了,就是将磁盘的储存片装到硬质金属盒子里可以得到更好的保护,而且在使用寿命上也比软盘优越得多,只有低格才对硬盘有很大的伤害,其它的读写是不要紧的,也就叫硬盘。4.磁盘与软盘硬盘的关系?磁盘是一种统称,即是一开始的软盘,又是现如今的硬盘,但是在现在,说起磁盘,都指的是硬盘。

磁盘的基本结构


(资料图)

盘片磁道扇区512字节,又是最小的物理单位柱面磁头

磁盘的预备知识

IDE,SCSI (已经被淘汰)

SATA III 与 SAS (企业使用较多)

M.2接口是为超极本(Ultrabook)量身定做的新一代接口标准,以取代原来的mSATA接口。无论是更小巧的规格尺寸,还是更高的传输性能,M.2都远胜于mSATAM2接口百度百科

你了解M.2固态硬盘吗?

装机到底要不要买M.2接口的SSD?

SATA、MSATA、PCIE和M2都是什么?

固态硬盘SATA和MSATA有什么区别?https://baike.baidu.com/item/m.2%E6%8E%A5%E5%8F%A3http://baijiahao.baidu.com/s?id=1604321789851430125&wfr=spider&for=pchttp://www.sohu.com/a/253988990_610530http://www.sohu.com/a/229021919_463982https://zhidao.baidu.com/question/754765227221408324.html

机械和固态的对比机械(HDD)固态(SSD)容量大价格低容量小价格高抗击打能力弱抗击打能力高读写速度稍慢读写速度很快数据恢复易数据恢复难使用时间无限使用时间1-2w次(使用完所有容量,或者格式化算一次)

尺寸:2.5英寸 3.5英寸 单位:B KB MB GB TB PB转速:7200 10K 15Kiops:每秒的输入和输出

磁盘设备的命令方式:

[root@web ~]# ll /dev/sd*brw-rw----. 1 root disk 8, 1 Jul 13 17:33 /dev/sda1    # 有分区,不用看sda(不存在了)brw-rw----. 1 root disk 8, 2 Jul 13 17:33 /dev/sdb2brw-rw----. 1 root disk 8, 3 Jul 13 17:33 /dev/sda5
设备名称     分区信息       设备类型/dev/sda    /dev/sda1    第一块物理磁盘第一分区    # sd开头为物理磁盘/dev/sdb    /dev/sdb2    第二块磁盘第二个分区/dev/vdd    /dev/vdd4    第四块虚拟磁盘的第四个分区    # vd开头为虚拟磁盘

系统中分区由数字编号表示,1-4表示给主分区使用和扩展分区,逻辑分区从5开始

https://baike.baidu.com/item/%E4%B8%BB%E5%BC%95%E5%AF%BC%E8%AE%B0%E5%BD%95/7612638

前面我们已经提到过MBR分区表只能分配4个主分区,但现在还有一种新型的分区表GPT,GPT支持分配128个主分区。注意MBR与GPT之间不能互转,会导致数据丢失。

http://www.360doc.com/content/18/0614/22/6140124_762487520.shtml

MBR位置:0磁头0磁道1扇区。

#显示磁盘分区信息的命令

[root@web ~]# df -hFilesystem      Size  Used Avail Use% Mounted on/dev/sda3        48G  3.0G   45G   7% /devtmpfs        980M     0  980M   0% /devtmpfs           991M     0  991M   0% /dev/shmtmpfs           991M   18M  973M   2% /runtmpfs           991M     0  991M   0% /sys/fs/cgroup/dev/sda1       197M  105M   93M  54% /boot/dev/sr0        4.3G  4.3G     0 100% /mnttmpfs           199M     0  199M   0% /run/user/0tmpfs           199M     0  199M   0% /run/user/1011[root@web ~]# du -sh /etc    # 查看目录或文件大小166M    /etc[root@web ~]# lsblkNAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT(盘的挂载点)sda      8:0    0   50G  0 disk ├─sda1   8:1    0  200M  0 part /boot├─sda2   8:2    0    2G  0 part [SWAP]└─sda3   8:3    0 47.8G  0 part /sr0     11:0    1  4.3G  0 rom  /mnt

# 在vm中添加硬盘,在设置中硬件下面点击添加硬盘,创建新的虚拟磁盘(不要勾选立即分配所有磁盘空间,否则会直接给空间)添加20g的做fdiks,添加3072g(3T)做gdisk通过ll /dev/sd*或lsblk查看是否识别,没有识别重启一次reboot

# 虚拟机添加磁盘分别为20G  3T,添加完成后要重启虚拟机[root@web ~]# ll /dev/sd*brw-rw----. 1 root disk 8,  0 Jul 16 18:33 /dev/sdabrw-rw----. 1 root disk 8,  1 Jul 16 18:33 /dev/sda1brw-rw----. 1 root disk 8,  2 Jul 16 18:33 /dev/sda2brw-rw----. 1 root disk 8,  3 Jul 16 18:33 /dev/sda3brw-rw----. 1 root disk 8, 16 Jul 16 18:33 /dev/sdbbrw-rw----. 1 root disk 8, 32 Jul 16 18:33 /dev/sdc[root@web ~]# lsblkNAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTsda      8:0    0   50G  0 disk ├─sda1   8:1    0  200M  0 part /boot├─sda2   8:2    0    2G  0 part [SWAP]└─sda3   8:3    0 47.8G  0 part /sdb      8:16   0   20G  0 disk sdc      8:32   0    3T  0 disk sr0     11:0    1  4.3G  0 rom  

fdisk 只支持MBR分区表,适用于2TB以下的分区。

一. 使用fdisk进行分区

1.[root@web ~]# fdisk /dev/sdbWelcome 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 tableBuilding a new DOS disklabel with disk identifier 0x5b38e62c.2.Command (m for help): mCommand action   a   toggle a bootable flag                   #切换分区启动标记   b   edit bsd disklabel                       #编辑sdb磁盘标签   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   #创建新的空白分区表** p   print the partition table                #显示分区表的信息** q   quit without saving changes              #不保存退出   s   create a new empty Sun disklabel         #创建新的Sun磁盘标签   t   change a partitions system id            #修改分区ID,可以通过l查看id   u   change display/entry units               #修改容量单位,磁柱或扇区   v   verify the partition table               #检验分区表** w   write table to disk and exit             #保存退出   x   extra functionality (experts only)       #拓展功能3.Command (m for help): nPartition type:   p   primary (0 primary, 0 extended, 4 free)   e   extendedSelect (default p): 4.回车(默认为p主分区) 或者输入pUsing default response pPartition number (1-4, default 1): 5.回车(默认分区1编号即可,方便记忆)First sector (2048-41943039, default 2048): 6.扇区从哪开始,回车,默认从2048开始即可Using default value 20487.到哪里结束,可以用多少扇区或者多少大小表示。如果默认就是最大值,这里选择1G大小Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +1GPartition 1 of type Linux and of size 1 GiB is set8.显示分区表信息Command (m for help): pDisk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x5b38e62c   Device Boot      Start         End      Blocks   Id  System/dev/sdb1            2048     2099199     1048576   83  LinuxCommand (m for help): nPartition type:   p   primary (1 primary, 0 extended, 3 free)   e   extendedSelect (default p): Using default response pPartition number (2-4, default 2): First sector (2099200-41943039, default 2099200): Using default value 2099200Last sector, +sectors or +size{K,M,G} (2099200-41943039, default 41943039): +2GPartition 2 of type Linux and of size 2 GiB is setCommand (m for help): pDisk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x5b38e62c   Device Boot      Start         End      Blocks   Id  System/dev/sdb1            2048     2099199     1048576   83  Linux/dev/sdb2         2099200     6293503     2097152   83  LinuxCommand (m for help): nPartition type:   p   primary (2 primary, 0 extended, 2 free)   e   extendedSelect (default p): Using default response pPartition number (3,4, default 3): First sector (6293504-41943039, default 6293504): Last sector, +sectors or +size{K,M,G} (14680064-41943039, default 41943039): +7GUsing default value 41943039Partition 3 of type Linux and of size 13 GiB is setCommand (m for help): pDisk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x5b38e62c   Device Boot      Start         End      Blocks   Id  System/dev/sdb1            2048     2099199     1048576   83  Linux/dev/sdb2         2099200     6293503     2097152   83  Linux/dev/sdb3        14680064    41943039    13631488   83  Linux# 删除不要的分区Command (m for help): dPartition number (1-3, default 3): 3Partition 3 is deletedCommand (m for help): pDisk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x5b38e62c   Device Boot      Start         End      Blocks   Id  System/dev/sdb1            2048     2099199     1048576   83  Linux/dev/sdb2         2099200     6293503     2097152   83  LinuxCommand (m for help): nPartition type:   p   primary (2 primary, 0 extended, 2 free)   e   extendedSelect (default p): Using default response pPartition number (3,4, default 3): First sector (6293504-41943039, default 6293504): Using default value 6293504Last sector, +sectors or +size{K,M,G} (6293504-41943039, default 41943039): +7GPartition 3 of type Linux and of size 7 GiB is setCommand (m for help): pDisk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x5b38e62c   Device Boot      Start         End      Blocks   Id  System/dev/sdb1            2048     2099199     1048576   83  Linux/dev/sdb2         2099200     6293503     2097152   83  Linux/dev/sdb3         6293504    20973567     7340032   83  Linux# 创建扩展分区(扩展分区并不存放数据, 是存放逻辑分区的)Command (m for help): nPartition type:   p   primary (3 primary, 0 extended, 1 free)   e   extendedSelect (default e): # 此时再创建主分区,就不能创建扩展分区了。默认为扩展分区Using default response eSelected partition 4First sector (20973568-41943039, default 20973568): Using default value 20973568Last sector, +sectors or +size{K,M,G} (20973568-41943039, default 41943039): +5G    # 把剩余大小都给扩展分区,再在里面创建逻辑分区,所以此处需要把剩余10G都写上Partition 4 of type Extended and of size 5 GiB is setCommand (m for help): pDisk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x5b38e62c   Device Boot      Start         End      Blocks   Id  System/dev/sdb1            2048     2099199     1048576   83  Linux/dev/sdb2         2099200     6293503     2097152   83  Linux/dev/sdb3         6293504    20973567     7340032   83  Linux/dev/sdb4        20973568    31459327     5242880    5  ExtendedCommand (m for help): dPartition number (1-4, default 4): Partition 4 is deletedCommand (m for help): nPartition type:   p   primary (3 primary, 0 extended, 1 free)   e   extendedSelect (default e): Using default response eSelected partition 4First sector (20973568-41943039, default 20973568): Using default value 20973568Last sector, +sectors or +size{K,M,G} (20973568-41943039, default 41943039): Using default value 41943039Partition 4 of type Extended and of size 10 GiB is setCommand (m for help): pDisk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x5b38e62c   Device Boot      Start         End      Blocks   Id  System/dev/sdb1            2048     2099199     1048576   83  Linux/dev/sdb2         2099200     6293503     2097152   83  Linux/dev/sdb3         6293504    20973567     7340032   83  Linux/dev/sdb4        20973568    41943039    10484736    5  Extended# 此时只能创建逻辑分区Command (m for help): nAll primary partitions are in useAdding logical partition 5First sector (20975616-41943039, default 20975616):      Using default value 20975616Last sector, +sectors or +size{K,M,G} (20975616-41943039, default 41943039): +5GPartition 5 of type Linux and of size 5 GiB is setCommand (m for help): pDisk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x5b38e62c   Device Boot      Start         End      Blocks   Id  System/dev/sdb1            2048     2099199     1048576   83  Linux/dev/sdb2         2099200     6293503     2097152   83  Linux/dev/sdb3         6293504    20973567     7340032   83  Linux/dev/sdb4        20973568    41943039    10484736    5  Extended/dev/sdb5        20975616    31461375     5242880   83  LinuxCommand (m for help): nAll primary partitions are in useAdding logical partition 6First sector (31463424-41943039, default 31463424): Using default value 31463424Last sector, +sectors or +size{K,M,G} (31463424-41943039, default 41943039): Using default value 41943039Partition 6 of type Linux and of size 5 GiB is setCommand (m for help): pDisk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x5b38e62c   Device Boot      Start         End      Blocks   Id  System/dev/sdb1            2048     2099199     1048576   83  Linux/dev/sdb2         2099200     6293503     2097152   83  Linux/dev/sdb3         6293504    20973567     7340032   83  Linux/dev/sdb4        20973568    41943039    10484736    5  Extended/dev/sdb5        20975616    31461375     5242880   83  Linux/dev/sdb6        31463424    41943039     5239808   83  Linux# 保存分区信息Command (m for help): wThe partition table has been altered!Calling ioctl() to re-read partition table.Syncing disks.# 可以通过ll /dev/sd*, 或者lsblk 查看

二.格式化,挂载

格式化分区,创建文件系统。[root@web ~]# mkfs.xfs  /dev/sdb1    # 只能对分区表格式化,不能对整个磁盘格式化meta-data=/dev/sdb1              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创建挂载点[root@web ~]# mkdir   /data1[root@web ~]# ll /data1total 0[root@web ~]# cp /etc/services   /data1    # 空目录即可,这里展示效果会被覆盖[root@web ~]# ll /data1total 656-rw-r--r--. 1 root root 670293 Jul 16 19:01 services挂载(临时挂载)[root@web ~]# mount /dev/sdb1  /data1[root@web ~]# ll /data1total 0[root@web ~]# df -hFilesystem      Size  Used Avail Use% Mounted on/dev/sda3        48G  3.0G   45G   7% /devtmpfs        980M     0  980M   0% /devtmpfs           991M     0  991M   0% /dev/shmtmpfs           991M  9.7M  981M   1% /runtmpfs           991M     0  991M   0% /sys/fs/cgroup/dev/sda1       197M  105M   93M  54% /boottmpfs           199M     0  199M   0% /run/user/0/dev/sdb1      1014M   33M  982M   4% /data1[root@web ~]# dd if=/dev/zero of=/data1/test.txt  bs=10M count=50    # 创建文件50+0 records in50+0 records out524288000 bytes (524 MB) copied, 2.13248 s, 246 MB/s[root@web ~]# ll /data1/total 512000-rw-r--r--. 1 root root 524288000 Jul 16 19:03 test.txt[root@web ~]# ll /data1/ -htotal 500M-rw-r--r--. 1 root root 500M Jul 16 19:03 test.txt[root@web ~]# df -hFilesystem      Size  Used Avail Use% Mounted on/dev/sda3        48G  3.0G   45G   7% /devtmpfs        980M     0  980M   0% /devtmpfs           991M     0  991M   0% /dev/shmtmpfs           991M  9.7M  981M   1% /runtmpfs           991M     0  991M   0% /sys/fs/cgroup/dev/sda1       197M  105M   93M  54% /boottmpfs           199M     0  199M   0% /run/user/0/dev/sdb1      1014M  533M  482M  53% /data1永久挂载[root@web ~]# vim /etc/fstab[root@web ~]# tail -1 /etc/fstab/dev/sdb1     /data1        xfs             defaults        0     0设备名        挂载点        文件系统类型      默认参数      是否备份  是否检查磁盘[root@web ~]# umount /data1/    # 取消挂载,可以写目录名或者设备名[root@web ~]# df -hFilesystem      Size  Used Avail Use% Mounted on/dev/sda3        48G  3.0G   45G   7% /devtmpfs        980M     0  980M   0% /devtmpfs           991M     0  991M   0% /dev/shmtmpfs           991M  9.7M  981M   1% /runtmpfs           991M     0  991M   0% /sys/fs/cgroup/dev/sda1       197M  105M   93M  54% /boottmpfs           199M     0  199M   0% /run/user/0[root@web ~]# mount -a    # 将/etc/fstab的所有内容重新加载(用于检测是否编辑正常,通过reboot测试万一异常修复比较麻烦)[root@web ~]# df -hFilesystem      Size  Used Avail Use% Mounted on/dev/sda3        48G  3.0G   45G   7% /devtmpfs        980M     0  980M   0% /devtmpfs           991M     0  991M   0% /dev/shmtmpfs           991M  9.7M  981M   1% /runtmpfs           991M     0  991M   0% /sys/fs/cgroup/dev/sda1       197M  105M   93M  54% /boottmpfs           199M     0  199M   0% /run/user/0/dev/sdb1      1014M  533M  482M  53% /data1重新选择一个挂载点[root@web ~]# umount  /data1/[root@web ~]# [root@web ~]# ll /data1/total 656-rw-r--r--. 1 root root 670293 Jul 16 19:01 services[root@web ~]# mkdir  /data2[root@web ~]# ll /data2total 0[root@web ~]# mount  /dev/sdb1  /data2[root@web ~]# ll /data2total 512000-rw-r--r--. 1 root root 524288000 Jul 16 19:03 test.txt

关键词: