Linux磁盘挂载

root@instance-txphg7nh-2:~# fdisk -l  #查看磁盘信息
Disk /dev/vda: 40 GiB, 42949672960 bytes, 83886080 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
Disklabel type: dos
Disk identifier: 0x46392edb

Device     Boot Start      End  Sectors Size Id Type
/dev/vda1  *     2048 83886046 83883999  40G 83 Linux


Disk /dev/vdb: 500 GiB, 536870912000 bytes, 1048576000 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@instance-txphg7nh-2:~# fdisk /dev/vdb  #进入磁盘

Welcome to fdisk (util-linux 2.31.1).
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.
Created a new DOS disklabel with disk identifier 0x89f6810c.

Command (m for help): m  #显示菜单

Help:

  DOS (MBR)
   a   toggle a bootable flag  #设定可启动标记
   b   edit nested BSD disklabel
   c   toggle the dos compatibility flag

  Generic
   d   delete a partition  #删除一个分区
   F   list free unpartitioned space
   l   list known partition types  #各分区类型所对应的ID
   n   add a new partition  #添加一个分区
   p   print the partition table  #显示该磁盘下的当前分区信息
   t   change a partition type
   v   verify the partition table
   i   print information about a partition

  Misc
   m   print this menu  #显示菜单
   u   change display/entry units
   x   extra functionality (experts only)

  Script
   I   load disk layout from sfdisk script file
   O   dump disk layout to sfdisk script file

  Save & Exit
   w   write table to disk and exit  #保存退出
   q   quit without saving changes  #不保存退出

  Create a new label
   g   create a new empty GPT partition table
   G   create a new empty SGI (IRIX) partition table
   o   create a new empty DOS partition table
   s   create a new empty Sun partition table


Command (m for help): p  #显示该磁盘下的当前分区信息
Disk /dev/vdb: 500 GiB, 536870912000 bytes, 1048576000 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
Disklabel type: dos
Disk identifier: 0x89f6810c

Command (m for help): n  #添加一个分区
Partition type
   p   primary (0 primary, 0 extended, 4 free)  #输入p为创建逻辑分区
   e   extended (container for logical partitions)  #输入e为创建扩展分区
Select (default p): p
Partition number (1-4, default 1): 1  #划分逻辑分区
First sector (2048-1048575999, default 2048): 1048575999  #磁盘分区大小

Created a new partition 1 of type 'Linux' and of size 512 B.

Command (m for help): p  #显示该磁盘下的当前分区信息
Disk /dev/vdb: 500 GiB, 536870912000 bytes, 1048576000 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
Disklabel type: dos
Disk identifier: 0x89f6810c

Device     Boot      Start        End Sectors  Size Id Type
/dev/vdb1       1048575999 1048575999       1  512B 83 Linux

Command (m for help): w  #保存退出
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

root@instance-txphg7nh-2:~# fdisk -l  #再次查看
Disk /dev/vda: 40 GiB, 42949672960 bytes, 83886080 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
Disklabel type: dos
Disk identifier: 0x46392edb

Device     Boot Start      End  Sectors Size Id Type
/dev/vda1  *     2048 83886046 83883999  40G 83 Linux


Disk /dev/vdb: 500 GiB, 536870912000 bytes, 1048576000 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
Disklabel type: dos
Disk identifier: 0x89f6810c

Device     Boot      Start        End Sectors  Size Id Type
/dev/vdb1       1048575999 1048575999       1  512B 83 Linux
root@instance-txphg7nh-2:~# mkfs.ext4 /dev/vdb  #格式化分区
mke2fs 1.44.1 (24-Mar-2018)
Found a dos partition table in /dev/vdb
Proceed anyway? (y,N) y
Creating filesystem with 131072000 4k blocks and 32768000 inodes
Filesystem UUID: bc440c38-2ac5-41e1-a532-79c9084dadb9
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
        4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
        102400000

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done     

root@instance-txphg7nh-2:~# echo /dev/vdb【磁盘分区】 /data【挂载目录】 ext4【文件格式】 defaults 0 0 >> /etc/fstab  #写入新分区信息 开机自动挂载 =>  echo /dev/vdb /data ext4 defaults 0 0 >> /etc/fstab
root@instance-txphg7nh-2:~# cat /etc/fstab 
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/vda1 during installation
UUID=0dfa4835-38d0-426d-bbb9-2e0056aa6e34 /               ext4    errors=remount-ro 0       1
/dev/vdb /data ext4 defaults 0 0
root@instance-txphg7nh-2:~# mkdir /data  #挂载目录
root@instance-txphg7nh-2:~# mount /dev/vdb /data  #挂载磁盘
root@instance-txphg7nh-2:~# df -h  #查看磁盘信息
Filesystem      Size  Used Avail Use% Mounted on
udev            7.9G     0  7.9G   0% /dev
tmpfs           1.6G  3.3M  1.6G   1% /run
/dev/vda1        40G  2.5G   36G   7% /
tmpfs           7.9G     0  7.9G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           7.9G     0  7.9G   0% /sys/fs/cgroup
tmpfs           1.6G     0  1.6G   0% /run/user/0
/dev/vdb        492G   73M  467G   1% /data
root@instance-txphg7nh-2:~# 

从你提供的错误信息来看,你正在尝试使用 `mkfs.ext4` 命令将 `/dev/mmcblk0p4` 分区格式化为 ext4 文件系统,但在过程中出现了以下关键错误: ``` mkfs.ext4: inode_size (128) * inodes_count (0) too big for a filesystem with 0 blocks, specify higher inode_ratio (-i) or lower inode count (-N). ``` ### 错误分析: 1. **“Found a dos partition table in /dev/mmcblk0p4”** 系统检测到该设备上存在 DOS 分区表(MBR),但你正在尝试直接格式化一个分区(`/dev/mmcblk0p4`),这可能是误操作。如果设备本身(如 `/dev/mmcblk0`)已经有分区表而你尝试格式化的是整个设备而不是分区,就可能出错。 2. **“filesystem with 0 blocks”** 这是关键错误。`mkfs.ext4` 无法确定该设备有多少可用块,说明它无法识别设备的大小,这通常意味着: - 设备没有正确识别(如 SD 卡未正确插入) - 你尝试格式化的是一个分区表所在的设备节点(如 `/dev/mmcblk0` 而不是 `/dev/mmcblk0p4`) - 或者设备已经损坏或未初始化 3. **inode_size * inodes_count too big** 因为 `inodes_count` 是 0,而 `mkfs.ext4` 试图计算 inode 表的大小时出现问题,导致报错。 --- ### 建议解决方案: 1. **确认设备路径是否正确:** 检查你是否真的要格式化 `/dev/mmcblk0p4`,而不是整个设备 `/dev/mmcblk0`。通常应格式化具体分区(如 `p1`, `p4`)。 2. **使用 `fdisk -l /dev/mmcblk0` 查看分区表:** 确认 `/dev/mmcblk0p4` 是否存在且大小是否正确。 3. **尝试重新插拔设备:** 确保设备被系统正确识别。可以尝试重新插拔 SD 卡或 USB 存储设备。 4. **使用 `-F` 强制格式化(谨慎使用):** ```bash mkfs.ext4 -F /dev/mmcblk0p4 ``` 这将跳过一些安全检查,但如果设备确实可用,可以尝试使用。 5. **检查设备是否损坏:** 可以用 `dmesg` 查看内核日志,确认是否有设备读写错误。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值