Mkfs command hangs while creating a new filesystem.

本文介绍了解决在Red Hat Enterprise Linux (RHEL) 6和7上使用mkfs.xfs和mkfs.ext4命令创建LVM卷文件系统时出现的挂起问题。通过使用-K选项禁用块丢弃,可以避免由于不支持的存储设备导致的系统调用ioctl()失败。

https://access.redhat.com/solutions/727333

 SOLUTION 已验证 - 已更新 2019年四月25日07:19 - 

English 

环境

  • Red Hat Enterprise Linux (RHEL) 6
  • Red Hat Enterprise Linux (RHEL) 7

问题

  • Both the mkfs.xfs and the mkfs.ext4 command stall on the ioctl() system call while trying to create a new file system on an lvm volume.
  • The machine appears to hang, and does not respond

决议

In order to create the filesystem use the -K option with mkfs command. It will disables the block discard at creating time. More information on mkfs man page:

Raw

        -K     Keep,  do  not  attempt  to discard blocks at mkfs time
                      (discarding blocks initially is useful on  solid  state
                      devices and sparse / thin-provisioned storage).

Example:

Raw

# mkfs.ext4 -K </dev/mapper/path_to_lvm_volume>   # For ext4 filesystem
# mkfs.xfs -K </dev/mapper/path_to_lvm_volume>      # For XFS filesystem

根源

The mkfs command issues a block discard command on the disk, but the underlying storage device cannot handle it.

诊断步骤

Collect the strace logs for mkfs command:

Raw

       # strace -f -tt -y -T -v -x -o /tmp/mkfs.out -s 4096  <mkfs command>

The strace logs for mkfs.xfs or mkfs.ext4 command shows that the command is hanging after issuing the ioctl 0x1277:

Raw

        $ tail  -2  mkfs.txt 
        1538  08:59:41.724086 write(1, "\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08\x08", 13) = 13 <0.000053>
        1538  08:59:41.724209 ioctl(3, 0x1277           <-------- hung after this
        [...]

From the kernel source, 0x1277 ioctl corresponds to BLKDISCARD:

Raw

        include/linux/fs.h:
        ------------------
        344 #define BLKDISCARD _IO(0x12,119)
        [...]

The mkfs command was issuing a block discard command to the disk but the disk device did not support the command, which caused the IO errors observed in first snip, which were then being logged.

当执行 `mkfs.vfat` 时提示 `/dev/mmcblk0p1 contains a mounted filesystem`,且设备有时挂载有时未挂载,可按照以下步骤解决: ### 检查文件系统挂载状态 使用 `mount` 命令查看 `/dev/mmcblk0p1` 是否已经挂载: ```bash mount | grep /dev/mmcblk0p1 ``` 若有输出,表明该设备已挂载。 ### 卸载文件系统 若 `/dev/mmcblk0p1` 已挂载,使用 `umount` 命令卸载: ```bash umount /dev/mmcblk0p1 ``` 若卸载失败,可能是有进程正在使用该文件系统。可使用 `lsof` 命令找出使用该文件系统的进程: ```bash lsof /dev/mmcblk0p1 ``` 根据输出结果,使用 `kill` 命令终止相应进程,再尝试卸载: ```bash kill -9 <进程ID> umount /dev/mmcblk0p1 ``` ### 重新执行 mkfs.vfat 命令 卸载成功后,重新执行 `mkfs.vfat` 命令格式化 `/dev/mmcblk0p1`: ```bash mkfs.vfat /dev/mmcblk0p1 ``` ### 防止自动挂载 若设备有时会自动挂载,可编辑 `/etc/fstab` 文件,注释掉与 `/dev/mmcblk0p1` 相关的挂载条目,避免系统启动时自动挂载该设备。 ```bash vi /etc/fstab ``` 找到类似如下的行: ```plaintext /dev/mmcblk0p1 /mmc vfat defaults 0 0 ``` 在行首添加 `#` 进行注释: ```plaintext # /dev/mmcblk0p1 /mmc vfat defaults 0 0 ``` ### 自动挂载配置 若需要在系统启动时自动挂载 `/dev/mmcblk0p1`,可编辑 `/etc/init.d/rcS` 文件,添加挂载命令: ```bash vi /etc/init.d/rcS ``` 在文件中加入一行: ```plaintext mount -t vfat /dev/mmcblk0p1 /mmc ``` 这样上电后开发板会自动挂载 SD 卡到主目录的 `mmc` 文件夹 [^1]。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值