Merge remote-tracking branch 'LCTT/master'

This commit is contained in:
Xingyu.Wang 2018-05-01 22:53:18 +08:00
commit d2ca50622f
7 changed files with 225 additions and 225 deletions

View File

@ -1,53 +1,55 @@
在 KVM 中测试 IPv6 网络(第 1 部分) 在 KVM 中测试 IPv6 网络(第 1 部分)
====== ======
> 在这个两篇的系列当中,我们将学习关于 IPv6 私有地址的知识,以及如何在 KVM 中配置测试网络。
![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/ipv6-networking.png?itok=swQPV8Ey) ![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/ipv6-networking.png?itok=swQPV8Ey)
要理解 IPv6 地址是如何工作的,没有比亲自动手去实践更好的方法了,在 KVM 中配置一个小的测试实验室非常容易 —— 也很有趣。这个系列的文章共有两个部分,我们将学习关于 IPv6 私有地址的知识,以及如何在 KVM 中配置测试网络。 要理解 IPv6 地址是如何工作的,没有比亲自动手去实践更好的方法了,在 KVM 中配置一个小的测试实验室非常容易 —— 也很有趣。这个系列的文章共有两个部分,我们将学习关于 IPv6 私有地址的知识,以及如何在 KVM 中配置测试网络。
### QEMU/KVM/虚拟机管理器 ### QEMU/KVM/虚拟机管理器
我们先来了解什么是 KVM。在这里我将使用 KVM 来表示 QEMU、KVM、以及虚拟机管理器的一个组合虚拟机管理器在 Linux 发行版中一般内置了。简单解释就是QEMU 模拟硬件,而 KVM 是一个内核模块,它在你的 CPU 上创建一个 “访客领地”,并去管理它们对内存和 CPU 的访问。虚拟机管理器是一个涵盖虚拟化和管理程序的图形工具。 我们先来了解什么是 KVM。在这里我将使用 KVM 来表示 QEMU、KVM、以及虚拟机管理器的一个组合虚拟机管理器在 Linux 发行版中一般内置了。简单解释就是QEMU 模拟硬件,而 KVM 是一个内核模块,它在你的 CPU 上创建一个 “访客领地”,并去管理它们对内存和 CPU 的访问。虚拟机管理器是一个涵盖虚拟化和管理程序的图形工具。
但是你不能被图形界面下 “点击” 操作的方式 "缠住" ,因为,它们也有命令行工具可以使用 —— 比如 virsh 和 virt-install。 但是你不能被图形界面下 “点击” 操作的方式 “缠住” ,因为,它们也有命令行工具可以使用 —— 比如 `virsh``virt-install`
如果你在使用 KVM 方面没有什么经验,你可以从 [在 KVM 中创建虚拟机:第 1 部分][1] 和 [在 KVM 中创建虚拟机:第 2 部分 - 网络][2] 开始学起。 如果你在使用 KVM 方面没有什么经验,你可以从 [在 KVM 中创建虚拟机:第 1 部分][1] 和 [在 KVM 中创建虚拟机:第 2 部分 - 网络][2] 开始学起。
### IPv6 唯一本地地址 ### IPv6 唯一本地地址
在 KVM 中配置 IPv6 网络与配置 IPv4 网络很类似。它们的主要不同在于这些怪异的长地址。[上一次][3],我们讨论了 IPv6 地址的不同类型。其中有一个 IPv6 单播地址类fc00::/7详细情况请查阅 [RFC 4193][4]),它类似于 IPv4 中的私有地址 —— 10.0.0.0/8、172.16.0.0/12、和 192.168.0.0/16。 在 KVM 中配置 IPv6 网络与配置 IPv4 网络很类似。它们的主要不同在于这些怪异的长地址。[上一次][3],我们讨论了 IPv6 地址的不同类型。其中有一个 IPv6 单播地址类,`fc00::/7`(详细情况请查阅 [RFC 4193][4]),它类似于 IPv4 中的私有地址 —— `10.0.0.0/8``172.16.0.0/12`、和 `192.168.0.0/16`
下图解释了这个唯一本地地址空间的结构。前 48 位定义了前缀和全局 ID随后的 16 位是子网,剩余的 64 位是接口 ID 下图解释了这个唯一本地地址空间的结构。前 48 位定义了前缀和全局 ID随后的 16 位是子网,剩余的 64 位是接口 ID
```
| 7 bits |1| 40 bits | 16 bits | 64 bits |
+--------|-+------------|-----------|----------------------------+
| Prefix |L| Global ID | Subnet ID | Interface ID |
+--------|-+------------|-----------|----------------------------+
```
| 7 bits |1| 40 bits | 16 bits | 64 bits |
+--------+-+------------+-----------+----------------------------+
| Prefix |L| Global ID | Subnet ID | Interface ID |
+--------+-+------------+-----------+----------------------------+
``` ```
下面是另外一种表示方法,它可能更有助于你理解这些地址是如何管理的: 下面是另外一种表示方法,它可能更有助于你理解这些地址是如何管理的:
```
| Prefix | Global ID | Subnet ID | Interface ID |
+--------|--------------|-------------|----------------------+
| fd | 00:0000:0000 | 0000 | 0000:0000:0000:0000 |
+--------|--------------|-------------|----------------------+
```
| Prefix | Global ID | Subnet ID | Interface ID |
+--------+--------------+-------------+----------------------+
| fd | 00:0000:0000 | 0000 | 0000:0000:0000:0000 |
+--------+--------------+-------------+----------------------+
``` ```
fc00::/7 共分成两个 /8 地址块fc00::/8 和 fd00::/8。fc00::/8 是为以后使用保留的。因此,唯一本地地址通常都是以 fd 开头的而剩余部分是由你使用的。L 位,也就是第八位,它总是设置为 1这样它可以表示为 fd00::/8。设置为 0 时,它就表示为 fc00::/8。你可以使用 `subnetcalc` 来看到这些东西: `fc00::/7` 共分成两个 `/8` 地址块,`fc00::/8` 和 `fd00::/8`。`fc00::/8` 是为以后使用保留的。因此,唯一本地地址通常都是以 `fd` 开头的,而剩余部分是由你使用的。`L` 位,也就是第八位,它总是设置为 `1`,这样它可以表示为 `fd00::/8`。设置为 `0` 时,它就表示为 `fc00::/8`。你可以使用 `subnetcalc` 来看到这些东西:
``` ```
$ subnetcalc fd00::/8 -n $ subnetcalc fd00::/8 -n
Address = fd00:: Address = fd00::
fd00 = 11111101 00000000 fd00 = 11111101 00000000
$ subnetcalc fc00::/8 -n $ subnetcalc fc00::/8 -n
Address = fc00:: Address = fc00::
fc00 = 11111100 00000000 fc00 = 11111100 00000000
``` ```
RFC 4193 要求地址必须随机产生。你可以用你选择的任何方法来造出个地址,只要它们以 `fd` 打头就可以,因为 IPv6 范围非常大,它不会因为地址耗尽而无法使用。当然,最佳实践还是按 RFCs 的要求来做。地址不能按顺序分配或者使用众所周知的数字。RFC 4193 包含一个构建伪随机地址生成器的算法,或者你可以在线找到任何生成器产生的数字 RFC 4193 要求地址必须随机产生。你可以用你选择的任何方法来造出个地址,只要它们以 `fd` 打头就可以,因为 IPv6 范围非常大,它不会因为地址耗尽而无法使用。当然,最佳实践还是按 RFC 的要求来做。地址不能按顺序分配或者使用众所周知的数字。RFC 4193 包含一个构建伪随机地址生成器的算法,或者你可以找到各种在线生成器。
唯一本地地址不像全局单播地址(它由你的因特网服务提供商分配)那样进行中心化管理,即使如此,发生地址冲突的可能性也是非常低的。当你需要去合并一些本地网络或者想去在不相关的私有网络之间路由时,这是一个非常好的优势。 唯一本地地址不像全局单播地址(它由你的因特网服务提供商分配)那样进行中心化管理,即使如此,发生地址冲突的可能性也是非常低的。当你需要去合并一些本地网络或者想去在不相关的私有网络之间路由时,这是一个非常好的优势。
@ -61,7 +63,7 @@ RFC4193 建议,不要混用全局单播地址的 AAAA 和 PTR 记录,因为
下周我们将讲解如何在 KVM 中配置这些 IPv6 的地址,并现场测试它们。 下周我们将讲解如何在 KVM 中配置这些 IPv6 的地址,并现场测试它们。
通过来自 Linux 基金会和 edX 的免费在线课程 ["Linux 入门" ][6] 学习更多的 Linux 知识。 通过来自 Linux 基金会和 edX 的免费在线课程 [“Linux 入门”][6] 学习更多的 Linux 知识。
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -69,7 +71,7 @@ via: https://www.linux.com/learn/intro-to-linux/2017/11/testing-ipv6-networking-
作者:[Carla Schroder][a] 作者:[Carla Schroder][a]
译者:[qhwdw](https://github.com/qhwdw) 译者:[qhwdw](https://github.com/qhwdw)
校对:[校对者ID](https://github.com/校对者ID) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出

View File

@ -2,89 +2,90 @@
====== ======
![](https://www.ostechnix.com/wp-content/uploads/2018/03/qr-filetransfer-720x340.png) ![](https://www.ostechnix.com/wp-content/uploads/2018/03/qr-filetransfer-720x340.png)
将文件从计算机传输到智能手机并不是什么大问题。你可以使用 USB 线将手机挂载到系统上,然后从文件管理器传输文件。此外,某些第三方应用程序(例如 [**KDE Connect**][1] 和 [**AirDroid**] [2])可帮助你轻松管理和传输系统中的文件至 Android 设备。今天,我偶然发现了一个名为 **“Qr-filetransfer”** 的超酷工具。它允许你通过扫描二维码通过 WiFi 将文件从计算机传输到移动设备而无须离开终端。是的,你没有看错! qr-filetransfer 是一个使用 Go 语言编写的免费的开源命令行工具。在这个简短的教程中,我们将学习如何使用 qr-transfer 将文件从 Linux 传输到任何移动设备。
将文件从计算机传输到智能手机并不是什么大问题。你可以使用 USB 线将手机挂载到系统上,然后从文件管理器传输文件。此外,某些第三方应用程序(例如 [KDE Connect][1] 和 [AirDroid] [2])可帮助你轻松管理和传输系统中的文件至 Android 设备。今天,我偶然发现了一个名为 “Qr-filetransfer” 的超酷工具。它允许你通过扫描二维码通过 WiFi 将文件从计算机传输到移动设备而无须离开终端。是的,你没有看错! Qr-filetransfer 是一个使用 Go 语言编写的自由开源命令行工具。在这个简短的教程中,我们将学习如何使用 Qr-filetransfer 将文件从 Linux 传输到任何移动设备。
### 安装 Qr-filetransfer ### 安装 Qr-filetransfer
首先,在你的系统上安装 Go 语言。 首先,在你的系统上安装 Go 语言。
在 Arch Linux 及其衍生版上: 在 Arch Linux 及其衍生版上:
``` ```
$ sudo pacman -S go $ sudo pacman -S go
``` ```
在基于 RPM 的系统(如 RHEL、CentOS、Fedora上运行 在基于 RPM 的系统(如 RHEL、CentOS、Fedora上运行
``` ```
$ sudo yum install golang $ sudo yum install golang
``` ```
或者: 或者:
``` ```
$ sudo dnf install golang $ sudo dnf install golang
``` ```
在基于 DEB 的系统上,例如 Debian、Ubuntu、Linux Mint你可以使用命令安装它 在基于 DEB 的系统上,例如 Debian、Ubuntu、Linux Mint你可以使用命令安装它
``` ```
$ sudo apt-get install golang $ sudo apt-get install golang
``` ```
在 SUSE/openSUSE 上: 在 SUSE/openSUSE 上:
``` ```
$ sudo zypper install golang $ sudo zypper install golang
``` ```
安装 Go 语言后,运行以下命令下载 qr-filetransfer 应用。 安装 Go 语言后,运行以下命令下载 Qr-filetransfer 应用。
``` ```
$ go get github.com/claudiodangelis/qr-filetransfer $ go get github.com/claudiodangelis/qr-filetransfer
``` ```
上述命令将在当前工作目录下的一个名为 **“go”** 的目录中下载 qr-filetrnasfer GitHub 仓库的内容。 上述命令将在当前工作目录下的一个名为 `go` 的目录中下载 Qr-filetransfer GitHub 仓库的内容。
将 Qr-filetransfer 的二进制文件复制到 PATH 中,例如 `/usr/local/bin/`
将 qt-filetransfer 的二进制文件复制到 PATH 中,例如 /usr/local/bin/。
``` ```
$ sudo cp go/bin/qr-filetransfer /usr/local/bin/ $ sudo cp go/bin/qr-filetransfer /usr/local/bin/
``` ```
最后,如下使其可执行: 最后,如下使其可执行:
``` ```
$ sudo chmod +x /usr/local/bin/qr-filetransfer $ sudo chmod +x /usr/local/bin/qr-filetransfer
``` ```
### 通过扫描二维码将文件从计算机传输到移动设备 ### 通过扫描二维码将文件从计算机传输到移动设备
确保你的智能手机已连接到与计算机相同的 WiFi 网络。 确保你的智能手机已连接到与计算机相同的 WiFi 网络。
然后,使用要传输的文件的完整路径启动 qt-filetransfer。 然后,使用要传输的文件的完整路径启动 `qt-filetransfer`
比如,我要传输一个 mp3 文件。 比如,我要传输一个 mp3 文件。
``` ```
$ qr-filetransfer Chill\ Study\ Beats.mp3 $ qr-filetransfer Chill\ Study\ Beats.mp3
``` ```
首次启动时qr-filetransfer 会要求你选择使用的网络接口,如下所示。 首次启动时,`qr-filetransfer` 会要求你选择使用的网络接口,如下所示。
``` ```
Choose the network interface to use (type the number): Choose the network interface to use (type the number):
[0] enp5s0 [0] enp5s0
[1] wlp9s0 [1] wlp9s0
``` ```
我打算使用 **wlp9s0** 接口传输文件,因此我输入 “1”。qr-filetransfer 会记住这个选择,除非你通过 **-force** 参数或删除程序存储在当前用户的家目录中的 **.qr-filetransfer.json** 文件,否则永远不会再提示你。 我打算使用 wlp9s0 接口传输文件,因此我输入 “1”。`qr-filetransfer` 会记住这个选择,除非你通过 `-force` 参数或删除程序存储在当前用户的家目录中的 `.qr-filetransfer.json` 文件,否则永远不会再提示你。
然后,你将看到二维码,如下图所示。 然后,你将看到二维码,如下图所示。
![][4] ![][4]
打开二维码应用(如果尚未安装,请从 Play 商店安装任何一个二维码读取程序)并扫描终端中显示的二维码。 打开二维码应用(如果尚未安装,请从 Play 商店安装任何一个二维码读取程序)并扫描终端中显示的二维码。
读取二维码后,系统会询问你是要复制链接还是打开链接。你可以复制链接并手动将其粘贴到移动网络浏览器上,或者选择“打开链接”以在移动浏览器中自动打开它。 读取二维码后,系统会询问你是要复制链接还是打开链接。你可以复制链接并手动将其粘贴到移动网络浏览器上,或者选择“打开链接”以在移动浏览器中自动打开它。
@ -94,34 +95,32 @@ Choose the network interface to use (type the number):
![][6] ![][6]
如果文件太大,请压缩文件,然后传输它 如果文件太大,请压缩文件,然后传输它:
``` ```
$ qr-filetransfer -zip /path/to/file.txt $ qr-filetransfer -zip /path/to/file.txt
``` ```
要传输整个目录,请运行: 要传输整个目录,请运行:
``` ```
$ qr-filetransfer /path/to/directory $ qr-filetransfer /path/to/directory
``` ```
请注意,目录在传输之前会被压缩。 请注意,目录在传输之前会被压缩。
qr-filetransfer 只能将系统中的内容传输到移动设备,反之不能。这个项目非常新,所以会有 bug。如果你遇到了任何 bug请在本指南最后给出的 GitHub 页面上报告。 `qr-filetransfer` 只能将系统中的内容传输到移动设备,反之不能。这个项目非常新,所以会有 bug。如果你遇到了任何 bug请在本指南最后给出的 GitHub 页面上报告。
干杯! 干杯!
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
via: https://www.ostechnix.com/transfer-files-from-computer-to-mobile-devices-by-scanning-qr-codes/ via: https://www.ostechnix.com/transfer-files-from-computer-to-mobile-devices-by-scanning-qr-codes/
作者:[SK][a] 作者:[SK][a]
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
选题:[lujun9972](https://github.com/lujun9972) 选题:[lujun9972](https://github.com/lujun9972)
译者:[geekpi](https://github.com/geekpi)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出

View File

@ -1,4 +1,4 @@
IT automation: How to make the case Translating by FelxiYFZ IT automation: How to make the case
====== ======
At the start of any significant project or change initiative, IT leaders face a proverbial fork in the road. At the start of any significant project or change initiative, IT leaders face a proverbial fork in the road.

View File

@ -1,3 +1,6 @@
Translating by MjSeven
How To Manage NodeJS Packages Using Npm How To Manage NodeJS Packages Using Npm
====== ======

View File

@ -1,176 +0,0 @@
Translating by kennethXia
Bootiso Lets You Safely Create Bootable USB Drive
======
![](https://www.ostechnix.com/wp-content/uploads/2018/04/USB-drive-720x340.png)
Howdy newbies! Some of you may often use **dd command** to do various things, like creating a USB drive or cloning disk partitions. Please be mindful that dd command is one of the dangerous and destructive command. If youre Linux beginner, mostly avoid using dd command to do stuffs. If you dont know what you are doing, you may wipe your hard drive in minutes. The dd command literally just takes bytes from **if** and writes them to **of**. It doesnt care what its overwriting, it doesnt care if theres a partition table in the way, or a boot sector, or a home folder, or anything important. It will simply do what it is told to do. Instead, use some user-friendly apps like [**Etcher**][1]. So you will know which device youre going to format before actually start creating bootable USB devices.
Today, I stumbled upon yet another utility named **“Bootiso”** , which is also used to safely create bootable USB drive. It is actually a BASH script, and is brilliant! It has some extra features that helps us to safely create bootable USB devices. If you want to be sure youre targeting a USB device (and not internal drive), or if you want autodetection of a USB device, you can use bootiso. Here is the significant advantages of using this script:
* If there is only one USB drive, Bootiso will automatically select it.
* If there are more than one USB drives present, it lets you to choose one of them from the list.
* Just in case you mistakenly choose one of Internal hard drive, it will exit without doing anything.
* It checks the selected ISO has the correct mime-type. If it has wrong mime-type, it will exit.
* It asserts that the selected item is not a partition and exit if it doesnt.
* It will prompt the user confirmation before erasing and partitioning the USB drive.
* Lists available USB drives.
* Installs syslinux bootloader (optional).
* Free and Open Source.
### Safely Create Bootable USB Drive Using Bootiso
Installing Bootiso is very easy. Download the latest version using command:
```
$ curl -L https://rawgit.com/jsamr/bootiso/latest/bootiso -O
```
Move the downloaded file to your **$PATH** , for example /usr/local/bin/.
```
$ sudo cp bootiso /usr/local/bin/
```
Finally, make it executable:
```
$ sudo chmod +x /usr/local/bin/bootiso
```
Done! Now, it is time to create bootable USB drives. First, let us see how many USB drives are present using command:
```
$ bootiso -l
```
Sample output:
```
Listing USB drives available in your system:
NAME HOTPLUG SIZE STATE TYPE
sdb 1 7.5G running disk
```
As you can see, I have only one USB drive. Let us go ahead and create the USB bootable from an ISO file using command:
```
$ bootiso bionic-desktop-amd64.iso
```
This command will prompt you to enter the sudo password. Type the password and hit ENTER key to install the missing dependencies (if there are any) and then create USB bootable device.
Sample output:
```
[...]
Listing USB drives available in your system:
NAME HOTPLUG SIZE STATE TYPE
sdb 1 7.5G running disk
Autoselecting `sdb' (only USB device candidate)
The selected device `/dev/sdb' is connected through USB.
Created ISO mount point at `/tmp/iso.c5m'
`bootiso' is about to wipe out the content of device `/dev/sdb'.
Are you sure you want to proceed? (y/n)>y
Erasing contents of /dev/sdb...
Creating FAT32 partition on `/dev/sdb1'...
Created USB device mount point at `/tmp/usb.QgV'
Copying files from ISO to USB device with `rsync'
Synchronizing writes on device `/dev/sdb'
`bootiso' took 303 seconds to write ISO to USB device with `rsync' method.
ISO succesfully unmounted.
USB device succesfully unmounted.
USB device succesfully ejected.
You can safely remove it !
```
If the your ISO file has the wrong mime-type, you will see the following error message:
```
Provided file `bionic-desktop-amd64.iso' doesn't seem to be an iso file (wrong mime type: `application/octet-stream').
Exiting bootiso...
```
You can, however, skip the mime-type check using **no-mime-check** option like below.
```
$ bootiso --no-mime-check bionic-desktop-amd64.iso
```
Like I already mentioned, Bootiso will automatically choose the USB drive if there is only one USB drive present in your system. So, we dont need to mention the usb disk path. If you have more than one devices connected, you can explicitly specify the USB device using **-d** flag like below.
```
$ bootiso -d /dev/sdb bionic-desktop-amd64.iso
```
Replace “/dev/sdb” with your own path.
If you dont specify **-d** flag when using more than one USB devices, Bootiso will prompt you to select from available USB drives.
Bootiso will ask the user confirmation before erasing and partitioning the USB devices. To auto-confirm this, use **-y** or **assume-yes** flag.
```
$ bootiso -y bionic-desktop-amd64.iso
```
You can also enable autoselecting USB devices in conjunction with **-y** option as shown below.
```
$ bootiso -y -a bionic-desktop-amd64.iso
```
Or,
```
$ bootiso --assume-yes --autoselect bionic-desktop-amd64.iso
```
Please remember it will work only if you have only one connected USB drive.
By default, Bootiso will create a **FAT 32** partition and then mount and copy the ISO contents using **“rsync”** program to your USB drive. You can also use “dd” instead of “rsync” if you want.
```
$ bootiso --dd -d /dev/sdb bionic-desktop-amd64.iso
```
If you want to increase the odds your USB will be bootable, use **“-b”** or **bootloader”** like below.
```
$ bootiso -b bionic-desktop-amd64.iso
```
The above command will install a bootloader with **syslinux** (safe mode). Please note that it doesnt work if you use “dd” option.
After creating the bootable device, Bootiso will automatically eject the USB drive. If you dont want it to automatically eject it, use **-J** or **no-eject** flag.
```
$ bootiso -J bionic-desktop-amd64.iso
```
Now, the USb device will remain connected. You can unmount it at anytime using “umount” command.
To display help section, run:
```
$ bootiso -h
```
And, thats all for now. Hope this script helps. More good stuffs to come. Stay tuned!
--------------------------------------------------------------------------------
via: https://www.ostechnix.com/bootiso-lets-you-safely-create-bootable-usb-drive/
作者:[SK][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
选题:[lujun9972](https://github.com/lujun9972)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://www.ostechnix.com/author/sk/
[1]:https://www.ostechnix.com/etcher-beauitiful-app-create-bootable-sd-cards-usb-drives/

View File

@ -1,3 +1,5 @@
translating by kennethXia
Getting started with Jenkins Pipelines Getting started with Jenkins Pipelines
====== ======

View File

@ -0,0 +1,170 @@
Bootiso 让你安全地创建 USB 启动设备
======
![](https://www.ostechnix.com/wp-content/uploads/2018/04/USB-drive-720x340.png)
你好,新兵!你们有些人经常使用 **dd 命令**做各种各样的事,比如创建 USB 启动盘或者克隆硬盘分区。不过请牢记dd 是一个危险且有毁灭性的命令。如果你是个 Linux 的新手,最好避免使用 dd 命令。如果你不知道你在做什么你可能会在几分钟里把硬盘擦掉。从原理上说dd 只是从 **“if”** 读取然后写到 **“of”** 上。它才不管往哪里写呢。它根本不关心那里是否有分区表、引导区、家目录或是其他重要的东西。你叫它做什么它就做什么。可以使用像 [**Etcher**][1] 这样的用户友好的应用来代替它。这样你就可以在创建 USB 引导设备之前知道你将要格式化的是哪块盘。
今天,我发现了另一个可以安全创建 USB 引导设备的工具 **Bootiso** 。它实际上是一个 BASH 脚本,但真的很智能!它有很多额外的功能来帮我们安全创建 USB 引导盘。如果你想确定你的目标是 USB 设备(而不是内部驱动器),或者如果你想检测 USB 设备,你可以使用 Bootiso。下面是使用此脚本的显著优点:
* 如果只有一个 USB 驱动器Bootiso 会自动选择它。
* 如果有一个以上的 USB 驱动器存在,它可以让你从列表中选择其中一个。
* 万一你错误地选择一个内部硬盘驱动器,它将退出而不做任何事情。
* 它检查选定的 ISO 是否具有正确的 MIME 类型。如果 MIME 类型不正确,它将退出。
* 它判定所选的项目不是分区,如果判定失败则退出。
* 它将在擦除和分区 USB 驱动器之前提示用户确认。
* 列出可用的 USB 驱动器。
* 安装 syslinux 引导系统 (可选)。
* 自由且开源。
### 使用 Bootiso 安全地创建 USB 驱动器
安装 Bootiso 非常简单。用这个命令下载最新版本:
```
$ curl -L https://rawgit.com/jsamr/bootiso/latest/bootiso -O
```
把下载的文件加到 **$PATH** 目录中,比如 /usr/local/bin/.
```
$ sudo cp bootiso /usr/local/bin/
```
最后,添加运行权限:
```
$ sudo chmod +x /usr/local/bin/bootiso
```
搞定!现在就可以创建 USB 引导设备了。首先,让我们用命令看看现在有哪些 USB 驱动器:
```
$ bootiso -l
```
输出:
```
Listing USB drives available in your system:
NAME HOTPLUG SIZE STATE TYPE
sdb 1 7.5G running disk
```
如你所见,我只有一个 USB 驱动器。让我们继续通过命令用 ISO 文件创建 USB 启动盘:
```
$ bootiso bionic-desktop-amd64.iso
```
这个命令会提示你输入 SUDO 密码。输入密码并回车来安装缺失的组件(如果有的话),然后创建 USB 启动盘。
输出:
```
[...]
Listing USB drives available in your system:
NAME HOTPLUG SIZE STATE TYPE
sdb 1 7.5G running disk
Autoselecting `sdb' (only USB device candidate)
The selected device `/dev/sdb' is connected through USB.
Created ISO mount point at `/tmp/iso.c5m'
`bootiso' is about to wipe out the content of device `/dev/sdb'.
Are you sure you want to proceed? (y/n)>y
Erasing contents of /dev/sdb...
Creating FAT32 partition on `/dev/sdb1'...
Created USB device mount point at `/tmp/usb.QgV'
Copying files from ISO to USB device with `rsync'
Synchronizing writes on device `/dev/sdb'
`bootiso' took 303 seconds to write ISO to USB device with `rsync' method.
ISO succesfully unmounted.
USB device succesfully unmounted.
USB device succesfully ejected.
You can safely remove it !
```
如果你的 ISO 文件 mine 类型不对,你会得到下列错误信息:
```
Provided file `bionic-desktop-amd64.iso' doesn't seem to be an iso file (wrong mime type: `application/octet-stream').
Exiting bootiso...
```
当然,你也能像下面那样使用 **no-mime-check** 选项来跳过 mime 类型检查。
```
$ bootiso --no-mime-check bionic-desktop-amd64.iso
```
就像我前面提到的如果系统里只有1个 USB 设备 Bootiso 将自动选中它。所以我们不需要告诉它 USB 设备路径。如果你连接了多个设备,你可以像下面这样使用 **-d** 来指明 USB 设备。
```
$ bootiso -d /dev/sdb bionic-desktop-amd64.iso
```
用你自己的设备路径来换掉 “/dev/sdb”.
在多个设备情况下,如果你没有使用 **-d** 来指明要使用的设备Bootiso 会提示你选择可用的 USB 设备。
Bootiso 在擦除和改写 USB 盘分区前会要求用户确认。使用 **-y** 或 **assume-yes** 选项可以跳过这一步。
```
$ bootiso -y bionic-desktop-amd64.iso
```
您也可以把自动选择 USB 设备与 **-y** 选项连用,如下所示。
```
$ bootiso -y -a bionic-desktop-amd64.iso
```
或者,
```
$ bootiso?--assume-yes?--autoselect bionic-desktop-amd64.iso
```
请记住,当你只连接一个 USB 驱动器时,它才会起作用。
Bootiso 会默认创建一个 **FAT 32** 分区,挂载后用 **“rsync”** 程序把 ISO 的内容拷贝到 USB 盘里。 如果你愿意也可以使用 “dd” 代替 “rsync” 。
```
$ bootiso --dd -d /dev/sdb bionic-desktop-amd64.iso
```
如果你想增加 USB 引导的成功概率,请使用 **“-b”** 或 **bootloader”** 选项。
```
$ bootiso -b bionic-desktop-amd64.iso
```
上面这条命令会安装 **syslinux** 引导程序安全模式。注意dd” 选项不可用.
在创建引导设备后Bootiso 会自动弹出 USB 设备。如果不想自动弹出,请使用 **-J** 或 **no-eject** 选项。
```
$ bootiso -J bionic-desktop-amd64.iso
```
现在USB 设备依然连接中。你可以使用 “umount” 命令随时卸载它。
需要完整帮助信息,请输入:
```
$ bootiso -h
好,今天就到这里。希望这个脚本对你有帮助。好货不断,不要走开哦!
--------------------------------------------------------------------------------
via: https://www.ostechnix.com/bootiso-lets-you-safely-create-bootable-usb-drive/
作者:[SK][a]
译者:[kennethXia](https://github.com/kennethXia)
校对:[校对者ID](https://github.com/校对者ID)
选题:[lujun9972](https://github.com/lujun9972)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://www.ostechnix.com/author/sk/
[1]:https://www.ostechnix.com/etcher-beauitiful-app-create-bootable-sd-cards-usb-drives/