linux 文件系统

linux 文件系统

概述

     文件系统其实就是一种数据的组织方法。格式化硬盘后操作系统就能在硬盘上进行操作。

文件系统组织数据的方法

     文件系统通常会将权限与属性放置到 inode 中,实际数据则放置到 data block 区块中。 另外,还有一个超级区块( superblock) 会记录整个文件系统的整体信息,包括 inode 与 block 的总量、使用量、剩余量等。每个 inode 与 block 都都有编号。CentOS操作系统7.0版本以后的系统默认都是采用了xfs文件系统。

 

superblock

     记录此filesystem的整体信息,包括inode/block的总量、使用量、剩余量,以及文件系统的格式与相关信息等;

inode

     记录文件的属性,一个文件占用一个inode,同时记录此文件的数据所在的 block号码。

block

     实际记录文件的内容,若文件太大时,会占用多个 block 。

xfs_db查看系统的superblock、inode、block信息

     使用xfs_db命令需要先umount /dev/sdb1。其中/dev/sdb1是xfs文件系统所在的分区,每个系统的可能分区不一样,有可能在/dev/sda。

命令:xfs_db-xr -c sb -c p /dev/sda1

以下运行结果就是superblock信息,其中包含inode、block信息。

运行结果

magicnum =0x58465342

blocksize = 4096                     //block size

dblocks = 262144                   //blocks count

rblocks = 0

rextents = 0

uuid =d4bcd44b-363a-478f-9ca8-84b53691210e

logstart = 131076

rootino = 64

rbmino = 65

rsumino = 66

rextsize = 1

agblocks = 65536

agcount = 4

rbmblocks = 0

logblocks = 2560

versionnum =0xb4b5

sectsize = 512                  //section szie

inodesize = 512               //indoe size

inopblock = 8

fname ="\000\000\000\000\000\000\000\000\000\000\000\000"

blocklog = 12

sectlog = 9

inodelog = 9

inopblog = 3

agblklog = 16

rextslog = 0

inprogress = 0

imax_pct = 25

icount = 512

ifree = 130

fdblocks = 211182

frextents = 0

uquotino = null

gquotino = null

qflags = 0

flags = 0

shared_vn = 0

inoalignmt = 4

unit = 0

width = 0

dirblklog = 0

logsectlog = 0

logsectsize = 0

logsunit = 1

features2 = 0x18a

bad_features2 =0x18a

features_compat =0

features_ro_compat= 0

features_incompat= 0x1

features_log_incompat= 0

crc = 0x5b6db7c6(correct)

spino_align = 0

pquotino = null

lsn = 0x100001177

meta_uuid =00000000-0000-0000-0000-000000000000

 

结果说明

magicnum    superblock magic number, 0x58465342('XFSB').

                     blocksize   filesystem block size in bytes.

                     dblocks     number of filesystem blocks present in thedata subvolume.

                     rblocks     number of filesystem blocks present in therealtime subvolume.

                     rextents    number of realtime extents that rblockscontain.

                     uuid        unique identifier of the filesystem.

                     logstart    starting filesystem block number of the log(journal).  If this value is 0 the log is"external".

                     rootino     root inode number.

                     rbmino      realtime bitmap inode number.

                     rsumino     realtime summary data inode number.

                     rextsize    realtime extent size in filesystem blocks.

                     agblocks   size of an allocation group in filesystem blocks.

                     agcount     number of allocation groups.

                     rbmblocks   number of realtime bitmap blocks.

                     logblocks   number of log blocks (filesystem blocks).

                     versionnum  filesystem version information.  This value is currently 1, 2, 3, or 4 in thelow 4 bits.  If the low bits are 4 thenthe

                                 other bitshave additional meanings.  1 is theoriginal value.  2 means that attributeswere used.  3 means that  version

                                 2  inodes (large  link counts) were used.  4 is the bitmask version of the versionnumber.  In this case, the other bits

                                 are used asflags (0x0010: attributes were used, 0x0020: version 2 inodes were used,0x0040: quotas  were  used, 0x0080:

                                 inode  cluster alignment  is  in force, 0x0100: data stripe alignment is in force, 0x0200: the shared_vnfield is used,

                                 0x1000:unwritten extent tracking is on, 0x2000: version 2 directories are in use).

                     sectsize    sector size in bytes, currently always512.  This is the size of the superblockand the other header blocks.

                     inodesize   inode size in bytes.

                     inopblock   number of inodes per filesystem block.

                     fname       obsolete, filesystem name.

                     fpack       obsolete, filesystem pack name.

                     blocklog    log2 of blocksize.

                     sectlog     log2 of sectsize.

                     inodelog    log2 of inodesize.

                     inopblog    log2 of inopblock.

