Linux disks and file systems

Source: Internet
Author: User

Linux disks and file systems

?? When we get a brand new disk, we are not able to use it directly, but need to be partitioned, formatted, and mounted before the operating system can recognize and write and read the data. Different operating systems vary in file systems, so the partitioning of disks is not the same.

I. Disk 1. Structure

?? In the computer field, disk is now the most used and most cost-effective storage medium. With the continuous development of storage technology, the disk is divided into mechanical hard disk and solid-state drive. Mechanical hard disk mainly by: platters, magnetic head, disc spindle and head controller, data converters, interfaces and other components. The data is stored on the platter, and the disc rotates at high speed under the drive of the motor, with a head on the storage surface of each platter, and the head responsible for writing and reading the data on the platter. As a result, a sudden power outage in the computer causes the integrity of the file being written to be corrupted, and daily use should prevent the computer from suddenly powering down.
Disk structure:

Head: (head) is responsible for reading and writing data to the disc, each of which corresponds to a magnetic head
Tracks: (track) divides the disk into concentric circles, numbered 0-1023 from the outside
Sector: (sector) divides the track into a number of sectors, which is the smallest storage unit for the disk, with each sector being 512bytes
Cylinder: (cylinder) The center of all platters on the same disk is on the hinge, and the same numbered tracks on each disk face together to form a cylinder, for example, 0 tracks of all the discs make up 0 cylinder faces.

2. How the disk is addressed

?? The way disks are addressed can be divided into CHS and LBA.
CHS

采用24bit寻址,因此最大寻址空间为2^24*512byte=8GB地址的前10bit表示柱面(cylinder),因此柱面的最大数量为:2^10=1024  中间8bit为磁头(head),磁头数等于盘面数,最大盘面数为:2^8=256最后6bit为扇区(sector),每一磁道可划分的扇区数为2^6=64  

LBA

?? LBA is an integer that completes the disk-specific addressing by converting to CHS format, with 48bit addressing, so the maximum space supports 128PB

Therefore, when the disk capacity is less than 8GB, it is possible to use CHS or LBA addressing. However, when the disk capacity is greater than 8GB, only LBA addressing can be used.

Two. Disk partitioning

?? After a certain understanding of how the disk is structured and addressed, we can then partition the disk.

1. Partitioning method

Partitioning methods include: MBR and GPT
Mbr

?? Mbr:master Boot Record, released in 1982, uses 32bit to identify the number of sectors, with a maximum partition of 2T, divided by cylinder. The No. 0 Track No. 0 Sector of the entire disk records the OS boot and partition information, so this piece of sector is important for the entire disk.

 0磁道0扇区:512bytes            446bytes:boot loader            64bytes:分区表,每16bytes标识一个分区,因此MBR最多可划分为                            4个主分区或者3主分区+1扩展(扩展可分为n个逻辑分区)  

Gpt

?? GPT:GUID partition table supports 128 partitions with no primary or secondary points. Using 128bit to represent the disk and partition GPT partition table, automatic backup at the head and tail, compared to MBR, GPT can adapt to a larger level of data and have the partition information backup function.

Partitioning methods in 2.linux

?? In the Linux system, the SCSI, SATA, SAS interface hard drives are named SD, followed by the a,b,c,d ... To name, the same piece of silver plate of the different sections of the word with ... To differentiate the naming.
Lsblk

lsblk命令用于列出块设备信息,查看磁盘是够已经被OS识别。[[email protected]~]#lsblkNAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTsda      8:0    0  200G  0 disk ├─sda1   8:1    0    1G  0 part /boot├─sda2   8:2    0   50G  0 part /├─sda3   8:3    0   30G  0 part /data├─sda4   8:4    0    1K  0 part └─sda5   8:5    0    3G  0 part [SWAP]sdb      8:16   0   20G  0 disk sr0     11:0    1  3.7G  0 rom  /media/cdrom

Parted

parted命令用于对磁盘分区的划分,其操作都是实时生效的,因此使用的时候应该慎重。parted /dev/sdb mklabel gpt|msdos  指定磁盘为MBR或GPTparted /dev/sdb print              打印磁盘分区信息到屏幕上parted /dev/sdb mkpart primary     创建分区,默认单位为Mparted /dev/sdb rm 1               删除分区 1

Fdisk and Gdisk

gdisk是一个类fdisk的GPT分区工具,其使用方法和fdisk一样fdisk -l [-u] [device] 查看分区fdisk /dev/sda 之后将进入交互界面fdisk子命令:   p 分区列表    t 更改分区类型    n 创建新分区    d 删除分区    v 校验分区    u 转换单位    w 保存并退出    q 不保存并退出

After the partition is complete, you need to re-read the hard disk partition table with the following command

To see if the kernel has identified a new partition:

cat /proc/partitions

