300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > linux命令mkfs_如何在Linux上使用mkfs命令

linux命令mkfs_如何在Linux上使用mkfs命令

时间:2024-06-13 19:01:23

相关推荐

linux命令mkfs_如何在Linux上使用mkfs命令

linux命令mkfs

Fatmawati Achmad Zaenuri/ShutterstockFatmawati Achmad Zaenuri / Shutterstock

You must create a file system before you can use any data storage device connected to a Linux computer. Learn how to usemkfsand other utilities to do just that for all sorts of file systems. We show you how.

必须先创建文件系统,然后才能使用连接到Linux计算机的任何数据存储设备。 了解如何使用mkfs和其他实用程序针对各种文件系统执行此操作。 我们向您展示如何。

mkfs制作文件系统 (mkfsMakes File Systems)

Themkfscommand makes file systems.On other operating systems, creating a file system is called formatting. Regardless of its name, it is the process that prepares a partition so that it can store data. The partition needs a way to store files, yes. But it also needs a mechanism to store the names and locations of those files, together with their metadata such as the file creation timestamp, the file modified timestamp, the size of the file, and so on.Oncemkfshas built the necessary framework for handling and storing file metadata, you can start adding files to the partition.

mkfs命令创建文件系统 。 在其他操作系统上,创建文件系统称为formatting 。 不管其名称如何,它都是准备分区以便存储数据的过程。 是的,分区需要一种存储文件的方式。 但是,它还需要一种机制来存储这些文件的名称和位置,以及它们的元数据,例如文件创建时间戳,文件修改时间戳,文件大小等等。 一旦mkfs构建了用于处理和存储文件元数据的必要框架,就可以开始将文件添加到分区了。

The syntax is very simple. You just tellmkfsthe device partition you want the file system created on, and what type of file system you want.That’s on the face of it. Behind the scenes, it’s a little different. For some time now on most Linux distributionsmkfshas been a wrapper formke2fs. Themkfscommand calls themke2fscommand and passes it the options you’ve specified. Poor oldmke2fsdoes all of the work but gets none of the glory.

语法非常简单。 您只需告诉mkfs您要在其上创建文件系统的设备分区,以及您想要哪种文件系统。 那是表面的。 在幕后,有点不同。 一段时间以来,在大多数Linux发行版中,mkfs一直是mke2fs的包装 。mkfs命令调用mke2fs命令并将其传递给您指定的选项。 较差的旧mke2fs完成所有工作,但不会获得任何荣耀。

The syntax ofmkfshas been updated, and the old format has been deprecated. Both forms will work, but we’ll use the modern style in this article.

mkfs的语法已更新,旧格式已被弃用。 两种形式都可以使用,但是在本文中我们将使用现代风格。

文件系统的选择 (The Choice of File Systems)

The modern way of usingmkfsis to type “mkfs.” and then the name of the file system you wish to create.

使用mkfs的现代方法是键入“ mkfs”。 然后是您要创建的文件系统的名称。

To see the file systems thatmkfscan create, type “mkfs” and then hit the Tab key twice. There’s no space after “mkfs”, just hit Tab twice.

要查看mkfs可以创建的文件系统,请键入“ mkfs”,然后按两次Tab键。 “ mkfs”后没有空格,只需按两次Tab键即可。

The list of available file systems is displayed in the terminal window. The screenshot is from Ubuntu 18.04 LTS. Other distributions may offer more or fewer options.We’ll run through these and describe each one briefly. After a quick word about journaling.

可用文件系统的列表显示在终端窗口中。 屏幕截图来自Ubuntu 18.04 LTS。 其他发行版可能提供更多或更少的选择。 我们将逐一介绍这些内容,并简要描述每个内容。 简要介绍日记之后。

Journaling is an important concept in file systems. The file systems records the pending file writes to a journal. As each file is written to, the journal is updated, and the pending write records are updated. This allows the file system to repair broken, partially written files that have occurred due to a catastrophic event such as a power cut. Some of the older file systems do not support journaling. Those that don’t, write to the disk less frequently because they don’t need to update the journal. They may perform faster, but they are more prone to damage due to interrupted file writes.

日志记录是文件系统中的重要概念。 文件系统将挂起的文件写入日志记录。 在写入每个文件时,将更新日志,并更新未决的写记录。 这允许文件系统修复由于灾难事件(例如断电)而发生的损坏的,部分写入的文件。 一些较旧的文件系统不支持日记功能。 那些不这样做的人则不需要频繁地写入磁盘,因为它们不需要更新日志。 它们的执行速度可能更快,但是由于文件写入中断而更容易造成损坏。

