使用 DD 命令制作 USB 启动盘
Windows 下有很多很好用的 USB 啟動盤制作工具,比如 Rufus,但是 MacOS 下這個類型的工具就少了很多,這里記錄下在 MacOS 中用 DD 命令制作 Linux USB 啟動盤的操作步驟。
操作步驟
查看磁盤掛載分區
使用命令diskutil list查看所在 U 盤的分區,找到 U 盤的掛載點,此處掛載點為/dev/disk2
$ diskutil list
/dev/disk2 (external, physical):
#: TYPE NAME SIZE IDENTIFIER
0: FDisk\_partition\_scheme *31.0 GB disk2
1: DOS\_FAT\_32 UNTITLED 31.0 GB disk2s1
卸載 U 盤掛載
使用diskutil unmountDisk命令,卸載 U 盤的掛載。
$ diskutil unmountDisk /dev/disk2
Unmount of all volumes on disk2 was successful
如果不卸載掛載點就寫入啟動盤,則會提示dd: /dev/disk2: Resource busy。
使用 dd 來來寫入 iso
使用 dd 命令來將 CentOS 寫入啟動盤,
sudo dd if=~/carl\_workSpace/software/os/CentOS-7-x86\_64-DVD-1810.iso of=/dev/rdisk2 bs=1m
注意:
此處~/carl_workSpace/software/os/CentOS-7-x86_64-DVD-1810.iso是我本地 CentOS 的路徑,需要替換成實際的路徑
/dev/rdisk2就是上面diskutil list列出的 U 盤掛載點, 并且注意,此處磁盤前面多了個 r,是rdisk2,而不是disk2,rdisk2是disk2的原始盤,目的是可以更快速的寫入。
寫入需要花費幾分鐘時間,期間可以使用 CTRL + T 來查看寫入進度,顯示如下:
109+0 records in
108+0 records out
113246208 bytes transferred in 7.430910 secs (15239884 bytes/sec)
也可以使用iostat來查看磁盤寫入進度
$ iostat -w 5
disk0 disk2 cpu load average
KB/t tps MB/s KB/t tps MB/s us sy id 1m 5m 15m
42.68 14 0.58 849.97 0 0.00 7 4 89 3.84 3.42 2.67
450.16 15 6.50 1024.00 7 7.19 3 3 94 3.70 3.39 2.67
85.34 124 10.33 1024.00 9 8.80 6 4 90 3.64 3.39 2.67
$
最終完成后,dd 命令輸出:
4376+0 records in
4376+0 records out
4588568576 bytes transferred in 539.126637 secs (8511115 bytes/sec)
寫入完成后,Macos 會有一個提示框,提示 “此電腦不能讀取您插入的磁盤。”
USB 啟動盤不能被 Macos 正常讀取,但是可以用來被當作啟動盤安裝 CentOS。
使用diskutil list可以查看到此時 U 盤的分區信息。
$ diskutil list
...
/dev/disk2 (external, physical):
#: TYPE NAME SIZE IDENTIFIER
0: FDisk\_partition\_scheme *31.0 GB disk2
1: 0xEF 8.9 MB disk2s2
$
彈出 U 盤
使用 “磁盤工具”APP 或者命令diskutil eject彈出 U 盤。
diskutil eject /dev/disk2
延伸
Macos 中 / dev/disk 和 / dev/rdisk 的區別
首先查看man hdiutil的描述:
Since any /dev entry can be treated as a raw disk image, it is worth noting which devices can be accessed when and how. /dev/rdisk nodes are character-special devices, but are “raw” in the BSD sense and force block-aligned I/O. They are closer to the physical disk than the buffer cache. /dev/disk nodes, on the other hand, are buffered block-special devices and are used primarily by the kernel’s filesystem code.
/dev/rdisk是原始讀取模式,沒有經過文件系統的文件緩存機制,因此速度比/dev/disk速度更快。
下面以 918M 大小的CentOS-7-x86_64-Minimal-1810.iso為例來比較/dev/rdisk和/dev/disk的寫入速度。兩者的命令分別為
# 寫入/dev/rdisk的速度
$ sudo dd if=CentOS-7-x86\_64-Minimal-1810.iso of=/dev/rdisk2 bs=1m
918+0 records in
918+0 records out
962592768 bytes transferred in 106.192945 secs (9064564 bytes/sec)
# 寫入/dev/disk的速度
sudo dd if=CentOS-7-x86\_64-Minimal-1810.iso of=/dev/disk2 bs=1m
918+0 records in
918+0 records out
962592768 bytes transferred in 3016.605565 secs (319098 bytes/sec)
可以看到寫入/dev/rdisk花費了 106 秒,而寫入/dev/disk花費了 3016 秒, 差別巨大。
Reference
CREATE CENTOS 7 BOOTABLE USB ON OSX
Why is “/dev/rdisk” about 20 times faster than “/dev/disk” in Mac OS X
總結
以上是生活随笔為你收集整理的使用 DD 命令制作 USB 启动盘的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: dnf平民有必要增幅吗(Dungeon)
- 下一篇: 【转】【海淘菜鸟变高手】超级详细版的美国