解决macOS High Sierra使用dd命令向USB设备拷贝数据非常缓慢的问题

最近在使用Raspberry Pi Zero W,在创建系统镜像的时候,使用如下命令,发现非常缓慢,时间往往以小时计算:

$ diskutil unmountDisk /dev/disk2

$ sudo dd if=~/Downloads/2018-06-27-raspbian-stretch-lite.img of=/dev/disk2

如果要解决这个问题,那么可以使用如下方式:

$ diskutil unmountDisk /dev/rdisk2

$ sudo dd if=~/Downloads/2018-06-27-raspbian-stretch-lite.img of=/dev/rdisk2 bs=1m

注意两个命令的区别,一个是 `/dev/disk2` ,一个是 `/dev/rdisk2` , 两者的区别可以通过如下命令来查看:

$ man hdiutil

可以看到如下介绍:

..........................

DEVICE SPECIAL FILES
     Since any /dev entry can be treated as a raw disk image, it is worth not-
     ing 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.

     It is not possible to read from a /dev/disk node while a filesystem is
     mounted from it, but anyone with read access to the appropriate
     /dev/rdisk node can use hdiutil verbs such as fsid or pmap with it.
     Beware that information read from a raw device while a filesystem is
     mounted may not be consistent because the consistent data is stored in
     memory or in the filesystem's journal.

     The DiskImages framework will attempt to use authopen(1) to open any
     device which it can't open (due to EACCES) for reading with open(2).
     Depending on session characteristics, this behavior can cause apparent
     hangs while trying to access /dev entries while logged in remotely (an
     authorization panel is waiting on console).

     Generally, the /dev/disk node is preferred for imaging devices (e.g.
     convert or create -srcdevice operations), while /dev/rdisk is usable for
     the quick pmap or fsid.  In particular, converting the blocks of a
     mounted journaled filesystem to a read-only image will prevent the volume
     in the image from mounting (the journal will be permanently dirty).

................................

根据介绍,rdisk属于原始设备(rawdisk),不必经过操作系统的文件系统缓冲处理,相当于直接操作硬件,速度非常快。但是像macOS High Sierra这种出现20x速度差别的情况,就不是太好理解了。

后面 `bs=1m` 参数也很重要,要求拷贝写入的时候整块 (`1MB`) 写入(否则是逐个字节操作,写入次数非常多,性能很差),这样才能起到加速作用。

参考链接


macOS High Sierra(10.13.6)使用HL-340(CH340/CH341)芯片的USB转串口设备

最近开发需要,购买了一堆的USB转串口设备,在Linux下面都是免驱动的,但是到了macOS High Sierra(10.13.6)上,无法正常识别。在Linux上通过lsusb可以看到如下信息:

Bus 001 Device 008: ID 1a86:7523 QinHeng Electronics HL-340 USB-Serial adapter

继续阅读macOS High Sierra(10.13.6)使用HL-340(CH340/CH341)芯片的USB转串口设备

macOS High Sierra(10.13.6)解决"Error: Running Homebrew as root is extremely dangerous and no longer supported."

macOS High Sierra(10.13.6)版本上,使用Homebrew安装python2的时候出现如下问题:

$ brew install python2
Warning: python@2 2.7.15_1 is already installed, it's just not linked
You can use `brew link python@2` to link this version.

$ brew link python@2
Linking /usr/local/Cellar/python@2/2.7.15_1... Error: Permission denied @ dir_s_mkdir - /usr/local/Frameworks

$ sudo brew link python@2
Password:
Error: Running Homebrew as root is extremely dangerous and no longer supported.
As Homebrew does not drop privileges on installation you would be giving all
build scripts full access to your system.

网上的解决方法是把整个/usr/local的所有者修改为当前用户,但是新版本的macOS High Sierra(10.13.6)已经不支持这样操作了,如下:

$ sudo chown -R `whoami` /usr/local
chown: /usr/local: Operation not permitted

那么解决方法如下:

