linux basis of the file and disk management system

Disk Management concepts

磁盘分区:对硬盘物理介质的逻辑划分。
磁盘分成多个分区,可以在不同的分区建立不同的文件系统。
磁盘格式化:创建文件系统的工作,会导致现有的分区中所有的数据被清除。
对磁盘进行分区和格式化将会导致数据丢失,分区格式化前需要对数据进行备份。
复制代码

everything is a file in linux, hard drives, partitions and other equipment are represented as files

For example the following disk

# /dev/sda5
/dev 硬件设备文件所在的目录
sd 表示串行设备, 除了sd外还有hd,表示IDE设备
a 硬盘的顺序号,以字母表示
5 分区的顺序号,以数字表示
复制代码

Traditional MBR partitioning

Master boot record

Master boot sector: the hard disk cylinder 0, head 0, 1 sector is called the master boot sector

Partition table: only four partition entries, the offset address 01BEH - 01FDH, each partition entry is 16 bytes long, 64 bytes total partition entries 1, 2 partition entries, partition entries 3, 4 partition entries

End tag: offset address 01FE - 01FF is 2 bytes or end marker 0xAA55 0x55AA, referred to as a "magic number" (magic number). If the flag error system can not boot

/dev/hdXX

Conventional IDE hard disk parallel, serial SATA drives are now substituted

1 of the host PC IDE hard expressed as hda, the second IDE hard disk / dev / hdb, IDE hard disk and so on four primary partitions may be expressed as hda1 to hda4

/dev/sdXX

SATA hard drive using the serial port, transfer rate, and mainstream hard drive

主分区,一个硬盘允许4个主分区
扩展分区:一个硬盘允许3个主分区,一个扩展分区
逻辑分区:在扩展分区上创建
复制代码

1. extended partition is used only for receiving logical partition, not a file system, and therefore can not be directly saved to files and directories in the extended partition.

2. partition stored in the extended partition is called a logical partition (Logic Partition). Each logical partition can be stored in a file system.

3. The number of logical partitions is always started from the 5, 1 to 4, as has been reserved for the use of primary and extended partitions

4. The hard disk, every device will have a partition of the partition symbol file; hard disk device after a specified file, rename the partition according to the identification number.

5. Main and Extended partitions: using the identification numbers 1-4.

6. logical partitions: Always use the identification number of 5-63. For example, / dev / hda first primary partition, which is the device file / dev / hdal; and / dev / sdb No. 1 hard logical partition, it uses the device file / dev / sdb5 of.

GUID Partition Table

Referred to as the GPT. GUID partition table disk called a GPT disk. EFI is a standard derived from the newer standard disk partition table structure. And the widespread use of the main boot record (MBR) partitioning scheme compared, GPT provides a more flexible disk partitioning scheme. It has the following advantages:

1、支持2TB以上的大硬盘.
2、每个磁盘的分区个数几乎没有限制。为什么说“几乎”呢?是因为Windows系统最多只
允许划分128个分区。不过也完全够用了。 
3、分区大小几乎没有限制。又是一个“几乎”。因为它用64位的整数表示扇区号。夸张
一点说,一个64位整数能代表的分区大小已经是个“天文数字”了,若干年内你都无法见
到这样大小的硬盘,更不用说分区了。
4、分区表自带备份。在磁盘的首尾部分分别保存了一份相同的分区表。其中一份被破
坏后,可以通过另一份恢复。
5、每个分区可以有一个名称(不同于卷标)。
复制代码

Why propose new partition scheme

(1)主分区数目不能超过4个的限制,很多时候4个主分区并不能满足需要。
(2)MBR分区方案无法支持超过2TB容量的磁盘。因为这一方案用4个字节存储分区的总
扇区数,最大能表示2的32次方的扇区个数,按每扇区512字节计算,每个分区最大不能
超过2TB。磁盘容量超过2TB以后,分区的起始位置也就无法表示了。在硬盘容量突飞猛
进的今天,2TB的限制将很快被突破。
复制代码

Partition management tool

# fdisk 分区管理工具
    fdisk -l 列出硬盘分区信息
    fdisk /dev/sda 交互模式操作sda设备
    m 显示所有可用命令
    p 显示硬盘分区信息
    n、e、p 创建新、扩展、主分区
    t 更改分区文件系统
    d 删除硬盘分区
    w、q 保存、不保存退出
磁盘分区设备名
Boot:表示引导分区
Start:表示一个分区的开始扇区
End:表示一个分区的结束扇区
Blocks:表示分区容量,单位是块,默认一个块是1KB
Id:一个两位的十六进制,表示分区类型
System:ID所定义分分区类型

# 创建一个大小为300M的主分区
root@computer: ~# fdisk /dev/sdb
命令(输入m获取帮助):m
命令(输入m获取帮助):n
Select (default p):
Using default response p
分区号(2-4,默认2):
起始扇区(19555689 - 16777296,默认为 1955859):
将使用默认值 1955859
Last扇区,+扇区 or +size(K, M, G)
# 保存退出,按照要求同步磁盘
# 需要系统重新启动才可以生效,如果不想重启系统,可以使用partprober /dev/sdb
复制代码

Establish and manage file systems

File System is the operating system used in the methods and data structures of the file on the disk or partition clear; namely organizational methods files on the disk. Linux default file system type used

EXT4, 第4代扩展(Extended)文件系统
SWAP,交换文件系统
复制代码

Other file system types supported by Linux

FAT16、FAT32、NTFS
XFS(高性能的日志文件系统,RHEL7默认使用的文件系统类型)、JFS(集群文件系统)
VFAT(虚拟文件分配表)
复制代码
# mkfs 创建文件系统
mkfs –t 文件系统类型 文件系统名
root@computer: ~# mkfs  -t ext4 /dev/sdb5  # 在/dev/sdb5上建立一个ext4分区
复制代码

Mounting File Systems

In the Linux operating system, the entire system has only one root directory, so use all the files in the root directory of a disk space and which in Linux, you must mount the file system to a directory under the root file system.

# mount 挂载文件系统、ISO镜像到指定文件夹
mount [ -t 类型] 存储设备 挂载点目录
mount -o loop ISO镜像文件  挂载点目录
user@computer: ~$ mount /dev/cdrom /mnt/cdrom  # 将/dev/cdrom挂载到/mnt/cdrom下
复制代码
# umount 卸载已挂载的文件系统
umount 存储设备位置
umount 挂载点目录
user@computer: ~$ unmount /dev/cdrom # 卸载已挂载的/dev/cdrom
复制代码

Boot automatically mount the file system

To achieve automatic loading system boot file, you need to be disposed in / etc / fstab profile

user@computer: ~$ cat /etc/fstab
LABEL=cloudimg-rootfs   /        ext4   defaults        0 0
设备位置             挂载点   文件系统类型
复制代码

Reproduced in: https: //juejin.im/post/5cfb74a1f265da1bd1464a00

Guess you like

Origin blog.csdn.net/weixin_34067102/article/details/91459794