How to see what is inside an ISO file on Mac OSX (10.9.5) using command line magic.

I’m in a hurry, just show me the commands

# Create the block device to access the ISO file:
hdiutil attach -imagekey diskiamge-class=CRawDiskImage -nomount myfile.iso

# The previous command told me the new device was:
hdiutil mount /dev/disk5

# Open a Finder window and look for the new disk which should be present.
open .

I’ve got time, tell me more

What if you want to check if the ISO is ok after creating one? What if you’ve downloaded an ISO file but don’t have a CD drive? How would do you deal with this?

Luckily, command line magic can help you with this. The “hdiutil” utility allows you to work with disk images like ISO files. The basic process is create a block device from the ISO file. Then mount the device which Finder can then use.

To create a block device which we can later “mount” we do:

$ hdiutil attach -imagekey diskiamge-class=CRawDiskImage -nomount 汉字图解学习手册.iso
/dev/disk5

This creates a new block device entry for the ISO file and called it “/dev/disk5”. Now we use “hdiutil” to mount the new block device as follows:

$ hdiutil mount /dev/disk5

You can open a Finder window or do so from the command line to see files:

$ open /Volumes/汉字图解学习手册

Success!

Bonus

You can eject the mounted volume using “hdiutil” as follows:

$ hdiutil eject /dev/disk5
"disk5" unmounted.
"disk5" ejected.

Handy References

© Copyright 2014 by Oisin Mulvihill.
Content licensed under the Creative Commons attribution-noncommercial-sharealike License.

How to copy a CD on Mac OSX and make an “ISO” file using command line magic.

I’m in a hurry, just show me the commands

# find the block device you want:
mount

# umount it:
sudo umount /dev/disk3s0

# create the ISO
dd if=/dev/disk3s0 of=myfile.iso

# own the ISO file
sudo chown $USER: myfile.iso

Related

I’ve got time, tell me more

Making an ISO file on the OSX (10.9.5) from the command line isn’t hard. An ISO file is the raw binary file from which other CDs can be burned.

Insert the CD you want to copy. Open a Terminal window and let us see where the CD is “mounted”. I do this as I need to find the CD block device. More on this later. To find my CD I use the “mount” utility. We’ll need this information in later steps:

$ mount
/dev/disk0s2 on / (hfs, NFS exported, local, journaled)
:
etc
:
/dev/disk3s0 on /Volumes/汉字图解学习手册 (..etc..)

In my case I can see the CD I want to copy, “汉字图解学习手册”, is mounted inside the /Volumes folder. The device which represents the CD drive (technically called a block device) is located here /dev/disk3s0. This may be different for people on other machines.

To make an exact copy of the CD, I need access to the raw binary information. This information is not just files and directories. It is also the underlying filesystem which organises the physical space available on the CD. This is where the block device comes in.

Before I can use the block device I need Finder to stop using it. To do this I unmount “/Volumes/汉字图解学习手册”. This will not eject the CD from the drive. To unmount I do the following as the administrator:

$ sudo umount /dev/disk3s0

Now I can copy the raw information as follows:

$ dd if=/dev/disk3s0 of=汉字图解学习手册.iso
144652+0 records in
144652+0 records out
74061824 bytes transferred in 63.915588 secs (1158744 bytes/sec)

This uses a special command line utility called dd. This is used to read and write binary information from block devices. A quick check to see the size of the ISO file using the “ls” utility reveals:

$ ls -lh 汉字图解学习手册.iso
-rw-r--r--  1 root  staff    71M 18 Oct 19:13 汉字图解学习手册.iso

Great, in my case the CD ISO is a small one at 71M. Normally CD iso files are roughly 600MB+.

You won’t be able to delete the ISO as a normal user. To gain access to it you will need to change ownership to yourself. This can be done using a command called “chown” as follows:

$ sudo chown $USER: 汉字图解学习手册.iso

$ ls -lh 汉字图解学习手册.iso
-rw-r--r--  1 oisin  staff    71M 18 Oct 19:13 汉字图解学习手册.iso

Success! You can now burn this ISO to another CD-R/RW using Disk Utility if you want.

Handy Reference

You might also like

© Copyright 2014 by Oisin Mulvihill.
Content licensed under the Creative Commons attribution-noncommercial-sharealike License.

Check I can connect to internet services

I often want to check can I connect to a service running on different machines. There are a number of ways to do this. I typically default to using telnet. This isn’t ideal and overkill when I just want to check a port is open (e.g. no firewall blocking the port). I decided today to look around for alternatives and have come up with the following script:

 This uses netcat if available or bash socket connections if not. You can use the bash function as follows:

    # Download and source the script.
    eval "$(curl https://raw.githubusercontent.com/oisinmulvihill/my-bash-helpers/master/lib/tcptest.sh)"

    # Connections over HTTP
    $ tcptest google.com 80
    Connection ok to 'google.com:80'

    # Connections over HTTPS
    $ tcptest google.com 443
    Connection ok to 'google.com:443'

No try a port google won’t have open:

    $ tcptest google.com 38475
    No one is listening on 'google.com:38475'