Ext2: The very first file system for Linux was the MINIXfile system. It was later replaced by the first file system ever written specifically for Linux, which wasExt. Ext2 was Ext’s successor. Ext2 is not a journaling file system.

Ext2:Linux的第一个文件系统是MINIX文件系统。 后来,它被有史以来第一个专门为Linux编写的文件系统Ext所取代。 Ext2是Ext的后继者 。 Ext2不是日记文件系统。

Ext3: This was the successor to Ext2, and can be thought of as Ext2 with journaling, which protects your file system from data corruption caused by crashes and sudden power loss.

Ext3:这是Ext2的后继产品 ,可以看作是带有日志记录的Ext2,它可以保护文件系统免受崩溃和突然断电导致的数据损坏。

Ext4: Ext4 is the standard file system for may Linux distributions. It is a solid, tried, and trusted file system. It has features that reduce file fragmentation and can be used with larger drives, partitions, and files than Ext3.

Ext4:Ext4是May Linux发行版的标准文件系统。 它是一个可靠,可靠的可靠文件系统。 它具有减少文件碎片的功能,并且与Ext3相比,可用于更大的驱动器,分区和文件。

BFS: This is the Boot File System, which is designed for one job and one only: to handle the files in the boot partition. It’s rare that you’d be creating a boot file system by hand. Your Linux installation process will do this for you.

BFS:这是引导文件系统 ,它仅适用于一项作业和一项:处理引导分区中的文件。 很少会手工创建启动文件系统。 您Linux安装过程将为您完成此任务。

FAT: The File Allocation Table file system was designed for floppy disks by a consortium of computer-industry heavyweights. It was introduced in 1977. The only reason you’d use this non-journaling file system is for compatibility with non-Linux operating systems.

FAT: 文件分配表文件系统是由计算机行业的重量级组织为软盘设计的。 它于1977年引入。使用此非日志文件系统的唯一原因是为了与非Linux操作系统兼容。

NTFS: The New Technology File System is a Microsoft journaling file system introduced with Windows NT. It was the successor to FAT.The only reason you’d use this file system is for compatibility with non-Linux operating systems.

NTFS: 新技术文件系统是Windows NT引入的Microsoft日记文件系统。 它是FAT的后继者。 您使用此文件系统的唯一原因是为了与非Linux操作系统兼容。

MINIX: Originally created by Andrew S. Tanenbaum as an educational aid, MINIX is a “mini-Unix” operating system. Nowadays, it is aimed at providing a self-healing and fault-tolerantoperating system. The MINIXfile systemwas designed as a simplified version of the Unix File System. Perhaps if you are cross-developing on a Linux computer and targetting a MINIX platform you may use this file system. Or perhaps you need compatibility with a MINIX computer for other reasons. Use cases for this file system on a Linux computer are not leaping out at me, but it’s available.

MINIX:最初由Andrew S. Tanenbaum创建,目的是作为一种教育工具, MINIX是一个“微型Unix”操作系统。 如今,它旨在提供一种自我修复和容错的操作系统。 MINIX文件系统被设计为Unix File System的简化版本 。 也许如果您正在Linux计算机上进行交叉开发并以MINIX平台为目标,则可以使用此文件系统。 或者,由于其他原因,您可能需要与MINIX计算机兼容。 Linux计算机上此文件系统的用例并没有引起我的兴趣,但可以使用。

VFAT: Virtual File Allocation Table, was introduced with Windows 95, and removed the eight-character limit for filenames. File names of up to 255 characters became possible. The only reason you’d use this file system is for compatibility with non-Linux operating systems.

VFAT: 虚拟文件分配表 ,是Windows 95引入的,并且删除了文件名的八个字符的限制。 最多可以使用255个字符的文件名。 您使用此文件系统的唯一原因是为了与非Linux操作系统兼容。

CRAMFS: The Compressed ROM File System is a read-only file system designed for embedded systems and specialist read-only uses, such as in the boot processes of Linux computers. It is common to have a small, transient, file system loaded first so that bootstrap processes can be launched to prepare for the “real” boot system to be mounted.

