Read Mac Hacks Online

Authors: Chris Seibold

Tags: #COMPUTERS / Operating Systems / Macintosh

Mac Hacks (7 page)

Chapter 2
. Mountain Lion Hacks

Mountain Lion is OS X version 10.8. If you count the public beta
version, that’s ten iterations of OS X—and it
still
isn’t perfect! That shouldn’t be surprising; there are millions of people
who use OS X and each one of them is going to want it to behave slightly
differently. Apple provides preferences that let you personalize a lot of
settings, but sometimes you need to go beyond what Apple provides to get
Mountain Lion running the way you want it. This chapter teaches you how to
get things just so.

Hack 8
. Copy the Mountain Lion Installer to a Flash Drive

Making
a portable copy of the Mountain Lion installer means you’ll
never need to spend time downloading it again. And there are many other
benefits of having a bootable copy of the Mountain Lion installer on hand,
as this hack explains.

Note: This hack describes copying the Mountain Lion installer to a
flash drive, but this technique also works for the Lion installer, and
you can use any storage media you wish. If you’re using an older version
of OS X than Lion, chances are your Mac came bundled with an emergency
boot disk—the install DVD that shipped with your Mac (it’s round,
silver, and labeled “OS X Install”).

The most obvious reason for having a copy of the installer on a
flash drive is that it saves you from downloading 4 GBs of data for every
Mac you want to install Mountain Lion on. Which means this is a must-have
hack for people with multiple Macs, but not an important hack for those
with just one Mac, right? Not so fast. It turns out that having a copy of
the installer on a flash drive is a great idea even if you only have a
single Mac.

Just what are the benefits of keeping a spare copy of Mountain Lion
installer laying around if you don’t intend to install Mountain Lion
again? For one thing, just because you don’t
intend
to install Mountain Lion again doesn’t mean you won’t end up reinstalling Mountain Lion. Things go wrong
and when they do you’ll be very glad that you’ve invested the time and
cost to create a backup installer.

You
might dismiss the idea of a standalone installer if you’re
familiar with OS X’s emergency procedures. When things go bad on your Mac,
you can start up your machine in Recovery Mode using a hidden partition
called the Recovery partition, which gives you access to some emergency
tools (Disk Utility, support documents, etc.) and lets you download
Mountain Lion again. The idea is slick but if the failure point is the
startup drive itself, then the Recovery partition won’t be available. In
addition, there’s a chance that the Recovery partition might not even
exist on your machine: if you’ve cloned your disk, that partition might
not have made the trip with the rest of your data. In that case, you’ll
definitely be glad you took the time to make a copy of the Mountain Lion
installer.

Finally, consider the time aspect of a system crash. The average
Internet download speed in the U.S. is 5.8 Mbps (worldwide, it’s 2.3
Mbps). The Mountain Lion installer is just over 4 GB, so if you’re using
an average American connection, you’re looking at over one and a half
hours just to download the installer. Factor in that your Mac isn’t going
to crash when you’ve got plenty of time (it’s some weird rule of computers—they only break during a time
crunch) and that it only takes 30 minutes to pull off this hack versus
several hours to redownload Mountain Lion and this becomes the must-do
hack of this book.

Quick Hack: Make a Flash Recovery Partition