This is really only a quick check as the connection could be slow. The tcptest will timeout after 5 seconds. The tcptest function is based on a mashup of three different stackoverflow answers:

© Copyright 2014 by Oisin Mulvihill.
Content licensed under the Creative Commons attribution-noncommercial-sharealike License.

On linux you often want to see what processes are running. I like to see a tree of parent and children processes running. Traditionally you could do to see using the “ps” command:

ps fax

1027 ?        Ssl    0:00 rsyslogd
1131 ?        S      0:00 upstart-file-bridge --daemon
1170 tty4     Ss+    0:00 /sbin/getty -8 38400 tty4
1173 tty5     Ss+    0:00 /sbin/getty -8 38400 tty5
1175 ?        Ssl    0:00 /usr/bin/python /usr/bin/salt-minion
1179 tty2     Ss+    0:00 /sbin/getty -8 38400 tty2
1180 tty3     Ss+    0:00 /sbin/getty -8 38400 tty3
1182 tty6     Ss+    0:00 /sbin/getty -8 38400 tty6
1183 ?        Ss     0:00 su - vagrant -c ipython notebook --pyl
1232 ?        Ss     0:00  \_ -su -c ipython notebook --pylab inl
1250 ?        Sl     0:01      \_ /usr/bin/python /usr/bin/ipython
1255 ?        Ss     0:00 acpid -c /etc/acpi/events -s /var/run/a
1257 ?        Ss     0:00 cron
1259 ?        Ss     0:00 atd
1273 ?        S      0:00 dnsmasq -u lxc-dnsmasq --strict-order 
1276 ?        Ss     0:00 nginx: master process /usr/sbin/nginx
1277 ?        S      0:00  \_ nginx: worker process
1278 ?        S      0:00  \_ nginx: worker process
1279 ?        S      0:00  \_ nginx: worker process
1280 ?        S      0:00  \_ nginx: worker process
1335 ?        Sl     0:00 /usr/sbin/VBoxService
1418 ?        Ssl    0:01 /usr/bin/ruby /usr/bin/puppet agent
1447 ?        Sl     0:00 ruby /usr/bin/chef-client -d -P /var/run
1474 tty1     Ss+    0:00 /sbin/getty -8 38400 tty1
1708 ?        Ss     0:00 /usr/sbin/sshd -D
3807 ?        Ss     0:00  \_ sshd: vagrant [priv]
3860 ?        S      0:00      \_ sshd: vagrant@pts/0
3861 pts/0    Ss     0:00          \_ -bash
4106 pts/0    R+     0:00              \_ ps fax

Thats ok however you have to re-run to see it updating. You could use “top” however I recently came across htop. This is very nice and shows the amount of CPU and memory usage “graphically” in the console. The one slight niggle for me are the initial settings which look a bit like:

image

You can configure it to show a tree and hide threads which I prefer:

image

The following are my settings. To keep the settings across machine set ups I copy them to the configuration file $HOME/.config/htop/htoprc

# Beware! This file is rewritten by htop when settings are changed in the interface.
# The parser is also very primitive, and not human-friendly.
fields=0 48 17 18 38 39 40 2 46 47 49 1
sort_key=46
sort_direction=1
hide_threads=1
hide_kernel_threads=1
hide_userland_threads=0
shadow_other_users=0
show_thread_names=0
highlight_base_name=0
highlight_megabytes=1
highlight_threads=0
tree_view=1
header_margin=1
detailed_cpu_time=0
cpu_count_from_zero=0
update_process_names=0
color_scheme=0
delay=15
left_meters=AllCPUs Memory Swap
left_meter_modes=1 1 1
right_meters=Tasks LoadAverage Uptime
right_meter_modes=2 2 2

Sublime Text Magic

image

One of the really handy features of most editors is to be able to search and replace. Many also allow you to use regular expressions to aid.

Sublime text, my current GUI based editor of choice, is no different. I recently remembered how to do “regex search and replace” using matches. I though I should document this so I will remember more quickly next time :)

I need to find all entries like “self.assertEquals(user.count(), 0)” and replace it with “assert user.count() ==  0”. On another line I have “        self.assertEquals(user.dump(), [])” which needs to become “assert user.dump() == []”. Doing this with “normal search and replace” would be impossible.

Enter the Regex magic. In the search and replace enable “Regular Expression” searching (Its the little button image with the “.*” in it). Then enter the expression “self.assertEquals\((.*),(.*)\)”. This tells what I’m looking for. The magic here are the two the (.*) parts. 

In the replace box I type the expression “assert \1 == \2”. The first (.*) can be refer to in the replace as \1,  the second as \2. I can now search and replace a broad range of entries that match the pattern. In this case 43 items I need to replace.

The tech interview is dead! Long live my github code…

I totally agree with this article explaining in detail why the The tech interview is dead!”. I just wish the London job scene would catch on to this. I do maybe 3+ of these a year. What hoops I’m asked to jump through tells me more about the prospective company then they realise.

I got my contract at Albion solely based on my "portfolio" of work on github. I just got an email saying “You start monday…”. I like to call this interviewing while you sleep :)

 

