怎样在 Linux 终端下使用 dd 命令创建一个临场 USB 驱动器
dd USB
![](/data/attachment/album/202109/15/104940ucajv4o4zb8934ll.jpg)


有很多的图形化工具可以用来创建<ruby> 临场 <rt>  live </rt></ruby> USB 驱动器。Linux 上的 [Etcher](https://itsfoss.com/install-etcher-linux/) 可能是最受欢迎的。为此，Ubuntu 也开发了自己的启动盘创建工具。


但是，资深 Linux 用户可能更喜欢使用 `dd` 命令在 Linux 终端中创建临场 USB，这会更快速便捷。


`dd` 命令是一个 [命令行](https://itsfoss.com/gui-cli-tui/) 工具，它提供了用来复制和转换文件的强大功能。


一个常见的使用示例是，用户使用 `dd` 命令将 ISO 文件写入到他们的外部存储设备（例如 USB 驱动盘），以用来给他们的电脑或者笔记本安装一个新的 Linux 发行版。


这就是我将在本教程中展示的内容。我将带你认识需要的命令，从终端找到我们的 USB 驱动器，然后对 ISO 文件进行实际刷写。


### 使用 dd 命令从 ISO 镜像创建临场 USB


在我向你展示步骤前，让我带你快速过一下你将要使用到的命令并解释它的作用。


这是一个使用命令刷写 ISO 的例子：



```
dd if="./filename.iso" of="/dev/sdb" status="progress" conv="fsync"

```

让我们来看看 [dd 命令](https://linuxhandbook.com/dd-command/) 实际都做了些什么。


#### 理解 dd 命令


![Explanation of the dd command for live USB creation](/data/attachment/album/202109/15/104948y88lpa9kv9pnyja8.png)


首先，你输入 `dd`。没错，这就是你要运行的程序的名称。


接下来，你指定 `if="./filename.iso"`。`if` 代表<ruby> 输入文件 <rt>  input file </rt></ruby>，告诉 `dd` 命令你将要向外部存储设备写入哪个文件。


之后，你输入 `of="/dev/sdb"`。和 `if` 一样，`of` 代表的是<ruby> 输出文件 <rt>  output file </rt></ruby>。


要记住的是，输出文件在技术上不必是系统上的文件。你还可以指定诸如外部设备路径之类的内容（如示例所示），它看起来像系统上的普通文件，但实际上指向连接到你机器的设备。


`status` 可以设定为 3 个选项：`none`、`noxfer` 和 `progress`。


* 你设置的 `progress` 选项将使 `dd` 任务显示有关已将多少 ISO 文件传输到存储驱动器的定期统计信息，以及对 `dd` 任务完成前需要多长时间的估计。
* 如果你改为设置 `none` 选项，`dd` 任务在写入 ISO 文件期间只会打印错误消息，并且删除进度条之类的内容。
* `noxfer` 选项隐藏了传输完成后打印的一些信息，例如从开始到完成所用的时间。


最后，你将 `conv` 选项设置为 `fsync`。这会导致 `dd` 任务在整个 ISO 文件写入 USB 驱动器之前不会报告成功写入。


如果你省略这个选项，`dd` 任务会工作的很好（并且实际上可能看起来运行得更快），但你可能会发现你的系统需要很长时间才能告诉你移除 USB 驱动器是安全的，因为它会在后台完成 ISO 的内容写入，从而允许你在此期间做其它事情。


**现在你明白了你必须做什么，让我们看看如何去做。**



> 
> **注意事项**
> 
> 
> 命令行是把双刃剑。当你在命令行使用类似于 `dd` 命令时必须十分小心。你必须确保你目标输出文件是正确的设备。一个错误的步骤就可能会格式化你的系统硬盘，你的操作系统也会因此而损坏。
> 
> 
> 


#### 第 0 步: 下载所需的 ISO 镜像


不用说，你需要有一个 ISO 镜像文件才能将其刷写到 USB 上。


我将使用 Ubuntu 20.04 ISO（可在此处[下载](https://ubuntu.com/download/desktop/thank-you?version=20.04.2.0&architecture=amd64)）来测试我之前介绍的 `dd` 命令。


#### 第 1 步: 获取 USB 盘符


插入你的 USB 驱动器。


我为 `of` 参数输入的具体路径是 `/dev/sdb`。USB 磁盘通常会标记为 `/dev/sdb`，但这不是硬性规定。


此路径可能因你的系统而异，你可以使用 `lsblk` 命令确认 USB 磁盘的路径。只需从列表中查找一个看起来像你的 USB 磁盘大小的驱动器，就可以了。


![](/data/attachment/album/202109/15/104948vezcp8t2cficeoo8.png)


如果你更熟悉 GUI 程序，还可以使用 GNOME Disks 等工具找到驱动器的路径。


![](/data/attachment/album/202109/15/104950ohbd73pg12hqixde.png)


现在你已经确认了外部驱动器的路径，让我们开始创建临场 USB。


#### 第 2 步：将 ISO 文件写入 USB 磁盘


在下载 ISO 文件的目录打开一个终端，然后运行以下命令（如果 `/dev/sdb` 与你的存储设备名称不同，请记住将其替换）：



```
sudo dd if="./ubuntu-20.04.2.0-desktop-amd64.iso" of="/dev/sdb" status="progress" conv="fsync"

```

之后，让 `dd` 去做剩下的事情，它会在完成后打印一条完成消息：


![](/data/attachment/album/202109/15/104951gvnnt5vfvhkcdfvh.png)


就像这样，你已经在 Linux 终端中使用 `dd` 命令刷写了 ISO 文件！


### 总结


现在，你可以通过终端做更多的事情，让你的工作效率大大提高。


对 `dd` 命令有任何没解决的问题，或者无法正常工作？请随时在下面的评论部分中留下你的问题。




---


via: <https://itsfoss.com/live-usb-with-dd-command/>


作者：[Hunter Wittenborn](https://itsfoss.com/author/hunter/) 选题：[lujun9972](https://github.com/lujun9972) 译者：[perfiffer](https://github.com/perfiffer) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
There are several graphical tools available for creating live USB. [Etcher on Linux](https://itsfoss.com/install-etcher-linux/) is probably the most popular. Ubuntu has its own Startup Disk Creator tool for this purpose.

However, advanced Linux users swear by the comfort and swiftness of creating live USBs in Linux terminal using the dd command.

The dd command is a [CLI tool](https://itsfoss.com/gui-cli-tui/) that gives you powerful features for copying and converting files.

A common use case that people use dd for is to write ISO files to an external storage device such as a USB drive, which can be used to do things like install a new Linux distribution onto a computer or laptop.

That’s what I am going to show in this tutorial. I’ll go over the commands you will need to run, finding our USB drive from the terminal, and then finally doing the actual flashing of the ISO file.

## Creating live USB from ISO with dd command

Before I show you the steps, let me quickly go over the command which you’ll be using and explain what it does.

Here’s the example command for flashing of the ISO:

`dd if="./filename.iso" of="/dev/sdb" status="progress" conv="fsync"`


Let’s go over what exactly that [dd command](https://linuxhandbook.com/dd-command/) is doing.

### Understanding the above dd command

![dd command for live usb creation](https://itsfoss.com/content/images/wordpress/2021/09/dd-command-for-live-usb-creation.png)

First, you enter `dd`

. As expected, this is just the name of the program you are going to run.

Next, you specify `if="./filename.iso"`

. `if`

stands for input file, which tells `dd`

what file you are going to be writing to the external storage drive.

After that, you enter `of="/dev/sdb"`

. As was with `if`

, `of`

simply stands for output file.

The thing to remember is that the output file doesn’t technically have to be a file on your system. You can also specify things like the path to an external device (as shown in the example), which just **looks** like a normal file on your system, but actually points to a device connected to your machine.

`status`

can be set to three options: `none`

, `noxfer`

and `progress.`


The `progress`

option that you set will cause dd to show periodic statistics on how much of the ISO has been transferred to the storage drive, as well as an estimation on how much longer it will be until dd is finished.

If you were to have set the `none`

option instead, dd would only print error messages during the writing of the ISO, thus removing things like the progress bar.

The `noxfer`

option hides some information that’s printed after a transfer is complete, such as how long it took from start to finish.

Lastly, you set the `conv`

option to `fsync`

. This causes dd to not report a successful write until the entire ISO has been written to the USB drive.

If you omit this option, dd will still write just fine (and might actually appear to run quicker), but you might find your system taking quite a while before it tells you it’s safe to remove the USB drive as it will finish writing the ISO’s content in the background, thus allowing you to do other things in the meantime.

*Now that you understand what you have to do, let’s see how to do it.*

Warning

The command line is a double-edged sword. Be extra careful when you are running a command like dd. You must make sure that you are using the correct device for the output file destination. One wrong step and you may format your main system disk and lose your operating system.

### Step 0: Download the desired ISO

This goes without saying that you need to have an ISO image file in order to flash it on a USB.

I am going to use Ubuntu 20.04 ISO (downloadable [here](https://ubuntu.com/download/desktop/thank-you?version=20.04.2.0&architecture=amd64)) to test the dd command I showed earlier.

### Step 1: Get the USB disk label

Plug in your USB disk.

The specific path I entered for `of`

was `/dev/sdb`

. The USB disks are usually labelled /dev/sdb but that’s not a hard and fast rule.

This path may differ on your system, but you can confirm the path of the drive with the `lsblk`

command. Just look for a listing that looks like the size of your USB drive, and that’ll be it.

![dd disks](https://itsfoss.com/content/images/wordpress/2021/08/dd_disks.png)

If you are more comfortable with GUI programs, you can also find the drive’s path with tools like GNOME Disks.

![dd gnome disks](https://itsfoss.com/content/images/wordpress/2021/08/dd_gnome_disks-800x440.png)

Now that you have established the path to our external drive, let’s create the live USB.

### Step 2: Writing the ISO file to the USB disk

Open up a terminal at the directory where the ISO file is downloaded, and run the following (remember to replace `/dev/sdb`

with the name of your storage device if it’s something different):

`sudo dd if="./ubuntu-20.04.2.0-desktop-amd64.iso" of="/dev/sdb" status="progress" conv="fsync"`


After that, just let dd do it’s thing, and it’ll print a completion message once it’s done:

![dd iso write](https://itsfoss.com/content/images/wordpress/2021/08/dd-iso-write-800x322.png)

And just like that, you’ve flashed an ISO with dd command in the Linux terminal!

## Wrapping Up

Now you’re on your way to doing even more things through the terminal, allowing you to do things faster and quicker than you might have been able to do before.

Got any remaining questions about the dd command, or something just not working right? Feel free to leave any of it in the comment section below.