CENTOS6 notifies the kernel to re-read the hard disk partition table

新增分区用partx -a /dev/DEVICEkpartx -a /dev/DEVICE -f: force删除分区用partx -d --nr M-N /dev/sdb

CentOS 5, 7: Using Partprobe
Partprobe/dev/sdb

Three. File system
?? The file system is the software structure that the operating system uses to explicitly store the files and data structures on the device, and is responsible for managing and storing them. Different operating systems have different file systems, and the following are common file systems in Linux:

Ext2: For cases where the partition capacity is not too large and is not updated frequently, such as the/boot partition.
EXT3: is an improved version of EXT2, which supports logging capabilities to help the system recover from anomalies caused by an unhealthy shutdown. It is commonly used as a universal file system
EXT4: Is the latest version of Ext file system. Provides a number of new features, including nanosecond timestamps, creation and use of jumbo Files (16TB), maximum 1EB file system, and speed improvements
XFS:SGI, support for file systems up to 8EB
Swap memory in the Swap:linux, with a hard disk partition as the swap partition, the physical memory will be used in the swap of low-frequency files.

Create a file system for a new partition

Mkfs

mkfs.FS_TYPE /dev/DEVICE 其中FS_TYPE为文件系统mkfs -t FS_TYPE /dev/DEVICE 也可以用-t后面加上文件系统    -L : 设定卷标

Mke2fs

mke2fs是ext系列文件系统专用管理工具-t {ext2|ext3|ext4} 指定文件系统-b {1024|2048|4096} 指定分区中一个块的大小-L ‘LABEL‘          指定卷标-j: 相当于 -t ext3-i #: 为数据空间中每多少个字节创建一个inode;此大小不应该小于block的大小-N #:指定分区中创建多少个inode-I :单个inode记录占用的磁盘空间大小,128---4096-m #: 默认5%,为管理人员预留空间占总空间的百分比-O FEATURE[,...]:启用指定特性-O ^FEATURE:关闭指定特性

Tune2fs

tune2fs用来重新设定ext系列文件系统可调整参数的值-l:查看指定文件系统超级块信息;super block-L ‘LABEL‘:修改卷标-m #:修预留给管理员的空间百分比-j: 将ext2升级为ext3-O: 文件系统属性启用或禁用, –O ^has_journal-o: 调整文件系统的默认挂载选项,–o ^acl-U UUID: 修改UUID号dumpe2fs:块分组管理,32768块-h:查看超级块信息,不显示分组信息
Four. Mounting

?? After we have finished creating the file system on the hard disk, we can happily use the new hard drive after the last step is mounted.

Mount: An association between an additional file system and an existing directory of the root file system, which makes this directory a gateway to other file accesses

Mount

mount 查看当前已挂载的所有设备mount DEVICE MOUNT_POINT 其中DEVICE为要挂载的设备。       1.设备文件,例如/dev/sdb2       2.卷标,例如-L ‘/mnt/sda1‘       3.UUID,设备的唯一标识,128bitMOUNT_POINT为挂载点,一般为一个空文件夹。mount常用命令选项-o options:(挂载文件系统的选项),多个选项使用逗号分隔async:异步模式 sync:同步模式,内存更改时,同时写磁盘atime/noatime:包含目录和文件diratime/nodiratime:目录的访问时间戳auto/noauto:是否支持自动挂载,是否支持-a选项exec/noexec:是否支持将文件系统上运行应用程序dev/nodev:是否支持在此文件系统上使用设备文件suid/nosuid:是否支持suid和sgid权限remount:重新挂载ro:只读 rw:读写user/nouser:是否允许普通用户挂载此设备,/etc/fstab使用acl:启用此文件系统上的acl功能loop: 使用loop设备defaults:相当于rw, suid, dev, exec, auto, nouser, async   

Unloading

umount DEVICEumount MOUNT_POINT

The mount of the above command will expire after the system reboot, and the mount information needs to be written to the/etc/fstab if it is permanently mounted.

/etc/fstab each row defines a file system to mount, and each column is a different option.

tmpfs                   /dev/shm                                  tmpfs   defaults        0 0  1                         2                                                    3        4                5 61、要挂载的设备或伪文件系统设备文件LABEL:LABEL=""UUID:UUID=""伪文件系统名称:proc, sysfs2、挂载点3、文件系统类型:ext4,xfs,nfs,none4、挂载选项:defaults ,acl,bind5、转储频率:0:不做备份 1:每天转储 2:每隔一天转储6、fsck检查的文件系统的顺序:允许的数字是0, 1, 和2    0:不自检    1:首先自检;一般只有rootfs才用    2:非rootfs使用

By completing the above, we will be happy to use the new hard drive, but for more advanced mounting and file system settings, making the data on the hard disk more secure, you need to learn and master more deeply.

Linux disks and file systems

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.