Introduction to Linux File Systems

Introduction of hard disk interface:

    1. IDE:并行接口,133MB/s   
    2. SCSI:并行接口,Ultrascsi320, 320MB/S, UltraSCSI640, 640MB/S
    3. SATA:串行接口,6gbps    6g/8  GB/S  
    4. SAS:串行接口,6gbps  是SCSI升级版

The transmission rate of the parallel interface is slow because parallelism is easy to cause electromagnetic interference, so it can only be low-frequency . Although the
serial interface has only one device, it can be high-frequency, so the speed is higher than that of the parallel block.

Mechanical hard disk diagram:
Introduction to Linux File Systems

Introduction to MBR:

The Master Boot Record (MBR, Main Boot Record) is a piece of boot code located at the front of the disk. It is responsible for judging the legitimacy of the partition and locating the partition boot information when the disk operating system reads and writes the disk.
The MBR is divided into three parts:

  1. 446bytes: bootloader, program, the program to boot the operating system;
  2. 64bytes: partition table, each 16bytes identifies a partition, and there can only be 4 partitions in total;
  3. 2bytes: the validity identifier of the MBR area; 55AA is valid;

block partitioning tool fdisk

centos6 start starts from cylinder
centos7 start starts from sector

Introduction to common options

n: create new partition
d: delete existing partition
t: modify partition type
l: view all existing IDs
w: save and exit
q: do not save and exit
m: view help information
p: display existing partition information

Create extended partition

[root@localhost ~]# fdisk /dev/sdb
Command (m for help): n
Partition type:
   p   primary (3 primary, 0 extended, 1 free)
   e   extended
Select (default e): e
Selected partition 4
First sector (46528512-62914559, default 46528512):
Using default value 46528512
Last sector, +sectors or +size{K,M,G} (46528512-62914559, default 62914559): +1G
Partition 4 of type Extended and of size 1 GiB is set

Command (m for help): p

Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 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: 0x00099ba6

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      391167      194560   83  Linux
/dev/sda2          391168     4585471     2097152   82  Linux swap / Solaris
/dev/sda3         4585472    46528511    20971520   83  Linux
/dev/sda4        46528512    48625663     1048576    5  Extended

Add logical partition

Command (m for help): n
Partition type:
   p   primary (3 primary, 0 extended, 1 free)
   e   extended
Select (default e): e
Selected partition 4
First sector (46528512-62914559, default 46528512):
Using default value 46528512
Last sector, +sectors or +size{K,M,G} (46528512-62914559, default 62914559): +5G
Partition 4 of type Extended and of size 5 GiB is set

w save partition operation

Flash partition information to the kernel

[root@localhost ~]# partx -a /dev/sda
partx: /dev/sda: error adding partitions 1-3
[root@localhost ~]# partx -a /dev/sda
partx: /dev/sda: error adding partitions 1-6
[root@localhost ~]# partx -a /dev/sda
partx: /dev/sda: error adding partitions 1-6

#删除操作 慎用
#[root@localhost ~]# partx -d /dev/sda6

#查看
[root@localhost ~]# cat /proc/partitions
major minor  #blocks  name

   8        0   31457280 sda
   8        1     194560 sda1
   8        2    2097152 sda2
   8        3   20971520 sda3
   8        4          1 sda4
   8        5    2097152 sda5
   8        6    1048576 sda6
   8       16   10485760 sdb
  11        0    1048575 sr0

The above completes the creation of the partition, and then creates a file system on the partition

File system diagram

Introduction to Linux File Systems

inode view

[root@localhost ~]# ls -i
33574978 anaconda-ks.cfg

Metadata view

[root@localhost ~]# stat anaconda-ks.cfg
  File: ‘anaconda-ks.cfg’
  Size: 1587        Blocks: 8          IO Block: 4096   regular file
Device: 803h/2051d  Inode: 33574978    Links: 1
Access: (0600/-rw-------)  Uid: (    0/    root)   Gid: (    0/    root)
Context: system_u:object_r:admin_home_t:s0
Access: 2018-04-22 06:29:43.493008377 -0400
Modify: 2018-04-22 06:29:43.494008377 -0400
Change: 2018-04-22 06:29:43.494008377 -0400
 Birth: -

VFS classification (Virtual File System)

Linux file system: ext2 (no journal function), ext3, ext4, xfs, reiserfs, btrfs
CD: iso9660
Network file system: nfs, cifs
Cluster file system: gfs2, ocfs2
Kernel-level distributed file system: ceph
Windows file system : vfat, ntfs
Pseudo file system: proc, sysfs, tmpfs, hugepagefs
Unix file system: UFS, FFS, JFS
Swap file system: swap
User space distributed file system: mogilefs, moosefs, glusterfs


