Linux Disk Management

Source: Internet
Author: User
Tags disk usage

I. Disk classification and storage unit 1. Classification
(1)传统硬盘(机械硬盘):IDE、SATA、SCSI等接口,廉价、但速度较慢(2)固态硬盘(SSD):SATA、PCI-E、M.2 2280,昂贵、但速度快
2. Unit of Measure
(1)b:算机识别最小单位 (8b = 1B)(2)B(字节):比特,用户使用最小单位 (1024B = 1KB)(3)KB(1024KB = 1MB)(4)MB(1024MB = 1GB)(5)GB(1024GB = 1TB)(6)TB(1024TB = 1PB)(7)PB(1024PB=1EB)(8)EB
Ii. partitioning 1. Partitioning scheme
(1)MBR:在磁盘暂占用512字节头部(446字节存储MBR引导记录、64存储分区表,每个分区16字节,2字节分隔符)     主分区:用于安装、启动系统     逻辑分区:只能用于存储数据     扩展分区:不能存储数据,只用于再次划分逻辑分区(2)MBR分区方案4个主分区 //只创建四个主分区在系统中3个主分区、1个扩展分区(逻辑分区) //创建三个主分区,一个扩展分区,在扩展分区下可自由创建多个逻辑分区
(3)GPT:每个磁盘分区都加上GPT头部,理论可以支持无限个主分区,但由于操作系统限制,最多只能创建128个主分区注:MBR只能支持2TB以下磁盘,而GPT可以支持2TB以上,并且GPT可支持UEFI引导
Linux硬盘存放目录:/dev/
2. Disk Presentation methods
SATA、SCSI:/dev/sdx(第一块a、依次类推)M.2:/dev/sdx(第一块a、依次类推)IDE:/dev/hdx(第一块a、依次类推)M.2(NVMe):/dev/nvmex(第一块0、依次类推)
3. Partition number
1-4:为主分区或扩展分区5-x:为逻辑分区,第一个逻辑分区5

Note : The default Linux partition uses the MBR partition table

Second, partition 1. View disk status
lsblk           //以树形结构显示磁盘或光盘的挂载情况fdisk -l            //详细查看磁盘信息echo "- - -" >/sys/class/scsi_host/hostx/scan   //立即重新扫描新增硬盘

Example :

2. Partitioning

case : Added 20G disk, divided into 3 primary partitions, two logic, 3 primary partitions, each 5G, and all remaining space is divided evenly between 2 logical partitions

(1)fdisk /dev/sdb       //对/deb/sdb磁盘分区;或采用cfdisk /dev/xxx  fdisk /dev/sdb --> n(新建分区) --> p(新建主分区) --> 1(输入主分区编号;1-4) --> 回车(起始柱面位置) --> +5G(分区需要空间,结束柱面位置) --> p(打印)//新建/dev/sdb1主分区,空间为5G  n(新建分区) --> p(新建主分区) --> 2(输入主分区编号;1-4) --> 回车(起始柱面位置) --> +5G(分区需要空间,结束柱面位置) --> p(打印)//新建/dev/sdb2主分区,空间为5G  n(新建分区) --> p(新建主分区) --> 3(输入主分区编号;1-4) --> 回车(起始柱面位置) --> +5G(分区需要空间,结束柱面位置) --> p(打印)//新建/dev/sdb3主分区,空间为5G  n(新建分区) --> e(新建扩展分区) -->  回车(起始柱面位置) --> 回车(分区使用所有剩余空间,结束柱面位置) --> p(打印)//新建/dev/sdb4扩展分区,空间为所有剩余空间  n(新建分区) --> 回车(起始柱面位置) --> +2G(分区需要空间,结束柱面位置) --> p(打印)//新建/dev/sdb5逻辑分区,空间为2G  n(新建分区) --> 回车(起始柱面位置) --> 回车(分区使用所有剩余空间,结束柱面位置) --> p(打印) --> w(保存并退出)//新建/dev/sdb6逻辑分区区,空间为所有剩余空间,并保存退出(2)partprobe            //刷新分区表

Note : fdisk can only partition MBR disks below 2TB, and Cfdisk can support more than 2TB GPT disks

Third, the format of

Format the disk and select the file system
Windows

fat:主要用于EFI引导,只能存储单个文件4G以下NTFS:常用于Windows,支持ACL及磁盘配额等特性(默认只能在Windows使用,而Linux只能读取内容,而不能写入(需安装ntfs-3g))  exfat:主要用于大容量U盘,可跨平台使用

Linux

ext4:第四代日志型文件系统,当前磁盘操作全部记录日志(不建议固态使用)btrfs:支持快照功能,但不稳定xfs:建议常使用单文件大容量环境mkfs.文件系统 /dev/xxx          //格式化指定磁盘分区并选择文件系统挂载mount /dev/xxx 目录           //将指定分区挂载到指定目录umount {/dev/xxx | 目录}          //卸载指定分区

Note : The Mount command is used by default, temporarily mounted, lost after reboot
Auto mount on Boot

vim /etc/fstab          //修改挂载文件挂载磁盘        挂载点     文件系统        权限列表        是否启用检测  检测的顺序/dev/cdrom              /mnt                     iso9660        defaults            0       0/dev/sdb1               /a                       ext4           defaults         0      0mount -a                //重新读取/etc/fstab文件,可用于检测文件是否有误mount                   //查看磁盘挂载情况(或使用lsblk)

Viewing mounted disk usage

df -Th //查看磁盘使用情况和挂载位置

Options :

-T:显示磁盘文件系统-h:以人性化显示容量

Example :

Linux Disk Management

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.