这里是一段防爬虫文本,请读者忽略。
本文原创首发于CSDN,作者IDYS
博客首页:https://blog.csdn.net/weixin_41633902/
本文链接:https://blog.csdn.net/weixin_41633902/article/details/105784761
-b指定块大小 -m指定预留空间百分比 -L 设置卷标
mke2fs -b 1024 -m 3 -L MYDATA -i
# 修改分区ID号
[root@dayuanshuai /]# 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): t
Partition number (1-4): 2
Hex code (type L to list codes): 82
Changed system type of partition 2 to 82 (Linux swap / Solaris)
Command (m for help): p
Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 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: 0xd406d040
Device Boot Start End Blocks Id System
/dev/sdb1 1 2 16033+ 83 Linux
/dev/sdb2 3 4 16065 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@dayuanshuai /]# partx -a -n 2 /dev/sdb
BLKPG: Device or resource busy
error adding partition 2 #虽然提示error但是没事
BLKPG: Device or resource busy
error adding partition 3
#设置为交换分区
[root@dayuanshuai /]# mkswap /dev/sdb2
Setting up swapspace version 1, size = 16060 KiB
no label, UUID=09727f1e-eb7c-4b64-9a17-542cb6879b59
# 查看分区信息
[root@dayuanshuai /]# blkid /dev/sdb2
/dev/sdb2: UUID="09727f1e-eb7c-4b64-9a17-542cb6879b59" TYPE="swap"
#查看Linux支持的文件系统类型
[root@dayuanshuai ~]# cat /proc/filesystems
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
nodev drm
ext4
# 查看Linux文件系统装载的所有内核模块
[root@dayuanshuai ~]# lsmod
Module Size Used by
tcp_diag 1041 0
inet_diag 9430 1 tcp_diag
ib_ipoib 81191 0
rdma_ucm 15739 0
ib_ucm 12360 0
ib_uverbs 40532 2 rdma_ucm,ib_ucm
ib_umad 13519 0
rdma_cm 36651 1 rdma_ucm
ib_cm 37444 3 ib_ipoib,ib_ucm,rdma_cm
iw_cm 33136 1 rdma_cm
ib_sa 24188 4 ib_ipoib,rdma_ucm,rdma_cm,ib_cm
ib_mad 41628 3 ib_umad,ib_cm,ib_sa
ib_core 83020 10 ib_ipoib,rdma_ucm,ib_ucm,ib_uverbs,ib_umad,rdma_cm,ib_cm,iw_cm,ib_sa,ib_mad
..... #省略
# 格式化分区,划分文件系统
[root@dayuanshuai ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=1024 (log=0)
分块大小=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
4016 inodes, 16032 blocks
801 blocks (5.00%) reserved for the super user
第一个数据块=1
Maximum filesystem blocks=16515072
2 block groups
8192 blocks per group, 8192 fragments per group
2008 inodes per group
Superblock backups stored on blocks:
8193
正在写入inode表: 完成
Creating journal (1024 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 26 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@dayuanshuai /]# e2label /dev/sdb2
MYDATA
# 修改/dev/sdb2分区文件系统的label为DATA
[root@dayuanshuai /]# e2label /dev/sdb2 "DATA"
[root@dayuanshuai /]# e2label /dev/sdb2
DATA
# 显示/dev/sdb1分区的属性信息
[root@dayuanshuai ~]# blkid /dev/sdb1
/dev/sdb1: UUID="de7f400a-511b-4aac-b141-97818146052b" TYPE="ext4"
# 显示/dev/sdb1分区的属性信息
[root@dayuanshuai /]# blkid /dev/sdb2
/dev/sdb2: LABEL="MYDATA" UUID="02c07346-6e58-4fa0-ad5d-a51971b9c82d" TYPE="ext4"
# 根据卷标查找设备
[root@dayuanshuai /]# blkid -L "MYDATA"
/dev/sdb2
# 根据UUID查找设备
[root@dayuanshuai /]# blkid -U 02c07346-6e58-4fa0-ad5d-a51971b9c82d
/dev/sdb2
# 查看指定分区的超级块信息
[root@dayuanshuai /]# tune2fs -l /dev/sdb2
tune2fs 1.41.12 (17-May-2010)
Filesystem volume name: DATA
Last mounted on:
Filesystem UUID: 02c07346-6e58-4fa0-ad5d-a51971b9c82d
Filesystem magic number: 0xEF53
..... #省略
# 启用日志功能
[root@dayuanshuai /]# tune2fs -0 'has_journal' /dev/sdb1
# 关闭日志功能
[root@dayuanshuai /]# tune2fs -O '^has_journal' /dev/sdb1
[root@dayuanshuai /]# dumpe2fs /dev/sdb1
.... 前面省略
Group 0: (Blocks 1-8192) [ITABLE_ZEROED]
校验和 0xab1e,1997个未使用的inode
主 superblock at 1, Group descriptors at 2-2
保留的GDT块位于 3-64
Block bitmap at 65 (+64), Inode bitmap at 81 (+80)
Inode表位于 97-347 (+96)
7608 free blocks, 1997 free inodes, 2 directories, 1997个未使用的inodes
可用块数: 80, 83-96, 600-8192
可用inode数: 12-2008
Group 1: (Blocks 8193-16031) [INODE_UNINIT, ITABLE_ZEROED]
校验和 0x1522,2008个未使用的inode
备份 superblock at 8193, Group descriptors at 8194-8194
保留的GDT块位于 8195-8256
Block bitmap at 66 (+4294959169), Inode bitmap at 82 (+4294959185)
Inode表位于 348-598 (+4294959451)
6751 free blocks, 2008 free inodes, 0 directories, 2008个未使用的inodes
可用块数: 9281-16031
可用inode数: 2009-4016
# dumpe2fs -h 只查看文件系统的超级块信息
[root@dayuanshuai /]# dumpe2fs -h /dev/sdb1
dumpe2fs 1.41.12 (17-May-2010)
Filesystem volume name:
Last mounted on:
Filesystem UUID: 319da001-4962-40c6-bff5-6df98106d672
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: 4016
Block count: 16032
Reserved block count: 801
Free blocks: 14359
注意:FS_TYPE一定要与分区上的文件系统类型相同
# 首先查看文件系统是否出现错误
[root@dayuanshuai /]# fsck.ext4 /dev/sdb1
e2fsck 1.41.12 (17-May-2010)
/dev/sdb1: clean, 11/4016 files, 1673/16032 blocks
#如果出现错误则使用fsck -r 交互式修复错误
[root@dayuanshuai /]# fsck -r /dev/sdb1
fsck from util-linux-ng 2.17.2
e2fsck 1.41.12 (17-May-2010)
/dev/sdb1: clean, 11/4016 files, 1673/16032 blocks
#强制,不管文件系统是否出现问题,直接修复,非常粗暴,不建议使用
[root@dayuanshuai /]# e2fsck -f /dev/sdb1