Recently, I am interested in SBC (single-board computer) and need to prepare a Linux development environment because many utilities/tools/packages are ONLY available on Linux (such as cross-compiler). I have 2 Mac mini and 1 MBP, and I want to share the Linux development environment among these computers with minimal efforts. Then, it comes to me to utilize Vagrant and VirtualBox to automate Linux environment setup.
Then, I meet several problems... Here I explain how those problems are solved, and the results are committed to github.
USB SD-Card Reader
Now popular SBCs use SD-card as storage to store Linux or Android, so it's necessary to use dd command to write Linux/Android images onto SD-card. For this purpoase, I select one combo card reader: Digifusion SD2 GO 120 in 1:
However, when the Digifusion card reader is connected to the USB port on my MBP, the card reader is automatically mounted by Mac OSX. Of course I can manually add USB filter with VirtualBox GUI
But I don't like GUI that breaks my idea to automate development environment setup. So, I need to automate it with VBoxManage.
Just keep a note about the performance comparison of bzip2 v.s. pbzip2. (Not professional and accurate...)
Quotation bzip2 is a freely available, patent free (see below), high-quality data compressor. pbzip2 is a parallel implementation of the bzip2 block-sorting file compressor that uses pthreads and achieves near-linear speedup on SMP machines.
Here are the experiment results:
bzip2 -k svndump.txt
pbzip2 with 2 processors
pbzip2 -k -p2 -9 svndump.txt
pbzip2 with 4 processors
pbzip2 -k -p4 -9 svndump.txt
pbzip2 with 8 processors
pbzip2 -k -p8 -9 svndump.txt
It's interesting that using 8 processors cannot double the compression speed of using 4 processors.
The test machine is 8cores Intel(R) Xeon(R) CPU E5620 @ 2.40GHz with CentOS 5.5.
The file to be compressed is a svn repository dump text file with size ~1.15GB:
To learn how to use node-serialport, I need to prepare an easy-to-verify development environment. So, I select VirtualBox + Vagrant + virtual serial port to setup the development environment. The article is to summarize how I setup step-by-step.
Before setup, following softwares need to be installed:
Note, it's very easy to install socat with homebrew:
I select precise64 as the basebox, and initiate the virtualbox:
Next step is to add following lines into the Vagrantfile file at current path:
The 1st line of modifyvm is to enable virtual serial port in virtualbox.
The 2nd line of modifyvm is to connect the virtual serial port to a software pipe on host OS (Mac). In this case, the local domain socket (/tmp/my_tty) is used.
Then, launch the box
Note, the first line is to make sure the socket file already exists before the virtual machine is started. The third line is to login the guest OS for manipulating virtual serial port.
VMWare Fusion Setup
Test with SocketServer on Host OS
At the Guest OS (Ubuntu 12.04 64 bits), the virtual serial port can be found at /dev/ttyS0. Then, we use screen tool to manipulate the serial port. Let's open a terminal, name it as T1, and type following command:
At the Host OS (Mac OSX), the file for local domain socket connected by virtual serial port is /tmp/my_tty. To monitor the domain socket, socat tool is used. Let's open another terminal, name it as T2, and type following command:
Then, when you type some characters on T1 then T2 shows those characters, and vice versa.
At T1, to exit from screen, please press ctrl-a k to kill it.
At T2, after the telnet process is killed, the socat process is also terminated.
Test with Virtual SerialPort on Host OS
The steps are similar to previous section, but the steps for T2 (2nd terminal) are different. Let's type socat -d -d /tmp/my_tty PTY. It might output following messages on the terminal:
socat indicates the named pipe for virtual serial port on host OS is created, and placed at /dev/ttys001. Then, type screen /dev/ttys001 38400. Finally, the virtual serial ports on both Guest and Host OSes are connected.