I started doodling while waiting for a program to pass tests. Its nerdy and simplistic view on things. But it got me thinking about how I feel about extremism, hatred and where I live.
London is my home. I’ve been living here for seven years now. It is the most diverse and fascinating places I’ve lived so far. There is always something going on. Be that interesting projects, fantastic food or things to see and do.
The 2005 terror attack on Shepherds Bush station (now called Shepherds Bush Market station), temporarily meant I had to stay at a friends house. I remember going to Starbucks then next morning. I wasn’t able to head home and had to go to work. The staff gave me free coffee and a sandwich. In a small way it showed people pulling together and not letting a such an thing hold us down.
Yesterdays events in Woolwich were really terrible. My heart goes out to the family of the victim. The world has changed a lot since September 2011. I’m no longer shocked that two people can to hold such extreme views, that make them feel butchering another human being is ok.
My concern is that we don’t let this attach divide us, as was no doubt the intention. This kind of thing, in a recession, is what fuels far right groups and their peddling of counter hate. I hope we can pull together and work to rid society of extremism in all forms.
Thats just me two cents.

I started doodling while waiting for a program to pass tests. Its nerdy and simplistic view on things. But it got me thinking about how I feel about extremism, hatred and where I live.

London is my home. I’ve been living here for seven years now. It is the most diverse and fascinating places I’ve lived so far. There is always something going on. Be that interesting projects, fantastic food or things to see and do.

The 2005 terror attack on Shepherds Bush station (now called Shepherds Bush Market station), temporarily meant I had to stay at a friends house. I remember going to Starbucks then next morning. I wasn’t able to head home and had to go to work. The staff gave me free coffee and a sandwich. In a small way it showed people pulling together and not letting a such an thing hold us down.

Yesterdays events in Woolwich were really terrible. My heart goes out to the family of the victim. The world has changed a lot since September 2011. I’m no longer shocked that two people can to hold such extreme views, that make them feel butchering another human being is ok.

My concern is that we don’t let this attach divide us, as was no doubt the intention. This kind of thing, in a recession, is what fuels far right groups and their peddling of counter hate. I hope we can pull together and work to rid society of extremism in all forms.

Thats just me two cents.

Macports and what you need.

I restored my Mac from time machine after installing a new SSD. Sadly my Macports didn’t work. When I tried to using it I got:

sudo port install coreutils

—->  Computing dependencies for coreutilsError: Unable to execute port: can’t read “build.cmd”: Failed to locate ‘make’ in path: ‘/opt/local/bin:/opt/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin’ or at its MacPorts configuration time location, did you move it?

This just meant the Developer tools weren’t installed. Although they did appear to be still there. The fix was straight forward enough. I just reinstalled "Command Line Tools (OS X Lion) for Xcode - March 2013" and I was back in action. 

New home for my blog.

Hello There,

Welcome to the new home for my SourceWeaver blog. I’m hoping to leverage Tumblr and Disqus. Tumblr is straight forward to use so I’m hoping this will let me create articles when I think of them. Rather then the extremely slow process of between contracts.

A helper for python package development

I like breaking Python development up into packages I can roll into eggs. The downside of this approach is typing “python setup.py …” a lot from the command line. To reduce typing I came up with the following Bash function. I use it a lot and would like to share with others. I place it in the public domain.

#!/bin/bash
# # Wrap python setup.py . By default it will # run a python setup.py develop. If there is a BASKET # environment variable set it will use this as the # sole source for egg dependancies. # # The function will first test for the presence of # the setup.py file. If its not present it will exit. # function sd() { if [ "$1" == "" ]; then COMMAND="develop" else COMMAND=$1 fi if [ -e setup.py ]; then if [ -z "$BASKET" ]; then # No basket defined so don't use it as a source python setup.py $COMMAND else # The BASKET if set will need to specify -i/-f. # For example: BASKET="-i http...." # For example: BASKET="-f http...." # if [ $COMMAND == "develop" ]; then # only use basket for develop. It does not work # with other options. python setup.py develop $BASKET else python setup.py $COMMAND fi fi else echo "No setup.py found here: '"`pwd`"'" fi }

You can add this to your ~/.bashrc or just use it from the command line:

source pythonsetup.sh

The ‘sd’ command willl now be available. Any command you can do to “python setup.py” can be used with “sd”.

#Example calls:


# Default (python setup.py develop):
$ sd
running develop
running egg_info
writing lib/boaconstructor.egg-info/PKG-INFO
writing eager_resources to lib/boaconstructor.egg-info/eager_resources.txt
:
etc
:
Installed /Users/omul/Dropbox/src/boaconstructor/lib
Processing dependencies for boaconstructor==0.4.0
Finished processing dependencies for boaconstructor==0.4.0



# Running tests (python setup.py test:
$ sd test
running test
running egg_info
:
etc
:
Test the utils module render which is used by the Template class. ... ok
testValueParsing (boaconstructor.tests.testboaconstructor.BoaConstructor)
Test parsing a dict entries value to recover the reference and ... ok

----------------------------------------------------------------------
Ran 15 tests in 0.010s

OK