Tag Archives: OSX - Page 2

Writing image to SD card on OSX

Since I play around with NSLU2, Raspberry PI’s and other experimental devices I tend to use the dd command quite a lot from time to time. The dd command is very powerful tool and if you make a mistake you vill probably have top work countless hours to get things right again, so that is why I now put this little howto up here

1. First we need to find the “system name” for the SD card

diskutil -list

Example output from my developer machine:

/dev/disk0
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *750.2 GB   disk0
   1:                        EFI                         209.7 MB   disk0s1
   2:                  Apple_HFS Macintosh HD            749.3 GB   disk0s2
   3:                 Apple_Boot Recovery HD             650.0 MB   disk0s3
/dev/disk1
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *2.0 TB     disk1
   1:                        EFI                         209.7 MB   disk1s1
   2:          Apple_CoreStorage                         2.0 TB     disk1s2
   3:                 Apple_Boot Boot OS X               134.2 MB   disk1s3
/dev/disk2
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                 Apple_HFSX My Book                *2.0 TB     disk2
/dev/disk3
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *7.9 GB     disk3
   1:                 DOS_FAT_32 RASPBMC                 7.9 GB     disk3s1

Here we can see my main drive /dev/disk0, my backup drive /dev/disk1 and /dev/disk2 and at the bottom we have a small disk with only 7,9 GB of space and this is my SD card. This makes the “system name” for my SD card /dev/disk3

2. Now its time to unmount the SD card (needed for the dd command on OSX)

diskutil unmountDisk /dev/disk3

3. And now time for the trick part, writing the image

dd if=raspbmc.img of=/dev/disk3

The tricky part is to get if(input file) and of(output file) option correct. My mnemonic for this it that of is called “overwrite file” instead of “output file”. Makes it easier to remember that the of disk will be overwritten – works for me 🙂

The dd command have no progress bar or anything that tells you how long time is left. This is quite annoying. (A dd operation of a 2g image to a SD card takes 30 minutes on my machine). To remedy this we can use another command pv

dd if=raspbmc.img |pv|dd of=/dev/disk3

This gives us a small progress bar to help us keep track of the dd process

Tested on OSX 10.7

Open multiple files in individual tabs in vim using script

I have always wanted one program to open to access all important (for me) files in a system. This can for instance be http.conf, passwd, groups and so on. Using tabs in vim, the -p option (from version 7 and above) and a small script can make vim into a nice little admin console:

I call my script ‘configs’ and it looks like this (put it in your PATH for easy access):

#!/bin/bash
sudo vim -p /etc/hosts /private/etc/php.ini /etc/httpd.conf

Too move between tabs in command mode:

gt - next tab
gT - previous tab

Too move between tabs in insert mode (and also in command mode):

CTRL + PgUp - next tab
CTRL + PgDown - previous tab  

Linking sites to htdocs in Xampp OSX

I usually do not want to put my webprojects inside the htdocs directory in the default Xampp setup. Depending on the type of project I want them in different places. One simple way to run them from htdocs (localhost/projectname) is to make symbolic links to the projects in the htdocs folder. Here is how I did it:

1. Navigate to the htdocs folder in the Xampp package, normaly ‘/Applications/XAMPP/htdocs/
2. Run the command ‘ln -s <path to project>‘. Eg ‘ln -s /Users/niklas/NetBeansProjects/project1

This will create a symbolic link called ‘project1‘ in you htdocs directory pointing to the ‘/Users/niklas/NetBeansProjects/project1‘ directory.

Apache will, with the default settings, run the project as if it really was inside the htdocs directory. Just navigate to ‘http://localhost/project1‘ and enjoy the result

There are other ways to accomplish the same result but this it the solution I like the best