mkfs, mkfs -t type = mkfs.type
ext:mke2fs
创建文件系统:mke2fs [OPTION]... DEVICE
-t {ext2|ext3|ext4}
-b {1024|2048|4096}
-L 'LABEL'
-j: mke2fs -t ext3
-i #:
-N #:
-m #: 预留磁盘空间占据多大百分比的空间为后期管理使用;
-O FEATURE[,...]
-O ^FEATURE:关闭此特性
has_journal
系统信息查看 blkid DEVICE
文件系统属性查看及调整工具:
e2lable e2lable DEVICE [LABEL]
tune2fs [OPTION]... DEVICE
显示ext系列文件系统的属性,或调整其属性;
-l:显示超级块中的信息;显示整个文件的属性及布局等相关信息;
-L 'LABEL':修改卷标;
-m #: 调整预留给管理员的管理空间百分比;
-j: ext2 --> ext3
-O:文件系统属性的启动或关闭
-o:文件系统默认挂载选项的启用或关闭
dumpe2fs:
-h: 仅显示超级块信息;
文件系统检测,在系统非正常关闭的情况下,或者感觉磁盘有损坏的情况下使用:
fsck: Filesystem check
fsck -t type 磁盘类型必须与磁盘真实类型一致否则对数据有损
fsck.type
-a: 自动修复错误
-r: 交互式修复错误
-f: 强制检测
[root@bogon ~]# fsck -t ext4 /dev/sdb1 fsck from util-linux 2.23.2 e2fsck 1.42.9 (28-Dec-2013) mydata: clean, 11/655360 files, 83137/2621184 blocks
e2fsck:ext系列文件系统专用的检测修复工具;
-y: 自动回答为“yes”
-f:force
文件系统的挂载和使用:
kernel --> rootfs(分区)
rootfs分区:
bin, sbin, etc, lib, lib64, dev, tmp, proc, sys
/sbin/init
将额外文件系统与根文件系统某现存的目录建立起关联关系,进而使得此目录做为其它文件系统访问入口的行为,称之为挂载;
解除此关联关系的过程:卸载;
挂载点:mount point, 设备挂载至目录;
注意:挂载点在挂载在之后,其内部原有的文件会被暂时隐藏;建立使用空目录做为挂载点;
挂载方法:
mount:通过读取/etc/mtab文件来显示当前系统所有已经挂载的设备;
mount -a:挂载/etc/fstab文件中的所有支持自动挂载的文件系统;
mount [options] [-o options] DEVICE MOUNT_POINT
[options]:命令选项
[-o options]:挂载选项
DEVICE: 要挂载的设备
(1) 设备文件:/dev/sda5
(2) 卷标:-L 'LABEL'
(3) UUID:-U 'UUID'
(4) 伪文件系统名称
MOUNT_POINT: 挂载点
常用选项:
-t type:文件系统类型
-r: 以“只读”方式挂载此文件系统
-w: 以“读写”方式挂载此文件系统
-n:每个文件系统在挂载时都会自动更新/etc/mtab文件,-n用于禁止此功能;
此时,如果想查看挂载的所有文件系统:cat /proc/mounts
-a: 自动挂载所有支持自动挂载的设备;
-B:绑定目录至另一个目录上;
-o 挂载选项:
async:异步模式
sync: 同步模式
atime/noatime:是否更新访问时间戳;
diratime/nodiratime:是否更新目录的访问时间戳;
auto/noauto: 是否允许此设备被自动挂载;
exec/noexec:是否允许执行此文件系统上应用程序;
dev/nodev:是否支持在此设备上使用设备文件;
suid/nosuid:
remount:重新挂载
ro
rw
user/nouser: 是否允许普通挂载此设备;
acl:是否支持此设备上使用facl;
defaults:rw, suid, dev, exec, auto, nouser, and async
umount:卸载命令
# umount DEVICE
# umount MOUNT_POINT
查看正在访问指定挂载点的进程:
# fuser -v MOUNT_POINT
终止所有正在访问指定的挂载点的进程:
# fuser -km MOUNT_POINT
交换分区:
free命令:
查看memory和swap的使用状态
-m: 以MB为单位
-g: 以GB为单位
mkswap:创建交换分区
mkswap [option] DEVICE
-L 'LABEL'
swapon:启用交换分区
swapon [option] [DEVICE]
-a: 激活所有交换分区
-p PRIORITY: 设定其优先级;
swapoff:禁用交换分区
swapoff [option] [DEVICE]
文件系统等空间占用信息的查看工个:
df: disk free
-h: human-readable
-i: inode数量
-P: 以Posix兼容的格式输出
du: disk usage
-h: human-readable
-s: summary
文件系统相关挂载配置文件:/etc/fstab
每行定义一个文件系统;
要挂载的设备或伪文件系统 挂载点 文件系统类型 挂载选项 转储频率 自检次序
要挂载的设备:
设备文件、LABEL=、UUID=、伪文件系统名称
挂载选项:
defaults
转储频率:
0: 不转储
1: 每天转储
2: 每隔一天转储
自检次序:
0:不自检
1:首先自检,通常只有/才为1
2:
...
文件系统上的链接文件:
硬链接:
两个路径指向同一个inode
不能对目录进行;
不能跨分区进行
指向同一个inode的多个不同路径; 创建文件的硬链接会增加inode的引用计数;删除硬链接仅是删除其一个访问路径,只到最后一个路径被删除;
符号链接:
链接文件的数据指向另一个文件路径;
可以对目录进行;
可以跨分区;
指向的是另一个文件路径;而非inode;
对文件创建符号链接不会增加其引用计数;删除原文件,符号链接文件也将无法;
ln [-s] SRC DEST
-s:symbolic link
-v:verbose
创建一个10G的文件系统,类型为ext4,要求开机可自动挂载至/mydata目录
[root@bogon ~]# fdisk -l Disk /dev/sda: 128.8 GB, 128849018880 bytes, 251658240 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x000e5d08 Device Boot Start End Blocks Id System /dev/sda1 * 2048 1026047 512000 83 Linux /dev/sda2 1026048 47171583 23072768 8e Linux LVM /dev/sda3 47171584 89114623 20971520 83 Linux Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/mapper/centos-usr: 10.7 GB, 10737418240 bytes, 20971520 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/mapper/centos-var: 10.7 GB, 10737418240 bytes, 20971520 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes [root@bogon ~]# fdisk /dev/sdb Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table Building a new DOS disklabel with disk identifier 0x01eef223. Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p Partition number (1-4, default 1): 1 First sector (2048-20971519, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): Using default value 20971519 Partition 1 of type Linux and of size 10 GiB is set Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@bogon ~]# fdisk -l Disk /dev/sda: 128.8 GB, 128849018880 bytes, 251658240 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x000e5d08 Device Boot Start End Blocks Id System /dev/sda1 * 2048 1026047 512000 83 Linux /dev/sda2 1026048 47171583 23072768 8e Linux LVM /dev/sda3 47171584 89114623 20971520 83 Linux Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x01eef223 Device Boot Start End Blocks Id System /dev/sdb1 2048 20971519 10484736 83 Linux Disk /dev/mapper/centos-usr: 10.7 GB, 10737418240 bytes, 20971520 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/mapper/centos-var: 10.7 GB, 10737418240 bytes, 20971520 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes [root@bogon ~]# mke2fs -t ext4 /dev/sd sda sda1 sda2 sda3 sdb sdb1 [root@bogon ~]# mke2fs -t ext4 /dev/sdb1 mke2fs 1.42.9 (28-Dec-2013) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 655360 inodes, 2621184 blocks 131059 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=2151677952 80 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 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done [root@bogon ~]# e2label /dev/sdb1 [root@bogon ~]# e2label /dev/sdb1 mydata [root@bogon ~]# e2label /dev/sdb1 mydata [root@bogon ~]# blkid /dev/sdb1 /dev/sdb1: LABEL="mydata" UUID="b42b248d-0281-4736-8e94-2997ac7e8e9c" TYPE="ext4" [root@bogon ~]# cp /etc/fstab /etc/fstabbak [root@bogon ~]# cd /mydata/ [root@bogon mydata]# ls [root@bogon mydata]# touch aaa [root@bogon mydata]# cd.. bash: cd..: command not found... [root@bogon mydata]# cd .. [root@bogon /]# mount /dev/sd sda sda1 sda2 sda3 sdb sdb1 [root@bogon /]# mount /dev/sdb1 /mydata/ [root@bogon /]# cd mydata/ [root@bogon mydata]# ll total 16 drwx------. 2 root root 16384 Sep 8 13:49 lost+found [root@bogon ~]# cat /etc/fstab # # /etc/fstab # Created by anaconda on Sun Sep 6 07:01:27 2015 # # 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=7568bf84-ac4a-4da4-b4b0-b656073d62b0 / btrfs subvol=root 0 0 UUID=75f891ed-9f28-4c9a-8105-c3751461ffab /boot xfs defaults 0 0 /dev/mapper/centos-usr /usr xfs defaults 0 0 /dev/mapper/centos-var /var xfs defaults 0 0 /dev/mapper/centos-swap swap swap defaults 0 0 UUID=b42b248d-0281-4736-8e94-2997ac7e8e9c /mydata ext4 defaults 0 0 [root@bogon ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda3 20G 44M 18G 1% / devtmpfs 487M 0 487M 0% /dev tmpfs 497M 0 497M 0% /dev/shm tmpfs 497M 6.9M 490M 2% /run tmpfs 497M 0 497M 0% /sys/fs/cgroup /dev/mapper/centos-usr 10G 5.9G 4.2G 59% /usr /dev/sdb1 9.8G 37M 9.2G 1% /mydata /dev/mapper/centos-var 10G 642M 9.4G 7% /var /dev/sda1 497M 127M 370M 26% /boot [root@bogon ~]# cd /mydata/ [root@bogon mydata]# ls lost+found [root@bogon mydata]# cd [root@bogon ~]# umount /mydata/ [root@bogon ~]# cd /mydata/ [root@bogon mydata]# ls aaa [root@bogon mydata]#