1.磁盘的分区主要分为基本分区(primary partion)和扩充分区(extension partion)两种,基本分区和扩充分区的数目之和不能大于四个。且基本分区可以马上被使用但不能再分区。扩充分区必须再进行分区后才能使用,也就是说它必须还要进行二次分区。那么由扩充分区再分下去的是什么呢?它就是逻辑分区(logical partion),况且逻辑分区没有数量上限制。
在 Linux 中,每一个硬件设备都映射到一个系统的文件,对于硬盘、光驱等 IDE 或 SCSI 设备也不例外。Linux把各种 IDE 设备分配了一个由 hd 前缀组成的文件;而对于各种 SCSI 设备,则分配了一个由 sd 前缀组成的文件。
对于ide硬盘,驱动器标识符为“hdx~”,其中“hd”表明分区所在设备的类型,这里是指ide硬盘了。“x”为盘号(a为基本盘,b为基本从属盘,c为辅助主盘,d为辅助从属盘),“~”代表分区,前四个分区用数字1到4表示,它们是主分区或扩展分区,从5开始就是逻辑分区。例,hda3表示为第一个ide硬盘上的第三个主分区或扩展分区,hdb2表示为第二个ide硬盘上的第二个主分区或扩展分区。对于scsi硬盘则标识为“sdx~”,scsi硬盘是用“sd”来表示分区所在设备的类型的,其余则和ide硬盘的表示方法一样,不在多说。
在 Linux 中规定,每一个硬盘设备最多能有 4个主分区(其中包含扩展分区)构成,任何一个扩展分区都要占用一个主分区号码,也就是在一个硬盘中,主分区和扩展分区一共最多是 4 个。
Linux 规定了主分区(或者扩展分区)占用 1 至 16 号码中的前 4 个号码。以第一个 IDE 硬盘为例说明,主分区(或者扩展分区)占用了 hda1、hda2、hda3、hda4,而逻辑分区占用了 hda5 到 hda16 等 12 个号码。
因此,Linux 下面每一个硬盘总共最多有 16 个分区。
IDE硬盘最多有64个分区
1.fdisk -l 查看系统分区详细信息
1 [root@test4 ~]# fdisk -l 2 Disk /dev/sda: 21.4 GB, 21474836480 bytes 3 255 heads, 63 sectors/track, 2610 cylinders 4 Units = cylinders of 16065 * 512 = 8225280 bytes 5 6 Device Boot Start End Blocks Id System 7 /dev/sda1 * 1 13 104391 83 Linux 8 /dev/sda2 14 2610 20860402+ 8e Linux LVM
注释:这个硬盘的大小是21.4GB,有255个磁面,63个扇区,2610磁柱(cylinders)
每个cylinder(磁柱)的容量是 8225280 bytes=8225.280 K(约为)=8.225280M(约为);
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1305 10377990 8e Linux LVM
id和System 表示的是一个意思,id看起来不太直观,我们要在fdisk 一个分区时,通过指定id来确认分区类型;比如 7表示的就NTFS 分区;这个在fdisk 中要通过t功能来指定。83是linux。下面的部分会提到;
说明:硬盘分区的表示:在Linux 是通过hd*x 或 sd*x 表示的:
其中* 表示的是a、b、c ... ...
另外x 表示的数字 1、2、3 ... ...
hd大多是IDE硬盘;sd大多是SCSI或移动存储;引导(Boot):表示引导分区,在上面的例子中sda1 是引导分区;
Start (开始):表示的一个分区从Xcylinder(磁柱)开始;
End (结束):表示一个分区到 Ycylinder(磁柱)结束;
2.fdisk 对磁盘进行分区
[root@test4 ~]# fdisk /dev/sda //对sda磁盘进行分区 Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. The number of cylinders for this disk is set to 2597. There is nothing wrong with that, but this is larger than 1024, and could in certain setups cause problems with: 1) software that runs at boot time (e.g., old versions of LILO) 2) booting and partitioning software from other OSs (e.g., DOS FDISK, OS/2 FDISK) Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) 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 //创建一个新的空白DOS分区表 p print the partition table //打印分区表 q quit without saving changes //退出不保存设置 s create a new empty Sun disklabel t change a partition's system id //改变分区的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):n Command action e extended //e是扩展分区 p primary partition (1-4) //p是主分区 p Partition number (1-4): 1 //定义分区数量 --主分区最多只能有四个 First cylinder (1-2597, default 1): 1 Last cylinder or +size or +sizeM or +sizeK (1-2597, default 2597): +100M Command (m for help): w //保存刚才的配置信息。 The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 22: 无效的参数. The kernel still uses the old table. The new table will be used at the next reboot. Syncing disks.
[root@test6 ~]# fdisk /dev/sda The number of cylinders for this disk is set to 2610. There is nothing wrong with that, but this is larger than 1024, and could in certain setups cause problems with: 1) software that runs at boot time (e.g., old versions of LILO) 2) booting and partitioning software from other OSs (e.g., DOS FDISK, OS/2 FDISK) Command (m for help): n First cylinder (1710-2610, default 1710): Using default value 1710 Last cylinder or +size or +sizeM or +sizeK (1710-2610, default 2610): +100M Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: 设备或资源忙. The kernel still uses the old table. The new table will be used at the next reboot. Syncing disks. [root@test6 ~]# partprobe /dev/sda //对硬盘进行更新 [root@test6 ~]# fdisk -l Disk /dev/sda: 21.4 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sda1 * 1 13 104391 83 Linux /dev/sda2 14 274 2096482+ 82 Linux swap / Solaris /dev/sda3 275 404 1044225 8e Linux LVM /dev/sda4 405 2610 17719695 5 Extended /dev/sda5 405 1709 10482381 83 Linux /dev/sda6 1710 1722 104391 83 Linux [root@test6 ~]# mkfs.ext3 /dev/sda6 //需要先进行格式化,才能使用 。mkfs -t ext3 /dev/sda5 (mkfs.ext3 一样效果 -t 指定类型 -b 指定block大小·) mke2fs 1.39 (29-May-2006) Filesystem label= OS type: Linux Block size=1024 (log=0) Fragment size=1024 (log=0) 26104 inodes, 104388 blocks 5219 blocks (5.00%) reserved for the super user First data block=1 Maximum filesystem blocks=67371008 13 block groups 8192 blocks per group, 8192 fragments per group 2008 inodes per group Superblock backups stored on blocks: 8193, 24577, 40961, 57345, 73729 Writing inode tables: done Creating journal (4096 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 23 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@test6 ~]# mount /dev/sda6 /mnt/sda7/ //进行挂载使用 anaconda-ks.cfg install.log install.log.syslog [root@test6 ~]# df -h 文件系统 容量 已用 可用 已用% 挂载点 /dev/sda5 9.7G 1.1G 8.1G 12% / /dev/sda1 99M 12M 83M 13% /boot tmpfs 252M 0 252M 0% /dev/shm /dev/hdc 3.9G 3.9G 0 100% /mnt/cdrom /dev/sda6 99M 5.6M 89M 6% /mnt/sda7
blkid命令
在Linux下可以使用blkid命令对查询设备上所采用文件系统类型进行查询。blkid主要用来对系统的块设备(包括交换分区)所使用的文件系统类型、LABEL、UUID等信息进行查询。要使用这个命令必须安装e2fsprogs软件包。
语法
blkid -L | -U blkid [-c ] [-ghlLv] [-o] [-s ][-t ] [-w ] [ ...] blkid -p [-s ] [-O ] [-S ][-o] ... blkid -i [-s ] [-o] ...
选项
-c <file> 指定cache文件(default: /etc/blkid.tab, /dev/null = none) -d don't encode non-printing characters -h 显示帮助信息 -g garbage collect the blkid cache -o <format> 指定输出格式 -k list all known filesystems/RAIDs and exit -s <tag> 显示指定信息,默认显示所有信息 -t <token> find device with a specific token (NAME=value pair) -l look up only first device with token specified by -t -L <label> convert LABEL to device name -U <uuid> convert UUID to device name -v 显示版本信息 -w <file> write cache to different file (/dev/null = no write) <dev> specify device(s) to probe (default: all devices) Low-level probing options: -p low-level superblocks probing (bypass cache) -i gather information about I/O limits -S <size> overwrite device size -O <offset> probe at the given offset -u <list> filter by "usage" (e.g. -u filesystem,raid) -n <list> filter by filesystem type (e.g. -n vfat,ext3)
1、列出当前系统中所有已挂载文件系统的类型: sudo blkid 2、显示指定设备 UUID: sudo blkid -s UUID /dev/sda5 3、显示所有设备 UUID: sudo blkid -s UUID 4、显示指定设备 LABEL: sudo blkid -s LABEL /dev/sda5 5、显示所有设备 LABEL: sudo blkid -s LABEL 6、显示所有设备文件系统: sudo blkid -s TYPE 7、显示所有设备: sudo blkid -o device 8、以列表方式查看详细信息: sudo blkid -o list
挂载概念简述:
根文件系统之外的其他文件要想能够被访问,都必须通过“关联”至根文件系统上的某个目录来实现,此关联操作即为“挂载”,此目录即为“挂载点”,解除此关联关系的过程称之为“卸载”
1.挂载:根文件系统外通过关联至根文件系统上的某个目录来实现访问
2.挂载点:mount_point,用于作为另一个文件系统的访问入口;
(1) 事先存在;
(2) 应该使用未被或不会被其它进程使用到的目录;
(3) 挂载点下原有的文件将会被隐藏;
挂载与卸载
挂载方法:mount DECE MOUNT_POINT
mount:通过查看/etc/mtab(文章最后会对/etc/mtab有个解释)文件显示当前系统已挂载的所有设备
命令使用格式:mount [-fnrsvw] [-t vfstype] [-o options] device dir
device:指明要挂载的设备;
(1) 设备文件:例如/dev/sda5
(2) 卷标:-L 'LABEL', 例如 -L 'MYDATA'
(3) UUID, -U 'UUID':例如 -U '0c50523c-43f1-45e7-85c0-a126711d406e'
(4) 伪文件系统名称:proc, sysfs, devtmpfs, configfs
dir:挂载点
事先存在;建议使用空目录;
进程正在使用中的设备无法被卸载;
常用命令选项:
-t vsftype:指定要挂载的设备上的文件系统类型;
-r: readonly,只读挂载;
-w: read and write, 读写挂载;
-n: 不更新/etc/mtab;
-a:自动挂载所有支持自动挂载的设备;(定义在了/etc/fstab文件中,且挂载选项中有“自动挂载”功能)
-L 'LABEL': 以卷标指定挂载设备;
-U 'UUID': 以UUID指定要挂载的设备;
-B, --bind: 绑定目录到另一个目录上;
注意:查看内核追踪到的已挂载的所有设备:cat /proc/mounts
………………………………………………………………………………………………………………………
-o options:(挂载文件系统的选项)
async:异步模式;
sync:同步模式;
atime/noatime:包含目录和文件;
diratime/nodiratime:目录的访问时间戳
auto/noauto:是否支持自动挂载
exec/noexec:是否支持将文件系统上应用程序运行为进程
dev/nodev:是否支持在此文件系统上使用设备文件;
suid/nosuid:是否支持在此文件系统上使用特殊权限
remount:重新挂载
ro:只读
rw:读写
user/nouser:是否允许普通用户挂载此设备
acl:启用此文件系统上的acl功能
注意:上述选项可多个同时使用,彼此使用逗号分隔;
默认挂载选项:defaults:rw, suid, dev, exec, auto, nouser, and async
上述信息可以通过查看超级块信息看到,这里不再对其进行演示。
………………………………………………………………………………………………………………………
命令演示:
1、指定文件系统将块设备挂载至指定空文件夹内:演示内容:1)没有指定文件系统,命令是否能正确执行;2)指定错误文件系统,命令是否能正确执行;3)挂载点有内容的文件夹,查看被挂载后其内容是否消失。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
通过上述演示,说明了如下事实:1)没有指定文件系统,块设备也可以正常挂载;2)指定与块设备不一致的文件系统类型则命令报错;3)挂载点有内容的文件夹,在挂载后内容消失,卸载后内容重现,也就是说挂载后会将原文件内容掩盖,但并不对其进行其他操作。
………………………………………………………………………………………………………………………
2、演示内容:1)指定卷标并以只读方式挂载;2)对目录进行挂载操作,查看其与硬链接与软链接有何不同。
[root@localhost device]# blkid /dev/sdb6
/dev/sdb6: LABEL="sdb6" UUID="8284450c-8cb9-45d7-a8b8-ed9ed9ef9e52" TYPE="xfs"
[root@localhost device]# mount -L 'sdb6' -r /device/
[root@localhost device]# touch /device/33
touch: 无法创建"/device/33": 只读文件系统
[root@localhost device]# umount /device/
[root@localhost /]# mount -B /etc/ /device/
[root@localhost /]# ll -i /
总用量 64
11341 lrwxrwxrwx. 1 root root 7 7月 19 23:54 bin -> usr/bin
128 dr-xr-xr-x. 4 root root 4096 8月 2 10:09 boot
3 drwxr-xr-x. 19 root root 3300 8月 23 09:10 dev
33554561 drwxr-xr-x. 129 root root 8192 8月 23 09:38 device
33554561 drwxr-xr-x. 129 root root 8192 8月 23 09:38 etc
158 drwxr-xr-x. 42 root root 4096 8月 22 09:00 home
通过上述演示,说明了如下事实:1)指定卷标挂载可行,以只读方式挂载后,无法对挂载点中的内容进行修改、创建等操作;2)目录的挂载实质上是硬链接,挂载后可以对里面的文件内容进行修改与删除。
注:文件夹的挂载在df中并不显示
………………………………………………………………………………………………………………………
卸载命令:umount
命令使用格式:
# umount DEVICE
# umount MOUNT_POINT
上面已经演示过umount的使用
fuser:查看正在访问指定文件系统的进程:
命令使用格式:
# fuser -v MOUNT_POINT
终止所有在正访问指定的文件系统的进程:慎用
# fuser -km MOUNT_POINT
交换分区swap
这里介绍下交换分区,通过实验演示交换分区的创建及挂载
挂载交换分区:
启用:swapon
swapon [OPTION]... [DEVICE]
-a:激活所有的交换分区;
-p PRIORITY:指定优先级;
禁用:swapoff [OPTION]... [DEVICE]
实验演示:
1、交换分区的创建:1)新创建一分区,2)修改新分区的类型,改为swap号码为82,3)格式化为swap
[root@localhost ~]# fdisk /dev/sdb
欢迎使用 fdisk (util-linux 2.23.2)。
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。
命令(输入 m 获取帮助):n
Partition type:
p primary (1 primary, 1 extended, 2 free)
l logical (numbered from 5)
Select (default p): l
添加逻辑分区 9
起始 扇区 (2928640-4196351,默认为 2928640):
将使用默认值 2928640
Last 扇区, +扇区 or +size{K,M,G} (2928640-4196351,默认为 4196351):+100M
分区 9 已设置为 Linux 类型,大小设为 100 MiB
命令(输入 m 获取帮助):p
磁盘 /dev/sdb:5368 MB, 5368709120 字节,10485760 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0xd391e822
设备 Boot Start End Blocks Id System
/dev/sdb1 2048 2099199 1048576 83 Linux
/dev/sdb2 2099200 4196351 1048576 5 Extended
/dev/sdb5 2101248 2306047 102400 83 Linux
/dev/sdb6 2308096 2512895 102400 83 Linux
/dev/sdb7 2514944 2719743 102400 83 Linux
/dev/sdb8 2721792 2926591 102400 83 Linux
/dev/sdb9 2928640 3133439 102400 83 Linux
命令(输入 m 获取帮助):t
分区号 (1,2,5-9,默认 9):9
Hex 代码(输入 L 列出所有代码):82
已将分区“Linux”的类型更改为“Linux swap / Solaris”
命令(输入 m 获取帮助):p
磁盘 /dev/sdb:5368 MB, 5368709120 字节,10485760 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0xd391e822
设备 Boot Start End Blocks Id System
/dev/sdb1 2048 2099199 1048576 83 Linux
/dev/sdb2 2099200 4196351 1048576 5 Extended
/dev/sdb5 2101248 2306047 102400 83 Linux
/dev/sdb6 2308096 2512895 102400 83 Linux
/dev/sdb7 2514944 2719743 102400 83 Linux
/dev/sdb8 2721792 2926591 102400 83 Linux
/dev/sdb9 2928640 3133439 102400 82 Linux swap / Solaris
命令(输入 m 获取帮助):w
The partition table has been altered!
Calling ioctl() to re-read partition table.
正在同步磁盘。
[root@localhost ~]# mkswap /dev/sdb9
正在设置交换空间版本 1,大小 = 102396 KiB
无标签,UUID=74bf2766-a01b-48ea-9082-2fad6b8e06a9
2、挂载交换分区:启用与禁用
[root@localhost ~]# free
total used free shared buff/cache available
Mem: 1001332 101756 535892 13424 363684 720328
Swap: 2097148 0 2097148
[root@localhost ~]# swapon /dev/sdb9
[root@localhost ~]# free
total used free shared buff/cache available
Mem: 1001332 101716 535924 13424 363692 720368
Swap: 2199544 0 2199544
[root@localhost ~]# swapoff /dev/sdb9
[root@localhost ~]# free
total used free shared buff/cache available
Mem: 1001332 102492 535152 13424 363688 719592
Swap: 2097148 0 2097148
实验涉及到的命令小结:
内存空间使用状态:free [OPTION]
-m: 以MB为单位
-g: 以GB为单位
文件系统空间占用等信息的查看工具:df
-h: human-readable
-i:inodes instead of blocks
-P: 以Posix兼容的格式输出;
查看某目录总体空间占用状态:du
du [OPTION]... DIR
-h: human-readable 人能看懂的格式及M,G
-s: summary
命令总结:mount, umount, free, df, du, swapon, swapoff, fuser
开机自动挂载
如果我们想实现开机自动挂载某设备,只要修改/etc/fstab文件即可。
Linux开机自动挂载存储的两种方式
登录服务器,给查看了下,发现确实是没有自动加载,df -h只能显示本地硬盘的分区,fdisk -l 还是能看到存储空间,这说明这个服务器连接存储是木有问题的。
输入history | grep mount,查看所有mount记录,最后一条为:mount /dev/emcpowerb1 /oracle/oradata。复制出来,粘贴到命令行,回车后就挂载上了。不过这个下次重启还是会有问题的,还是彻底解决吧。解决办法有俩:
1:把mount 的命令放到/etc/rc.d/rc.local 里面去,vi /etc/rc.d/rc.local ,然后把mount /dev/emcpowerb1 /oracle/oradata这个命令塞进去。保存退出就好了。
2:修改/etc/fstab文档
先vi或vim /etc/fstab
LABEL=/ / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2
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
LABEL=SWAP-sda2 swap swap defaults 0 0
这个就是fstab的内容了,把要挂载的盘信息加到里面吧:
LABEL=/ / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2
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
LABEL=SWAP-sda2 swap swap defaults 0 0
/dev/emcpowerb1 /oracle/oradata ext3 defaults 0 0
保存退出,等重启服务器就可以生效了。
关于linux开机之后自动加载挂载的分区,这块,涉及到的文件是/etc/fstab文件
关于这个文件的描述说明如下:
要求:
1)根目录/必须载入,而且要先于其他载入点被载入
2)其他载入点必须为已建立的目录
3)若进行卸载,必须先将工作目录移到载入点及其子目录之外
/etc/fstab里面每列大概意思为:
第一列为设备号或该设备的卷标,即需要挂载的文件系统或存储设备;
第二列为挂载点
第三列为文件系统或分区的类型
第四列为文件系统参数,即挂载选项,详细参考man mount.命令,defaults就没有问题,除非你有特殊需求;
第五列为dump选项,设置是否让备份程序dump备份文件系统。0:不备份,1:备份,2:备份(但比1重要性小)。设置了该参数后,Linux中使用dump命令备份系统的时候就可以备份相应设置的挂载点了。
第六列为是否在系统启动的时候,用fsck检验分区,告诉fsck程序以什么顺序检查文件系统。因为有些挂载点是不需要检验的,比如:虚拟内存swap、/proc等。0:不检验,1:要检验,2要检验(但比1晚检验),一般根目录设置为1,其他设置为2就可以了。
文件挂载的配置文件:/etc/fstab
查看此文件可知
每行定义一个要挂载的文件系统;
其每行的格式如下
要挂载的设备或伪文件系统 挂载点 文件系统类型 挂载选项 转储频率 自检次序
UUID=6efb8a23-bae1-427c-ab10-3caca95250b1 /boot xfs defaults 0 0
要挂载的设备或伪文件系统:设备文件、LABEL(LABEL="")、UUID(UUID="")、伪文件系统名称(proc, sysfs)
挂载点:指定的文件夹
挂载选项:defaults
转储频率:
0:不做备份
1:每天转储
2:每隔一天转储
自检次序:
0:不自检
1:首先自检;一般只有rootfs才用1;
/etc/fstab和/etc/mtab的区别
/etc/fstab文件的作用:
记录了计算机上硬盘分区的相关信息,启动 Linux 的时候,检查分区的 fsck 命令,和挂载分区的 mount 命令,都需要 fstab 中的信息,来正确的检查和挂载硬盘。
/etc/mtab文件的作用:
先看它的英文是:
This changes continuously as the file /proc/mount changes. In other words, when filesystems are mounted and unmounted, the change is immediately reflected in this file.
记载的是现在系统已经装载的文件系统,包括操作系统建立的虚拟文件等;而/etc/fstab是系统准备装载的。 每当 mount 挂载分区、umount 卸载分区,都会动态更新 mtab,mtab 总是保持着当前系统中已挂载的分区信息,fdisk、df 这类程序,必须要读取 mtab 文件,才能获得当前系统中的分区挂载情况。当然我们自己还可以通过读取/proc/mount也可以来获取当前挂载信息
1.磁盘管理常用命令
1.1 ls -i 文件名 查看文件存储在哪个innode中
1 [root@test6 ~]# ls -i lstest 2 1179659 lstest
1.2 ls -id 文件夹名 查看文件夹存储在哪个innode中
1 [root@test6 ~]# ls -id lstest1 2 1179661 lstest1
1.3 filefrag -v 文件名 查看文件存储block具体位置
1 [root@test6 ~]# filefrag -v lstest 2 Checking lstest 3 Filesystem type is: ef53 4 Filesystem cylinder groups is approximately 78 5 Blocksize of file lstest is 4096 6 File size of lstest is 5 (1 blocks) 7 First block: 1183744 8 Last block: 1183744 9 lstest: 1 extent found
2.硬盘工具:
2.1 dumpe2fs /dev/sda1 查看分区superblock 和blockgroup等详细信息
View Code
2.2 fsck /dev/sda 检查硬盘情况 -C 显示检查过程 -f 强制检查
2.3 badblocks /dev/sda5 检查硬盘坏道 -sv 显示进度和结果
df 查看文件系统(-h 以合适的单位示系统大小 -T 显示系统类型)
du 查看文件夹大小,包含文件夹里面文件
du -s 仅仅查看文件夹大小
du -h 以M方式显示大小,方便查看
fuser -mv /mnt 当显示 设备正在忙的时候,可以使用这个命令查看使用进程
tune2fs -l /dev/sda 查看磁盘参数(-h 查看可选选项,进行选项更改)
1 [root@test6 ~]# tune2fs -l /dev/sda5 2 tune2fs 1.39 (29-May-2006) 3 Filesystem volume name: / //卷标 4 Last mounted on: <not available> 5 Filesystem UUID: 4b64bcce-0acc-40f2-85e6-07e198152c20 6 Filesystem magic number: 0xEF53 7 Filesystem revision #: 1 (dynamic) 8 Filesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery sparse_super large_file 9 Default mount options: user_xattr acl 10 Filesystem state: clean 11 Errors behavior: Continue 12 Filesystem OS type: Linux 13 Inode count: 2621440 14 Block count: 2620595 15 Reserved block count: 131029 16 Free blocks: 2257390 17 Free inodes: 2582833 18 First block: 0 19 Block size: 4096 20 Fragment size: 4096 21 Reserved GDT blocks: 639 22 Blocks per group: 32768 23 Fragments per group: 32768 24 Inodes per group: 32768 25 Inode blocks per group: 1024 26 Filesystem created: Tue Mar 28 07:57:02 2017 27 Last mount time: Tue Mar 28 08:29:56 2017 28 Last write time: Tue Mar 28 08:29:56 2017 29 Mount count: 3 30 Maximum mount count: -1 //超过最大次数,则需要对分区进行自检 31 Last checked: Tue Mar 28 07:57:02 2017 32 Check interval: 0 (<none>) 33 Reserved blocks uid: 0 (user root) 34 Reserved blocks gid: 0 (group root) 35 First inode: 11 36 Inode size: 128 37 Journal inode: 8 38 First orphan inode: 163883 39 Default directory hash: tea 40 Directory Hash Seed: 8633f5c3-e870-428e-8ce3-7d636f0ef80a 41 Journal backup: inode blocks
e21able /dev/sda7 aa 卷标的另一种改法