There are many useful tools for creating USB bootable disks under Windows, such as Rufus , but there are many less tools of this type under MacOS. Here are the DD
steps to create a Linux USB bootable disk with commands in MacOS.
Steps
View disk mount partitions
Use the command diskutil list
to view the partition of the USB flash drive, and find the mount point of the USB flash drive, where the mount point is/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
Uninstall the U disk mount
Use diskutil unmountDisk
the command to unmount the U disk.
$ diskutil unmountDisk /dev/disk2
Unmount of all volumes on disk2 was successful
If you write to the boot disk without unmounting the mount point, you will be prompted dd: /dev/disk2: Resource busy
.
use dd to write iso
Use the dd command to write CentOS to the boot disk,
sudo dd if=~/carl\_workSpace/software/os/CentOS-7-x86\_64-DVD-1810.iso of=/dev/rdisk2 bs=1m
Notice:
- Here
~/carl_workSpace/software/os/CentOS-7-x86_64-DVD-1810.iso
is the path of my local CentOS, which needs to be replaced with the actual path /dev/rdisk2
It is the mount point of the USB disk listed abovediskutil list
, and note that there is an extra r in front of the disk here , which isrdisk2
, notdisk2
,rdisk2
thedisk2
original disk, and the purpose is to write faster.
It takes a few minutes to write, during which you can use CTRL + T to view the writing progress, as shown below:
109+0 records in
108+0 records out
113246208 bytes transferred in 7.430910 secs (15239884 bytes/sec)
You can also use iostat
to view the disk writing progress
$ 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
$
When finally done, the dd command output:
4376+0 records in
4376+0 records out
4588568576 bytes transferred in 539.126637 secs (8511115 bytes/sec)
After the writing is complete, Macos will have a prompt box saying "This computer cannot read the disk you inserted."
The USB boot disk cannot be read normally by Macos, but it can be used as a boot disk to install CentOS.
Use diskutil list
to view the partition information of the U disk at this time.
$ diskutil list
...
/dev/disk2 (external, physical):
#: TYPE NAME SIZE IDENTIFIER
0: FDisk\_partition\_scheme \*31.0 GB disk2
1: 0xEF 8.9 MB disk2s2
$
Eject the USB drive
Use the "Disk Utility" APP or commands diskutil eject
to eject the USB flash drive.
diskutil eject /dev/disk2
extend
The difference between /dev/disk and /dev/rdisk in Macos
First look at man hdiutil
the description:
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
is a raw read mode that doesn't go through the file system's file caching mechanism, so it's /dev/disk
faster than speed.
Let's take the 918M size CentOS-7-x86_64-Minimal-1810.iso
as an example to compare /dev/rdisk
and /dev/disk
write speed. The commands for both are
# 写入/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)
It can be seen that the write /dev/rdisk
took 106 seconds, while the write /dev/disk
took 3016 seconds, the difference is huge.