Skip to content →

Tag: OS

Solution: dd too slow on Mac OS X

When I was cloning SD cards on Mac OS X using `dd’, it takes ages to get things done. I was using the following command:

diskutil unmountDisk /dev/disk2
sudo dd bs=1m if=~/Downloads/2013-10-09.alice.img of=/dev/disk2

It takes much less time when using /dev/rdisk2 instead of /dev/disk2:

diskutil unmountDisk /dev/disk2
sudo dd bs=1m if=~/Downloads/2013-10-09.alice.img of=/dev/rdisk2

The reason is that rdisks are “raw” thus resulting in a higher R/W speed, according to `man hdiutil` [1]:

/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.

[1] http://superuser.com/questions/631592/mac-osx-why-is-dev-rdisk-20-times-faster-than-dev-disk

58 Comments

A “normal” sed on Mac

The `sed` program on Mac is not a standard (GNU) one. To get the normal one, use brew:

brew install gnu-sed

After this, alter PATH. For example, add the following line to your `~/.bash_profile`:

PATH="/usr/local/opt/gnu-sed/libexec/gnubin:$PATH"

And now you have a normal sed!

 

2 Comments

OpenVPN client TLS-Auth problem on Windows

It seems that the OpenVPN Client on windows does not support TLS-Auth with a separate key file. So instead, you can paste your key contents in your openvpn client’s config file and use some thing like the following (inline ta.key):

client
dev tun
proto udp

# enter the server's hostname
# or IP address here, and port number
remote server_ip port_number

resolv-retry infinite
nobind
persist-key
persist-tun

# Use the full filepaths to your
# certificates and keys
ca "C:\\yabroad.tblk\\ca.crt"
cert "C:\\yabroad.tblk\\client.crt"
key "C:\\yabroad.tblk\\client.key"

key-direction 1

<tls-auth>
#
# 2048 bit OpenVPN static key
#
-----BEGIN OpenVPN Static key V1-----
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-----END OpenVPN Static key V1-----
</tls-auth>


ns-cert-type server
comp-lzo
verb 1

When not using the above but using something like:

tls-auth ta.key 1  # which works for tunnelblick

The server log shows something like:

Thu Apr 18 20:55:26 2013 TLS Error: incoming packet authentication failed from [AF_INET] IP_ADDRESS:60454
Thu Apr 18 20:55:57 2013 Authenticate/Decrypt packet error: packet HMAC authentication failed
20 Comments

GitHub couples

I’m feeling good today because of theses things:

  1. My mobile phone ran out of battery and the alarm clock didn’t ring this morning, but I still managed to get up just in time and caught the bus at the last minute — and arrived at the company at my usual time.
  2. My manager told me it looks positive to renew my contract and hopefully it will be one and half years. He also says he tries to get it done before the summer vacation, which makes my life a lot easier. Also he says it’s possible to save my holidays till winter. So I’ll be back in China for some time in winter this year.
  3. A very old lady managed to stop and got on the bus even though she waved her hand a bit late to the bus driver. The bus driver was polite and that what I like about Finland: people generally don’t get angry.
  4. Here’s one very funny and geeky picture I saw from xda-developers. In case the link gets invalidated later, the picture reads: “So, where did you two meet?” “Windows users: at the office” “Mac users: at Starbucks” “Linux users: GitHub”.

 

Leave a Comment

Downgrade Preview in OS X Lion

I’ve had enough with the slow Preview application in Lion. After some digging I found this tutorial to downgrade the Preview in Lion to the Snow Leopard version. Basically you need to have a copy of both the Preview.app and /System/Library/PrivateFrameworks/MeshKit.framework from Snow Leopard. If you need to associate the default app to open pdf/png with the downgraded Preview, you have to delete the original Preview.app.

tar -pczf Preview.app.tar.gz /Applications/Preview.app
sudo rm -rf /Applications/Preview.app

Update: after installing OS X updates you need to remove the Preview.app again and put the SL Preview.app to /Applications/ directory.

Leave a Comment

i386-jos-elf toolchain on OS X Lion

Yesterday friend and I decided to follow the MIT Operating System Engineering course together in order to get a deep understanding of OS’s. And today I started setting up the cross compling environment for the labs. At first I wanted to get the toolchain from macports, but unluckily it didn’t successfully build binutils on my Mac. As a result, I started building the toolchain from the source code, following the instructions at http://pdos.csail.mit.edu/6.828/2011/tools.html.

The programs you need for the toolchain include binutils, gcc, and gdb. For compiling gcc you also need GMP, MPFR, and MPC. The source codes are available at:

wget http://ftpmirror.gnu.org/binutils/binutils-2.21.1.tar.bz2
wget ftp://ftp.gmplib.org/pub/gmp-5.0.4/gmp-5.0.4.tar.bz2
wget http://www.mpfr.org/mpfr-current/mpfr-3.1.0.tar.bz2
wget http://www.multiprecision.org/mpc/download/mpc-0.8.2.tar.gz
wget http://ftpmirror.gnu.org/gcc/gcc-4.5.1/gcc-core-4.5.1.tar.bz2
wget http://ftpmirror.gnu.org/gdb/gdb-6.8a.tar.gz

Unzip them in a directory and build binutils, gcc, and gdb one by one.

$ tar jxvf binutils-2.21.1.tar.bz2
$ cd binutils-2.21.1
$ ./configure --target=i386-jos-elf --disable-nls && make && sudo make install

In order to build gcc, GMP, MPFR and MPC needs to be built first.

$ mkdir -p libs/install
$ mv gmp-5.0.4.tar.bz2 mpfr-3.1.0.tar.bz2 mpc-0.8.2.tar.gz libs/
$ tar jxvf gmp-5.0.4.tar.bz2
$ mkdir gmp-build; cd gmp-build
$ ../gmp-5.0.4/configure --prefix=$(cd ../install && pwd)
$ make && sudo make install
$ cd ..
$ tar jxvf mpfr-3.1.0.tar.bz2
$ mkdir mpfr-build; cd mpfr-build
$ ../mpfr-3.1.0/configure --prefix=/Users/daoyuanli/Downloads/i386-elf-gcc/libs/install/ --with-gmp=/Users/daoyuanli/Downloads/i386-elf-gcc/libs/install/
$ make && sudo make install
$ cd ..
$ tar zxvf mpc-0.8.2.tar.gz
$ mkdir mpc-build; cd mpc-build
$ ./configure --prefix=/Users/daoyuanli/Downloads/i386-elf-gcc/libs/install/ --with-gmp=/Users/daoyuanli/Downloads/i386-elf-gcc/libs/install/ --with-mpfr=/Users/daoyuanli/Downloads/i386-elf-gcc/libs/install/
$ make ; sudo make install
$ cd ..
$ tar jxvf gcc-core-4.5.1.tar.bz2
$ mkdir gcc-build; cd gcc-build
$ ../gcc-4.5.1/configure --target=i386-jos-elf --disable-nls --without-headers --with-newlib --disable-threads --disable-shared --disable-libmudflap --disable-libssp --with-gmp=/Users/daoyuanli/Downloads/i386-elf-gcc/libs/install/ --with-mpfr=/Users/daoyuanli/Downloads/i386-elf-gcc/libs/install/ --with-mpc=/Users/daoyuanli/Downloads/i386-elf-gcc/libs/install/
$ make ; sudo make install

Note that it’s essential to build gcc in a directory different from the source code directory to avoid compiling errors.

Then make gdb:

$ tar zxvf gdb-6.8a.tar.gz
$ mkdir gdb-build; cd gdb-build
$ ../gdb-6.8/./configure --target=i386-jos-elf --program-prefix=i386-jos-elf- --disable-werror
$ make && sudo make install

QEMU is available in macports:

$ sudo port install qemu
15 Comments