CRAMFS: 压缩ROM文件系统是一个只读文件系统,设计用于嵌入式系统和专业只读用途,例如Linux计算机的引导过程中。 通常会先加载一个小型的临时文件系统,以便启动引导进程来为要安装的“实际”启动系统做准备。

MSDOS: The file system of the Microsoft Disk Operating System. Released in 1981, it’s an elementary file system that is as basic as it gets. The first version didn’t even have directories. It holds a place of prominence in computing history but,beyond compatibility with legacy systems, there is little reason to use it today.

MSDOS: Microsoft磁盘操作系统的文件系统。 它发布于1981年,是一个基本的基本文件系统。 第一个版本甚至没有目录。 它在计算历史上占有举足轻重的地位,但是,除了与传统系统的兼容性之外,当今几乎没有理由使用它。

实验文件系统的安全方法 (A Safe Way to Experiment With File Systems)

Creating a file system on a partition is destructive to any data that might already reside on that partition. Using a spare hard drive—or even a spare computer—is the perfect way to experiment with creating and using different file systems. But of course, many people don’t have spare hardware lying around, waiting to be experimented on.

在分区上创建文件系统会破坏该分区上可能已经存在的所有数据。 使用备用硬盘驱动器或什至是备用计算机,是尝试创建和使用不同文件系统的理想方法。 但是,当然,很多人没有多余的硬件在等待实验。

However, we can create an image file and create file systems within that. Once we mount it, we can use it as though it were a regular partition. We can explore and experiment with file systems without a need for spare hardware.We’ll use theddcommand to create our image file.

但是,我们可以创建一个映像文件并在其中创建文件系统。 一旦挂载它,就可以像使用常规分区一样使用它。 我们无需备用硬件即可探索和试验文件系统。 我们将使用dd命令创建图像文件 。

The image file is created by taking source data and putting it into an image.We need to tellddwhere to get its source data. We’ll use theif(input file) option to tellddto use /dev/zero as the input data source. This will be a stream of zeroes.

通过获取源数据并将其放入图像中来创建图像文件。 我们需要告诉dd何处获取其源数据。 我们将使用if(输入文件)选项来告诉dd使用/ dev / zero作为输入数据源。 这将是零流。

Theof(output file) option allows us to provide a name for the image file. We’ll call it “howtogeek.img”.

of(输出文件)选项允许我们为图像文件提供名称。 我们将其称为“ howtogeek.img”。

The size of the image file is determined by the size and number of blocks we add to it.We’re using thebs(block size) option to request a block size of 1 MB and thecountoption to request 250 blocks. This will give us a file system of 250 MB. When you issue this command, adjust the number of blocks to suit your needs and the spare capacity you have on your Linux computer.

图像文件的大小取决于我们添加到其中的块的大小和数量。 我们使用bs(块大小)选项来请求1 MB的块大小,使用count选项来请求250个块。 这将为我们提供250 MB的文件系统。 发出此命令时,请调整块数以适合您的需求以及Linux计算机上的备用容量。

dd if=/dev/zero of=~/howtogeek.img bs=1M count=250

The file is created for us andddreports that there were 250 blocks created for us, as requested.

该文件是为我们创建的,并且dd报告根据请求为我们创建了250个块。

We can look at our image file withls:

我们可以使用ls查看我们的图像文件:

ls -hl

It’s 250 MB as expected, which is encouraging.

预期达到250 MB,这令人鼓舞。

创建文件系统 (Creating the File System)

Let’s pick a file system to use. We’ll go back in time and use Ext2, which is the earliest version of Ext that this implementation ofmkfscan create. This is a non-journaling file system, so don’t store anything precious in it without having backups elsewhere. We use themkfs.ext2variant of themkfscommand, and we tell it to use our image file as the target.

让我们选择一个要使用的文件系统。 我们将回到过去并使用Ext2,这是mkfs实现可以创建的Ext的最早版本。 这是一个非日志文件系统,因此,如果没有其他地方的备份,请不要在其中存储任何珍贵的文件。 我们使用mkfs命令的mkfs.ext2变体,并告诉它使用我们的映像文件作为目标。

mkfs.ext2 ~/howtogeek.img

The file system is created, and some details of the file system are displayed.

创建文件系统,并显示文件系统的一些详细信息。

As you can see from the highlighted text,mke2fsmakes an appearance.

从突出显示的文本中可以看到,mke2fs出现了。

Now we have a container for the file system—the image file—which is standing in for a hard drive in this scenario. Inside that container, we’ve created a file system. Now we need to mount the file system so that we can use it.

