高级Linux运维工程师必备技能(扫盲篇)

                      高级Linux运维工程师必备技能(扫盲篇)

                                            作者:尹正杰

版权声明:原创作品,谢绝转载!否则将追究法律责任。

  在了解文件系统之前,我们要学习一下磁盘存储数据的方式,大家都知道文件从内存若要持久化存储的话就得把它存到硬盘上,想毕都知道文件存入磁盘都是二进制存取的。那么硬盘是如何存储的呢?我们现在标配基本上都是1T呢,现在都是2017了,500G的硬盘都已经遭嫌弃了。
                      高级Linux运维工程师必备技能(扫盲篇)
1.生活小知识。
  上面是一幅图可以看到,有磁头,而且这个磁头是悬浮在盘面上的,如果这个盘面有震动,很可能直接滑到盘面,导致上面写的数据被划掉,造成数据丢失,因此,我们在购买硬盘的时候都写着不能强剧烈震动。硬盘在工作的时候,这个盘面一直在转,如果访问里面的数据,需要一定时间,我们称之为“平均寻道时间”。把不同盘面上的相同磁道(可以理解就是盘面上的一个圈,整个盘面有好多个这个样的打圈小圈形成的)划分成同一个分区内部。那么这些维护不同盘面的相同编号的磁道我们成为柱面(cylinder).磁盘划分实际上是按照柱面划分的,那么很显然在最外层的柱面划分出来的分区的性能是最好的,你可能会问为什么?原因很简单,就是在相同的角速度中,最外层的周长是最大(也就意味着它存储的数据将越多)。因此我们在划分分区的时候依次划分C,D,E硬盘,最先划分的是C盘(分区软件默认把C盘划分到最外层),因此大家都用C盘做系统盘是有原因的哟!
 
2.MBR分区
在整块硬盘的最外侧磁道上,在第零("0")个扇区上,这个扇区是不能用来划分区的,因为这个扇区上存放着整块磁盘的分区信息。这个分区通常被称作为MBR(Master Boot Record,主引导记录 )分区(现在都流行GPT分区了),这个扇区仅仅占用了512个字节(bytes),你可别小看这512bytes,
a>.它保函了引导加载器(bootloader,其占用了446bytes);
b>.fat,即分区表,其占用了64bytes,每16bytes一个分区,总共只能分区4个[据说比尔盖茨层发表过言论:“硬盘这么小,有谁能用到多余4个分区呢?)【当时的硬盘都很小而且特别贵,只有几百兆(M)大小】”;
c>.5A,其为十六进制的“5A”,占用最后2个字节,用来标记这个MBR分区是否是有效数据的(2个字节被填充了2个5A,MBR有效性标记)。
硬盘内部都是真空的,为什么呢?因为它要旋转,有的硬盘的转速高达1.5w/m,如果不坐车真空的这么高的转速很容易和真空中的微粒发生碰撞,导致温度过高!所以不要轻易拆开硬盘,基本上你拆开就不是真空了,即使拆开后能用,也用不了多长时间就会坏掉的。
 
3.扩展分区与逻辑分区
随着硬盘的存储数据进一步的增长,我们分区4个是远远够用的,因此需要从4个主分区中拿出一个分区单独,用来存放其他的分区信息我们叫它为“扩展分区”,如果这个扩展分区足够大,就可以对其进行划分多个分区让不同用户使用。因此这个扩展分区(引用额外的分区表)是不能被格式化的,这样它就不能被使用,需要额外划分出一个或多个逻辑分区才能被使用。
 
4.MBR分区方法
a>.4个主分区
b>.3个主分区和一个扩展分区。
注意:MBR最大支持2T的硬盘。大于2TB就得使用GPT分区格式!
 
5.硬盘接口
DMA:Direct Memory Access (直接内存访问机制)
磁盘设备存放于/dev/文件夹下,
IDE接口的磁盘:/dev/hda、/dev/hdb、/dev/hdc、/dev/hdd
SCSI接口的磁盘:/dev/sda、/dev/sdb、/dev/sdc、/dev/sdd
/dev/XdYZ
/dev/ 表示的是一个设备目录
X h IDE硬盘
s SATA、SISC、U盘
Y a 第一块硬盘
b 第二块硬盘
c 第三块硬盘
。。。。。。。。。。
 
Z 1-3表示主分区,4一般为扩展分区
5是逻辑分区第一个分区
6是逻辑分区第二个分区
。。。。。。。。。。
a>.IDE(ATA):并口,每个控制器可接两个硬盘,master/slave,133MB/S(这个速率就是被淘汰的根部原因)
/dev/hd[a-z](注意:在Centos6.x版本以后,所有的硬盘即便是IDE接口的都被识别为sd,早起的设备被设置为hd)
/dev//hda[1-4](标识4个主分区)
/dev/hda[5+](逻辑分区5开始)
b>.SCSI:Small Computer System Interface (小型计算机接口,在读取数据上效率很高,因为它有单独的SCSI控制器,容错能力强且抗衰老【但是价格贵啊,相同存储空间是机械硬盘的8倍价格呢!】) 速率:320mb/s 也是并口的 (有的人为了省钱用IDE做raid阵列)
c>.SATA(Serial):300Mbps,600Mbps,6Gbps
d>.SAS:6Gbps
e>.USB:2.0接口: 3.0接口:
6.查看系统是如何识别磁盘分区的
 [root@yinzhengjie ~]# cat /proc/partitions  #查看系统识别的分区
major minor #blocks name 8 0 292968750 sda
8 16 292968750 sdb
9 127 278290432 md127
259 0 512000 md127p1
259 1 277777408 md127p2
253 0 52428800 dm-0
253 1 33038336 dm-1
253 2 192307200 dm-2
[root@yinzhengjie ~]#
  注意:如果你对你的硬盘剩余的空间进行分区后,新加的分区信息内核是不能识别的,需要内核去重读硬件的分区表,重启是不顶事的!我在生产环境中就遇到过这么一个坑。
 
7.根在内核
  根做为访问文件的入口,那么这个根到底在硬盘上呢?还是在操作系统上呢?根实际上是在内核中,我们访问数据都是操作系统将这个硬盘挂在到了根下,然后我们去访问它而已。那你又会问了,那内核在哪啊?答案是在磁盘上。
实际上,在装载内核之前,先启动的是bootloader(内核未启动就还没有文件系统存在),bootloader区磁盘上找到内核并启动,内核启动后会自动生成一个“/”(根),并将磁盘的文件都挂在到“/”下,这就形成了文件系统。
 
8.linux目录
 /bin,/sbin                         #存放系统自身完成自己的启动和基本运行机制索要提供的程序;。
/usr/bin,/usr/sbin #存放完成操作系统基本功能的所提供的二进制程序;
/usr/local/bin,/usr/local/sbin #存放第三方程序;
/lib,/lib64,/usr/lib,/usr/lib64 #存放库文件的;
/etc/     #存放配置文件的;
/media,/mnt      #用于挂在的目录,当然你也可以自定义的;
/dev     #存放各种设备文件;
/proc,/sys    #存放运行中的内存映射数据;
/home,/root      #存放各普通用户的家目录,比如 /home/yinzhengjie;
/var    #存放日志的目录;
/opt,/misc    #触发挂在目录;
/srv     #存放服务相关数据的;
/tmp     #存放各种临时文件,每次关机时自动清理;
/boot       #存放内核、引导菜单等启动文件;
 #!/usr/bin/env python