agblklog    log2 of agblocks (rounded up).

                     rextslog    log2 of rextents.

                     inprogress  mkfs.xfs(8) or xfs_copy(8) aborted beforecompleting this filesystem.

                     imax_pct    maximum percentage of filesystem space usedfor inode blocks.

                     icount      number of allocated inodes.

                     ifree       number of allocated inodes that are notin use.

                     fdblocks    number of free data blocks.

                     frextents   number of free realtime extents.

                     uquotino    user quota inode number.

                     pquotino    project quota inode number; this iscurrently unused.

                     qflags      quota status flags (0x01: user quotaaccounting is on, 0x02: user quota limits are enforced, 0x04:  quotacheck has  been

                                 run  on user quotas, 0x08: project quota accounting is on, 0x10: project quotalimits are enforced, 0x20: quotacheck has

                                 been run onproject quotas).

                     flags       random flags. 0x01: only read-onlymounts are allowed.

                     shared_vn   shared version number (shared readonlyfilesystems).

                     inoalignmt  inode chunk alignment in filesystem blocks.

                     unit        stripe or RAID unit.

                     width       stripe or RAID width.

                     dirblklog   log2 of directory block size (filesystemblocks).

 

xfs文件系统相关的命令

xfs_admin、xfs_db 、xfs_freeze、xfs_info       xfs_logprint、xfs_mkfile、xfs_repair  、xfontsel 、xfs_bmap 、xfsdump、 xfs_fsr、xfsinvutil、xfs_mdrestore、xfs_ncheck 、xfsrestore 、xfreerdp、xfs_copy、xfs_estimate   xfs_growfs、 xfs_io、xfs_metadump、xfs_quota 、xfs_rtcp  。

这些命令的使用方法在这里就不一一列出了。

 

附录

磁盘的物理组成

整颗磁盘的组成主要有:

1)圆形的盘片( 主要记录数据的部分),一个硬盘有可能有多个盘片。

2)机械手臂,与在机械手臂上的磁头( 可读写盘片上的数据) 。

3)主轴马达,可以转动盘片,让机械手臂的磁头在盘片上读写数据。

 

盘片上的物理组成

1)扇区( Sector)为最小的物理储存单位,且依据磁盘设计的不同,目前主要有 512Bytes。不同的硬盘设计可能导致扇区的大小可能为1024、4096字节。

2)将扇区组成一个圆,那就是柱面(Cylinder) ;

 

MBR 分区表中,第一个扇区最重要,里面有:( 1) 主要开机区( Master boot record,MBR) 及分区表( partition table) , 其中 MBR 占有 446 Bytes,而 partition table 则占有 64 Bytes。

 

硬盘分区后的详细信息

[root@localhost ~]# fdisk -l

磁盘 /dev/sda:21.5 GB, 21474836480 字节,41943040 个扇区

Units = 扇区 of 1 * 512 = 512 bytes

扇区大小(逻辑/物理):512 字节 / 512 字节

I/O 大小(最小/最佳):512 字节 / 512 字节

磁盘标签类型:dos

磁盘标识符:0x0000306f

 

   设备 Boot      Start         End      Blocks  Id  System

/dev/sda1   *       2048     2099199     1048576  83  Linux

/dev/sda2         2099200   41943039    19921920   8e Linux LVM

从上图看出,我的硬盘的扇区是512字节。硬盘分了两个区,分别为/dev/sda1、/dev/sda2。

 

df -T 只可以查看已经挂载的分区和文件系统类型。

[root@localhost~]# df -T

文件系统            类型        1K-块     已用    可用 已用% 挂载点

/dev/mapper/cl-rootxfs      17811456 13677300 4134156   77% /

devtmpfs            devtmpfs   483408       0  483408    0% /dev

tmpfs               tmpfs      499316        0 499316    0% /dev/shm

tmpfs               tmpfs      499316     7224 492092    2% /run

tmpfs               tmpfs      499316        0 499316    0% /sys/fs/cgroup

/dev/sda1           xfs       1038336  226456  811880   22% /boot

tmpfs               tmpfs       99864       20  99844    1% /run/user/0

其中类型就是文件系统类型。

参考资料

[1]. https://en.wikipedia.org/wiki/Hard_disk_drive

[2]. https://en.wikipedia.org/wiki/Cylinder-head-sector

[3]. man xfs_db

[4].http://xfs.org/docs/xfsdocs-xml-dev/XFS_User_Guide/tmp/en-US/html/index.html

[5].http://xfs.org/docs/xfsdocs-xml-dev/XFS_User_Guide/tmp/en-US/html/ch11s11.html

[6].http://xfs.org/docs/xfsdocs-xml-dev/XFS_Filesystem_Structure/tmp/en-US/html/index.html 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值