Showing posts with label mac. Show all posts
Showing posts with label mac. Show all posts

Saturday, March 14, 2009

Printing from the command line in Mac OSX

I had to print close to 50 individual PDF files and one way to do that was to open each one of them and then print them. But there is a fundamental issue with that. I am lazy. Opening 50 files and then printing them was not something I wanted to do on a Saturday morning.

So, I fired up the browser and started searching for ways to print from the command line and got lucky with the first hit. 'lp' is a command line tool that submits files for printing or alters a pending job and it is very easy to use. To print a bunch of pdf files in a folder, type the following commands in the terminal:
# Printing to default printer.

lp *.pdf

# Printing a document to the default printer in landscape mode

lp -o landscape foo.pdf

# Printing the first and the second pages of the document

lp -P 1,2 foo.pdf

# Printing pages between 4 and 20 in landscape mode

lp -P 4-20 -o landscape foo.pdf

# Printing to a non-default printer called "bar"

lp -d "bar" foo.pdf
More information is available in the man document for 'lp'.

P.S.: I did not use 'really' in this blog post. Oops!! I think I just did it again.

Saturday, January 17, 2009

It is all 'fsck'ed up

A couple of days ago, my MacBook Pro(MBP) refused to boot up. When booting from the Mac OS X partition, I got the usual spinning logo, then it would shut off completely. I did not realize there was an issue until after about five or so attempts at booting, all of which failed.

One of my options would have been to boot up the MBP in target disk mode, mount the volume on another Mac and run Disk Utility to find out any potential issues. Since, I had no other Mac machine handy, I decided to boot from the Mac OS X install disk and run the Disk Utility app that is in there.

Disk Utility detected a rather cryptic problem called 'invalid sibling link' error while verifying the catalog file. Also, interestingly, the 'Repair Disk' option in Disk Utility was grayed out.

I was desperate now. There was a lot of data in that partition which I needed and had no backup of. Thankfully, I was able to fix the problem and here is how I did it.

But, what is 'invalid sibling link' error?

To understand this, let us first, very briefly, look at how a HFS+ volume is structured.

An HFS+ volume contains five special files:
  1. Catalog file: Describes the folder and file hierarchy of the volume. It is organized as a "balanced tree" for fast and efficient searches.
  2. Extents overflow file: This keeps track of the allocation blocks that are allocated to each file as extent (extent-based file systems allocate disk blocks in large groups at a single time, which forces sequential allocation, of course this is somewhat of an oversimplification).
  3. Allocation file: Specifies whether an allocation block is free. This is stored in a bitmap, specifying a free allocation block with a "clear bit".
  4. Attributes file: Contains attribute information regarding files or folder.
  5. Startup file: Allows computers to boot that do have built in support for HFS+ file systems
Catalog files, Extents overflow files and Attribute files are stored in data structures that are technically known as B-trees (technically the HFS B-Trees are a variant of B+-Trees which Apple's technical documentation calls them B*-Trees.)

The Catalog tree (which describes a file or a folder) contains records which, for efficiency, are grouped into fixed length blocks called nodes. The B-trees are structured in such way that the records are in the leaf nodes. These records are sorted and indexed for fast searching which could physically scatter the nodes around the B-tree file. So, all the nodes are linked together to form a doubly linked list which allows the traversal of leaves in the same directory.

If, for whatever reason, the link between the leaves breaks (technically, becomes an invalid or dangling pointer), then we end up with an error like 'invalid sibling link'.

Now that we understand what the problem really is (through the rather oversimplified write-up that preceded this), here is how to fix the problem.
  1. Start in single user mode by holding down Command-S while booting (in my case the problem occurred on the boot volume so this was required).
  2. Once the text scrolls all the way down you should be at a command prompt
  3. Enter fsck -fy (fsck is a file system consistency and repair tool. the 'f' option is to force checks even on a clean file system and the 'y' is to just blindly say 'yes' to every option that may come up. Read the man document on fsck for more detailed explanations).
  4. If it reports 'FILE SYSTEM WAS MODIFIED' repeat from step 3 again.
  5. Keep repeating until it says 'The volume appears to be OK' (or something to that extent) or you give up ;-).
  6. If successful, type reboot to reboot.
Running fsck multiple times may be necessary. In my case I had to run it 4 times before the problem was fixed.

Googling for 'invalid sibling link' returns thousands of results but none of them really explain what causes the problem. Here is another good solution (and a great discussion) to the same problem.

If neither of these solutions work, then Alsoft's DiskWarrior (which will set up back by $99.95) could be another option although even this tool has varying degrees of success.

The first thing I did, after successfully rebooting, was to setup Time Machine. After this episode, I realized the need for a good backup solution. If things are beyond repair, then I at least know that my data is safe. :-)

Saturday, December 27, 2008

Boot Camp and BSOD

BSOD on my MBP

I have been using Boot Camp for a week now and never really had any issue with it until today. I experienced two bouts of BSOD in less than 10 minutes. Ironically, both the crashes happened when I was writing a blog post about my experience with Boot Camp. The BSOD was because Apple's Multitouch Trackpad drivers (applemtp.sys) and this appears to be a known issue.

I, honestly, never thought I would see a BSOD on my MBP ;-). But hey, when it can happen to the high and mighty, how can I, a mere mortal, be spared.

Saturday, December 20, 2008

Boot Camp

I have been a mac user for about two years now but never used 'Boot Camp' to install Windows on a Mac Book Pro because of some not so popular corporate security policies.

After I got the new machine, I didn't waste too much time. 

The experience was not really smooth for me. I wanted to install Windows XP Professional on a FAT32 partition so that I could easily access the partition from Mac OS X. I started by allocating 32 GB for the windows partition using BootCamp and and the installation started after a reboot. I could not get the bl**dy installation alway failed after the initial setup screen. 

Microsoft recommends a maximum of 32 GB for a FAT32 partition. During installation there is no way to get around this. After a bit of Googling, I decided to format the windows paritition with NTFS. But that did not work either. The initial installation would go through but after that I would get a 'bad disk' error.

I changed gears and made a backup copy of the XP install CD (before I get yelled at, I confirmed that this is legal since my original CD could be faulty). I tried the installation again with an NTFS paritition. This time I got 'could not find 'hal.dll' message. 

After a bit more googling, I saw several explanations for this including a corrupted boot.ini file. So, with a renewed gusto, I tried installing again. But this time I created a 20 GB FAT32 parition and continued. Lo and behold the installation went through fine.

After the installation, I just popped in the Leopard CD that came with the Mac and in less than 10 minutes I had everything working.

The trackpad did not work well even after the driver installs. This was  a known issue and a software update fixed it. 

I am not really sure if I really want to use XP but it is good to know I do have an option. When I have some time, I will install VMWare Fusion and check how well I can run XP off the boot camp parition.

Instructions for boot camp install are available here.

Friday, December 19, 2008

The new Mac Book Pro

It has been a while since my last post. I have been wanting to write a few reviews for quite a while but there were other things happening in my life which took precedence.

I got a the new MacBook Pro and I am already in love with it. The design is much better than the earlier version. The screen is bigger and the gesture support on the trackpad make things more interesting. You can find a good in-depth review on Ars Technica (Part1, Part2).