How to create a bootable OS X Mountain Lion (10.8) USB drive from Linux

Found this from here, since it was useful I decided to paste it here.

I saw a few guides on how to make a bootable OS X flash drive, but not many on how to do it without already having access to an OS X machine. Here are my ugly notes on creating a bootable OS X Mountain Lion (10.8)USB drive from/with Linux.

The copy of OS X 10.8 (Mountain Lion) I downloaded was in the form of a file named “InstallESD.dmg”. First, you’ll need to open it. You will need p7zip installed. If you try to dmg2img this file, you won’t get very far, so just extract it with 7-zip:

7z x InstallESD.dmg

The unrolled dmg file I found was 4348218934 bytes in size and had an md5sum of 8b4869920cd740414fe6b7e3f0b1be3e. Inside was another file with the same name (although it is slightly smaller) which is the actual install image. The internal dmg file (the one we really want) was 4333438336 bytes in size and had an md5sum of 68fd407bb74e4a2dd1913ce8bae80fc4. It must be converted prior to mounting, and for this you will need dmg2img installed.

cd InstallMacOSX.pkg 
dmg2img InstallESD.dmg 

The resulting img file was only 137322496 in bytes and had an md5sum of 05b5788f10f7300c457e2aed735eb83a. Now find the offset to properly mount the install partition in the resulting file.

hexdump -C InstallESD.img | grep “48 2b 00 04”
00008400  48 2b 00 04 80 00 01 00  31 30 2e 30 00 00 00 00  |H+……10.0….|

I got “00008400” which is hex for 33792 in decimal:

$echo $((0x00008400))
33792

We need to subtract 1024 from this number to find the target offset:

$echo ‘33792-1024’|bc
32768

Now make the loop device:

losetup -o 32768 /dev/loop0 /path/to/InstallMacOSX.pkg/InstallESD.img

And finally, mount it:

mount -t hfsplus /dev/loop0 /mnt/tmp/or/wherever/you/want

Next, I re-initialized an 8GB USB flash drive with an MSDOS partition table and created an HFS+ partition with gparted after installing these packages: hfsprogs hfsplus hfsutils.

Next, mount the HFS+ USB device R/W and cd to the /mount/point/of/loop/device and copy the contents of the mounted image:

tar cvf – * | tar xvf – -C /mount/point/to/hfs/usb/drive

Sync, unmount, insert USB drive into the Mac and power it on while holding down the OPTION key.

How to Open a Port on Redhat, CentOS or Fedora Linux

By default iptables firewall stores its configuration at /etc/sysconfig/iptables file. You need to edit this file and add rules to open port number.

Note: if you have SELinux  enabled, you’ll need to allow the port with semanage.

Open port 80

To open a different port just enter the port number.

Open flle /etc/sysconfig/iptables:

# vi /etc/sysconfig/iptables

Append rule as follows:

A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

Save and close the file.  Restart iptables:

# /etc/init.d/iptables restart

or,

#service iptables restart

 

Verify that port is open

Run the following command:

netstat -tulpn | less

Make sure iptables is allowing the port you enabled:

iptables -L -n

If you need more info you can refer to the man page:

man iptables

Vim Commands Cheat Sheet

This is a Vim (Vi IMproved) cheat sheet, listing some useful, essential and most often used Vim commands.  Most of the information was acquired here.

Vi is a command line text editor.  To use it, from command line type in vi followed by the file name you want to edit.

Example:

vi filename.txt

 

Working with files
Vim command Action
:e filename Open a new file. You can use the Tab key for automatic file name completion, just like at the shell command prompt.
:w filename Save changes to a file. If you don’t specify a file name, Vim saves as the file name you were editing. For saving the file under a different name, specify the file name.
:q Quit Vim. If you have unsaved changes, Vim refuses to exit.
:q! Exit Vim without saving changes.
:wq Write the file and exit.
:x Almost the same as :wq, write the file and exit if you’ve made changes to the file. If you haven’t made any changes to the file, Vim exits without writing the file.
These Vim commands and keys work both in command mode and visual mode.
Vim command Action
j or Up Arrow Move the cursor up one line.
k or Down Arrow Down one line.
h or Left Arrow Left one character.
l or Right Arrow Right one character.
e To the end of a word.
E To the end of a whitespace-delimited word.
b To the beginning of a word.
B To the beginning of a whitespace-delimited word.
0 To the beginning of a line.
^ To the first non-whitespace character of a line.
$ To the end of a line.
H To the first line of the screen.
M To the middle line of the screen.
L To the the last line of the screen.
:n Jump to line number n. For example, to jump to line 42, you’d type :42
Inserting and overwriting text
Vim command Action
i Insert before cursor.
I Insert to the start of the current line.
a Append after cursor.
A Append to the end of the current line.
o Open a new line below and insert.
O Open a new line above and insert.
C Change the rest of the current line.
r Overwrite one character. After overwriting the single character, go back to command mode.
R Enter insert mode but replace characters rather than inserting.
The ESC key Exit insert/overwrite mode and go back to command mode.
Deleting text
Vim command Action
x Delete characters under the cursor.
X Delete characters before the cursor.
dd or :d Delete the current line.
Entering visual mode
Vim command Action
v Start highlighting characters. Use the normal movement keys and commands to select text for highlighting.
V Start highlighting lines.
The ESC key Exit visual mode and return to command mode.
Editing blocks of text
Note: the Vim commands marked with (V) work in visual mode, when you’ve selected some text. The other commands work in the command mode, when you haven’t selected any text.
Vim command Action
~ Change the case of characters. This works both in visual and command mode. In visual mode, change the case of highlighted characters. In command mode, change the case of the character uder cursor.
> (V) Shift right (indent).
< (V) Shift left (de-indent).
c (V) Change the highlighted text.
y (V) Yank the highlighted text. In Windows terms, “copy the selected text to clipboard.”
d (V) Delete the highlighted text. In Windows terms, “cut the selected text to clipboard.”
yy or :y or Y Yank the current line. You don’t need to highlight it first.
dd or :d Delete the current line. Again, you don’t need to highlight it first.
p Put the text you yanked or deleted. In Windows terms, “paste the contents of the clipboard”. Put characters after the cursor. Put lines below the current line.
P Put characters before the cursor. Put lines above the current line.
Undo and redo
Vim command Action
u Undo the last action.
U Undo all the latest changes that were made to the current line.
Ctrl + r Redo.
Vim command Action
/pattern Search the file for pattern.
n Scan for next search match in the same direction.
N Scan for next search match but opposite direction.

Editor Commands

All these commands can be added to your vimrc file so they are always available when you  start vim.  To use them while in the editor, hit “esc then :”.

Enable Colorsheme (you can replace “default” with any of the themes installed. i.e. delek, elflord, evening, etc.)

colorscheme default

Turn Syntax On/Off

syntax on
syntax off

Highlight searched word

Note: you can also use # and * to search for the word your cursor is on.

Enable

set hlsearch

Disable

nohlsearch
noh