简介
在本实验中,我们将探索 Linux 的 mkdosfs
命令,该命令用于在分区上创建 DOS 文件系统或格式化 USB 驱动器。mkdosfs
命令是 dosfstools
包的一部分,该包提供了用于创建和检查 MS-DOS FAT 文件系统的工具。我们将学习如何在分区上创建 DOS 文件系统,以及如何使用 DOS 文件系统格式化 USB 驱动器。本实验涵盖了 mkdosfs
命令的实用示例和常见选项。
在本实验中,我们将探索 Linux 的 mkdosfs
命令,该命令用于在分区上创建 DOS 文件系统或格式化 USB 驱动器。mkdosfs
命令是 dosfstools
包的一部分,该包提供了用于创建和检查 MS-DOS FAT 文件系统的工具。我们将学习如何在分区上创建 DOS 文件系统,以及如何使用 DOS 文件系统格式化 USB 驱动器。本实验涵盖了 mkdosfs
命令的实用示例和常见选项。
在这一步中,我们将学习 mkdosfs
命令,该命令用于在分区上创建 DOS 文件系统或格式化 USB 驱动器。mkdosfs
命令是 dosfstools
包的一部分,该包提供了用于创建和检查 MS-DOS FAT 文件系统的工具。
首先,让我们检查系统上是否安装了 dosfstools
包:
sudo apt-get update
sudo apt-get install -y dosfstools
示例输出:
Reading package lists... Done
Building dependency tree... Done
The following additional packages will be installed:
libfuse2
The following NEW packages will be installed:
dosfstools libfuse2
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
mkdosfs
命令用于在分区或设备上创建 DOS 文件系统。其基本语法为:
sudo mkdosfs [options] <device>
其中 <device>
是你想要格式化的分区或设备。
mkdosfs
命令的一些常见选项包括:
-F 12|16|32
:指定 FAT 类型(12、16 或 32 位)-n <volume-name>
:设置卷标名称-S <sector-size>
:设置扇区大小(默认为 512 字节)-c
:在格式化前检查设备的坏块让我们尝试在一个分区上创建 DOS 文件系统:
sudo mkdosfs -F 32 /dev/sdb1
示例输出:
mkdosfs 4.2 (2021-01-31)
/dev/sdb1 has 20971520 sectors of 512 bytes.
Creating a FAT32 filesystem in the volume with 20971520 available sectors.
Creating boot sector...
Creating FAT table...
Reserving space for root directory...
Writing directory entries...
Writing FAT tables...
Writing root directory...
在这个示例中,我们在 /dev/sdb1
分区上创建了一个 FAT32 文件系统。
在这一步中,我们将学习如何使用 mkdosfs
命令在分区上创建 DOS 文件系统。
首先,让我们在系统上创建一个新的分区。我们可以使用 fdisk
命令来完成此操作:
sudo fdisk /dev/sdb
示例输出:
Welcome to fdisk (util-linux 2.38).
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 0x1d7d1d7d.
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-20971519, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-20971519, default 20971519):
Created a new partition 1 of type 'Linux' and of size 10 GiB.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
在这个示例中,我们在 /dev/sdb
设备上创建了一个新的主分区。
现在,让我们在新分区上创建一个 DOS 文件系统:
sudo mkdosfs -F 32 /dev/sdb1
示例输出:
mkdosfs 4.2 (2021-01-31)
/dev/sdb1 has 20971520 sectors of 512 bytes.
Creating a FAT32 filesystem in the volume with 20971520 available sectors.
Creating boot sector...
Creating FAT table...
Reserving space for root directory...
Writing directory entries...
Writing FAT tables...
Writing root directory...
我们已经在 /dev/sdb1
分区上创建了一个 FAT32 文件系统。
在这一步中,我们将学习如何使用 mkdosfs
命令将 USB 驱动器格式化为 DOS 文件系统。
首先,让我们将 USB 驱动器插入系统。我们可以使用 lsblk
命令来识别设备:
lsblk
示例输出:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 465.8G 0 disk
├─sda1 8:1 0 512M 0 part /boot/efi
└─sda2 8:2 0 465.3G 0 part /
sdb 8:16 1 7.5G 0 disk
在这个示例中,USB 驱动器被识别为 /dev/sdb
。
现在,让我们使用 DOS 文件系统格式化 USB 驱动器:
sudo mkdosfs -F 32 /dev/sdb
示例输出:
mkdosfs 4.2 (2021-01-31)
/dev/sdb has 15523840 sectors of 512 bytes.
Creating a FAT32 filesystem in the volume with 15523840 available sectors.
Creating boot sector...
Creating FAT table...
Reserving space for root directory...
Writing directory entries...
Writing FAT tables...
Writing root directory...
我们已经在 /dev/sdb
USB 驱动器上创建了一个 FAT32 文件系统。
在本实验中,我们学习了 mkdosfs
命令,该命令用于在分区上创建 DOS 文件系统或格式化 USB 驱动器。我们首先检查了系统上是否安装了 dosfstools
包,然后探索了 mkdosfs
命令的基本语法和常见选项。接着,我们演示了如何使用 mkdosfs
命令在分区上创建 FAT32 文件系统。最后,我们学习了如何使用 DOS 文件系统格式化 USB 驱动器。