现在,我们有了文件系统的容器(图像文件),在这种情况下,该容器代表了硬盘驱动器。 在该容器内,我们创建了一个文件系统。 现在我们需要挂载文件系统,以便可以使用它。

This is a temporary set-up, so we’ll make a mount point within /mnt called “geek.” We’ll remove it when we’re finished.

这是一个临时设置,因此我们将在/ mnt中创建一个称为“怪胎”的挂载点 。 完成后,我们将其删除。

sudo mkdir /mnt/geek

Now we can mount our image file.

现在我们可以挂载映像文件了。

sudo mount ~/howtogeek.img /mnt/geek

We need to change the file ownership of the mount point so that we have read and write access to it.

我们需要更改挂载点的文件所有权 ,以便我们对其具有读写权限。

sudo chown dave:users /mnt/geek/

And now we should be able to use our new file system. Let’s change into the file system, and copy some files to it.

现在,我们应该能够使用我们的新文件系统了。 让我们转到文件系统,然后将一些文件复制到其中。

cd /mnt/geek

cp ~/Documents/Code/*.? .

This will copy all files with a single-letter extension from the ~/Documents/Code directory to our new file system. Let’s check that they were copied.

这会将所有带有单字母扩展名的文件从〜/ Documents / Code目录复制到我们的新文件系统。 让我们检查一下它们是否已被复制。

ls

The files have been copied, so our file system has been created, mounted and used. Or so we think. Let’s double-check. From our home directory, we’ll unmount the file system. Note there is only one “n” in umount.

文件已被复制,因此我们的文件系统已创建,安装和使用。 还是我们认为。 让我们仔细检查一下。 从主目录中,我们将卸载文件系统 。 请注意, umount中只有一个“ n”。

sudo umount /mnt/geek

Now, if we pop back to /mnt/geek and check for files, we shouldn’t find any because they are inside our image file, and that has been unmounted.

现在,如果我们跳回到/ mnt / geek并检查文件,则找不到任何文件,因为它们在我们的映像文件中,并且已被卸载。

cd /mnt/geek

ls

进一步探索 (Further Exploration)

Now we’ve got the process worked out, trying another file system should be easy. We’ll use the MINIX file system this time. In our home directory, we can create a new file system inside our existing image file.

现在我们已经完成了流程,尝试另一个文件系统应该很容易。 这次我们将使用MINIX文件系统。 在主目录中,我们可以在现有映像文件中创建一个新文件系统。

Be careful!If there are any important files on the file system inside the image file, mount the image file, and retrieve thembeforeyou create a new file system.

小心!如果映像文件中文件系统上有重要文件,请挂载映像文件,然后在创建新文件系统之前将其检索。

mkfs.minix ~/howtogeek.image

Without any hint of asking you “if you’re sure,” the new file system is created over the old one. We can mount our image file with exactly the same command as before:

没有任何询问您“是否确定”的提示,新文件系统是在旧文件系统之上创建的。 我们可以使用与之前完全相同的命令挂载映像文件:

sudo mount ~/howtogeek.img /mnt/geek

Let’s change into the new file system at /mnt/geek and see if we can create a file.

让我们转到/ mnt / geek的新文件系统,看看是否可以创建文件。

touch geek.txt

ls -ahl geek.txt

And, as simply and as quickly as that, we’ve created a new file system, mounted it, and we can use it.

而且,如此简单快捷地,我们创建了一个新的文件系统,将其挂载,我们可以使用它。

卸下安装点 (Removing the Mount Point)

When you’re all done, we can remove the “geek” mount point. To do that we’ll use rmdir:

完成所有操作后,我们可以删除“怪胎”安装点。 为此,我们将使用rmdir :

cd /mnt

sudo rmdir geek

杂耍火 (Juggling With Fire)

With Linux, as with most things, you learn by doing. The problem with some commands is that they are potentially destructive. The dilemma is how to practice using them without putting your system or data at risk?

与大多数事情一样,使用Linux可以边做边学。 某些命令的问题在于它们可能具有破坏性。 难题是如何在不使系统或数据面临风险的情况下练习使用它们?

You now have a simple method of creating and trying out file systems withmkfsthat leaves your computer untouched.

您现在有了使用mkfs创建和试用文件系统的简单方法,这使您的计算机保持不变。

翻译自: /443342/how-to-use-the-mkfs-command-on-linux/

linux命令mkfs

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。