Maybe
you’re happy with the recovery tools Apple supplies but
you’re still worried that if your Mac’s hard drive fails, the Recovery
partition will be unavailable—a legitimate fear. The obvious solution is
to copy the Recovery partition to
a disk. You could do that with the Terminal, but Apple makes it even
easier. The
Recovery
Disk Assistant program
makes the process of creating said disk
painless. For more detailed instructions, see
[Hack #2]
.

The first step in creating a backup of the installer is to download
Mountain Lion. If you’ve already downloaded and installed Mountain Lion,
you’re not out of luck—you can download Mountain Lion again via the App
Store,
just make sure you don’t install Mountain Lion once the
download is complete
. If you do, the installer will disappear
and you’ll have to repeat the download process.

Once
you have Mountain Lion downloaded, you’ll probably be
tempted to just copy the installer onto the target flash drive. Doing that
would save you from spending time downloading the installer again, but
what we are after is a
bootable
installer. Why
bootable? Well, your data is likely protected if you use Time Machine or
another similar backup option (see
[Hack #1]
), but when things go south you need
something you can boot from because you can’t start your computer using
Time Machine. So here’s how to create a bootable installer.

First, locate the Mountain Lion installer (which is aptly named
Install OS X Mountain Lion). Some users will be tempted to find it using
LaunchPad. LaunchPad is a great way to
launch
applications, but for the purposes of this hack, you’ll want to find the
actual location of the installer. The default location is in the
Applications folder, but if you’ve modified your Mac you might find the
file elsewhere. For most Macs the path will look like this:
[startup drive]/Applications/Install OS X Mountain
Lion
. If that doesn’t match your Mac, no big deal—Spotlight can
find the file for you. Once you’ve found the file, right-click it, select
Show Package Contents from the pop-up menu (
Figure 2-1
), and you’re on your
way.

Figure 2-1. The Application icons you see in OS X are actually packages that
hold a wide variety of program resources. Selecting Show Package
Contents allows you to see what makes up the application.

Once you’ve selected Show Package Contents, you’ll discover a folder
you’ve probably never seen before that’s unimaginatively named “Contents.”
Opening this folder reveals a
dizzying number of files and folders. You’re
after the one called
Install
ESD.dmg
and you’ll find it in the Shared
Support folder.

Now
it’s time for Disk Utility to lend a hand. Launch Disk
Utility
(
Applications

Utilities

Disk
Utility
), and then drag
InstallESD.dmg
onto the left side of Disk Utility window (
Figure 2-2
). When you let go of
your mouse, Disk Utility adds
InstallESD.dmg
to its source list.

Figure 2-2. Disk Utility is picky about where you can drag the file’s icon
file—aim for the lower half of the window’s left pane. (This process
doesn’t actually move the file—
InstallESD.dmg
stays
in the Shared Support folder—it just adds it as a source for Disk
Utility to use.)

Now you can insert the media you want to restore the file to (if
you’ve already inserted the destination flash drive, that won’t cause any
problems).

Note: The Mountain Lion installer is just over 4 GB so you’ll want
a flash drive that’s at least 5 GB. 5 GB isn’t a common size, though, so
you’ll likely have to settle for an 8 GB flash drive (you can find them
for less than $10 if you shop around). And
don’t
try to repurpose a flash drive you already own that contains valuable
data—this process will erase the data on the drive.

Once the drive is mounted and ready, in the Disk Utility window,
click the Restore tab. Then drag the
destination disk to, you guessed it, the Destination field. (In
Figure 2-3
, the disk is named
“jumpstart”.) Next, drag
InstallESD.dmg
to the Source field. When
everything is just right, Disk Utility will look a lot like
Figure 2-3
.

Figure 2-3. Be careful with what you select as the destination, because the
data on the destination disk will be overwritten.

Once everything is in place, it’s time to let your computer works
its magic. Click Restore, click Erase (you’ll lose any data that’s already
on the flash disk), and authenticate with an admin level password.

Once your computer is happy that you are who you say you are, it’ll
bow to your will and start restoring
InstallESD.dmg
to the flash drive. How long the
task takes depends on your Mac. On a
2009 24

iMac, it took about 20 minutes. Disk Utility
will tell you what it’s doing while it’s doing it, and estimate the time
the task will take. Feel free to turn your attention elsewhere—the
remainder of the process is a hands-free experience.

Note: Depending on what order you perform the steps in, you might
see an error message that reads “Could not restore – Invalid argument.”
You can ignore this warning and just click OK—your drive is fine and
ready to go.

What’s the last step? Seeing if all your hard work paid off! The
quick and easy way to check whether everything went as planned is to head
to System Preferences→Startup Disk. When you see your newly made drive as
an option there (
Figure 2-4
), you know
everything has worked! Now let’s hope you never need to use your new
bootable
installer!

Figure 2-4. Your new disk is ready to power your Mac on restart. If you look
inside it, you’ll find the installer and system files you
expect.
Hack 9
. Resurrect Web Sharing in Mountain Lion

Mountain
Lion got rid of one very useful feature: Web Sharing.
However, the underlying technology is still there, so you can add that
functionality back to Mountain Lion.

You may want to use Web Sharing if you’re interested in doing things
like hosting a web page (
[Hack #15]
). In Mountain Lion,
there’s no longer a Web Sharing option in System Preferences interface
(it’s still available in Mountain Lion Server, though), and Apache is
disabled by default. (Apache is a full-fledged web server that’s part of
OS X). Now that there’s no button to click enable Web Sharing, turning it
on requires a few more steps.

Note: This hack explains how to bring your Apache web server back
to life after a Mountain Lion upgrade. If you want an easy way to run
multiple local web-development environments (such as different versions
of PHP) and aren’t already using Mountain Lion’s built-in Apache server,
you might want to look into
MAMP
instead.

First,
you need to start Apache. Open a Terminal window and
type:

sudo apachectl start

You’ll need to authenticate (that’s the
sudo
part: it stands for “super user do” and
tells your Mac that you have the power), and you’ll probably wonder if
you’ll have to do this
every
time you log out or shut
down. Don’t worry—I’ll show you how to automate the authentication process
in a minute.

If you had a previous setup under an older version of OS X, once you
start Apache, you’ll probably quickly notice that your virtual hosts
aren’t working. So let’s get them
working.

You’re
going to have to make some changes to the configuration
file, and it’s best to do that with a text editor. OS X has
a few different text editors built in; for this exercise
let’s use nano in the Terminal. Open the file by typing:

sudo nano /private/etc/apache2/httpd.conf

Nano will open the file for you in a Terminal-type fashion (
Figure 2-5
).

Figure 2-5. Editing the
httpd.conf
file in the nano
editor.

Next, uncomment line 477 (very close to the end of the file) by
deleting the
#
at the beginning of the line. When
you’re done, the line should look like this:

Include /private/etc/apache2/extra/httpd-vhosts.conf

If
you want to use PHP, you need to enable the included PHP
5.3.13. Uncomment line 117, too, so that it reads like so:

LoadModule php5_module libexec/apache2/libphp5.so

Once you’ve made those one or two edits, hit Control-O to save the
file. Then restart the Apache server by opening a Terminal window
and
typing:

sudo apachectl restart
Automating Apache

To
make Apache run all the time, you need a way to launch it
in the background with root (administrator) permissions. There’s more
than one way to pull this off. The short script below does it with a
launchd daemon. (Launchd is what starts and stops daemons, and daemons
are processes that run in the background without your intervention.
There’s also a way to do it with a single command, but the launchd
method is more informative.)

Create a file called
com.
brettterpstra
.apache.plist
(you can change the
brettterpstra
part to whatever you like, but
keep the
.plist
filetype) in
~/Library/LaunchDaemons
(create this folder if it’s
not already there). By default, this folder is owned by the root user
and the group “wheel” with permissions 644 and contains the
following:





Label
com.brettterpstra.apache
ProgramArguments

/usr/sbin/apachectl
start

RunAtLoad



This
file has to be owned by root so it can run automatically
without authentication. To
change the file’s owner to root, open a Terminal window,
navigate to the directory the file is in, and then type:

chown root
com.brettterpstra.apache.plist

This method of changing the file’s owner works and it is pretty
cool, but if you are upgraded to Mountain Lion from a previous version
of OS X, you might be able to use an even easier method. If you’re
upgraded there should still be a launchd daemon in your System Library
folder that you can simply enable. To do that, open a Terminal window
and type:

sudo defaults write /System/Library/LaunchDaemons/org.apache.httpd Disabled -bool false

Now apachectl launches by default when your system starts up,
without any intervention from
you.


Brett Terpstra

Other books

Wagonmaster by Nita Wick
El enemigo de Dios by Bernard Cornwell
Surrender To A Scoundrel by Julianne Maclean
La gaya ciencia by Friedrich Nietzsche
The Blighted Cliffs by Edwin Thomas
Zenith by Julie Bertagna
Wolf in the Shadows by Marcia Muller
Pariah by Fingerman, Bob


readsbookonline.com Copyright 2016 - 2024