Linux 磁盘/分区/修复 命令 |
您所在的位置:网站首页 › 硬盘检查修复命令 › Linux 磁盘/分区/修复 命令 |
目录 1. lsblk(list block devices) 2. fdisk(fragment disk) 3. gdisk 4. mkfs(make filesystem) 5. df(display file-system disk space usage) 6. du 7. fsck(file-system check) 8. xfs_repair 9. blkid 10. parted 11. partprobe 12. tune2fs 13. xfs_admin 14. dumpe2fs 1. lsblk(list block devices)查看当前系统分区情况 格式:lsblk -[dfimpt] [device] 选项 作用 -d 仅列出磁盘本身,不列出该磁盘的分区数据 -f 同时列出该磁盘内的文件系统名称 -i 使用ASCII的线段输出,不使用复杂的编码 -m 同时输出该装置在/dev下的权限 -p 列出完整文件名,而不是仅列出最后的名字 -t 列出磁盘的详细数据,包括磁盘队列机制、预读写的数据量大小等 lsblk -pi 字段 字段 含义 MAJ Major(主要device代码) MIN Minor(次要device代码) RM 是否为removable device,如USB RO 是否为只读device(rom) TYPE 是disk、partition还是rom设备 2. fdisk(fragment disk)对MBR进行分区 fdisk [abc@ubuntu ~]$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 20G 0 disk ├─sda1 8:1 0 18G 0 part / ├─sda2 8:2 0 1K 0 part └─sda5 8:5 0 2G 0 part [SWAP] sdb 8:16 0 2G 0 disk sr0 11:0 1 1024M 0 rom [abc@ubuntu ~]$ sudo parted -l Model: VMware, VMware Virtual S (scsi) Disk /dev/sda: 21.5GB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 1 1049kB 19.3GB 19.3GB primary ext4 boot 2 19.3GB 21.5GB 2144MB extended 5 19.3GB 21.5GB 2144MB logical linux-swap(v1) Model: VMware, VMware Virtual S (scsi) Disk /dev/sdb: 2147MB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 1 1049kB 1075MB 1074MB primary [abc@ubuntu ~]$ sudo 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 0x42cb820f. 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) 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): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p Partition number (1-4, default 1): Using default value 1 First sector (2048-4194303, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-4194303, default 4194303): +2G Value out of range. Last sector , +sectors or +size{K,M,G} (2048-4194303, default 4194303): +1G Command (m for help): W The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [abc@ubuntu ~]$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 20G 0 disk ├─sda1 8:1 0 18G 0 part / ├─sda2 8:2 0 1K 0 part └─sda5 8:5 0 2G 0 part [SWAP] sdb 8:16 0 2G 0 disk └─sdb1 8:17 0 1G 0 part sr0 11:0 1 1024M 0 rom 3. gdisk对GPT分区 4. mkfs(make filesystem)将分区格式化为指定文件系统 mkfs.filesystem [-b bsize] [-d parms] [-i parms] [-l parms] [-L lable] [-f] [-r parms] 选项 作用 mkfs[tab][tab] 显示支持的文件系统 -t 选择文件系统 mkfs.[filesystem] 选择文件系统 -b 后面接的是区块容量,范围是512B-64K。不过Linux最大为4K -d 后面接的是data section(数据区)的相关参数值 -f 如果设备内已经有了文件系统,则需要使用-f强制格式化 -i 与inode有较相关的设置 -L 后面接这个文件系统的标头名称Label name -r 指定realtime section(实时运行区)的相关设置值 -d参数 参数 作用 agcount=num 设置需要几个存储群组的意思(AG),通常与CPU有关 agsize=数值 每个AG设置为多少容量的意思。通常agcount/agsize只选一个设置 file 指的是格式化的设备是个文件而不是个设备的意思(例如虚拟磁盘) size=数值 data section的容量。你可以设置大小 su=数值 当有RAID(磁盘列阵)时,代表stripe的数值大小,与下面的sw搭配使用 sw=数值 当有RAID时,用于保存数据的 磁盘数量 (需扣除备份盘与备用盘) sunit=数值 与su意思相同。不过单位使用的是几个sector(512B)的意思(一个stripe由多少个扇区组成) swidth=数值 就是su*sw的数值,但是以几个sector(512B)来设置-i 参数 参数 作用 size=number 最小的是256B,最大是2K。一般使用256B就足够了 internal=[0/1] log设备是否为内置。默认1为内置,如果使用外部设备,使用下面设置 logdev=dev_name log设备为后面接的那个设备上面的意思,需设置internal=0才可以 size=number 指定这块登录区的容量,通常最小得要512个区块,大约2M=以上才行 -r 参数 参数 作用 extsize=number 就是那个重要的extent区块数值,一般不需设置。但有RAID时,最好设置与swidth的数值相同较佳。最小为4K,最大为1G 显示分区使用情况 df -[ahikHTm] 选项 作用 -a 列出所有filesystem,包括系统特有的/proc等文件系统 -k 以KBytes的容量显示各文件系统 -m 以MBytes的容量显示各文件系统 -h 以GBytes、MBytes、KBytes格式显示 -H 以M=1000K取代M=1024K的进位 -T 显示partition的filesystem名称 -i 不用磁盘容量,以inode的数量表示 查询指定目录的磁盘占用情况 du -[ahskm] 选项 作用 -a 显示所有文件与目录容量 -h 以GBytes、MBytes、KBytes格式显示 -s 仅显示总量 -S 不显示目录下的总计 -k 以KBytes的容量显示 -m 以MBytes的容量显示 ext4文件系统的检验和修正 针对ext4,可以直接使用 选项 作用 -a 如果检测到错误,自动修复文件系统 -A 检查/etc/fstab文件中列出的所有文件系统 -C 给支持进度条功能的文件系统显示一个进度条(只有ext2和ext3) -N 不进行检查,只显示哪些检查会执行 -r 出现错误时提示 -s 检查多个文件系统时,依次进行检查 -t 指定要检查的文件系统类型 -T 启动时不显示头部信息 -V 在检查时产生详细输出 -y 检测到错误时自动修复文件系统fsck.ext4 -[pf] [-b superblock] device_name 选项 作用 -p 自动回复y来进行修复 -f 强制检查。当fsck未发现unclean标识,不进行细致检查,加此选项,可强制进行细致检查。 -D 针对文件系统下的目录进行优化配置 -b 后接superblock的位置,当superblock损毁时,可通过此选项尝试修复。 [abc@ubuntu ~]$ sudo dumpe2fs -h /dev/sdb1|grep "Blocks per group" dumpe2fs 1.42.9 (4-Feb-2014) Blocks per group: 32768 [abc@ubuntu ~]$ sudo fsck.ext4 -b 32768 /dev/sdb1 fsck from util-linux 2.20.1 e2fsck 1.42.9 (4-Feb-2014) /dev/sdb1 was not cleanly unmounted, check forced. 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 Block bitmap differences: +(98304--98368) +(163840--163904) Fix? yes Free blocks count wrong for group #0 (28585, counted=28579). Fix? yes Free blocks count wrong for group #1 (32703, counted=32700). Fix? yes Free blocks count wrong (249509, counted=249500). Fix? yes Free inodes count wrong for group #0 (8181, counted=8171). Fix? yes Directories count wrong for group #0 (2, counted=6). Fix? yes Free inodes count wrong (65525, counted=65515). Fix? yes /dev/sdb1: ***** FILE SYSTEM WAS MODIFIED ***** /dev/sdb1: 21/65536 files (0.0% non-contiguous), 12644/262144 blocks 8. xfs_repairxfs 文件系统的检验和修正 xfs_repair 修复文件系统时,任务很庞大,该文件系统不能被挂载,应该卸载后再处理。 xfs_repair -[fnd] device_name 选项 作用 -f device_name其实不是实体device而是文件 n 单纯检测并不修改文件系统的数据 -d 通常在单人维护模式下,针对根目录进行检查与修复,不能随便使用 9. blkid(block id)显示磁盘属性,列出其UUID等参数 列出磁盘的分区表类型和分区类型 格式:parted print 更新 Linux 核心分区表信息 格式:partprobe [-s] 修改 ext4 的 label name 与 UUID tune2fs [-l] [-L Label] [-U uuid] device_name 选项 作用 -l 显示superblock内的数据 -L 修改Label名称 -U 修改UUID 13. xfs_admin修改 xfs 文件系统的 uuid 与 label name xfs_admin [-lu] [-L label] [-U uuid] 选项 作用 -l 显示设备的label name -u 显示设备的UUID -L 设置设备的label -U 设置设备的uuid 14. dumpe2fs用于打印 “ext2/ext3” 文件系统的超级块和快组信息 dumpe2fs [options] 选项 作用 -b 打印文件系统中预留的块信息 -ob 指定检查文件系统时使用的超级块 -OB 检查文件系统时使用的指定的块大小 -h 仅显示超级块信息 -i 从指定的文件系统映像文件中读取文件系统信息 -x 以16进制格式打印信息块成员 [abc@ubuntu ~]$ sudo dumpe2fs -h /dev/sdb1 [sudo] password for abc: dumpe2fs 1.42.9 (4-Feb-2014) Filesystem volume name: Last mounted on: /tmp Filesystem UUID: 07c1bdab-d8ea-4a3c-b2d6-8310675ab9bc Filesystem magic number: 0xEF53 Filesystem 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_isize Filesystem flags: signed_directory_hash Default mount options: user_xattr acl Filesystem state: clean Errors behavior: Continue Filesystem OS type: Linux Inode count: 65536 Block count: 262144 Reserved block count: 13107 Free blocks: 249500 Free inodes: 65515 First block: 0 Block size: 4096 Fragment size: 4096 Reserved GDT blocks: 63 Blocks per group: 32768 Fragments per group: 32768 Inodes per group: 8192 Inode blocks per group: 512 Flex block group size: 16 Filesystem created: Thu Nov 26 02:57:37 2020 Last mount time: Thu Nov 26 03:16:53 2020 Last write time: Thu Nov 26 03:18:37 2020 Mount count: 1 Maximum mount count: -1 Last checked: Thu Nov 26 02:57:37 2020 Check interval: 0 () Lifetime writes: 49 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: ccfe301b-1efb-4ad7-bf3d-b49bf87f92da Journal backup: inode blocks Journal features: journal_incompat_revoke Journal size: 32M Journal length: 8192 Journal sequence: 0x00000008 Journal start: 0 |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |