• 使用 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
    

    注意:

    1. 此处~/carl_workSpace/software/os/CentOS-7-x86_64-DVD-1810.iso是我本地 CentOS 的路径,需要替换成实际的路径
    2. /dev/rdisk2就是上面diskutil list列出的 U 盘挂载点, 并且注意,此处磁盘前面多了个 r,是rdisk2,而不是disk2rdisk2disk2的原始盘,目的是可以更快速的写入。

    写入需要花费几分钟时间,期间可以使用 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

  • 相关阅读:
    bug-- java.lang.RuntimeException: Type “Klass*"
    ThreadPoolExecutor源码分析二
    ThreadPoolExecutor源码分析一
    java动态代理框架
    liunx 中一个命令可以检测 ps -C java --no-heading| wc -l 一般用于shell脚步编写用
    log4j.properties 使用说明
    图文详解MyEclipse中新建Maven webapp项目的步骤(很详细)
    MySQL高可用性之Keepalived+Mysql(双主热备)
    使用cglib动态创建类,添加方法
    2017年5月5日 星红桉liunx动手实践mysql 主主双机热备
  • 原文地址:https://www.cnblogs.com/asimov/p/13960841.html
Copyright © 2020-2023  润新知