Linux文件系统管理:
mkfs, mkfs -type = mkfs.ext2,3,4
例:
[root@localhost ~]# mkfs -type ext4 /dev/sdb mkfs.ype: No such file or directory [root@localhost ~]# mkfs -t ext4 /dev/sdb mke2fs 1.41.12 (17-May-2010) /dev/sdb is entire device, not just one partition! Proceed anyway? (y,n) y Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 1310720 inodes, 5242880 blocks 262144 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=4294967296 160 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 25 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
ext: mke2fs
例:
[root@localhost ~]# mkfs.ext4 /dev/sdb mke2fs 1.41.12 (17-May-2010)/dev/sdb is entire device, not just one partition!Proceed anyway? (y,n) yFilesystem label=OS type: LinuxBlock size=4096 (log=2)Fragment size=4096 (log=2)Stride=0 blocks, Stripe width=0 blocks1310720 inodes, 5242880 blocks262144 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=4294967296160 block groups32768 blocks per group, 32768 fragments per group8192 inodes per groupSuperblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000Writing inode tables: done Creating journal (32768 blocks): doneWriting superblocks and filesystem accounting information: doneThis filesystem will be automatically checked every 37 mounts or180 days, whichever comes first. Use tune2fs -c or -i to override.
创建文件系统
mke2fs [OPTION]..DEVICE
-t ext2,ext3,ext4
-b 1024,2048,4096
-L 'Lable'卷标
-j mke2fs -t ext
-i inode
-N 保留多少inode
-m 预留磁盘空间占据多少百分比为后期管理
-O FEATURE[...]开启预留特性
-O^FEATUEW[...]关闭预留特性
文件系统属性查看及调整工具:
e2lable:管理文件系统卷标
e2lable DEVICE [LAVLE]
例:
[root@localhost ~]# e2label /dev/sdb 'mydisk' [root@localhost ~]# e2label /dev/sdb
mydisk
tune2fs:显示文件系统属性,或调整文件系统属性
-l 显示superblock信息
-L LABLE 修改卷标
-m 管理预留给管理员的空间
-j ext2-->ext3
-O 启用或禁用特性
-o 文件系统默认挂载选项的开启或关闭
例1:
[root@localhost ~]# tune2fs -l /dev/sdb tune2fs 1.41.12 (17-May-2010)Filesystem volume name: mydiskLast mounted on:Filesystem UUID: e2ec1086-064d-4eac-950f-0672a508213eFilesystem magic number: 0xEF53Filesystem revision #: 1 (dynamic)Filesystem features: has_journal ext_attr resize_inode dir_index filetype extent flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isizeFilesystem flags: signed_directory_hash Default mount options: (none)Filesystem state: cleanErrors behavior: ContinueFilesystem OS type: LinuxInode count: 1310720Block count: 5242880Reserved block count: 262144Free blocks: 5116591Free inodes: 1310709First block: 0Block size: 4096Fragment size: 4096Reserved GDT blocks: 1022Blocks per group: 32768Fragments per group: 32768Inodes per group: 8192Inode blocks per group: 512Flex block group size: 16Filesystem created: Sun Sep 6 19:08:01 2015Last mount time: n/aLast write time: Sun Sep 6 19:10:29 2015Mount count: 0Maximum mount count: 37Last checked: Sun Sep 6 19:08:01 2015Check interval: 15552000 (6 months)Next check after: Fri Mar 4 19:08:01 2016Lifetime writes: 452 MBReserved blocks uid: 0 (user root)Reserved blocks gid: 0 (group root)First inode: 11Inode size: 256Required extra isize: 28Desired extra isize: 28Journal inode: 8Default directory hash: half_md4Directory Hash Seed: 4fc68caf-3b7f-401e-8022-707100c2b923Journal backup: inode blocks
dumpe2fs显示文件系统布局及superblock信息
例:
dumpe2fs /dev/sdb
文件系统检测系统
fsck 文件系统检测
fsck -t test = fsck.type
-a 自动修复文件系统错误
-f 交互式修复
-F 强制检测
例:
[root@localhost ~]# fsck.ext4 -a /dev/sdb mydisk: clean, 11/1310720 files, 126289/5242880 blocks
e2fsck: ext文件系统专用检测工具
-y 自动修复错误
-f 强制检测
例:
[root@localhost ~]# e2fsck -f /dev/sdb e2fsck 1.41.12 (17-May-2010) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information mydisk: 11/1310720 files (0.0% non-contiguous), 126289/5242880 blocks
文件系统挂载及使用
kernel --> rootfs分区
rootfs分区
bin,sbin,boot,etc,lib,lib64,dev,tmp,usr,proc
将额外的文件系统与根文件系统某先问的目录建立起关联关系,进而使此目录变为其他目录的入口,成为挂载
接触此关联关系的过程,称为卸载
挂载点:mount point 设备挂载至此目录
注意:挂载点需要为空目录
挂载方法:mount:通过读取/etc/mtab文件来显示当前系统所有已
mount -a 挂载/etc/fstab额文件中所有支持自动挂载的设备
mount [OPTION] [-o OPTION] DEVICE MOUNT_POINT
[option]命令选项
[-o option]挂在选项
DEVICE:要挂载的设备
(1)设备文件:/dev/sda
(2)卷标 -L
(3)UUID -U
(4)伪文件系统 文件名挂载
常用选项
-t 文件系统属性
-r 以只读模式挂载
-w 以读写方式挂载
-n 每个文件系统在挂载时都会自动更新/etc/mtab -n禁止此功能
-a 自动挂载所有支持自动挂载的设备
-B 绑定目录至另一个目录
例:
[root@localhost ~]# mkdir /mydata [root@localhost ~]# mount -o rw,async,noatime /dev/sdb /mydata
-o挂载选项
async 异步模式
sync 同步模式
atime/noatime 是否更新访问时间戳
diratime/nodiratime 是否更新访问目录时间戳
auto/noauto 是否允许此设备是否自动挂载
exec/noexec 是否允许执行此文件系统上的可执行程序
dev/nodev 是否支持此设备上使用设备文件
suid/nosudi
remount 重新挂载
ro/rw
user/nouser 是否允许普通用户挂载此设备
acl 是否允许此设备使用facl
umount:卸载命令
umount DEVICE
umount MOUNT_POINT
例:
[root@localhost ~]# umount /dev/sdb [root@localhost ~]# umount /mydata
查看正在访问指定挂载点的进程
fuser -v mount_point
终止所有正在访问指定挂载点的进程
fuser -km mount_point
例:
[root@localhost ~]# fuser -v /mydata USER PID ACCESS COMMAND/mydata: root 2476 ..c.. bash [root@localhost ~]# fuser -km /mydata/mydata: 2476c
交换分区:
free命令
查看menmory和swap使用状态
free -m以MB显示
例:
[root@localhost ~]# free -m total used free shared buffers cachedMem: 1862 253 1609 0 51 63-/+ buffers/cache: 137 1724 Swap: 3071 0 3071
free -g以G显示(4舍5入显示)
例:
[root@localhost ~]# free -g total used free shared buffers cached Mem: 1 0 1 0 0 0 -/+ buffers/cache: 0 1 Swap: 2 0 2
练习:
创建一个10G的文件系统,类型为ext4,要求开机可自动挂载至/mydata目录
[root@localhost ~]# fdisk -l /dev/sdb Disk /dev/sdb: 21.5 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x13a6c9bf Device Boot Start End Blocks Id System/dev/sdb1 1 1306 10490413+ 83 Linux [root@localhost fs]# kpartx -a /dev/sdb1 [root@localhost fs]# mkfs.ext4 /dev/sdb1mke2fs 1.41.12 (17-May-2010)Filesystem label=OS type: LinuxBlock size=4096 (log=2)Fragment size=4096 (log=2)Stride=0 blocks, Stripe width=0 blocks655776 inodes, 2622603 blocks131130 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=268854886481 block groups32768 blocks per group, 32768 fragments per group8096 inodes per groupSuperblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632Writing inode tables: done Creating journal (32768 blocks): doneWriting superblocks and filesystem accounting information: doneThis filesystem will be automatically checked every 39 mounts or180 days, whichever comes first. Use tune2fs -c or -i to override. [root@localhost fs]# e2label /dev/sdb1 'mydata'[root@localhost fs]# e2label /dev/sdb1mydata [root@localhost fs]#vim /etc/fstab LABEL=mydata /mydata ext4 defaults 0 0