大纲node
1、硬盘物理结构及相关结构linux
2、硬盘逻辑结构及相关概念shell
3、Ext2文件系统逻辑结构vim
4、读取、建立、删除、复制、剪切过程centos
5、软连接与硬连接联系与区别缓存
6、虚拟文件系统安全
6、文件系统管理相关命令bash
1、硬盘物理结构及相关概念网络
1.硬盘内部视角实物图数据结构
2.硬盘内部视角逻辑图
3.扇区、磁道、柱面图
磁头(head)数:每一个盘片通常有上下两面,分别对应1个磁头,共2个磁头,实现数据的存取
磁道(track):当磁盘旋转时,磁头若保持在一个位置上,则每一个磁头都会在磁盘表面划出一个圆形轨迹,这些圆形轨迹就叫作磁道,从外边缘的0开始编号,根据磁化方向来存数数据0和1
柱面(cylinder):不一样盘片的相同编号的磁道构成的圆柱面就被称之为柱面,磁盘的柱面数与一个盘面上的磁道数是相等的
扇区(sector):每一个磁道都别切分红不少扇形区域,每一个磁道的扇区数量相同,每一个扇区大小为512字节
圆盘(platter):就是硬盘的盘片,为实现大容量,通常都是多个
硬盘的容量=柱面数×磁头数×扇区数×512(字节数)
2、硬盘逻辑结构及相关概念
1.总体逻辑结构图
2.MBR(Master Boot Record)
硬盘的0柱面、0磁头、1扇区称为主引导扇区(也叫主引导记录MBR)。它由三个部分组成:硬盘主引导程序(BootLoader)、硬盘分区表DPT(Disk Partition table)和魔数(Magic Number)。
Boot Loader:主引导程序,启动操做系统的一段代码,占446个字节
DPT:占64个字节,硬盘中分区有多少以及每一分区的大小都记在其中
Magic Number:占2个字节,固定为0xAA55或0x55AA,这取决于处理器类型,若是是小端模式处理器(如Intel系列),则该值为0xAA55;若是是大端模式处理器(如Motorola6800),则该值为0x55AA
3.主分区、扩展分区、逻辑分区示意图
①主分区+扩展分区<=4
②扩展分区最多只有一个
③要么是三主一扩展,要么是四个主分区,那么剩余未分区的空间将没法使用
4.Ext2文件系统逻辑结构
一个分区最开始处是Boot Sector,而后就是多个块组每一个块组又能够细分为以下组成部分:
Super Block:记录此 filesystem 的总体信息,包括inode/block的总量、使用量、剩余量, 以及文件系统的格式与相关信息等;因为super block很重要 ,在每一个 block group都会存一份进行备份.
GDT:Group Descriptor Table,块组描述符,由不少块组描述符组成,整个分区分红多少个块组就对应有多少个块组描述符。每一个块组描述符(Group Descriptor)存储一个块组的描述信息,例如在这个块组中从哪里开始是inode表,从哪里开始是数据块,空闲的inode和数据块还有多少个等等。和超级块相似,块组描述符表在每一个块组的开头也都有一份拷贝
Block Bitmap:块位图就是用来描述整个块组中哪些块已用哪些块空闲的,它自己占一个块,其中的每一个bit表明本块组中的一个块,这个bit为1表示该块已用,这个bit为0表示该块空闲可用
inode Bitmap:和块位图相似,自己占一个块,其中每一个bit表示一个inode是否空闲可用
inode Table:一个文件除了数据须要存储以外,一些描述信息也须要存储,例如文件类型(常规、目录、符号连接等),权限,文件大小,建立/修改/访问时间等,也就是ls-l命令看到的那些信息,这些信息存在inode中而不是数据块中,每一个文件都有一个inode,一个块组中的全部inode组成了inode表,inode表占多少个块在格式化时就要决定并写入块组描述符中
Data Blocks:对于常规文件,文件的数据存储在数据块中,对于目录,该目录下的全部文件名和目录名存储在数据块中,文件名保存在它所在目录的数据块中,除文件名以外,ls -l命令看到的其它信息都保存在该文件的inode中,目录也是一种文件,是一种特殊类型的文件,对于符号连接,若是目标路径名较短则直接保存在inode中以便更快地查找,若是目标路径名较长则分配一个数据块来保存设备文件、FIFO和socket等特殊文件没有数据块,设备文件的主设备号和次设备号保存在inode中
Inode Table
目录文件
注:
①其实文件名和文件类型都是在目录中存放,而文件的其余元数据信息则是在Inode中存放
②文件系统各分区之间物理视角上是并行的,逻辑视角上必须得有上下级关系,全部的文件都必须直接或间接从根开始
4、读取、建立、删除、复制、剪切过程
一、读取文件:例如/etc/httpd/httpd.conf
首先根是自引用的,也就是根的Inode号是已知的,再根据Inode Table能够知道根的Inode号对应的Block号,而后找到对应的block,block里面有个目录项,也即Dentry,每一个目录项记录了根下全部直接子目录的Inode与文件名的对应关系(也包括文件类型等),例如var对应的Inode号为2883585,etc对应的Inode号为1507329等等,此时找到etc文件对应的Inode号,再经过查找Inode Table能够得知etc文件对应的Block,再经过读取Block里面的Dentry能够得知httpd文件对应的Inode,再查找Inode Table能够查到httpd文件对应的Block,再在对应的Block里面查询Dentry能够得知httpd.conf文件对应的Inode号,再次查询Inode Table能够找到对应的Block,因而数据就能够读取了
二、建立文件:例如/etc/testfile.txt
想要建立一个文件,首先得先给这个文件分配Inode和Block。首先扫描Inode Bitmap查找空闲Inode,再去Inode Table中写入想要建立文件的元数据,例如权限、属主属组、大小、时间戳、以及这个Inode对应所占据的Block。而后再找到根的Inode,找到根对应的Block,里面Dentry记录了etc及其对应的Inode,再经过Inode Table找到etc文件对应的Block,因而在Dentry里面添加一条记录,testfile.txt与其对应的Inode号,文件类型等信息。到此一个文件便建立了。
三、删除文件:例如/etc/fstab
删除文件直接上级目录(etc)里面的那条Dentry记录,Inode Bitmap里面把文件(fstab)原先对应的Inode号标记为未使用,Block Bitmap中把文件(fstab)原先对应的Block标记为未使用。删除文件自己并无删除文件所对应的Block和Inode,也就是说Block上的数据并无被抹除,除非后面向其Block中覆盖数据
四、复制文件
复制文件本质就是新建一个文件,并填充源文件数据的过程,详细可参考上面的建立和读取文件过程
五、剪切文件
在同一个分区下,剪切速度很是快,这是由于其本质也只是将Dentry记录换一个目录而已,因此根本就不涉及什么耗时的操做。而跨分区剪切文件的过程其实就是在另一个分区上建立一个新文件,并复制,复制完成以后再删除原先分区上数据的一个过程。
5、软链接与硬连接联系与区别
一、软链接(符号连接)与硬连接联系
软链接本质:在Inode Table中本该存储Block号信息的地方存储了一个路径,如:/etc/httpd/httpd.conf,因此软链接文件的大小都是其对应的文件路径的字符个数
硬连接本质:Inode号相同的文件彼此均可称为硬连接,只是再另一个目录中添加的Dentry记录为同一个Inode而已
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
ln
-
make
links between files
# 给文件建立连接
SYNOPSIS
ln
[-s -
v
] SRC DEST
-s:建立软连接
-
v
:显示建立详细过程
[root@soysauce
test
]
# ll /etc/rc.sysinit # 权限为777,而且大小为所指向的字符个数
lrwxrwxrwx. 1 root root 15 Aug 28 10:32
/etc/rc
.sysinit -> rc.d
/rc
.sysinit
[root@soysauce
test
]
# ln -s inittab inittab_soft # 建立软链接
[root@soysauce
test
]
# ln inittab inittab_hard # 建立硬连接
[root@soysauce
test
]
# ll -i
total 8
265301 -rw-r--r-- 2 root root 884 Nov 23 13:25 inittab
265301 -rw-r--r-- 2 root root 884 Nov 23 13:25 inittab_hard
# 硬连接inode号与源文件相同
265310 lrwxrwxrwx 1 root root 7 Nov 23 13:55 inittab_soft -> inittab
[root@soysauce
test
]
# ll -i
total 8
265301 -rw-r--r-- 2 root root 884 Nov 23 13:25 inittab
# 此时硬连接次数都为2
265301 -rw-r--r-- 2 root root 884 Nov 23 13:25 inittab_hard
265310 lrwxrwxrwx 1 root root 7 Nov 23 13:55 inittab_soft -> inittab
[root@soysauce
test
]
# rm -f inittab # 删除源文件
[root@soysauce
test
]
# ll -i
total 4
265301 -rw-r--r-- 1 root root 884 Nov 23 13:25 inittab_hard
# 此时硬连接次数变为了1
265310 lrwxrwxrwx 1 root root 7 Nov 23 13:55 inittab_soft -> inittab
# 此时软链接也一直在闪烁
[root@soysauce
test
]
# head -3 inittab_hard # 由于篇幅缘由,顾只查看3行
# inittab is only used by upstart for the default runlevel.
#
# ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
|
二、软链接(符号连接)与硬连接区别
硬连接:
①只能对文件建立,不能应用于目录
②不能跨文件系统
③建立硬连接会增长文件被连接的次数
④硬连接次数为1时,再删除就是完全删除了
⑤删除源文件不会影响连接文件
软连接:
①可应用于目录
②能够跨文件系统
③不会增长被连接文件的连接次数
④其大小为指定的路径所包含的字符个数
⑤删除源文件会影响连接文件
3.硬连接与复制的区别
互为硬连接的两文件inode号确定是相同的,对应的block号也是相同的;而复制的文件inode号和block号也确定不相同,只是block里面存储的数据是同样而已
6、虚拟文件系统
虚拟文件系统又称虚拟文件系统转换(Virual Filesystem Switch ,简称VFS)。说它虚拟,是由于它全部的数据结构都是在运行之后才创建,并在卸载时删除,而在磁盘上并无存储这些数据结构,显然若是只有VFS,系统是没法工做的,由于它的这些数据结构不能凭空而来,只有与实际的文件系统,如Ext二、Minix、MSDOS、VFAT等相结合,才能开始工做,因此VFS并非一个真正的文件系统。与VFS相对,咱们称Ext二、Minix、MSDOS等为具体文件系统。
VFS与内核其它子系统之间关系
VFS提供一个统一的接口(实际上就是file_operatoin数据结构),一个具体文件系统要想被Linux支持,就必须按照这个接口编写本身的操做函数,而将本身的细节对内核其它子系统隐藏起来。于是,对内核其它子系统以及运行在操做系统之上的用户程序而言,全部的文件系统都是同样的。实际上,要支持一个新的文件系统,主要任务就是编写这些接口函数。
归纳说来,VFS主要有如下几个做用:
(1)对具体文件系统的数据结构进行抽象,以一种统一的数据结构进行管理。
(2)接受用户层的系统调用 ,例如write、open、stat、link等等。
(3)支持多种具体文件系统之间相互访问。
(4)接受内核其余子系统的操做请求,特别是内存管理子系统
注:以上内容都是摘自深刻分析Linux内核源码第8章第一节VFS概述
7、文件系统管理相关命令
一、fdisk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
fdisk
- Partition table manipulator
for
Linux
# Linux分区表操做工具软件
SYNOPSIS
fdisk
[-uc] [-b sectorsize] [-C cyls] [-H heads] [-S sects] device
交互式命令
m:显示帮助信息
p: 显示当前硬件的分区,包括没保存的改动
n: 建立新分区,e: 扩展分区,p: 主分区
d: 删除一个分区
w: 保存退出
q: 不保存退出
t: 修改分区类型,L: 查看全部支持的分区类型
l: 显示全部支持的分区类型
[root@soysauce ~]
# fdisk /dev/sdb
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (
command
'c'
) and change display
units
to
sectors (
command
'u'
).
Command (m
for
help): p
# 显示全部的分区
Disk
/dev/sdb
: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors
/track
, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical
/physical
): 512 bytes / 512 bytes
I
/O
size (minimum
/optimal
): 512 bytes / 512 bytes
Disk identifier: 0x84c99918
Device Boot Start End Blocks Id System
/dev/sdb1
1 262 2104483+ 83 Linux
Command (m
for
help): n
# 新建一个分区
Command action
e extended
p primary partition (1-4)
p
# 创建主分区
Partition number (1-4): 2
# 指定分区号
First cylinder (263-2610, default 263):
# 分区起始柱面,默认便可
Using default value 263
Last cylinder, +cylinders or +size{K,M,G} (263-2610, default 2610): +3G
# 分区结束柱面,可直接指定大小
Command (m
for
help): t
# 修改分区类型
Partition number (1-4): 2
Hex code (
type
L to list codes): L
# 输入t以后是L选项,若是直接查看则是l
0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 39 Plan 9 82 Linux swap / So c1 DRDOS
/sec
(FAT-
2 XENIX root 3c PartitionMagic 83 Linux c4 DRDOS
/sec
(FAT-
3 XENIX usr 40 Venix 80286 84 OS
/2
hidden C: c6 DRDOS
/sec
(FAT-
4 FAT16 <32M 41 PPC PReP Boot 85 Linux extended c7 Syrinx
5 Extended 42 SFS 86 NTFS volume
set
da Non-FS data
6 FAT16 4d QNX4.x 87 NTFS volume
set
db CP
/M
/ CTOS / .
7 HPFS
/NTFS
4e QNX4.x 2nd part 88 Linux plaintext de Dell Utility
8 AIX 4f QNX4.x 3rd part 8e Linux LVM
df
BootIt
9 AIX bootable 50 OnTrack DM 93 Amoeba e1 DOS access
a OS
/2
Boot Manag 51 OnTrack DM6 Aux 94 Amoeba BBT e3 DOS R
/O
b W95 FAT32 52 CP
/M
9f BSD
/OS
e4 SpeedStor
c W95 FAT32 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi eb BeOS fs
e W95 FAT16 (LBA) 54 OnTrackDM6 a5 FreeBSD ee GPT
f W95 Ext'd (LBA) 55 EZ-Drive a6 OpenBSD ef EFI (FAT-12
/16/
10 OPUS 56 Golden Bow a7 NeXTSTEP f0 Linux
/PA-RISC
b
11 Hidden FAT12 5c Priam Edisk a8 Darwin UFS f1 SpeedStor
12 Compaq diagnost 61 SpeedStor a9 NetBSD f4 SpeedStor
14 Hidden FAT16 <3 63 GNU HURD or Sys ab Darwin boot f2 DOS secondary
16 Hidden FAT16 64 Novell Netware af HFS / HFS+ fb VMware VMFS
17 Hidden HPFS
/NTF
65 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 70 DiskSecure Mult b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 75 PC
/IX
bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 80 Old Minix be Solaris boot ff BBT
1e Hidden W95 FAT1
Hex code (
type
L to list codes): 82
Changed system
type
of partition 2 to 82 (Linux swap / Solaris)
Command (m
for
help): w
# 保存退出
The partition table has been altered!
Calling ioctl() to re-
read
partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@soysauce ~]
# cat /proc/partitions # 查看当前内核已识别的分区
major minor
#blocks name
8 0 20971520 sda
8 1 512000 sda1
8 2 20458496 sda2
8 16 20971520 sdb
8 17 2104483 sdb1
253 0 18423808 dm-0
253 1 2031616 dm-1
[root@soysauce ~]
# partx -a /dev/sdb # 通知内核重读分区表信息,RHEL5或者CentOS上通常是partprobe命令
BLKPG: Device or resource busy
error adding partition 1
[root@soysauce ~]
# cat /proc/partitions
major minor
#blocks name
8 0 20971520 sda
8 1 512000 sda1
8 2 20458496 sda2
8 16 20971520 sdb
8 17 2104483 sdb1
8 18 3156772 sdb2
# 此时sdb2已经读取到了
253 0 18423808 dm-0
253 1 2031616 dm-1
[root@soysauce ~]
# mkswap -L MYDATA/dev/sdb2 # 格式化交换分区
Setting up swapspace version 1, size = 3156768 KiB
LABEL=MYDATA, UUID=2f0ca25b-e6f8-45ae-a239-00f5b38f7275
[root@soysauce ~]
# free -m
total used
free
shared buffers cached
Mem: 988 176 812 0 67 37
-/+ buffers
/cache
: 71 917
Swap: 1983 0 1983
# 此时还未启用刚才建立的那个交换分区
[root@soysauce ~]
# swapon /dev/sdb2 # 启用刚刚建立的交换分区
[root@soysauce ~]
# free -m
total used
free
shared buffers cached
Mem: 988 178 810 0 67 37
-/+ buffers
/cache
: 73 915
Swap: 5066 0 5066
# 此时能够看到已然生效
[root@soysauce ~]
# swapoff /dev/sdb2 # 关闭交换分区
[root@soysauce ~]
# free -m
total used
free
shared buffers cached
Mem: 988 176 812 0 67 37
-/+ buffers
/cache
: 71 917
Swap: 1983 0 1983
# 此时能够看到已然关闭
|
二、mke2fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
mke2fs - create an ext2
/ext3/ext4
filesystem
# 建立ext2/ext3/ext4文件系统
SYNOPSIS
mke2fs [options] DEVICE
-j:建立ext3类型文件系统
-b BLOCK_SIZE:指定块大小,默认为4096;可用取值为102四、2048或4096
-L LABEL:指定分区卷标
-m
#:指定预留给超级用户的块数百分比,默认值为%5
-i
#:用于指定为多少字节的空间建立一个inode,默认为8192;应为block的2^n倍
-t FSTYPE:指定文件系统类型
-N
#:指定inode个数
-F:强制建立文件系统,无论其是否处于挂载状态
-E:用户指定额外文件系统属性
-q:执行时不显示任何信息,经常使用于脚本
-c:检查是否有损坏的区块
[root@soysauce ~]
# fdisk /dev/sdb # 建立一个分区完整过程
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x84c99918.
Changes will remain
in
memory only,
until
you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (
command
'c'
) and change display
units
to
sectors (
command
'u'
).
Command (m
for
help): n
# 新建一个分区
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
# 本身选择分区号,1-4中选
First cylinder (1-2610, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +2G
Command (m
for
help): w
# 保存建立的分区并退出
The partition table has been altered!
Calling ioctl() to re-
read
partition table.
Syncing disks.
[root@soysauce ~]
# cat /proc/partitions # 查看当前内核已经读取到的分区信息
major minor
#blocks name
8 0 20971520 sda
8 1 512000 sda1
8 2 20458496 sda2
8 16 20971520 sdb
8 17 2104483 sdb1
# 我这里内核已经读取到了sdb1,而在CentOS5上可能须要执行prartprobe命令
253 0 18423808 dm-0
253 1 2031616 dm-1
[root@soysauce ~]
# mke2fs -j /dev/sdb1 # 建立ext3格式的文件系统
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS
type
: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
131648 inodes, 526120 blocks
26306 blocks (5.00%) reserved
for
the super user
First data block=0
Maximum filesystem blocks=541065216
17 block
groups
32768 blocks per group, 32768 fragments per group
7744 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Writing inode tables:
done
Creating journal (16384 blocks):
done
Writing superblocks and filesystem accounting information:
done
This filesystem will be automatically checked every 24 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@soysauce ~]
# mke2fs -t ext4 /dev/sdb1 # 建立ext4格式的文件系统
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS
type
: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
131648 inodes, 526120 blocks
26306 blocks (5.00%) reserved
for
the super user
First data block=0
Maximum filesystem blocks=541065216
17 block
groups
32768 blocks per group, 32768 fragments per group
7744 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Writing inode tables:
done
Creating journal (16384 blocks):
done
Writing superblocks and filesystem accounting information:
done
This filesystem will be automatically checked every 20 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
|
三、blkid
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
blkid -
command
-line utility to
locate
/print
block device attributes
# 定位或打印块设备属性信息
SYNOPSIS
blkid [options] [DEVICE]
-s <tag>:显示指定信息,默认显示全部信息
-o
format
:指定显示格式,经常使用list
[root@soysauce ~]
# blkid
/dev/sda1
: UUID=
"7a79d653-e9b7-43f2-a2c1-e41af29b3f5d"
TYPE=
"ext4"
/dev/sda2
: UUID=
"aNiMxY-uTa4-IcVC-1FD7-i2S9-kwnV-lF4BMS"
TYPE=
"LVM2_member"
/dev/mapper/vg_centos6-lv_root
: UUID=
"09b9916a-7424-4be3-9dc8-5222b699ef33"
TYPE=
"ext4"
/dev/mapper/vg_centos6-lv_swap
: UUID=
"2a88de6d-5333-4077-b13e-117bbf60c5d6"
TYPE=
"swap"
[root@soysauce ~]
# blkid -o device # 只显示设备名
/dev/sda1
/dev/sda2
/dev/mapper/vg_centos6-lv_root
/dev/mapper/vg_centos6-lv_swap
[root@soysauce ~]
# blkid -s UUID /dev/sda1 # 只显示/dev/sda1的UUID
/dev/sda1
: UUID=
"7a79d653-e9b7-43f2-a2c1-e41af29b3f5d"
|
四、e2lable
1
2
3
4
5
6
7
8
|
e2label - Change the label on an ext2
/ext3/ext4
filesystem
# 改变ext2/ext3/ext4文件系统的卷标
SYNOPSIS
e2label device [ new-label ]
[root@soysauce ~]
# e2label /dev/sdb1 SOYSAUCE # 修改/dev/sdb1卷标
[root@soysauce ~]
# e2label /dev/sdb1 # 查看/dev/sdb1卷标
SOYSAUCE
|
五、tune2fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
tune2fs - adjust tunable filesystem parameters on ext2
/ext3/ext4
filesystems
# 调整文件系统参数信息
SYNOPSIS
tune2fs [options] DEVICE
-j:不损害原有数据,将ext2升级至ext3
-L LABEL:设定或修改卷标
-m
#:调整预留百分比
-r
#:指定预留块数
-o:设定默认挂载选项,经常使用的acl
-c
#:指定挂载次数达到#次以后进行自检,0或-1表关闭此功能
-C
#:指定文件系统已经被挂载的次数
-i
#:每挂载使用多少天后进行自检;0或-1表示关闭此功能
-l:显示超级块中的信息
[root@soysauce ~]
# tune2fs -j /dev/sdb1 # 无损升级至ext3文件系统
tune2fs 1.41.12 (17-May-2010)
Creating journal inode:
done
This filesystem will be automatically checked every 22 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@soysauce ~]
# blkid /dev/sdb1
/dev/sdb1
: UUID=
"79d72bb3-9b67-45cd-8e77-2b37349db88c"
SEC_TYPE=
"ext2"
TYPE=
"ext3"
[root@soysauce ~]
# tune2fs -m 8 /dev/sdb1 # 调整预留块百分比为%8
tune2fs 1.41.12 (17-May-2010)
Setting reserved blocks percentage to 8% (42089 blocks)
[root@soysauce ~]
# tune2fs -l /dev/sdb1 # 查看超级块信息
tune2fs 1.41.12 (17-May-2010)
Filesystem volume name: <none>
Last mounted on: <not available>
Filesystem UUID: 79d72bb3-9b67-45cd-8e77-2b37349db88c
Filesystem magic number: 0xEF53
Filesystem revision
#: 1 (dynamic)
Filesystem features: has_journal ext_attr resize_inode dir_index filetype sparse_super large_file
Filesystem flags: signed_directory_hash
Default
mount
options: (none)
Filesystem state: clean
Errors behavior: Continue
Filesystem OS
type
: Linux
Inode count: 131648
Block count: 526120
Reserved block count: 42089
Free blocks: 500671
Free inodes: 131637
First block: 0
Block size: 4096
Fragment size: 4096
Reserved GDT blocks: 128
Blocks per group: 32768
Fragments per group: 32768
Inodes per group: 7744
Inode blocks per group: 484
Filesystem created: Mon Nov 23 20:24:17 2015
Last
mount
time
: n
/a
Last write
time
: Mon Nov 23 20:26:43 2015
Mount count: 0
Maximum
mount
count: 22
Last checked: Mon Nov 23 20:24:17 2015
Check interval: 15552000 (6 months)
Next check after: Sat May 21 20:24:17 2016
Reserved blocks uid: 0 (user root)
Reserved blocks gid: 0 (group root)
First inode: 11
Inode size: 256
Required extra isize: 28
Desired extra isize: 28
Journal inode: 8
Default directory
hash
: half_md4
Directory Hash Seed: 98e59dee-37cb-4cf4-96bb-47ab22e61c0d
Journal backup: inode blocks
|
六、dumpe2fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
dumpe2fs - dump ext2
/ext3/ext4
filesystem information
# 显示文件系统超级块信息和块组描述符
SYNOPSIS
dumpe2fs [options] DEVICE
-h:查看超级块信息,但不包括GDT(块组描述表)
[root@soysauce ~]
# dumpe2fs -h /dev/sdb1 # 查看超级块信息,不显示GDT
dumpe2fs 1.41.12 (17-May-2010)
Filesystem volume name: <none>
Last mounted on: <not available>
Filesystem UUID: 79d72bb3-9b67-45cd-8e77-2b37349db88c
Filesystem magic number: 0xEF53
Filesystem revision
#: 1 (dynamic)
Filesystem features: has_journal ext_attr resize_inode dir_index filetype sparse_super large_file
Filesystem flags: signed_directory_hash
Default
mount
options: (none)
Filesystem state: clean
Errors behavior: Continue
Filesystem OS
type
: Linux
Inode count: 131648
Block count: 526120
Reserved block count: 42089
Free blocks: 500671
Free inodes: 131637
First block: 0
Block size: 4096
Fragment size: 4096
Reserved GDT blocks: 128
Blocks per group: 32768
Fragments per group: 32768
Inodes per group: 7744
Inode blocks per group: 484
Filesystem created: Mon Nov 23 20:24:17 2015
Last
mount
time
: n
/a
Last write
time
: Mon Nov 23 20:26:43 2015
Mount count: 0
Maximum
mount
count: 22
Last checked: Mon Nov 23 20:24:17 2015
Check interval: 15552000 (6 months)
Next check after: Sat May 21 20:24:17 2016
Reserved blocks uid: 0 (user root)
Reserved blocks gid: 0 (group root)
First inode: 11
Inode size: 256
Required extra isize: 28
Desired extra isize: 28
Journal inode: 8
Default directory
hash
: half_md4
Directory Hash Seed: 98e59dee-37cb-4cf4-96bb-47ab22e61c0d
Journal backup: inode blocks
Journal features: (none)
Journal size: 64M
Journal length: 16384
Journal sequence: 0x00000001
Journal start: 0
|
七、fsck
1
2
3
4
5
6
7
8
9
10
|
fsck
- check and repair a Linux
file
system
# 检查并修复Linux文件系统
SYNOPSIS
-a:自动修复
-t FSTYPE:指定文件系统类型,能够不指,但必定不能指错
[root@soysauce ~]
# fsck /dev/sdb1 # 我这里文件系统是clean状态,因此没有检查
fsck
from util-linux-ng 2.17.2
e2fsck 1.41.12 (17-May-2010)
/dev/sdb1
: clean, 11
/131648
files, 25449
/526120
blocks
|
八、e2fsck
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
e2fsck - check a Linux ext2
/ext3/ext4
file
system
# 检查并修复ext系列文件系统
SYNOPSIS
e2fsck [options] DEVICE
-f:强制检查
-p:自动修复
[root@soysauce ~]
# e2fsck /dev/sdb1
e2fsck 1.41.12 (17-May-2010)
/dev/sdb1
: clean, 11
/131648
files, 25449
/526120
blocks
[root@soysauce ~]
# e2fsck -f /dev/sdb1 # 强制检查文件系统
e2fsck 1.41.12 (17-May-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/sdb1
: 11
/131648
files (0.0% non-contiguous), 25449
/526120
blocks
|
九、mount
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
mount
-
mount
a filesystem
# 挂载文件系统
SYNOPSIS
mount
[options] [-o options] DEVICE MOUNT_POINT
-a:表示挂载
/etc/fstab
文件中定义的全部文件系统
-n:默认状况下,
mount
命令每挂载一个设备,都会把挂载的设备信息保存至
/etc/mtab
文件;使用—n选项意味着挂载设备时,不把信息写入此文件
-t FSTYPE:指定正在挂载设备上的文件系统的类型;不使用此选项时,
mount
会调用blkid命令获取对应文件系统的类型
-r:只读挂载,挂载光盘时经常使用此选项
-w:读写挂载
-o:指定额外的挂载选项,也即指定文件系统启用的属性;
remount:从新挂载当前文件系统
ro:挂载为只读
rw:读写挂载
loop:挂载本地回环设备
挂载:将新的文件系统关联至当前根文件系统
卸载:将某文件系统与当前根文件系统的关联关系预以移除
[root@soysauce ~]
# mount # 不带任何参数的mount命令能够显示当前已挂载的文件系统
/dev/mapper/vg_centos6-lv_root
on /
type
ext4 (rw)
proc on
/proc
type
proc (rw)
sysfs on
/sys
type
sysfs (rw)
devpts on
/dev/pts
type
devpts (rw,gid=5,mode=620)
tmpfs on
/dev/shm
type
tmpfs (rw)
/dev/sda1
on
/boot
type
ext4 (rw)
none on
/proc/sys/fs/binfmt_misc
type
binfmt_misc (rw)
[root@soysauce ~]
# mount -o ro /dev/sdb1 /mnt/ # 以只读方式挂载
[root@soysauce ~]
# echo "hello" >> /mnt/a.txt
-
bash
:
/mnt/a
.txt: Read-only
file
system
# 不能写文件
[root@soysauce ~]
# mount -o remount,rw /mnt/ # 以可读写方式从新挂载
[root@soysauce ~]
# echo "hello" >> /mnt/a.txt
[root@soysauce ~]
# cd /mnt/
[root@soysauce mnt]
# ls
a.txt lost+found
[root@soysauce mnt]
# cat a.txt # 写入成功
hello
[root@soysauce ~]
# cat /etc/fstab
LABEL=/ / ext3 defaults,barrier=0 1 1
tmpfs
/dev/shm
tmpfs defaults 0 0
devpts
/dev/pts
devpts gid=5,mode=620 0 0
sysfs
/sys
sysfs defaults 0 0
proc
/proc
proc defaults 0 0
要挂载的设备 挂载点 文件系统类型 挂载选项 转储频率(每多少天作一次彻底备份) 文件系统检测次序(只有根能够为1)
|
十、fuser
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
fuser - identify processes using files or sockets
# 报告进程使用的文件或是网络套接字
SYNOPSIS
fuser [options] DEVICE
-
v
:查看某文件上正在运行的进程
-k:杀死正在访问某文件的进程
-m:显示访问挂载点的进程
[root@soysauce ~]
# mount /dev/sdb1 /mnt/ # 挂载/dev/sdb1至/mnt目录下
[root@soysauce ~]
# cd /mnt/ # 切换进/mnt目录
[root@soysauce mnt]
# umount /mnt/ # 此时我就站在/mnt目录下,卸载确定卸不掉
umount
:
/mnt
: device is busy.
(In some cases useful info about processes that use
the device is found by
lsof
(8) or fuser(1))
[root@soysauce mnt]
# fuser -km /mnt/ # 强行结束正在访问/mnt挂载点的进程,而后直接把我踢下线了...
/mnt/
: 1860c
Connection closed by foreign host.
Disconnected from remote host(CentOS6.5) at 22:20:33.
Type `help' to learn how to use Xshell prompt.
|
十一、free
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
free
- Display amount of
free
and used memory
in
the system
# 显示系统中已用的和未用的内存总和
SYNOPSIS
free
[-b | -k | -m] [-o] [-s delay ] [-t] [-l] [-V]
-m:以M为单位来显示
[root@soysauce ~]
# free -m
total used
free
shared buffers cached
Mem: 988 176 812 0 67 37
-/+ buffers
/cache
: 71 917
Swap: 1983 0 1983
第一行:内存总大小、已使用空间大小、剩余空间大小、共享内存、缓冲数据大小、缓存数据大小
第二行:UsedMem-(buffers+cached)为真实使用空间、FreeMem+(buffers+cached)为真实剩余空间
第三行:总交换分区大小、已使用交换分区大小、剩余交换分区大小
|
十二、du
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
du
- estimate
file
space usage
# 报告磁盘空间使用状况
SYNOPSIS
du
[OPTION]... [FILE]...
du
[OPTION]... --files0-from=F
-s:仅显示总计,只列出最后加总的值
-h:作单位换算的
[root@soysauce ~]
# du -sh /root/ # 统计总大小
1.3M
/root/
[root@soysauce ~]
# du -h /root/ # 统计目录下每单个文件大小
4.0K
/root/
.pki
/nssdb
8.0K
/root/
.pki
4.0K
/root/
.ansible
/cp
8.0K
/root/
.ansible
8.0K
/root/test
36K
/root/
.vim
/syntax
48K
/root/
.vim
20K
/root/
.
ssh
136K
/root/scripts
1.3M
/root/
|
1三、df
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
df
- report
file
system disk space usage
# 报告文件系统磁盘空间的使用状况
SYNOPSIS
df
[OPTION]... [FILE]...
-a:查看全部的文件系统
-h:作单位换算
-i:显示inode使用状况
-P:以POSIX风格显示
-T:显示文件系统类型
[root@soysauce ~]
# df -ihT # 显示Inode使用状况
Filesystem Type Inodes IUsed IFree IUse% Mounted on
/dev/mapper/vg_centos6-lv_root
ext4 1.1M 40K 1.1M 4% /
tmpfs tmpfs 124K 1 124K 1%
/dev/shm
/dev/sda1
ext4 126K 38 125K 1%
/boot
/dev/sdb1
ext3 129K 12 129K 1%
/mnt
[root@soysauce ~]
# df -hT # 显示磁盘空间使用状况
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg_centos6-lv_root
ext4 18G 2.3G 15G 14% /
tmpfs tmpfs 495M 0 495M 0%
/dev/shm
/dev/sda1
ext4 485M 33M 427M 8%
/boot
/dev/sdb1
ext3 2.0G 68M 1.8G 4%
/mnt
|
1四、dd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
dd
- convert and copy a
file
# 复制文件并对原文件进行转化和格式化处理
SYNOPSIS
dd
[OPERAND]...
dd
OPTION
if
=数据来源
of=数据存储目录
bs=
#:指定块大小,单位默认为字节,也能够指定M、G等
count=
#:指定读取的块数
seek=
#:建立数据文件时,跳过的空间大小
[root@soysauce ~]
# dd if=/dev/sda of=/root/mbr.back bs=512 count=1 # 备份mbr
1+0 records
in
1+0 records out
512 bytes (512 B) copied, 0.000675345 s, 758 kB
/s
[root@soysauce ~]
# dd if=/dev/zero of=/root/zerofile bs=1M count=1 seek=1023 # 跳过前面1023M,建立一个假的1G文件
1+0 records
in
1+0 records out
1048576 bytes (1.0 MB) copied, 0.00649022 s, 162 MB
/s
[root@soysauce ~]
# ll -h /root/zerofile # ls看到的是假的1G
-rw-r--r-- 1 root root 1.0G Nov 24 11:07
/root/zerofile
[root@soysauce ~]
# du -sh /root/zerofile # du看到的是真实的大小,为1M
1.0M
/root/zerofile
|
1五、mknod
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
mknod
-
make
block or character special files
# 建立块设备文件或字符设备文件
SYNOPSIS
mknod
[OPTION]... NAME TYPE [MAJOR MINOR]
-m:设置权限
-Z:设置安全的上下文
[root@soysauce ~]
# mknod /dev/mydev b 65 0 # 建立一个主设备号为65 次设备号为0的块设备文件
[root@soysauce ~]
# ll /dev/mydev
brw-r--r-- 1 root root 65, 0 Nov 24 11:34
/dev/mydev
[root@soysauce ~]
# mknod -m 600 /dev/mysdev b 65 1 # -m指定权限为600
[root@soysauce ~]
# ll /dev/mysdev
brw------- 1 root root 65, 1 Nov 24 11:36
/dev/mysdev
|
本文出自 “Hello,Linux” 博客,请务必保留此出处http://soysauce93.blog.51cto.com/7589461/1715655