$ sudo chown -R `whoami` /usr/local/Homebrew/

$ sudo chown -R $(whoami) $(brew --prefix)/*

$ sudo mkdir /usr/local/Frameworks

$ sudo chown -R `whoami` /usr/local/Frameworks/

完成上面的操作后,我们可以看到已经能成功操作了:

$ brew link python@2
Linking /usr/local/Cellar/python@2/2.7.15_1... 5 symlinks created

#如果曾经安装过pip可能导致pip被链接到系统的python版本,可是系统目录上各种无权限,因此我们移除已经安装的pip,重新链接pip到brew安装的python

$ sudo rm -rf /usr/local/bin/pip

$ brew reinstall python2

参考链接


macOS High Sierra下的minicom要如何按出 meta key ?

以前常在 Linux 的 Terminal 下使用 minicom 这个小程序来操作 USB to Serial (也就是 USB to RS-232) 来连接「数据采集卡」、Router、Switch 等网络设备

一般 Linux 底下的 minicom 使用 control + <Fn> 来操作一些 minicom 的一些特定功能
例如 control + x 就是 hang up 并退出 minicom

后来换成 OS X 之后的 minicom ,要求使用「meta key」组合键,如下图:

继续阅读macOS High Sierra下的minicom要如何按出 meta key ?

OS X EI Caption(10.11.6)通过SSH启用VNC远程桌面

家里的一台Mac mini(Early 2009)安装了OS X EI Caption系统,启用了SSHVNC远程桌面。但是在某次系统更新的时候,由于涉及到Remote Desktop Client的更新,导致无法正常登录VNC远程桌面,但是可以正常使用SSH登录。

则使用如下命令重新启用VNC远程桌面服务:

$ export VNC_PASSWORD=mypasswd

$ sudo  /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -activate -configure -access -on -clientopts -setvnclegacy -vnclegacy yes -setreqperm -reqperm yes -clientopts -setvncpw -vncpw $VNC_PASSWORD -restart -agent -privs -all

如果需要关闭VNC远程桌面服务,则使用如下命令:

$ sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -deactivate -configure -access -off

参考链接


How to enable OS X screen sharing (VNC) through SSH?

macOS High Sierra系统上Windows 10远程桌面

微软曾经为macOS提供过Windows远程桌面,但是已经非常长时间没有更新过了,导致在macOS High Sierra系统上的远程桌面是无法连接Windows 10的。

其实微软还是为最新的macOS High Sierra提供了远程桌面程序的,在苹果应用商店的应用名为Microsoft Remote Desktop Beta,但是遗憾的是,设置了只能美国的用户才能下载。因此我们需要手工下载,然后安装。

可以在本站下载一份目前的最新拷贝。

Microsoft Remote Desktop Beta

参考链接


macOS High Sierra下使用brew安装支持x265的ffmpeg以及转码

使用

$ brew install ffmpeg

安装ffmpeg默认是不支持x265

使用

$ brew reinstall ffmpeg --with-x265

重新安装即可。

一般直接的H265数据流(比如从摄像头抓取的H265裸数据流保存的文件),是没办法在MacOS上直接播放的,必须进行转码。简单的转码命令如下:

$ ffmpeg -i input.h265 -c:v libx265 output.mp4

参考链接


关闭Safari英文矫正功能

macOS High Sierra系统上使用Safari进行搜索的时候,总是莫名其妙的被修改搜索词,导致搜索结果驴唇不对马嘴。搜索了一下,这个锅应该是输入法导致的,最可恶的是不能拒绝输入法的推荐词汇,可以使用如下方式关闭输入法的自动英文矫正功能。

继续阅读关闭Safari英文矫正功能

macOS Sierra升级到macOS High Sierra后执行cc,git命令报错

macOS Sierra升级到macOS High Sierra后执行cc,git等命令报错,错误信息如下:

xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun

解决方法如下:

$ xcode-select --install

参考链接


mac更新系统后Git不能用,提示missing xcrun at