#_*_coding:utf-8_*_
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/
#EMAIL:y1053419035@qq.com '''
/:根目录,一般根目录下只存放目录,不要存放文件,/etc、/bin、/dev、/lib、/sbin应该和根目录放置在一个分区中 /bin:/usr/bin:可执行二进制文件的目录,如常用的命令ls、tar、mv、cat等。 /boot:放置linux系统启动时用到的一些文件。/boot/vmlinuz为linux的内核文件,以及/boot/gurb。建议单独分区,分区大小200M即可 /dev:存放linux系统下的设备文件,访问该目录下某个文件,相当于访问某个设备,常用的是挂载光驱mount /dev/cdrom /mnt。 /etc:系统配置文件存放的目录,不建议在此目录下存放可执行文件,重要的配置文件有/etc/inittab、/etc/fstab、/etc/init.d、/etc/X11、/etc/sysconfig、/etc/xinetd.d修改配置文件之前记得备份。 注:/etc/X11存放与x windows有关的设置。 /home:系统默认的用户家目录,新增用户账号时,用户的家目录都存放在此目录下,~表示当前用户的家目录,~test表示用户test的家目录。建议单独分区,并设置较大的磁盘空间,方便用户存放数据 /lib:/usr/lib:/usr/local/lib:系统使用的函数库的目录,程序在执行过程中,需要调用一些额外的参数时需要函数库的协助,比较重要的目录为/lib/modules。 /lost+fount:系统异常产生错误时,会将一些遗失的片段放置于此目录下,通常这个目录会自动出现在装置目录下。如加载硬盘于/disk 中,此目录下就会自动产生目录/disk/lost+found /mnt:/media:光盘默认挂载点,通常光盘挂载于/mnt/cdrom下,也不一定,可以选择任意位置进行挂载。 /opt:给主机额外安装软件所摆放的目录。如:FC4使用的Fedora 社群开发软件,如果想要自行安装新的KDE 桌面软件,可以将该软件安装在该目录下。以前的 Linux 系统中,习惯放置在 /usr/local 目录下 /proc:此目录的数据都在内存中,如系统核心,外部设备,网络状态,由于数据都存放于内存中,所以不占用磁盘空间,比较重要的目录有/proc/cpuinfo、/proc/interrupts、/proc/dma、/proc/ioports、/proc/net/*等 /root:系统管理员root的家目录,系统第一个启动的分区为/,所以最好将/root和/放置在一个分区下。 /sbin:/usr/sbin:/usr/local/sbin:放置系统管理员使用的可执行命令,如fdisk、shutdown、mount等。与/bin不同的是,这几个目录是给系统管理员root使用的命令,一般用户只能"查看"而不能设置和使用。 /tmp:一般用户或正在执行的程序临时存放文件的目录,任何人都可以访问,重要数据不可放置在此目录下 /srv:服务启动之后需要访问的数据目录,如www服务需要访问的网页数据存放在/srv/www内 /usr:应用程序存放目录,/usr/bin存放应用程序,/usr/share存放共享数据,/usr/lib存放不能直接运行的,却是许多程序运行所必需的一些函数库文件。/usr/local:存放软件升级包。/usr/share/doc:系统说明文件存放目录。/usr/share/man: 程序说明文件存放目录,使用 man ls时会查询/usr/share/man/man1/ls.1.gz的内容建议单独分区,设置较大的磁盘空间 /var:放置系统执行过程中经常变化的文件,如随时更改的日志文件/var/log,/var/log/message:所有的登录文件存放目录,/var/spool/mail:邮件存放的目录,/var/run:程序或服务启动后,其PID存放在该目录下。建议单独分区,设置较大的磁盘空间
'''

Linux目录详细版本,猛戳这里!!

 
9.用来对设备进行分区的命令
用于分区的管理工具:fdisk,sfdisk,parted
a>.查看分区信息
 [root@yinzhengjie ~]# fdisk -l /dev/[sh]d[a-z]  #使用文件名通配过滤掉没有用的信息(不是正则表达式哟),可以看出下面只有2个硬盘

 Disk /dev/sda: 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: 0x00059922 Device Boot(是否可引导) Start End Blocks Id(对应文件系统的ID) System
/dev/sda1 *(*表示可以引导) 1 39 307200 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 39 2358 18631680 83 Linux
/dev/sda3 2358 2611 2031616 82 Linux swap / Solaris Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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: 0x00000000 [root@yinzhengjie ~]#
b>虚拟文件系统
              高级Linux运维工程师必备技能(扫盲篇)
VFS:(Virtual File System)#虚拟文件系统
基本文件系统:Ext3,Ext3,Ext4,Reiserfs(早起的suse用的就是该文件系统哟),xfs(支持单个巨大的文件),JFS(日志文件系统,IBM开发的),vfat,NTFS
交换分区:swap
集群文件系统:GFS2(红帽系统研发,谷歌都再用呢),OCFS2(甲骨文公司研发,用的人不多)
网络文件系统:NFS,smbfs(window是CIFS)
光盘:iso9660
c>.对磁盘进行分区
 #!/usr/bin/env python
#_*_coding:utf-8_*_
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/
#EMAIL:y1053419035@qq.com '''
fdisk:
d 删除分区
n:新建一个分区
p:列出已有分区
t:调至分区ID
l:列出内核支持的分区id
w:保存退出
q:不保存退出
m:帮助
'''
 #!/usr/bin/env python
#_*_coding:utf-8_*_
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/
#EMAIL:y1053419035@qq.com '''
[root@yinzhengjie ~]# 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 0x8614a108.
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): m #查看帮助
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only) Command (m for help): p #列出已有分区 Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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: 0x8614a108 Device Boot Start End Blocks Id System Command (m for help): n #新建一个分区
Command action
e extended #扩展分区
p primary partition (1-4) #主分区
p #选择主分区
Partition number (1-4): 1 #选择编号
First cylinder (1-1305, default 1): #选择分区的起始点,默认为1
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305): +1G #创建一个1G的主分区 Command (m for help): n #再新建一个分区
Command action
e extended
p primary partition (1-4)
p #选择类型为主分区
Partition number (1-4): 2 #设置编号为2
First cylinder (133-1305, default 133):
Using default value 133
Last cylinder, +cylinders or +size{K,M,G} (133-1305, default 1305): +1G #创建一个1G的分区 Command (m for help): n #再新建一个分区
Command action
e extended
p primary partition (1-4)
p #选择类型为主分区
Partition number (1-4): 3 #这只编号为3
First cylinder (265-1305, default 265):
Using default value 265
Last cylinder, +cylinders or +size{K,M,G} (265-1305, default 1305): +2G #创建一个2G的分区 Command (m for help): n #再新建一个分区
Command action
e extended
p primary partition (1-4)
e #由于已经设置了3个主分区了,所以我将第四个分区设置为扩展分区,便于我创建更多的逻辑分区
Selected partition 4
First cylinder (527-1305, default 527):
Using default value 527
Last cylinder, +cylinders or +size{K,M,G} (527-1305, default 1305):
Using default value 1305 Command (m for help): p #列出已有分区 Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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: 0x8614a108 Device Boot Start End Blocks Id System
/dev/sdb1 1 132 1060258+ 83 Linux #这就是主分区,ID为83
/dev/sdb2 133 264 1060290 83 Linux
/dev/sdb3 265 526 2104515 83 Linux
/dev/sdb4 527 1305 6257317+ 5 Extended #折就是扩展分区,ID为5 Command (m for help): n #新建一个分区
First cylinder (527-1305, default 527):
Using default value 527
Last cylinder, +cylinders or +size{K,M,G} (527-1305, default 1305): +5G #创建一个5G的逻辑分区。 Command (m for help): P #列出已有分区 Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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: 0x8614a108 Device Boot Start End Blocks Id System
/dev/sdb1 1 132 1060258+ 83 Linux #主分区
/dev/sdb2 133 264 1060290 83 Linux
/dev/sdb3 265 526 2104515 83 Linux
/dev/sdb4 527 1305 6257317+ 5 Extended #扩展分区
/dev/sdb5 527 1180 5253223+ 83 Linux #这就是新建的逻辑分区 Command (m for help): W #保存退出 验证是否分区成功:
[root@yinzhengjie ~]# 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: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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: 0x8614a108 Device Boot Start End Blocks Id System
/dev/sdb1 1 132 1060258+ 83 Linux
/dev/sdb2 133 264 1060290 83 Linux
/dev/sdb3 265 526 2104515 83 Linux
/dev/sdb4 527 1305 6257317+ 5 Extended
/dev/sdb5 527 1180 5253223+ 83 Linux Command (m for help): q [root@yinzhengjie ~]#
'''

用fdisk 工具对磁盘进行分区过程

 #!/usr/bin/env python
#_*_coding:utf-8_*_
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/
#EMAIL:y1053419035@qq.com #让操作系统重读分区表,获取最新的分区信息。
'''
[root@yinzhengjie ~]# cat /proc/partitions #查看系统识别的分区,发现没有我们的分区
major minor #blocks name 8 0 292968750 sda
8 16 292968750 sdb
9 127 278290432 md127
259 0 512000 md127p1
259 1 277777408 md127p2
253 0 52428800 dm-0
253 1 33038336 dm-1
253 2 192307200 dm-2
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# kpartx -l /dev/sdb #列出已添加的所有分区信息
sdb1 : 0 2120517 /dev/sdb 63
sdb2 : 0 2120580 /dev/sdb 2120580
sdb3 : 0 4209030 /dev/sdb 4241160
sdb4 : 0 2 /dev/sdb 8450190
sdb5 : 0 10506447 /dev/sdb 8450253
[root@yinzhengjie ~]# kpartx -af /dev/sdb #强行添加分区信息
[root@yinzhengjie ~]# kpartx -a /dev/sdb #重读分区表信息
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# ls /dev/sdb* #发现系统以及识别了这几个分区
/dev/sdb /dev/sdb1 /dev/sdb2 /dev/sdb3 /dev/sdb4 /dev/sdb5
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# cat /proc/partitions #查看分区表
major minor #blocks name 8 0 20971520 sda
8 1 307200 sda1
8 2 18631680 sda2
8 3 2031616 sda3
8 16 10485760 sdb
8 17 1060258 sdb1
8 18 1060290 sdb2
8 19 2104515 sdb3
8 20 1 sdb4
8 21 5253223 sdb5
253 0 1060258 dm-0
253 1 1060290 dm-1
253 2 2104515 dm-2
253 3 1 dm-3
253 4 5253223 dm-4
[root@yinzhengjie ~]# ''' #提示,如果你的操作系统是Centos5的话执行以下命令就好使了
[root@yinzhengjie ~]# partprobe #但是这个条命令不适合CentOs6!

用kpartx 让系统重读分区表

 #!/usr/bin/env python
#_*_coding:utf-8_*_
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/
#EMAIL:y1053419035@qq.com '''
[root@yinzhengjie ~]# 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: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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: 0x8614a108 Device Boot Start End Blocks Id System
/dev/sdb1 1 132 1060258+ 83 Linux
/dev/sdb2 133 264 1060290 83 Linux
/dev/sdb3 265 526 2104515 83 Linux
/dev/sdb4 527 1305 6257317+ 5 Extended
/dev/sdb5 527 1180 5253223+ 83 Linux Command (m for help): d #删除分区
Partition number (1-5): 5 #选择相应的编号,在她给定的数值内选取哟 Command (m for help): p #发现已经删除成功了 Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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: 0x8614a108 Device Boot Start End Blocks Id System
/dev/sdb1 1 132 1060258+ 83 Linux
/dev/sdb2 133 264 1060290 83 Linux
/dev/sdb3 265 526 2104515 83 Linux
/dev/sdb4 527 1305 6257317+ 5 Extended Command (m for help): w #保存配置并退出
The partition table has been altered! Calling ioctl() to re-read partition table.
Syncing disks.
[root@yinzhengjie ~]# '''

用fdisk删除分区信息

 #!/usr/bin/env python
#_*_coding:utf-8_*_
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/
#EMAIL:y1053419035@qq.com '''
[root@yinzhengjie ~]# 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: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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: 0x8614a108 Device Boot Start End Blocks Id System
/dev/sdb1 1 132 1060258+ 83 Linux
/dev/sdb2 133 264 1060290 83 Linux
/dev/sdb3 265 526 2104515 83 Linux #主分区
/dev/sdb4 527 1305 6257317+ 5 Extended Command (m for help): t #调整分区ID
Partition number (1-5): 3 #选择分区标号
Hex code (type L to list codes): L #查看ID对应的文件系统类型。 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 #选择 Linux swap / So分区类型
Changed system type of partition 3 to 82 (Linux swap / Solaris) Command (m for help): P #查看当前类型 Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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: 0x8614a108 Device Boot Start End Blocks Id System
/dev/sdb1 1 132 1060258+ 83 Linux
/dev/sdb2 133 264 1060290 83 Linux
/dev/sdb3 265 526 2104515 82 Linux swap / Solaris #果真已经变成了交换分区
/dev/sdb4 527 1305 6257317+ 5 Extended Command (m for help): t #修改分区类型
Partition number (1-5): 3 #还是选择之前修改的分区
Hex code (type L to list codes): 83 #修改会之前的分区类型
Changed system type of partition 3 to 83 (Linux) Command (m for help): p #查看分区情况 Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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: 0x8614a108 Device Boot Start End Blocks Id System
/dev/sdb1 1 132 1060258+ 83 Linux
/dev/sdb2 133 264 1060290 83 Linux
/dev/sdb3 265 526 2104515 83 Linux
/dev/sdb4 527 1305 6257317+ 5 Extended Command (m for help): w #保存当前配置
The partition table has been altered! Calling ioctl() to re-read partition table.
Syncing disks.
[root@yinzhengjie ~]#
'''

用fdisk修改分区类型

 
10.创建文件系统
                        高级Linux运维工程师必备技能(扫盲篇)
  你可以使用2个扇区(512字节)为一个块(block),那么这个一个快的大小就是1kb,4个扇区就是2kb,8个扇区就是4kb.那么问题来了,这个每个单位的块导师是1kb好呢?还是2kb或是4kb好呢?这就要看你存储的数据的大小了,如果你存储的数据是大文件的话,当然block越大越好,这样block存储相同的数据block越大,用的块数就越少,如果你存储的是小文件的话,当然block越小越好,因为block过大,存进去的数据却很小就造成了浪费!(因为一个block只能存储一个数据源)。
  注意,在存储数据的时候,一个block只能属于一个文件,不能同时属于2个文件。硬连接除外,其实硬链接指的还是一同一个文件。也就是说,不同的文件不能使用相同的磁盘块。这些磁盘块都有其编号的,是为了方便数据源(主要是inode)只想存储数据的块(block)
  磁盘碎片,就是不是连续的块(block)存储着属于同一个文件的数据,这样就导致了在存取的时候特别麻烦,大大的降低了磁盘的工作效率。如下图:
                            高级Linux运维工程师必备技能(扫盲篇)
  日志文件系统是可以将源数据(indoe)和块数据都写入日志区,等都写入成功了在把数据分别写入到源数据区和块数据区,假如你才写文档的时候,如果突然断电,恰巧你刚刚好写完数据,那么他回将数据分别写入indoe和block区域中,如果你没有写完,他就会对比在日志区的inode和block对应的是否完整,如果不完整,日志区会自动将Inode删除,清除掉不完整的block,就完成了一次自检模式。
                              高级Linux运维工程师必备技能(扫盲篇)
#!/usr/bin/env python
#_*_coding:utf-8_*_
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/
#EMAIL:y1053419035@qq.com ''' mke2fs:
配置文件:/etc/mke2fs.conf
-t:指定文件类型{ext2|ext3|ext4}
-j:用于创建Ext3文件系统,相当于-t ext3
-L label: 指定卷标,
-b{||}:指定块大小
-i # :#个字节给指定一个indone
-N # : 直接指定预留多少个indone
-I # : 指定Inode大小
-m # :预留给管理员的空间百分比,默认为5
-O :指定分区特性
e2label /dev/SOMEDEVICE 查看卷标, e2label /dev/SOMEDEVICE Label 直接更改卷标 e2label /dev/SOMEDEVICE “” 删除卷标 blkid 查看UUID和TYPE dumpe2fs 查看超级块和是否有碎片
-h:仅显示超级块中保存的信息 tune2fs:调整mke2fs的信息
-l:查看超级块中的信息
-L: 设定卷标
-m:预留管理员的空间百分比
-j:如果原来的文件系统为ext2,-j能够将其提升为ext3
-o:[^]mount-options[,...] 指定默认挂载选项
-O:[^]feature[,...] 调整分区特性
tune2fs -o 挂载选项 设备
tune2fs -o ^设备选项 取消 fsck:文件系统检测
-t 文件类型 设备
-f 强行检测
-a 自动修复错误
-r 交互式修复错误 e2fsck
-t 指定时间
-y 自动回答为yes
-f 强行检测
'
 #!/usr/bin/env python
#_*_coding:utf-8_*_
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/
#EMAIL:y1053419035@qq.com '''
[root@yinzhengjie ~]# mke2fs /dev/sdb3 #格式化该分区,默认为ext2文件系统
mke2fs 1.41.12 (17-May-2010)
Filesystem label= #卷标
OS type: Linux
Block size=4096 (log=2) #块大小是4K
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
131648 inodes, 526128 blocks #节点书和块数。
26306 blocks (5.00%) reserved for the super user #有5.00%的block给管理用,这个比例是可以调整的
First data block=0
Maximum filesystem blocks=541065216 #最大块数
17 block groups #有17个块组
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
Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 39 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override #表示每39次挂载或者180天(半年)文件系统会自动检测一次。.
[root@yinzhengjie ~]#
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# mke2fs -j /dev/sdb3 #格式化该分区,指定格式为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, 526128 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 #与ext2相比多出来的项目,存放日志的区域。
Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 38 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override. #这里的是38次挂载或者6个月进行一次挂载,和ext2的区别。
[root@yinzhengjie ~]#
'''

用mke2fs的-j参数格式化分区

 #!/usr/bin/env python
#_*_coding:utf-8_*_
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/
#EMAIL:y1053419035@qq.com '''
[root@yinzhengjie ~]# mke2fs -L Data -t ext4 /dev/sdb3 #指定卷标和文件系统格式
mke2fs 1.41.12 (17-May-2010)
Filesystem label=Data #这就是卷标
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
131648 inodes, 526128 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 38 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@yinzhengjie ~]#
'''

用mke2fs的-L用法展示

 #!/usr/bin/env python
#_*_coding:utf-8_*_
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/
#EMAIL:y1053419035@qq.com '''
[root@yinzhengjie ~]# e2label /dev/sdb3 #查看卷标名
Data
[root@yinzhengjie ~]# e2label /dev/sdb3 MYDATA #修改卷标名
[root@yinzhengjie ~]# e2label /dev/sdb3
MYDATA
[root@yinzhengjie ~]#
'''

用e2label查看或修改卷标名

 #!/usr/bin/env python
#_*_coding:utf-8_*_
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/
#EMAIL:y1053419035@qq.com '''
[root@yinzhengjie ~]# mke2fs -b 2048 -m 3 -t ext4 /dev/sdb3
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=2048 (log=1) #被修改的块大小为2048
Fragment size=2048 (log=1)
Stride=0 blocks, Stripe width=0 blocks
131560 inodes, 1052256 blocks
31567 blocks (3.00%) reserved for the super user #给管理员预留的block,这个就是通过上面的“-m”参数实现的。
First data block=0
Maximum filesystem blocks=538968064
65 block groups
16384 blocks per group, 16384 fragments per group
2024 inodes per group
Superblock backups stored on blocks:
16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816 Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 29 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@yinzhengjie ~]#
'''

mke2fs的-b与-m参数的用法展示

 #!/usr/bin/env python
#_*_coding:utf-8_*_
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/
#EMAIL:y1053419035@qq.com '''
[root@yinzhengjie ~]# blkid /dev/sdb3 #查看分区的UUID和TYPE,我们可以用uuid来进行挂载
/dev/sdb3: UUID="87f7686e-09bd-4a1e-a567-4939c6a4dcab" TYPE="ext4"
[root@yinzhengjie ~]#
'''

blkid 查看UUID和TYPE

 #!/usr/bin/env python
#_*_coding:utf-8_*_
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/
#EMAIL:y1053419035@qq.com '''
[root@yinzhengjie ~]# dumpe2fs /dev/sdb3
dumpe2fs 1.41.12 (17-May-2010)
Filesystem volume name: <none>
Last mounted on: <not available>
Filesystem UUID: 87f7686e-09bd-4a1e-a567-4939c6a4dcab
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: has_journal ext_attr resize_inode dir_index filetype extent flex_bg sparse_super huge_file uninit_bg dir_nlink extra_isize
Filesystem flags: signed_directory_hash
Default mount options: (none)
Filesystem state: clean
Errors behavior: Continue
Filesystem OS type: Linux
Inode count: 131560
Block count: 1052256
Reserved block count: 31567
Free blocks: 998268
Free inodes: 131549
First block: 0
Block size: 2048
Fragment size: 2048
Reserved GDT blocks: 512
Blocks per group: 16384
Fragments per group: 16384
Inodes per group: 2024
Inode blocks per group: 253
Flex block group size: 16
Filesystem created: Thu May 11 12:42:49 2017
Last mount time: n/a
Last write time: Thu May 11 12:42:49 2017
Mount count: 0
Maximum mount count: 29
Last checked: Thu May 11 12:42:49 2017
Check interval: 15552000 (6 months)
Next check after: Tue Nov 7 11:42:49 2017
Lifetime writes: 97 MB
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: ff3c9e24-63aa-462a-9d6d-863f99c556d0
Journal backup: inode blocks
Journal features: (none)
Journal size: 64M
Journal length: 32768
Journal sequence: 0x00000001
Journal start: 0 Group 0: (Blocks 0-16383) [ITABLE_ZEROED] #显示组名,存储数据的block编号,如果你的Bolck和上个组没有连接上就说明存在磁盘碎片
Checksum 0x8fce, unused inodes 2013 #没有用的inode有多少个
Primary superblock at 0, Group descriptors at 1-2
Reserved GDT blocks at 3-514
Block bitmap at 515 (+515), Inode bitmap at 531 (+531)
Inode table at 547-799 (+547)
11779 free blocks, 2013 free inodes, 2 directories, 2013 unused inodes
Free blocks: 4605-16383
Free inodes: 12-2024
Group 1: (Blocks 16384-32767) [INODE_UNINIT, ITABLE_ZEROED]
Checksum 0xd2d4, unused inodes 2024
Backup superblock at 16384, Group descriptors at 16385-16386
Reserved GDT blocks at 16387-16898
Block bitmap at 516 (+4294951428), Inode bitmap at 532 (+4294951444)
Inode table at 800-1052 (+4294951712)
15869 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 16899-32767
Free inodes: 2025-4048
Group 2: (Blocks 32768-49151) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0x209d, unused inodes 2024
Block bitmap at 517 (+4294935045), Inode bitmap at 533 (+4294935061)
Inode table at 1053-1305 (+4294935581)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 32768-49151
Free inodes: 4049-6072
Group 3: (Blocks 49152-65535) [INODE_UNINIT, ITABLE_ZEROED]
Checksum 0x595b, unused inodes 2024
Backup superblock at 49152, Group descriptors at 49153-49154
Reserved GDT blocks at 49155-49666
Block bitmap at 518 (+4294918662), Inode bitmap at 534 (+4294918678)
Inode table at 1306-1558 (+4294919450)
15869 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 49667-65535
Free inodes: 6073-8096
Group 4: (Blocks 65536-81919) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0x4c65, unused inodes 2024
Block bitmap at 519 (+4294902279), Inode bitmap at 535 (+4294902295)
Inode table at 1559-1811 (+4294903319)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 65536-81919
Free inodes: 8097-10120
Group 5: (Blocks 81920-98303) [INODE_UNINIT, ITABLE_ZEROED]
Checksum 0x86c0, unused inodes 2024
Backup superblock at 81920, Group descriptors at 81921-81922
Reserved GDT blocks at 81923-82434
Block bitmap at 520 (+4294885896), Inode bitmap at 536 (+4294885912)
Inode table at 1812-2064 (+4294887188)
15869 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 82435-98303
Free inodes: 10121-12144
Group 6: (Blocks 98304-114687) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0x8dba, unused inodes 2024
Block bitmap at 521 (+4294869513), Inode bitmap at 537 (+4294869529)
Inode table at 2065-2317 (+4294871057)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 98304-114687
Free inodes: 12145-14168
Group 7: (Blocks 114688-131071) [INODE_UNINIT, ITABLE_ZEROED]
Checksum 0x5fe4, unused inodes 2024
Backup superblock at 114688, Group descriptors at 114689-114690
Reserved GDT blocks at 114691-115202
Block bitmap at 522 (+4294853130), Inode bitmap at 538 (+4294853146)
Inode table at 2318-2570 (+4294854926)
15869 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 115203-131071
Free inodes: 14169-16192
Group 8: (Blocks 131072-147455) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0x0451, unused inodes 2024
Block bitmap at 523 (+4294836747), Inode bitmap at 539 (+4294836763)
Inode table at 2571-2823 (+4294838795)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 131072-147455
Free inodes: 16193-18216
Group 9: (Blocks 147456-163839) [INODE_UNINIT, ITABLE_ZEROED]
Checksum 0xb130, unused inodes 2024
Backup superblock at 147456, Group descriptors at 147457-147458
Reserved GDT blocks at 147459-147970
Block bitmap at 524 (+4294820364), Inode bitmap at 540 (+4294820380)
Inode table at 2824-3076 (+4294822664)
15869 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 147971-163839
Free inodes: 18217-20240
Group 10: (Blocks 163840-180223) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0x544a, unused inodes 2024
Block bitmap at 525 (+4294803981), Inode bitmap at 541 (+4294803997)
Inode table at 3077-3329 (+4294806533)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 163840-180223
Free inodes: 20241-22264
Group 11: (Blocks 180224-196607) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0x3e65, unused inodes 2024
Block bitmap at 526 (+4294787598), Inode bitmap at 542 (+4294787614)
Inode table at 3330-3582 (+4294790402)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 180224-196607
Free inodes: 22265-24288
Group 12: (Blocks 196608-212991) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0x407e, unused inodes 2024
Block bitmap at 527 (+4294771215), Inode bitmap at 543 (+4294771231)
Inode table at 3583-3835 (+4294774271)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 196608-212991
Free inodes: 24289-26312
Group 13: (Blocks 212992-229375) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0x3bb2, unused inodes 2024
Block bitmap at 528 (+4294754832), Inode bitmap at 544 (+4294754848)
Inode table at 3836-4088 (+4294758140)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 212992-229375
Free inodes: 26313-28336
Group 14: (Blocks 229376-245759) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0x0dce, unused inodes 2024
Block bitmap at 529 (+4294738449), Inode bitmap at 545 (+4294738465)
Inode table at 4089-4341 (+4294742009)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 229376-245759
Free inodes: 28337-30360
Group 15: (Blocks 245760-262143) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0x7e95, unused inodes 2024
Block bitmap at 530 (+4294722066), Inode bitmap at 546 (+4294722082)
Inode table at 4342-4594 (+4294725878)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 245760-262143
Free inodes: 30361-32384
Group 16: (Blocks 262144-278527) [INODE_UNINIT, ITABLE_ZEROED]
Checksum 0x0990, unused inodes 2024
Block bitmap at 262144 (+0), Inode bitmap at 262160 (+16)
Inode table at 262176-262428 (+32)
12304 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 266224-278527
Free inodes: 32385-34408
Group 17: (Blocks 278528-294911) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0xcd8f, unused inodes 2024
Block bitmap at 262145 (+4294950913), Inode bitmap at 262161 (+4294950929)
Inode table at 262429-262681 (+4294951197)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 278528-294911
Free inodes: 34409-36432
Group 18: (Blocks 294912-311295) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0xdf82, unused inodes 2024
Block bitmap at 262146 (+4294934530), Inode bitmap at 262162 (+4294934546)
Inode table at 262682-262934 (+4294935066)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 294912-311295
Free inodes: 36433-38456
Group 19: (Blocks 311296-327679) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0xd576, unused inodes 2024
Block bitmap at 262147 (+4294918147), Inode bitmap at 262163 (+4294918163)
Inode table at 262935-263187 (+4294918935)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 311296-327679
Free inodes: 38457-40480
Group 20: (Blocks 327680-344063) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0xfb98, unused inodes 2024
Block bitmap at 262148 (+4294901764), Inode bitmap at 262164 (+4294901780)
Inode table at 263188-263440 (+4294902804)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 327680-344063
Free inodes: 40481-42504
Group 21: (Blocks 344064-360447) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0x57e5, unused inodes 2024
Block bitmap at 262149 (+4294885381), Inode bitmap at 262165 (+4294885397)
Inode table at 263441-263693 (+4294886673)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 344064-360447
Free inodes: 42505-44528
Group 22: (Blocks 360448-376831) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0xee70, unused inodes 2024
Block bitmap at 262150 (+4294868998), Inode bitmap at 262166 (+4294869014)
Inode table at 263694-263946 (+4294870542)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 360448-376831
Free inodes: 44529-46552
Group 23: (Blocks 376832-393215) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0x420d, unused inodes 2024
Block bitmap at 262151 (+4294852615), Inode bitmap at 262167 (+4294852631)
Inode table at 263947-264199 (+4294854411)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 376832-393215
Free inodes: 46553-48576
Group 24: (Blocks 393216-409599) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0xb3ac, unused inodes 2024
Block bitmap at 262152 (+4294836232), Inode bitmap at 262168 (+4294836248)
Inode table at 264200-264452 (+4294838280)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 393216-409599
Free inodes: 48577-50600
Group 25: (Blocks 409600-425983) [INODE_UNINIT, ITABLE_ZEROED]
Checksum 0xaab1, unused inodes 2024
Backup superblock at 409600, Group descriptors at 409601-409602
Reserved GDT blocks at 409603-410114
Block bitmap at 262153 (+4294819849), Inode bitmap at 262169 (+4294819865)
Inode table at 264453-264705 (+4294822149)
15869 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 410115-425983
Free inodes: 50601-52624
Group 26: (Blocks 425984-442367) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0xab55, unused inodes 2024
Block bitmap at 262154 (+4294803466), Inode bitmap at 262170 (+4294803482)
Inode table at 264706-264958 (+4294806018)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 425984-442367
Free inodes: 52625-54648
Group 27: (Blocks 442368-458751) [INODE_UNINIT, ITABLE_ZEROED]
Checksum 0x28a7, unused inodes 2024
Backup superblock at 442368, Group descriptors at 442369-442370
Reserved GDT blocks at 442371-442882
Block bitmap at 262155 (+4294787083), Inode bitmap at 262171 (+4294787099)
Inode table at 264959-265211 (+4294789887)
15869 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 442883-458751
Free inodes: 54649-56672
Group 28: (Blocks 458752-475135) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0x73c6, unused inodes 2024
Block bitmap at 262156 (+4294770700), Inode bitmap at 262172 (+4294770716)
Inode table at 265212-265464 (+4294773756)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 458752-475135
Free inodes: 56673-58696
Group 29: (Blocks 475136-491519) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0xb9dd, unused inodes 2024
Block bitmap at 262157 (+4294754317), Inode bitmap at 262173 (+4294754333)
Inode table at 265465-265717 (+4294757625)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 475136-491519
Free inodes: 58697-60720
Group 30: (Blocks 491520-507903) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0xef7a, unused inodes 2024
Block bitmap at 262158 (+4294737934), Inode bitmap at 262174 (+4294737950)
Inode table at 265718-265970 (+4294741494)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 491520-507903
Free inodes: 60721-62744
Group 31: (Blocks 507904-524287) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0xa124, unused inodes 2024
Block bitmap at 262159 (+4294721551), Inode bitmap at 262175 (+4294721567)
Inode table at 265971-266223 (+4294725363)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 507904-524287
Free inodes: 62745-64768
Group 32: (Blocks 524288-540671) [INODE_UNINIT, ITABLE_ZEROED]
Checksum 0xcb02, unused inodes 2024
Block bitmap at 524288 (+0), Inode bitmap at 524304 (+16)
Inode table at 524320-524572 (+32)
12304 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 528368-540671
Free inodes: 64769-66792
Group 33: (Blocks 540672-557055) [INODE_UNINIT, ITABLE_ZEROED]
Checksum 0x1cd5, unused inodes 2024
Block bitmap at 524289 (+4294950913), Inode bitmap at 524305 (+4294950929)
Inode table at 524573-524825 (+4294951197)
0 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks:
Free inodes: 66793-68816
Group 34: (Blocks 557056-573439) [INODE_UNINIT, ITABLE_ZEROED]
Checksum 0x0ed8, unused inodes 2024
Block bitmap at 524290 (+4294934530), Inode bitmap at 524306 (+4294934546)
Inode table at 524826-525078 (+4294935066)
0 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks:
Free inodes: 68817-70840
Group 35: (Blocks 573440-589823) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0x17e4, unused inodes 2024
Block bitmap at 524291 (+4294918147), Inode bitmap at 524307 (+4294918163)
Inode table at 525079-525331 (+4294918935)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 573440-589823
Free inodes: 70841-72864
Group 36: (Blocks 589824-606207) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0x390a, unused inodes 2024
Block bitmap at 524292 (+4294901764), Inode bitmap at 524308 (+4294901780)
Inode table at 525332-525584 (+4294902804)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 589824-606207
Free inodes: 72865-74888
Group 37: (Blocks 606208-622591) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0x9577, unused inodes 2024
Block bitmap at 524293 (+4294885381), Inode bitmap at 524309 (+4294885397)
Inode table at 525585-525837 (+4294886673)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 606208-622591
Free inodes: 74889-76912
Group 38: (Blocks 622592-638975) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0x2ce2, unused inodes 2024
Block bitmap at 524294 (+4294868998), Inode bitmap at 524310 (+4294869014)
Inode table at 525838-526090 (+4294870542)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 622592-638975
Free inodes: 76913-78936
Group 39: (Blocks 638976-655359) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0x809f, unused inodes 2024
Block bitmap at 524295 (+4294852615), Inode bitmap at 524311 (+4294852631)
Inode table at 526091-526343 (+4294854411)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 638976-655359
Free inodes: 78937-80960
Group 40: (Blocks 655360-671743) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0x713e, unused inodes 2024
Block bitmap at 524296 (+4294836232), Inode bitmap at 524312 (+4294836248)
Inode table at 526344-526596 (+4294838280)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 655360-671743
Free inodes: 80961-82984
Group 41: (Blocks 671744-688127) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0x7bca, unused inodes 2024
Block bitmap at 524297 (+4294819849), Inode bitmap at 524313 (+4294819865)
Inode table at 526597-526849 (+4294822149)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 671744-688127
Free inodes: 82985-85008
Group 42: (Blocks 688128-704511) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0x69c7, unused inodes 2024
Block bitmap at 524298 (+4294803466), Inode bitmap at 524314 (+4294803482)
Inode table at 526850-527102 (+4294806018)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 688128-704511
Free inodes: 85009-87032
Group 43: (Blocks 704512-720895) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0xf9dc, unused inodes 2024
Block bitmap at 524299 (+4294787083), Inode bitmap at 524315 (+4294787099)
Inode table at 527103-527355 (+4294789887)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 704512-720895
Free inodes: 87033-89056
Group 44: (Blocks 720896-737279) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0xb154, unused inodes 2024
Block bitmap at 524300 (+4294770700), Inode bitmap at 524316 (+4294770716)
Inode table at 527356-527608 (+4294773756)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 720896-737279
Free inodes: 89057-91080
Group 45: (Blocks 737280-753663) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0x7b4f, unused inodes 2024
Block bitmap at 524301 (+4294754317), Inode bitmap at 524317 (+4294754333)
Inode table at 527609-527861 (+4294757625)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 737280-753663
Free inodes: 91081-93104
Group 46: (Blocks 753664-770047) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0x2de8, unused inodes 2024
Block bitmap at 524302 (+4294737934), Inode bitmap at 524318 (+4294737950)
Inode table at 527862-528114 (+4294741494)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 753664-770047
Free inodes: 93105-95128
Group 47: (Blocks 770048-786431) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0x63b6, unused inodes 2024
Block bitmap at 524303 (+4294721551), Inode bitmap at 524319 (+4294721567)
Inode table at 528115-528367 (+4294725363)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 770048-786431
Free inodes: 95129-97152
Group 48: (Blocks 786432-802815) [INODE_UNINIT, ITABLE_ZEROED]
Checksum 0x8a8c, unused inodes 2024
Block bitmap at 786432 (+0), Inode bitmap at 786448 (+16)
Inode table at 786464-786716 (+32)
12304 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 790512-802815
Free inodes: 97153-99176
Group 49: (Blocks 802816-819199) [INODE_UNINIT, ITABLE_ZEROED]
Checksum 0x5d7a, unused inodes 2024
Backup superblock at 802816, Group descriptors at 802817-802818
Reserved GDT blocks at 802819-803330
Block bitmap at 786433 (+4294950913), Inode bitmap at 786449 (+4294950929)
Inode table at 786717-786969 (+4294951197)
15869 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 803331-819199
Free inodes: 99177-101200
Group 50: (Blocks 819200-835583) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0x5c9e, unused inodes 2024
Block bitmap at 786434 (+4294934530), Inode bitmap at 786450 (+4294934546)
Inode table at 786970-787222 (+4294935066)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 819200-835583
Free inodes: 101201-103224
Group 51: (Blocks 835584-851967) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0x566a, unused inodes 2024
Block bitmap at 786435 (+4294918147), Inode bitmap at 786451 (+4294918163)
Inode table at 787223-787475 (+4294918935)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 835584-851967
Free inodes: 103225-105248
Group 52: (Blocks 851968-868351) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0x7884, unused inodes 2024
Block bitmap at 786436 (+4294901764), Inode bitmap at 786452 (+4294901780)
Inode table at 787476-787728 (+4294902804)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 851968-868351
Free inodes: 105249-107272
Group 53: (Blocks 868352-884735) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0xd4f9, unused inodes 2024
Block bitmap at 786437 (+4294885381), Inode bitmap at 786453 (+4294885397)
Inode table at 787729-787981 (+4294886673)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 868352-884735
Free inodes: 107273-109296
Group 54: (Blocks 884736-901119) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0x6d6c, unused inodes 2024
Block bitmap at 786438 (+4294868998), Inode bitmap at 786454 (+4294869014)
Inode table at 787982-788234 (+4294870542)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 884736-901119
Free inodes: 109297-111320
Group 55: (Blocks 901120-917503) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0xc111, unused inodes 2024
Block bitmap at 786439 (+4294852615), Inode bitmap at 786455 (+4294852631)
Inode table at 788235-788487 (+4294854411)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 901120-917503
Free inodes: 111321-113344
Group 56: (Blocks 917504-933887) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0x30b0, unused inodes 2024
Block bitmap at 786440 (+4294836232), Inode bitmap at 786456 (+4294836248)
Inode table at 788488-788740 (+4294838280)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 917504-933887
Free inodes: 113345-115368
Group 57: (Blocks 933888-950271) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0x3a44, unused inodes 2024
Block bitmap at 786441 (+4294819849), Inode bitmap at 786457 (+4294819865)
Inode table at 788741-788993 (+4294822149)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 933888-950271
Free inodes: 115369-117392
Group 58: (Blocks 950272-966655) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0x2849, unused inodes 2024
Block bitmap at 786442 (+4294803466), Inode bitmap at 786458 (+4294803482)
Inode table at 788994-789246 (+4294806018)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 950272-966655
Free inodes: 117393-119416
Group 59: (Blocks 966656-983039) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0xb852, unused inodes 2024
Block bitmap at 786443 (+4294787083), Inode bitmap at 786459 (+4294787099)
Inode table at 789247-789499 (+4294789887)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 966656-983039
Free inodes: 119417-121440
Group 60: (Blocks 983040-999423) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0xf0da, unused inodes 2024
Block bitmap at 786444 (+4294770700), Inode bitmap at 786460 (+4294770716)
Inode table at 789500-789752 (+4294773756)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 983040-999423
Free inodes: 121441-123464
Group 61: (Blocks 999424-1015807) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0x3ac1, unused inodes 2024
Block bitmap at 786445 (+4294754317), Inode bitmap at 786461 (+4294754333)
Inode table at 789753-790005 (+4294757625)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 999424-1015807
Free inodes: 123465-125488
Group 62: (Blocks 1015808-1032191) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0x6c66, unused inodes 2024
Block bitmap at 786446 (+4294737934), Inode bitmap at 786462 (+4294737950)
Inode table at 790006-790258 (+4294741494)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 1015808-1032191
Free inodes: 125489-127512
Group 63: (Blocks 1032192-1048575) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0x2238, unused inodes 2024
Block bitmap at 786447 (+4294721551), Inode bitmap at 786463 (+4294721567)
Inode table at 790259-790511 (+4294725363)
16384 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 1032192-1048575
Free inodes: 127513-129536
Group 64: (Blocks 1048576-1052255) [INODE_UNINIT, ITABLE_ZEROED]
Checksum 0xb5ee, unused inodes 2024
Block bitmap at 1048576 (+0), Inode bitmap at 1048592 (+16)
Inode table at 1048608-1048860 (+32)
3425 free blocks, 2024 free inodes, 0 directories, 2024 unused inodes
Free blocks: 1048577-1048591, 1048593-1048607, 1048861-1052255
Free inodes: 129537-131560
[root@yinzhengjie ~]#
'''

用dumpe2fs 查看超级块和是否有碎片

 #!/usr/bin/env python
#_*_coding:utf-8_*_
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/
#EMAIL:y1053419035@qq.com '''
[root@yinzhengjie ~]# dumpe2fs -h /dev/sdb3 #仅显示超级块中保存的信息
dumpe2fs 1.41.12 (17-May-2010)
Filesystem volume name: <none> #文件系统卷标名称
Last mounted on: <not available> #上一次上面时候挂载的
Filesystem UUID: 87f7686e-09bd-4a1e-a567-4939c6a4dcab
Filesystem magic number: 0xEF53 #文件的魔术号
Filesystem revision #: 1 (dynamic)
Filesystem features: has_journal ext_attr resize_inode dir_index filetype extent flex_bg sparse_super huge_file uninit_bg dir_nlink extra_isize #支持的默认属性
Filesystem flags: signed_directory_hash
Default mount options: (none)
Filesystem state: clean
Errors behavior: Continue
Filesystem OS type: Linux
Inode count: 131560
Block count: 1052256
Reserved block count: 31567
Free blocks: 998268
Free inodes: 131549
First block: 0
Block size: 2048
Fragment size: 2048
Reserved GDT blocks: 512
Blocks per group: 16384
Fragments per group: 16384
Inodes per group: 2024
Inode blocks per group: 253
Flex block group size: 16
Filesystem created: Thu May 11 12:42:49 2017
Last mount time: n/a
Last write time: Thu May 11 12:42:49 2017
Mount count: 0
Maximum mount count: 29
Last checked: Thu May 11 12:42:49 2017
Check interval: 15552000 (6 months)
Next check after: Tue Nov 7 11:42:49 2017
Lifetime writes: 97 MB
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: ff3c9e24-63aa-462a-9d6d-863f99c556d0
Journal backup: inode blocks
Journal features: (none)
Journal size: 64M
Journal length: 32768
Journal sequence: 0x00000001
Journal start: 0 [root@yinzhengjie ~]#
'''

dumpe2fs的-h参数用法展示

 #!/usr/bin/env python
#_*_coding:utf-8_*_
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/
#EMAIL:y1053419035@qq.com '''
[root@yinzhengjie ~]# tune2fs -l /dev/sdb3 #查看超级块中的信息。
tune2fs 1.41.12 (17-May-2010)
Filesystem volume name: <none>
Last mounted on: <not available>
Filesystem UUID: 87f7686e-09bd-4a1e-a567-4939c6a4dcab
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: has_journal ext_attr resize_inode dir_index filetype extent flex_bg sparse_super huge_file uninit_bg dir_nlink extra_isize
Filesystem flags: signed_directory_hash
Default mount options: (none)
Filesystem state: clean
Errors behavior: Continue
Filesystem OS type: Linux
Inode count: 131560
Block count: 1052256
Reserved block count: 31567
Free blocks: 998268
Free inodes: 131549
First block: 0
Block size: 2048
Fragment size: 2048
Reserved GDT blocks: 512
Blocks per group: 16384
Fragments per group: 16384
Inodes per group: 2024
Inode blocks per group: 253
Flex block group size: 16
Filesystem created: Thu May 11 12:42:49 2017
Last mount time: n/a
Last write time: Thu May 11 12:42:49 2017
Mount count: 0
Maximum mount count: 29
Last checked: Thu May 11 12:42:49 2017
Check interval: 15552000 (6 months)
Next check after: Tue Nov 7 11:42:49 2017
Lifetime writes: 97 MB
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: ff3c9e24-63aa-462a-9d6d-863f99c556d0
Journal backup: inode blocks
[root@yinzhengjie ~]#
[root@yinzhengjie ~]#
'''

用tune2fs查看超级块中的信息。

 #!/usr/bin/env python
#_*_coding:utf-8_*_
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/
#EMAIL:y1053419035@qq.com '''
[root@yinzhengjie ~]# tune2fs -l /dev/sdb3 #查看/dev/sdb3 超级块中的信息
tune2fs 1.41.12 (17-May-2010)
Filesystem volume name: <none>
Last mounted on: <not available>
Filesystem UUID: 87f7686e-09bd-4a1e-a567-4939c6a4dcab
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: has_journal ext_attr resize_inode dir_index filetype extent flex_bg sparse_super huge_file uninit_bg dir_nlink extra_isize #含有分区特性“huge_file”
Filesystem flags: signed_directory_hash
Default mount options: (none)
Filesystem state: not clean
Errors behavior: Continue
Filesystem OS type: Linux
Inode count: 131560
Block count: 1052256
Reserved block count: 31567
Free blocks: 998268
Free inodes: 131549
First block: 0
Block size: 2048
Fragment size: 2048
Reserved GDT blocks: 512
Blocks per group: 16384
Fragments per group: 16384
Inodes per group: 2024
Inode blocks per group: 253
Flex block group size: 16
Filesystem created: Thu May 11 12:42:49 2017
Last mount time: n/a
Last write time: Thu May 11 13:04:33 2017
Mount count: 0
Maximum mount count: 29
Last checked: Thu May 11 12:42:49 2017
Check interval: 15552000 (6 months)
Next check after: Tue Nov 7 11:42:49 2017
Lifetime writes: 97 MB
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: ff3c9e24-63aa-462a-9d6d-863f99c556d0
Journal backup: inode blocks
[root@yinzhengjie ~]# tune2fs -O ^huge_file /dev/sdb3 #关闭/dev/sdb3的huge_file分区特性
tune2fs 1.41.12 (17-May-2010) Please run e2fsck on the filesystem. [root@yinzhengjie ~]# tune2fs -l /dev/sdb3
tune2fs 1.41.12 (17-May-2010)
Filesystem volume name: <none>
Last mounted on: <not available>
Filesystem UUID: 87f7686e-09bd-4a1e-a567-4939c6a4dcab
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: has_journal ext_attr resize_inode dir_index filetype extent flex_bg sparse_super uninit_bg dir_nlink extra_isize #果真huge_file的分区特性没了
Filesystem flags: signed_directory_hash
Default mount options: (none)
Filesystem state: not clean
Errors behavior: Continue
Filesystem OS type: Linux
Inode count: 131560
Block count: 1052256
Reserved block count: 31567
Free blocks: 998268
Free inodes: 131549
First block: 0
Block size: 2048
Fragment size: 2048
Reserved GDT blocks: 512
Blocks per group: 16384
Fragments per group: 16384
Inodes per group: 2024
Inode blocks per group: 253
Flex block group size: 16
Filesystem created: Thu May 11 12:42:49 2017
Last mount time: n/a
Last write time: Thu May 11 13:04:49 2017
Mount count: 0
Maximum mount count: 29
Last checked: Thu May 11 12:42:49 2017
Check interval: 15552000 (6 months)
Next check after: Tue Nov 7 11:42:49 2017
Lifetime writes: 97 MB
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: ff3c9e24-63aa-462a-9d6d-863f99c556d0
Journal backup: inode blocks
[root@yinzhengjie ~]# tune2fs -O huge_file /dev/sdb3 #打开/dev/sdb3的huge_file分区特性
tune2fs 1.41.12 (17-May-2010)
[root@yinzhengjie ~]# tune2fs -l /dev/sdb3
tune2fs 1.41.12 (17-May-2010)
Filesystem volume name: <none>
Last mounted on: <not available>
Filesystem UUID: 87f7686e-09bd-4a1e-a567-4939c6a4dcab
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: has_journal ext_attr resize_inode dir_index filetype extent flex_bg sparse_super huge_file uninit_bg dir_nlink extra_isize #/dev/sdb3的huge_file分区特性又有了
Filesystem flags: signed_directory_hash
Default mount options: (none)
Filesystem state: not clean
Errors behavior: Continue
Filesystem OS type: Linux
Inode count: 131560
Block count: 1052256
Reserved block count: 31567
Free blocks: 998268
Free inodes: 131549
First block: 0
Block size: 2048
Fragment size: 2048
Reserved GDT blocks: 512
Blocks per group: 16384
Fragments per group: 16384
Inodes per group: 2024
Inode blocks per group: 253
Flex block group size: 16
Filesystem created: Thu May 11 12:42:49 2017
Last mount time: n/a
Last write time: Thu May 11 13:05:00 2017
Mount count: 0
Maximum mount count: 29
Last checked: Thu May 11 12:42:49 2017
Check interval: 15552000 (6 months)
Next check after: Tue Nov 7 11:42:49 2017
Lifetime writes: 97 MB
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: ff3c9e24-63aa-462a-9d6d-863f99c556d0
Journal backup: inode blocks
[root@yinzhengjie ~]#
'''

tune2fs的对特性的开启与关闭用法展示

 #!/usr/bin/env python
#_*_coding:utf-8_*_
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/
#EMAIL:y1053419035@qq.com '''
[root@yinzhengjie ~]# fsck -t ext4 /dev/sdb3 #对文件系统检测
fsck from util-linux-ng 2.17.2
e2fsck 1.41.12 (17-May-2010)
/dev/sdb3 was not cleanly unmounted, check forced.
Pass 1: Checking inodes, blocks, and sizes #检测 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/sdb3: 11/131560 files (0.0% non-contiguous), 53988/1052256 blocks
[root@yinzhengjie ~]#
'''

用fsck进行文件类型检查

 

11.创建交换分区

 #!/usr/bin/env python
#_*_coding:utf-8_*_
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/
#EMAIL:y1053419035@qq.com '''
如果物理内存不够用时,可以将那些最近很少使用的页面数据(Page)置换出去,即切换到硬盘上,但是要注意的是内
存文件的格式和硬盘中文件的格式是不一样的,所以这个分区必须格式化成跟内存兼容的模式不能转换成文件的格式。以便
把内存的page直接存入这个分区,方便内存直接调用。而这个页面(page)数据对于32位的操作系统一个page大概是4K左右,
对于64位操作系统这个page大小是可变的,4k-2M的大小都是比较常见的。事实上到底能使用多大的页面(page)取决于CPU
而不取决于内存哟!这就是虚拟内存的概念。在linux上我们称之为交换分区。记住,虚拟内存必须是一个单独的分区。 那么问题来了:虚拟内存能代替物理内存运行程序吗?
答案是否定的,只是使用虚拟内存暂时保存数据,而不是代替物理内存运行程序。
虚拟内存的作用是这样的:
   当运行某个大程序、大游戏,需要的内存超过空闲内存但小于物理内存总量时,会暂时把内存里这些数据放到磁盘
上的虚拟内存里,空出物理内存运行游戏。等退出游戏后,又会把虚拟内存里的东西读出来,放回物理内存。所以,虚拟
内存,并不是用来虚拟物理内存的,而是暂存数据的。如果对内存的需求大于物理内存总量,那虚拟内存设多大都不管用。
电脑内存太低,根本的方法还是增加物理内存,才能流畅。虚拟内存机制上就不管用,即使管用,比物理内存低100倍的速
度,也管不上什么实际的作用。所以,虚拟内存大了是没用的,反而白占用磁盘空间。
''' '''
交换分区:
mkswap 格式化为虚拟内存
-L label 指定卷标
swapon 启动虚拟内存
-a 启动所有的虚拟分区
-p:指定优先级
swapoff 关闭虚拟内存
更多参数请参考man mkswap
''' 
 #!/usr/bin/env python
#_*_coding:utf-8_*_
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/
#EMAIL:y1053419035@qq.com '''
[root@yinzhengjie ~]# 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: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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: 0x8614a108 Device Boot Start End Blocks Id System
/dev/sdb1 1 132 1060258+ 83 Linux
/dev/sdb2 133 264 1060290 83 Linux
/dev/sdb3 265 526 2104515 83 Linux
/dev/sdb4 527 1305 6257317+ 5 Extended
/dev/sdb5 527 919 3156741 83 Linux
/dev/sdb6 920 1181 2104483+ 83 Linux #我想讲第6个分区弄成交换分区。 Command (m for help): t #调整分区ID
Partition number (1-6): 6 #选择分区编号为6
Hex code (type L to list codes): L #查看分区类型所对应的ID号,我们发现“82”就是交换分区的编号 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 6 to 82 (Linux swap / Solaris) Command (m for help): P #查看当前分区情况 Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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: 0x8614a108 Device Boot Start End Blocks Id System
/dev/sdb1 1 132 1060258+ 83 Linux
/dev/sdb2 133 264 1060290 83 Linux
/dev/sdb3 265 526 2104515 83 Linux
/dev/sdb4 527 1305 6257317+ 5 Extended
/dev/sdb5 527 919 3156741 83 Linux
/dev/sdb6 920 1181 2104483+ 82 Linux swap / Solaris Command (m for help): W #保存并退出
The partition table has been altered! Calling ioctl() to re-read partition table.
Syncing disks.
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# fdisk -l /dev/sdb #查看分区信息 Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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: 0x8614a108 Device Boot Start End Blocks Id System
/dev/sdb1 1 132 1060258+ 83 Linux
/dev/sdb2 133 264 1060290 83 Linux
/dev/sdb3 265 526 2104515 83 Linux
/dev/sdb4 527 1305 6257317+ 5 Extended
/dev/sdb5 527 919 3156741 83 Linux
/dev/sdb6 920 1181 2104483+ 82 Linux swap / Solaris
[root@yinzhengjie ~]#
'''

调整分区为交换分区(swap)格式

 #!/usr/bin/env python
#_*_coding:utf-8_*_
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/
#EMAIL:y1053419035@qq.com '''
[root@yinzhengjie ~]# kpartx -af /dev/sdb
[root@yinzhengjie ~]# partx -a /dev/sdb #重读分区表信息,其实也可以不用敲击这些命令的如果你是一块新硬盘的话。
BLKPG: Device or resource busy
error adding partition 1
BLKPG: Device or resource busy
error adding partition 2
BLKPG: Device or resource busy
error adding partition 3
BLKPG: Device or resource busy
error adding partition 4
BLKPG: Device or resource busy
error adding partition 5
BLKPG: Device or resource busy
error adding partition 6
[root@yinzhengjie ~]#
'''

用partx 重读一下分区表,避免系统未识别最新分区信息。

 #!/usr/bin/env python
#_*_coding:utf-8_*_
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/
#EMAIL:y1053419035@qq.com '''
[root@yinzhengjie ~]# mkswap /dev/sdb6 #将分区格式化成swap格式
Setting up swapspace version 1, size = 2104476 KiB
no label, UUID=41687bb2-c775-489c-9b32-1e4be73c233b #看见没有,这里是“no label”,是因为我没有定义卷标名。
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# mkswap -L myswap /dev/sdb6 #用-L参数定义一个卷标名。
Setting up swapspace version 1, size = 2104476 KiB
LABEL=myswap, UUID=0553b99a-ee75-4476-8eda-70c591206467 #看见没,“LABEL=myswap”这就是我定义的卷标名称。
[root@yinzhengjie ~]#
'''

用mkswap定义卷标名称

 #!/usr/bin/env python
#_*_coding:utf-8_*_
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/
#EMAIL:y1053419035@qq.com '''
[root@yinzhengjie ~]# cat /proc/meminfo | grep "^S" #查看当前交换分区大小
SwapCached: 0 kB
SwapTotal: 2031612 kB #目前交换分区大小为2G
SwapFree: 2031612 kB #表示空闲交换分区大小
Shmem: 1444 kB
Slab: 75020 kB
SReclaimable: 15620 kB
SUnreclaim: 59400 kB
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# swapon /dev/sdb6 #启用我们已经格式化好的交换分区“/dev/sdb”
[root@yinzhengjie ~]# cat /proc/meminfo | grep "^S" #再次查看当前交换分区大小
SwapCached: 0 kB
SwapTotal: 4136088 kB #我们发现交换分区大小变大了2G
SwapFree: 4136088 kB
Shmem: 1444 kB
Slab: 75148 kB
SReclaimable: 15656 kB
SUnreclaim: 59492 kB
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# swapoff /dev/sdb6 #关闭交换分区“/dev/sdb”
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# cat /proc/meminfo | grep "^S" #验证是否关闭成功
SwapCached: 0 kB
SwapTotal: 2031612 kB #发现的确是少了2G的空间
SwapFree: 2031612 kB
Shmem: 1444 kB
Slab: 75068 kB
SReclaimable: 15636 kB
SUnreclaim: 59432 kB
[root@yinzhengjie ~]# '''

swapon和swapoff的用法展示

12.获取IDE磁盘的相关信息

 #!/usr/bin/env python
#_*_coding:utf-8_*_
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/
#EMAIL:y1053419035@qq.com '''
hdparm
-i 从操作系统读取
-I 直接从硬盘读取
-g 显示硬盘的布局信息
-t 测试硬盘的性能
-T 测试硬盘的性能 '''
 #!/usr/bin/env python
#_*_coding:utf-8_*_
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/
#EMAIL:y1053419035@qq.com '''
一个磁头一次可以读取128位信息,系统就会认为它被虚拟成128个磁头(heads)。所以两个磁头(一个盘片有两个面,
一个盘面有一个磁头,所以说一个盘片有2个磁头)就是256个虚拟磁头(heads)。
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# fdisk -l /dev/sdb #我们可以看出来磁盘的信息 Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders #这里有255个磁头其实是工业生产导致,理论上就是256大家知道即可。
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: 0x8614a108 Device Boot Start End Blocks Id System
/dev/sdb1 1 132 1060258+ 83 Linux
/dev/sdb2 133 264 1060290 83 Linux
/dev/sdb3 265 526 2104515 83 Linux
/dev/sdb4 527 1305 6257317+ 5 Extended
/dev/sdb5 527 919 3156741 83 Linux
/dev/sdb6 920 1181 2104483+ 82 Linux swap / Solaris
[root@yinzhengjie ~]#
''' '''
[root@yinzhengjie ~]# hdparm -i /dev/sdb #从操作系统读取 /dev/sdb:
SG_IO: bad/missing sense data, sb[]: 70 00 05 00 00 00 00 0a 00 00 00 00 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
HDIO_GET_IDENTITY failed: Invalid argument
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# hdparm -I /dev/sdb #直接从硬盘读取 /dev/sdb:
SG_IO: bad/missing sense data, sb[]: 70 00 05 00 00 00 00 0a 00 00 00 00 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ATA device, with non-removable media
Standards:
Likely used: 1
Configuration:
Logical max current
cylinders 0 0
heads 0 0
sectors/track 0 0
--
Logical/Physical Sector size: 512 bytes
device size with M = 1024*1024: 0 MBytes
device size with M = 1000*1000: 0 MBytes
cache/buffer size = unknown
Capabilities:
IORDY not likely
Cannot perform double-word IO
R/W multiple sector transfer: not supported
DMA: not supported
PIO: pio0
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# hdparm -g /dev/sdb #显示硬盘的布局信息 /dev/sdb:
geometry = 1305(柱面数)/255(磁头,heads)/63(每磁道的扇区数), sectors = 20971520(总的扇区数), start = 0(从第几个扇区开始)
[root@yinzhengjie ~]# '''

hdparm用法展示

13.挂载

 #!/usr/bin/env python
#_*_coding:utf-8_*_
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/
#EMAIL:y1053419035@qq.com '''
挂载分类:
手动挂载
按需挂载(autofs,这种效率比较低,当用的时候才去挂载,需要等待时间。)
开机自动挂载 mount[options] -t 文件类型 -o option 设备 挂载点
[options] : 命令的选项
-n:不更新/etc/mtab文件
--bind:dir1 dir2 将目录挂载到目录上,使得dir2也能访问dir1的文件
-t fstype
-r 只读挂载
-w:读写挂载
-L lable 以卷标指定,也可以使用LABLE="lable"
-U UUID:使用UUID挂载,也可以使用 UUID="uuid"
-o options:挂载时启动分区特性
async:异步I/O
sync:同步I/O
noatime/atime 是否更新文件时间戳,不是特别重要的文件,建议noatime
auto: 是否能够被mount -a 自动挂载所有(/etc/fstab中)的文件自动挂载
dev/nodev:是否能创建设备文件
diratime/nodirtime:是否更新目录的时间戳
exec/noexec:是否允许执行二进制程序
_netdev:网络设备
remount:重新挂载
relatime/norelatime 是否实时更新
acl 文件访问控制列表 挂载点:挂载以后原始数据将被隐藏
1、选择空闲目录
2、必须事先存在
卸载:
1、空闲时可以卸载
2、其实也可以强行卸载
umount 设备|挂载点 直接使用mount可以显示当前系统的挂载信息,也可以查看/proc/mounts或者/etc/mtab 光盘:
/dev/cdrom /dev/dvdrom /dev/sr0
[-t iso9660]
'''
 #!/usr/bin/env python
#_*_coding:utf-8_*_
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/
#EMAIL:y1053419035@qq.com '''
[root@yinzhengjie ~]# cat /proc/filesystems #查看内核能识别的文件系统类型
nodev sysfs #其中“nodev”表示非设备文件系统,即伪文件系统,后面的参数是“sysfs”。
nodev rootfs
nodev bdev
nodev proc
nodev cgroup
nodev cpuset
nodev tmpfs
nodev devtmpfs
nodev binfmt_misc
nodev debugfs
nodev securityfs
nodev sockfs
nodev usbfs
nodev pipefs
nodev anon_inodefs
nodev inotifyfs
nodev devpts
nodev ramfs
nodev hugetlbfs
iso9660 #这就是设备文件系统,光盘
nodev pstore
nodev mqueue
nodev selinuxfs
ext4 #这个也是设备文件系统,前面没有“nodev”进行标识。
nodev vmhgfs
nodev fuse
fuseblk
nodev fusectl
[root@yinzhengjie ~]#
'''

查看内核能识别的文件系统类型

 #!/usr/bin/env python
#_*_coding:utf-8_*_
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/
#EMAIL:y1053419035@qq.com '''
[root@yinzhengjie ~]# mkdir /yinzhengjie #创建一个挂载目录
[root@yinzhengjie ~]# mount #查看当前的挂载信息
/dev/sda2 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,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
vmware-vmblock on /var/run/vmblock-fuse type fuse.vmware-vmblock (rw,nosuid,nodev,default_permissions,allow_other)
[root@yinzhengjie ~]# mount /dev/sdb1 /yinzhengjie/ #将第二块设备的第一个分区挂载到"/yinzhengjie"目录下。
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# mount #再次查看挂载信息,发现多出来了最后一项
/dev/sda2 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,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
vmware-vmblock on /var/run/vmblock-fuse type fuse.vmware-vmblock (rw,nosuid,nodev,default_permissions,allow_other)
/dev/sdb1 on /yinzhengjie type ext4 (rw) #发现了挂载的目录
[root@yinzhengjie ~]# ll /yinzhengjie/ #查看挂载点信息,出现了“lost+found”目录表示挂载成功
total 16
drwx------. 2 root root 16384 May 12 04:31 lost+found
[root@yinzhengjie ~]# cd /yinzhengjie/
[root@yinzhengjie yinzhengjie]# touch {1..5}.txt #我们创建5个文件看看
[root@yinzhengjie yinzhengjie]# ll #发现也能成功创建文件,文件名是存在挂载目录下的。
total 16
-rw-r--r--. 1 root root 0 May 12 04:36 1.txt
-rw-r--r--. 1 root root 0 May 12 04:36 2.txt
-rw-r--r--. 1 root root 0 May 12 04:36 3.txt
-rw-r--r--. 1 root root 0 May 12 04:36 4.txt
-rw-r--r--. 1 root root 0 May 12 04:36 5.txt
drwx------. 2 root root 16384 May 12 04:31 lost+found
[root@yinzhengjie yinzhengjie]# cd #回到自己的家目录去
[root@yinzhengjie ~]# umount /yinzhengjie/ #卸载挂载点
[root@yinzhengjie ~]# mount #再一次查看挂载信息,发现之前的挂载点不见了。
/dev/sda2 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,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
vmware-vmblock on /var/run/vmblock-fuse type fuse.vmware-vmblock (rw,nosuid,nodev,default_permissions,allow_other)
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# ll /yinzhengjie/ #发现这个目录的文件也没有了,原因是卸载成功了,数据还存在那块设备上。
total 0
[root@yinzhengjie ~]#
'''

mount的基本使用展示

 #!/usr/bin/env python
#_*_coding:utf-8_*_
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/
#EMAIL:y1053419035@qq.com '''
[root@yinzhengjie ~]# ll /yinzhengjie/ #查看目录为空。
total 0
[root@yinzhengjie ~]# mount #先查看挂载之前的信息
/dev/sda2 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,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
vmware-vmblock on /var/run/vmblock-fuse type fuse.vmware-vmblock (rw,nosuid,nodev,default_permissions,allow_other)
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# tune2fs -L yinzhengjie /dev/sdb1 #给这个分区设置一个卷标名称。
tune2fs 1.41.12 (17-May-2010)
[root@yinzhengjie ~]# e2label /dev/sdb1 #查看这个卷标名称
yinzhengjie
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# mount LABEL="yinzhengjie" /yinzhengjie/ #把卷标名称为"yinzhengjie" 的设备挂载到“/yinzhengjie/”这个目录下来。
[root@yinzhengjie ~]# mount #查看挂载后的信息
/dev/sda2 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,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
vmware-vmblock on /var/run/vmblock-fuse type fuse.vmware-vmblock (rw,nosuid,nodev,default_permissions,allow_other)
/dev/sdb1 on /yinzhengjie type ext4 (rw) #这里有记录,说明挂载成功了。
[root@yinzhengjie ~]# ll /yinzhengjie/ #看一下挂载目录,果真是访问到了数据
total 16
-rw-r--r--. 1 root root 0 May 12 04:36 1.txt
-rw-r--r--. 1 root root 0 May 12 04:36 2.txt
-rw-r--r--. 1 root root 0 May 12 04:36 3.txt
-rw-r--r--. 1 root root 0 May 12 04:36 4.txt
-rw-r--r--. 1 root root 0 May 12 04:36 5.txt
drwx------. 2 root root 16384 May 12 04:31 lost+found
[root@yinzhengjie ~]#
'''

mount命令基于卷标挂载用法展示

 #!/usr/bin/env python
#_*_coding:utf-8_*_
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/
#EMAIL:y1053419035@qq.com '''
[root@yinzhengjie ~]# ll /yinzhengjie/
total 0
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# mount #查看挂载信息
/dev/sda2 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,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
vmware-vmblock on /var/run/vmblock-fuse type fuse.vmware-vmblock (rw,nosuid,nodev,default_permissions,allow_other)
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# blkid /dev/sdb1 #先查看设备的UUID信息
/dev/sdb1: LABEL="yinzhengjie" UUID="768fe361-9425-4928-b2d9-641064d1052a" TYPE="ext4"
[root@yinzhengjie ~]# mount UUID="768fe361-9425-4928-b2d9-641064d1052a" /yinzhengjie/ #将上面查阅到的UUID=
"768fe361-9425-4928-b2d9-641064d1052a"赋值下来,它就是“/dev/sdb1”这块设备,我们将它挂载到"/yinzhengjie"目录下。
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# mount #查看挂载信息
/dev/sda2 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,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
vmware-vmblock on /var/run/vmblock-fuse type fuse.vmware-vmblock (rw,nosuid,nodev,default_permissions,allow_other)
/dev/sdb1 on /yinzhengjie type ext4 (rw)
[root@yinzhengjie ~]# ll /yinzhengjie/ #发现能够成功范围数据。
total 16
-rw-r--r--. 1 root root 0 May 12 04:36 1.txt
-rw-r--r--. 1 root root 0 May 12 04:36 2.txt
-rw-r--r--. 1 root root 0 May 12 04:36 3.txt
-rw-r--r--. 1 root root 0 May 12 04:36 4.txt
-rw-r--r--. 1 root root 0 May 12 04:36 5.txt
drwx------. 2 root root 16384 May 12 04:31 lost+found
[root@yinzhengjie ~]#
'''

mount命令基于UUID进行挂载用法展示

 #!/usr/bin/env python
#_*_coding:utf-8_*_
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/
#EMAIL:y1053419035@qq.com '''
[root@yinzhengjie ~]# mount #查看挂载信息
/dev/sda2 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,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
vmware-vmblock on /var/run/vmblock-fuse type fuse.vmware-vmblock (rw,nosuid,nodev,default_permissions,allow_other)
/dev/sdb1 on /yinzhengjie type ext4 (rw) #发现这个设备的挂载的权限是"读写(rw)"模式
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# mount -o remount,ro /dev/sdb1 #我们对其进行重新挂载,并将挂载后权限设置为只读模式。
[root@yinzhengjie ~]# mount
/dev/sda2 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,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
vmware-vmblock on /var/run/vmblock-fuse type fuse.vmware-vmblock (rw,nosuid,nodev,default_permissions,allow_other)
/dev/sdb1 on /yinzhengjie type ext4 (ro) #过着,权限变成了只读(ro)了。
[root@yinzhengjie ~]# '''

mount命令的remount重新挂载用法展示

 #!/usr/bin/env python
#_*_coding:utf-8_*_
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/
#EMAIL:y1053419035@qq.com '''
[root@yinzhengjie ~]# mount
/dev/sda2 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,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
vmware-vmblock on /var/run/vmblock-fuse type fuse.vmware-vmblock (rw,nosuid,nodev,default_permissions,allow_other)
/dev/sdb1 on /yinzhengjie type ext4 (ro) #权限是只读
[root@yinzhengjie ~]# mount -o remount,rw,acl /dev/sdb1 #启用文件访问控制列表功能(acl)
[root@yinzhengjie ~]# mount
/dev/sda2 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,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
vmware-vmblock on /var/run/vmblock-fuse type fuse.vmware-vmblock (rw,nosuid,nodev,default_permissions,allow_other)
/dev/sdb1 on /yinzhengjie type ext4 (rw,acl) #发现真的有acl和rw权限了。
[root@yinzhengjie ~]# '''

mount命令启动acl功能用法展示

 #!/usr/bin/env python
#_*_coding:utf-8_*_
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/
#EMAIL:y1053419035@qq.com '''
[root@yinzhengjie ~]# tune2fs -o acl /dev/sdb1 #给该分区添加ACL熟悉,让其挂载的时候默认就支持ACL
tune2fs 1.41.12 (17-May-2010)
[root@yinzhengjie ~]# tune2fs -l /dev/sdb1 | grep ^D #查看该分区信息
Default mount options: acl #我们发现是启用了acl功能的,在mount的选项的时候它会自动支持该参数。
Desired extra isize: 28
Default directory hash: half_md4
Directory Hash Seed: 63cd7ef0-15f3-4e20-978a-82472a392459
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# mount /dev/sdb1 /yinzhengjie/
[root@yinzhengjie ~]# mount
/dev/sda2 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,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
vmware-vmblock on /var/run/vmblock-fuse type fuse.vmware-vmblock (rw,nosuid,nodev,default_permissions,allow_other)
/dev/sdb1 on /yinzhengjie type ext4 (rw) #注意这里尽管没有acl显示,但是它还是有acl属性的,因为那个分区本身就支持acl,是咱们给配置的。
[root@yinzhengjie ~]#
如果你想取消mount这个参数咋办呢?很简单,只要加一个“^”这个符号就好使了,如下:
[root@yinzhengjie ~]# tune2fs -o ^acl /dev/sdb1
tune2fs 1.41.12 (17-May-2010)
[root@yinzhengjie ~]# tune2fs -l /dev/sdb1 | grep ^D
Default mount options: (none) #发现该属性的确是没有啦!为空!
Desired extra isize: 28
Default directory hash: half_md4
Directory Hash Seed: 63cd7ef0-15f3-4e20-978a-82472a392459
[root@yinzhengjie ~]#
'''

利用tune2fs给mount添加默认acl功能用法展示

 #!/usr/bin/env python
#_*_coding:utf-8_*_
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/
#EMAIL:y1053419035@qq.com '''
[root@yinzhengjie ~]# mkdir -p /media/yinzhengjie/cdrom #创建挂载点
[root@yinzhengjie ~]# ls -l /dev/cdrom #查看媒体文件所对应的链接
lrwxrwxrwx. 1 root root 3 May 12 02:38 /dev/cdrom -> sr0
[root@yinzhengjie ~]# ls -l /dev/sr0
brw-rw----+ 1 root cdrom 11, 0 May 12 02:38 /dev/sr0
[root@yinzhengjie ~]# ls -l /dev/dvd
lrwxrwxrwx. 1 root root 3 May 12 02:38 /dev/dvd -> sr0
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# mount -o ro /dev/cdrom /media/yinzhengjie/cdrom/ #以只读(ro)的方式挂载,等价于:mount -r /dev/cdrom /media/yinzhengjie/cdrom/
[root@yinzhengjie ~]# mount
/dev/sda2 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,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
vmware-vmblock on /var/run/vmblock-fuse type fuse.vmware-vmblock (rw,nosuid,nodev,default_permissions,allow_other)
/dev/sdb1 on /yinzhengjie type ext4 (rw)
/dev/sr0 on /media/yinzhengjie/cdrom type iso9660 (ro)
[root@yinzhengjie ~]# ll /media/yinzhengjie/cdrom/
total 712
-r--r--r--. 2 root root 14 Oct 24 2014 CentOS_BuildTag
dr-xr-xr-x. 3 root root 2048 Oct 24 2014 EFI
-r--r--r--. 2 root root 212 Nov 27 2013 EULA
-r--r--r--. 2 root root 18009 Nov 27 2013 GPL
dr-xr-xr-x. 3 root root 2048 Oct 24 2014 images
dr-xr-xr-x. 2 root root 2048 Oct 24 2014 isolinux
dr-xr-xr-x. 2 root root 686080 Oct 24 2014 Packages
-r--r--r--. 2 root root 1354 Oct 19 2014 RELEASE-NOTES-en-US.html
dr-xr-xr-x. 2 root root 4096 Oct 24 2014 repodata
-r--r--r--. 2 root root 1706 Nov 27 2013 RPM-GPG-KEY-CentOS-6
-r--r--r--. 2 root root 1730 Nov 27 2013 RPM-GPG-KEY-CentOS-Debug-6
-r--r--r--. 2 root root 1730 Nov 27 2013 RPM-GPG-KEY-CentOS-Security-6
-r--r--r--. 2 root root 1734 Nov 27 2013 RPM-GPG-KEY-CentOS-Testing-6
-r--r--r--. 1 root root 3380 Oct 24 2014 TRANS.TBL
[root@yinzhengjie ~]#
'''

mount命令用只读的方式挂载光盘

 #!/usr/bin/env python
#_*_coding:utf-8_*_
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/
#EMAIL:y1053419035@qq.com '''
[root@yinzhengjie ~]# umount /dev/sr0 #卸载给设备报错了
umount: /media/yinzhengjie/cdrom: device is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1)) #说是用lsof和fuser命令可以找到这个设备被谁使用
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# fuser /media/yinzhengjie/cdrom/ #看一下是哪个进程再访问这个设备
/media/yinzhengjie/cdrom/: 2420c
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# fuser -v /media/yinzhengjie/cdrom/ #查看详细信息,到底是哪个用户和对应的进程在访问该设备。
USER PID ACCESS COMMAND
/media/yinzhengjie/cdrom/:
root 2420 ..c.. bash
[root@yinzhengjie ~]# who #其实是我自己开了2个设备在测试呢!
root pts/0 2017-05-12 03:08 (172.16.3.210)
root pts/1 2017-05-12 05:42 (172.16.3.210)
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# fuser -km /media/yinzhengjie/cdrom/ #将正在访问的该设备的用户踢出去。
/media/yinzhengjie/cdrom/: 2420c
[root@yinzhengjie ~]# who #执行了上个命令,哪个用户就被提出终端了!
root pts/1 2017-05-12 05:42 (172.16.3.210)
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# umount /dev/sr0 #再一次执行卸载,发现没有报错
[root@yinzhengjie ~]# mount #也成功卸载掉了
/dev/sda2 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,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
vmware-vmblock on /var/run/vmblock-fuse type fuse.vmware-vmblock (rw,nosuid,nodev,default_permissions,allow_other)
[root@yinzhengjie ~]#
'''

umount卸载报错解决方案展示

 #!/usr/bin/env python
#_*_coding:utf-8_*_
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/
#EMAIL:y1053419035@qq.com '''
其实mount命令是通过“/proc/mounts[也是和内核相关的文件哟]”这个文件获取到当前系统上正在挂载的相关信息,只不过mount用了比较让我们易
读的方式输出出来而已。
[root@yinzhengjie ~]# cat /proc/mounts
rootfs / rootfs rw 0 0
proc /proc proc rw,relatime 0 0
sysfs /sys sysfs rw,seclabel,relatime 0 0
devtmpfs /dev devtmpfs rw,seclabel,relatime,size=490820k,nr_inodes=122705,mode=755 0 0
devpts /dev/pts devpts rw,seclabel,relatime,gid=5,mode=620,ptmxmode=000 0 0
tmpfs /dev/shm tmpfs rw,seclabel,relatime 0 0
/dev/sda2 / ext4 rw,seclabel,relatime,barrier=1,data=ordered 0 0
none /selinux selinuxfs rw,relatime 0 0
devtmpfs /dev devtmpfs rw,seclabel,relatime,size=490820k,nr_inodes=122705,mode=755 0 0
/proc/bus/usb /proc/bus/usb usbfs rw,relatime 0 0
/dev/sda1 /boot ext4 rw,seclabel,relatime,barrier=1,data=ordered 0 0
none /proc/sys/fs/binfmt_misc binfmt_misc rw,relatime 0 0
vmware-vmblock /var/run/vmblock-fuse fuse.vmware-vmblock rw,nosuid,nodev,relatime,user_id=0,group_id=0,default_permissions,allow_other 0 0
/dev/sdb1 /yinzhengjie ext4 rw,seclabel,relatime,barrier=1,data=ordered 0 0
[root@yinzhengjie ~]#
我们知道mount命令可以让我们用来挂载以及查看相关相信,但是最终的数据存放在哪里呢?当然是要有一个配置文件了,其中“/etc/mtab ”就是一个用来存放
挂载信息的。
[root@yinzhengjie ~]# cat /etc/mtab
/dev/sda2 / ext4 rw 0 0
proc /proc proc rw 0 0
sysfs /sys sysfs rw 0 0
devpts /dev/pts devpts rw,gid=5,mode=620 0 0
tmpfs /dev/shm tmpfs rw,rootcontext="system_u:object_r:tmpfs_t:s0" 0 0
/dev/sda1 /boot ext4 rw 0 0
none /proc/sys/fs/binfmt_misc binfmt_misc rw 0 0
vmware-vmblock /var/run/vmblock-fuse fuse.vmware-vmblock rw,nosuid,nodev,default_permissions,allow_other 0 0
/dev/sdb1 /yinzhengjie ext4 rw 0 0
[root@yinzhengjie ~]#
让我们来做个测试,我们卸载一个挂载点,看这个配置文件是否也发生变化。
[root@yinzhengjie ~]# umount /dev/sdb1 #我们卸载之前手动挂载的分区
[root@yinzhengjie ~]# cat /etc/mtab #再次查看该配置文件,果不其然,随着mount命令将挂载信息删除了。
/dev/sda2 / ext4 rw 0 0
proc /proc proc rw 0 0
sysfs /sys sysfs rw 0 0
devpts /dev/pts devpts rw,gid=5,mode=620 0 0
tmpfs /dev/shm tmpfs rw,rootcontext="system_u:object_r:tmpfs_t:s0" 0 0
/dev/sda1 /boot ext4 rw 0 0
none /proc/sys/fs/binfmt_misc binfmt_misc rw 0 0
vmware-vmblock /var/run/vmblock-fuse fuse.vmware-vmblock rw,nosuid,nodev,default_permissions,allow_other 0 0
[root@yinzhengjie ~]#
'''

扩展:mount的前世今生

14.查看磁盘信息命令

a>.df 磁盘空间使用状态报告

 #!/usr/bin/env python
#_*_coding:utf-8_*_
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/
#EMAIL:y1053419035@qq.com
'''
[root@yinzhengjie ~]# df #默认是以KB为单位的
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 18208184 2504904 14771696 15% /
tmpfs 502172 72 502100 1% /dev/shm
/dev/sda1 289293 28473 245460 11% /boot
[root@yinzhengjie ~]# df -m #以MB为空间
Filesystem 1M-blocks Used Available Use% Mounted on
/dev/sda2 17782 2447 14426 15% /
tmpfs 491 1 491 1% /dev/shm
/dev/sda1 283 28 240 11% /boot
[root@yinzhengjie ~]# df -h #将文件大小显示易读格式
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 18G 2.4G 15G 15% /
tmpfs 491M 72K 491M 1% /dev/shm
/dev/sda1 283M 28M 240M 11% /boot
[root@yinzhengjie ~]# df -i #显示inode数量
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda2 1164592 98347 1066245 9% /
tmpfs 125543 3 125540 1% /dev/shm
/dev/sda1 76912 38 76874 1% /boot
[root@yinzhengjie ~]# df -ih #划算成一度单位,注意下面的M或者K表示的不是文件的大小,而是表示的数字K=1000,M=1000000
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda2 1.2M 97K 1.1M 9% /
tmpfs 123K 3 123K 1% /dev/shm
/dev/sda1 76K 38 76K 1% /boot
[root@yinzhengjie ~]# df -P #全部显示,就是当Filesystem名称过长的时候,不会换行显示。
Filesystem 1024-blocks Used Available Capacity Mounted on
/dev/sda2 18208184 2504908 14771692 15% /
tmpfs 502172 72 502100 1% /dev/shm
/dev/sda1 289293 28473 245460 11% /boot
[root@yinzhengjie ~]# df -Ph #将文件大小显示易读格式且每行信息不换行显示。
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 18G 2.4G 15G 15% /
tmpfs 491M 72K 491M 1% /dev/shm
/dev/sda1 283M 28M 240M 11% /boot
[root@yinzhengjie ~]# df -Ph /dev/sda1 #可以单独查看一个分区情况。
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 283M 28M 240M 11% /boot
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# df -T #显示时显示文件类型
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/sda2 ext4 18208184 2504920 14771680 15% /
tmpfs tmpfs 502172 72 502100 1% /dev/shm
/dev/sda1 ext4 289293 28473 245460 11% /boot
[root@yinzhengjie ~]#
'''

b>.du 显示文件占用磁盘的情况

 #!/usr/bin/env python
#_*_coding:utf-8_*_
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/
#EMAIL:y1053419035@qq.com
'''
[root@yinzhengjie ~]# ls -ldh /etc/ #查看目录大小,很明显不准确!
drwxr-xr-x. 102 root root 4.0K May 12 05:48 /etc/
[root@yinzhengjie ~]# du -s /etc/ #用du查看文件大小,默认为K.
39788 /etc/
[root@yinzhengjie ~]# du -sh /etc/ #用du查看目录大小,默认为M
39M /etc/
[root@yinzhengjie ~]# du -sh /etc/sysconfig/network-scripts/ifcfg-eth0 #我们也可以查看文件的大小
4.0K /etc/sysconfig/network-scripts/ifcfg-eth0
[root@yinzhengjie ~]# '''

 

15.开机自动挂载

 #!/usr/bin/env python
#_*_coding:utf-8_*_
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/
#EMAIL:y1053419035@qq.com
'''
开机自动挂载
/etc/rc.d/rc.sysinit:系统初始化脚本
其中一个功能:挂载/etc/fstab文件中定义的文件系统挂载点
[root@yinzhengjie ~]# cat /etc/fstab #
# /etc/fstab
# Created by anaconda on Tue Apr 11 05:43:15 2017
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=421dd611-48a1-4a71-9f06-60605f68ef0d / ext4 defaults 1 1
UUID=003bdf87-a068-4553-b506-f174b1f82ed6 /boot ext4 defaults 1 2
UUID=1020e7eb-2f17-4a4d-b8bf-36776dcbf547 swap swap defaults 0 0
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
[root@yinzhengjie ~]#
我们看以下挂载的格式,从左往右一次又6列参数,那么这6列参数是啥意思呢?请看以下分析:
1>.要挂载的设备:设备文件、LABEL=”ladel” UUID
2>.挂载点:有的文件系统没有挂载点 swap没有挂载点,挂载点为swap
3>.文件系统类型:
4>.挂载选项:多个选项间使用逗号分隔
5>.转储频率:
0:从不备份
1:每日备份
2:每隔一天备份
6>.自检次序
1:首先自检,通常只能被/使用
2-9:顺序
0:从不自检
'''
 #!/usr/bin/env python
#_*_coding:utf-8_*_
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/
#EMAIL:y1053419035@qq.com
'''
[root@yinzhengjie ~]# vim + /etc/fstab #编辑mount配置文件,并将光标移动在最后一行,“+”参数表示最后一行
[root@yinzhengjie ~]# cat /etc/fstab #在最后一行添加你需要开机挂载的设备和目录。 #
# /etc/fstab
# Created by anaconda on Tue Apr 11 05:43:15 2017
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=421dd611-48a1-4a71-9f06-60605f68ef0d / ext4 defaults 1 1
UUID=003bdf87-a068-4553-b506-f174b1f82ed6 /boot ext4 defaults 1 2
UUID=1020e7eb-2f17-4a4d-b8bf-36776dcbf547 swap swap defaults 0 0
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
/dev/sdb1 /yinzhengjie ext4 defaults,acl 0 0 #这就是我们新加的一行。
[root@yinzhengjie ~]# mount #查看当前挂载项。
/dev/sda2 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,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
vmware-vmblock on /var/run/vmblock-fuse type fuse.vmware-vmblock (rw,nosuid,nodev,default_permissions,allow_other)
[root@yinzhengjie ~]# mount -a #重新加载“ /etc/fstab”把fstab里面没有挂载的信息进行挂载,其功效等同于重做操作系统时进行的自动挂载。或者执行“init 6”再查看配置文件是否生效。
[root@yinzhengjie ~]# mount #再次查看当前挂载项。
/dev/sda2 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,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
vmware-vmblock on /var/run/vmblock-fuse type fuse.vmware-vmblock (rw,nosuid,nodev,default_permissions,allow_other)
/dev/sdb1 on /yinzhengjie type ext4 (rw,acl) #发现最后一行多出了一行挂载信息。说明你操作成功了。
[root@yinzhengjie ~]# '''

修改 /etc/fstab配置文件进行开机自动挂载展示

16.查看内存空间使用状态

 #!/usr/bin/env python
#_*_coding:utf-8_*_
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/
#EMAIL:y1053419035@qq.com
'''
[root@yinzhengjie ~]# cat /proc/meminfo #查看内存信息
MemTotal: 1004348 kB
MemFree: 671056 kB
Buffers: 18764 kB
Cached: 126240 kB
SwapCached: 0 kB
Active: 108700 kB
Inactive: 110672 kB
Active(anon): 74616 kB
Inactive(anon): 1184 kB
Active(file): 34084 kB
Inactive(file): 109488 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 4136088 kB
SwapFree: 4136088 kB
Dirty: 164 kB
Writeback: 0 kB
AnonPages: 74376 kB
Mapped: 42396 kB
Shmem: 1440 kB
Slab: 75132 kB
SReclaimable: 15608 kB
SUnreclaim: 59524 kB
KernelStack: 1560 kB
PageTables: 10916 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 4638260 kB
Committed_AS: 336672 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 156112 kB
VmallocChunk: 34359567284 kB
HardwareCorrupted: 0 kB
AnonHugePages: 12288 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
DirectMap4k: 6144 kB
DirectMap2M: 1042432 kB
DirectMap1G: 0 kB
[root@yinzhengjie ~]# free -m #其实free命令的数据时取自“/proc/meminfo”文件的,知识为了易读性可以用free -m参数查看内存使用情况
total used free shared buffers cached
Mem: 980 325 655 1 18 123
-/+ buffers/cache: 183 797 #这一行才是正点,其他的都是虚的,实际使用内存为183,实际空余内存为797
Swap: 4039 0 4039
[root@yinzhengjie ~]# free -g #这个参数是以GB为单位,列出磁盘中内存信息,空余查看内存比较大的时候用,如果你的内存不深就很少的话就会跟我一样出现下面的尴尬参数了。
total used free shared buffers cached
Mem: 0 0 0 0 0 0
-/+ buffers/cache: 0 0
Swap: 3 0 3
[root@yinzhengjie ~]# '''

17.dd命令常用参数展示:

 #!/usr/bin/env python
#_*_coding:utf-8_*_
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/
#EMAIL:y1053419035@qq.com '''
dd命令:
bs:一次读多大的数据量
count:读取次数
if:输入文件
of:输出文件
dd if=input_file of=output_file
dd if=input_file of=output_file bs=#[b|k|m|g] count=#
cat /dev/cdrom > /tmp/linux.iso #制作光盘
/dev/zero:吐01的
'''
 #!/usr/bin/env python
#_*_coding:utf-8_*_
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/
#EMAIL:y1053419035@qq.com
'''
[root@yinzhengjie ~]# cat /etc/issue
CentOS release 6.6 (Final)
Kernel \r on an \m This is Yin Zhengjie's server [root@yinzhengjie ~]#
[root@yinzhengjie ~]# dd if=/etc/issue of=/tmp/issue.dd
0+1 records in #读了多少个
0+1 records out #输出了多少个
84 bytes (84 B) copied, 0.00011992 s, 700 kB/s #多少字节被复制,一共花了多长时间,每秒钟传输数据的平局速度。
[root@yinzhengjie ~]# cat /tmp/issue.dd #查看内容的确被复制
CentOS release 6.6 (Final)
Kernel \r on an \m This is Yin Zhengjie's server [root@yinzhengjie ~]# '''

利用dd拷贝文件效率要高与cp命令

  其实dd相比cp是一个更低级的命令,跟语言一样,语言越高级越接近用户,处理速度就越慢,语言越低级就越接近机器,处理速度就越快,那么为什么dd命令处理速度要相比cp更快呢?其实很简单,cp命令才拷贝文件的时候,先通过VFS系统(即虚拟文件系统)将源数据通通的读取出来,然后在将这些数据传给VFS,并通过文件系统在重新生成一份一模一样的数据才完成了拷贝功能,但是dd命令就不一样了,他绕过了VFS系统,直接找到源数据的inode所对应的blocks,直接将这些blocks内存中拷贝一份,这就是两者的差距。

                 高级Linux运维工程师必备技能(扫盲篇)

 #!/usr/bin/env python
#_*_coding:utf-8_*_
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/
#EMAIL:y1053419035@qq.com
'''
[root@yinzhengjie ~]# dd if=/dev/zero of=/yinzhengjie.swapfile bs=1M count=100 #创建一个100M的文件
100+0 records in
100+0 records out
104857600 bytes (105 MB) copied, 0.145994 s, 718 MB/s
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# ll -h / | grep yinzhengjie #验证文件是否创建成功
drwxr-xr-x. 3 root root 4.0K May 12 04:36 yinzhengjie
-rw-r--r--. 1 root root 100M May 12 10:46 yinzhengjie.swapfile #发现有这个100M的文件
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# mkswap -f /yinzhengjie.swapfile #强制将这个文件格式化成交换分区
Setting up swapspace version 1, size = 102396 KiB
no label, UUID=f5896342-dd1f-4980-8806-2086ae3fec90
[root@yinzhengjie ~]# free -m #先查看内存信息
total used free shared buffers cached
Mem: 980 890 90 1 451 227
-/+ buffers/cache: 212 768
Swap: 4039 0 4039 #我们发现现在的total=4039
[root@yinzhengjie ~]# swapon /yinzhengjie.swapfile #开启这个文件的交换分区
[root@yinzhengjie ~]# free -m #发现果然多了100M的swap分区
total used free shared buffers cached
Mem: 980 890 90 1 451 227
-/+ buffers/cache: 212 768
Swap: 4139 0 4139 #我们发现现在的total=4139
[root@yinzhengjie ~]#
'''

利用dd命令创建一个swap分区文件,但是不到玩不得不要用!

以下是dd生产环节中常用的几个案例:

 #!/usr/bin/env python
#_*_coding:utf-8_*_
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/
#EMAIL:y1053419035@qq.com '''
linux制作光盘的2种方式:
[root@yinzhengjie ~]# dd if=/dev/cdrom of=/yinzhengjie/linux.iso #利用dd命令制作光盘,方法一
[root@yinzhengjie ~]# cat /dev/cdrom > /yinzhengjie/linux.iso #利用cat命令制作光盘,方法二
linux中的磁盘对拷贝:
[root@yinzhengjie ~]# dd if=/dev/sda of=/dev/sdb #即将/dev/sda设备的信息拷贝一份到/dev/sdb上去。
[root@yinzhengjie ~]# dd if=/dev/sda of=/tmp/myfile bs=512 count=1 #讲/dev/sda的MBR分区进行备份,当分区表破坏时,可以用/tmp/myfile进行还原。
[root@yinzhengjie ~]# dd if=/dev/zero of=/dev/sdb bs=512 count=1 #删除/dev/sdb的分区信息,当然里面的数据还是可以找回来的,可以通过专业的数据恢复工具。
[root@yinzhengjie ~]# dd if=/dev/zero of=/yinzhengjie.swapfile bs=1M count=100 #创建一个100M的本地回环设备,可以用来做分区格式化的(当然得需要一些额外的操作)
''' #这里只是dd命令的冰山一角,想要了解dd命令更多的用法,请参考man帮助,在哪里或许你能找到你感兴趣的参数。

18.巧记归档命令

 #!/usr/bin/env python
#_*_coding:utf-8_*_
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/
#EMAIL:y1053419035@qq.com '''
文件链接
ln 源文件 目标文件
硬链接:
不能跨分区,
指向同一个indone的两个位置
不能对目录创建硬链接
硬链接会改变文件被链接的次数
符号链接:
ln -s
符号链接可以跨分区
符号链接文件跟源文件不同一个inode
可以对目录创建符号链接
符号链接不会改变源文件被链接的次数 dev 第一个表示主设备号 第二个表示次设备号 压缩工具
zip:
gzip:gunzip= gzip -d,zcat
后缀:.gz
-c 指定要压缩的文件
bzip2,bunzip2
-k 保留源文件
后缀 .bz
xz
后缀.xz
-#:指定压缩比 1-9,默认的为6 归档工具:
tar [options] file.tar file1....
-c:创建归档
-x:展开归档
-t:不展开而直接查看被归档的文件
-z:使用gzip压缩
-j:使用bz2压缩
-J:使用xz压缩 '''
上一篇:编写Spark的WordCount程序并提交到集群运行[含scala和java两个版本]


下一篇:进程通信类型 管道是Linux支持的最初Unix IPC形式之一 命名管道 匿名管道