Specific implementation of mke2fs

mke2fs common options

mke2fs [OPTIONS] device
-t {ext2|ext3|ext4}: indicates the type of file system to be created
mkfs.ext4 = mkfs -t ext4 = mke2fs -t ext4
-b {1024|2048|4096}: indicates the block of the file system Size;
-L LABEL: specify volume label;
-j: create a file system ext3 with journaling function;
mke2fs -j = mke2fs -t ext3 = mkfs -t ext3 = mkfs.ext3
-i #: bytes-per-inode, specify The ratio of inode to bytes; that is, how many bytes to create an Indode;
-N #: Directly specify the number of inodes to be created for this file system;
-m #: Specify the reserved space, percentage; default 5%
-O [^]FEATURE: Create the target file system with the specified features;

# 格式化会损坏原有数据,慎用
[root@localhost ~]# mkfs.ext4 /dev/sda5
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)                            #每块大小
Fragment size=4096 (log=2)     
Stride=0 blocks, Stripe width=0 blocks
131072 inodes, 524288 blocks                       #inode数量  block数量
26214 blocks (5.00%) reserved for the super user   #超级块
First data block=0                                 #编号始
Maximum filesystem blocks=536870912                #编号末
16 block groups                                    #块组
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:               #超级块备份地址
    32768, 98304, 163840, 229376, 294912 

Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done

View inode size

[root@localhost ~]# dumpe2fs -h /dev/sda5 |grep node
数据块大小:524288*4096/1024/1024/1024 = 2G
inode数据大小:131072*256 /1024/1024 = 32M   
#所以是先有数据块,从数据块中提取部分作为inode

Label settings:

[root@localhost ~]# e2label /dev/sda5
mydata
[root@localhost ~]# e2label /dev/sda5 MYDATE
[root@localhost ~]# e2label /dev/sda5
MYDATE

blkid view file format type

[root@localhost ~]# blkid /dev/sda5
/dev/sda5: UUID="18003fb5-93d9-4822-b998-0f2f99323798" TYPE="ext4"

tune2fs View or modify some attributes of the ext series file system

Common options

-j: ext2 --> ext3;
-L LABEL: modify volume label;
-m #: adjust the percentage of reserved space;
-O [^]FEATHER: enable or disable a feature;
-o [^]mount_options: enable or disable Turn off some kind of default mount option

#View block usage

[root@localhost ~]# tune2fs -l /dev/sda5   

set acl property setfacl getfacl property

[root@localhost ~]# tune2fs -o acl  /dev/sda5
[root@localhost ~]# tune2fs -l /dev/sda5 |grep 'Default mount options'
[root@localhost ~]# tune2fs -o ^acl  /dev/sda5

Self-check tool e2fsck

Common options

-y: Automatically answer yes to all questions;
-f: Force detection even if the filesystem is clean;

[root@localhost ~]# e2fsck /dev/sda5
e2fsck 1.42.9 (28-Dec-2013)
MYDATE: clean, 11/131072 files, 69339/2097152 blocks

mount tool mount

Common options

-r: readonly, read-only mount;
-w: read and write, read-write mount;
-n: By default, the operation of device mounting or unmounting will be updated to the /etc/mtab file synchronously; -n uses To disable this feature;
-t vfstype: specify the type of file system on the device to be mounted; in most cases, it can be omitted, in this case mount will judge the file system type of the device to be mounted by blkid;
-L LABEL: Specify the device by volume label when mounting;
mount -L LABEL dir
-U UUID: specify the device by UUID when mounting;
mount -U UUID dir
-o options: mount option
sync/async: synchronous/asynchronous operation;
atime/noatime: whether the file or directory updates its access timestamp when it is accessed;
diratime/nodiratime: whether the directory updates its access timestamp when it is accessed;
remount: remount;
acl: support using the facl function;
ro: only Read
rw: read and write
dev/nodev: whether to allow the creation of device files on this device; mknod
exec/noexec: whether to allow running program files on this device;
auto/noauto: whether to automatically mount
user/nouser: whether to allow ordinary users to hang Load this file system;
suid/nosuid: whether to allow the special permissions of suid and sgid on program files to take effect;
relatime : Update atime when mtime is newer than atime
. Defaults: Use default options: rw, suid, dev, exec, auto, nouser, async, and relatime.

mount

[root@localhost mnt]# mount /dev/sda5 t1/
[root@localhost t1]# mount |grep 't1'
/dev/sda5 on /mnt/t1 type xfs (rw,relatime,seclabel,attr2,inode64,noquota)

uninstall

[root@localhost mnt]# umount t1/
[root@localhost mnt]# umount /dev/sda5

Force uninstall

[root@localhost mnt]# fuser -km t1

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324759562&siteId=291194637