Tuesday, June 26, 2007

Setting up a Mac Server behind a Router

http://homepage.mac.com/car1son/static_port_fwd_intro.html

etting up a Mac Server behind a Router

This is a guide to setting up your home network with a Cable/DSL Router (Wireless or Wired) so you can run a server that's accessible from outside your home through the internet.

I've tried wherever possible to make this information applicable to a wide range of home network routers, using specific examples from the LinkSys router and Apple Airport Base Station that I use myself. You can also find lots of other useful information on the subject at this site.

The basic procedure, covered in detail with screenshots on the pages that follow, is to start the server on a Mac, set the Mac to a fixed IP address, configure the Router to forward the correct service port(s) to that IP address, determine the public IP Address of your network, and then connect to it.


What's the Problem?

Setting up a service on a Mac, such as Personal File Sharing, FTP, web server, or remote access, so that it can be accessed from elsewhere the internet requires a few tricks.

The basic problem is that your Router is controlling all your external internet connections. It will need some geeky instructions about what to do when it gets a request from the internet so it will pass it on to the Mac.

Consider the 4-computer home LAN illustrated on the right-hand side of this picture:

LinkSys Router NAT Diagram

There are four computers on this LAN. Each computer is uniquely identified by an IP Address, which is the four-part number used by the internet to uniquely identity every computer. (In this example, these are 192.168.1.101, 192.168.1.102, etc.) But these IP Addresses are only Private (or "local"); They are only valid on your local LAN (also called your sub-network). They identity your computers to each other and to the Router, but not to the internet. Furthermore, if you used the simplest way to connect your computers and used DHCP (the Dynamic Host Configuration Protocol, which automatically assigned computers on the network an IP address as they join), these IP addresses were assigned dynamically by the router and can change with time.

Your ISP has assigned your network a unique Public IP Address (or external IP address), which is how other systems on the internet identity the (In this example, this is 66.167.43.161.) Also, if your ISP uses PPPoE (common for DSL providers) or DHCP (common for Cable providers) for your internet service, that IP Address can change over time, too.

(Your Router actually has two IP Addresses, one that it's been assigned on the WAN port and uses with the internet, which is how the internet sees your home; and, one IP Address that it uses locally on your LAN and WiFi ports, which is how your home computers know it. On this LinkSys-based network, the LAN side knows the Router as 192.168.1.1.)


Wednesday, June 13, 2007

More: Mac系统日常维护

http://www.macattorney.com/ts.html

Mac系统日常维护

Delete Cache Files

Why: Cache files are temporary receptacles for data that help OS X and its applications work faster. They can become corrupted or simply too large to function well. If you're experiencing odd issues with an application—such as preferences that won't load or menus that contain strange characters—or if an application or the system seems sluggish, it may be a cache-related issue.

When: Removing cache files once or twice a month works well for most people, but if your Mac is always on and working, you may want to remove cache files once a week to prevent corruption.

Who: Everyone.

A cache is a place to store something temporarily so the OS or a program can retrieve and use it in a hurry. G4 and G5 processors have caches that help them handle instructions more quickly. OS X uses disk-based caches that hold copies of graphics, frequently performed calculations, and the contents of dynamic menus. Caches help reduce application launch times, speed up the display of screen data, and make Web sites load faster.

You'll find OS X's cache files in the System: Library: Caches folder, in your user folder's Library folder, and in folders within individual applica-tion folders. The easiest way to remove most of them is to use one of the tools listed in the "Managing Mac Maintenance" chart. (Except for Safari's caches, these tools generally don't affect application-specific caches; you'll have to wrangle these files yourself.)


Regularly deleting your cache files is a good idea. And if you're seeing slowdowns or other unexplained behaviors, there's no harm in trying to rout the bad behavior by deleting the cache files.

Delete Log Files

Why: Log files record system- and application-related activity. They grow over time, using disk space to store data you'll never need.

When: Log files don't normally grow excessively large, so you can delete them only when you want to reclaim drive space.

Who: Users concerned with freeing every bit of available drive space, and users who make extensive use of FTP, Web, and other bundled Unix applications.

As you work, your OS and applications automatically create log files that record everything from the mundane to the important. Large log files don't cause system instability, but when diminishing disk space becomes a concern, there are a couple of ways to clean up.

Like cache files, log files are stored in several places, from the system level (in the /var/log and /Library/Logs folders) to your user folder (~/Library/Logs). You can run OS X's built-in daily, weekly, and monthly maintenance scripts to take care of the system-level log files. To root out log files at the user level, you need either the Console application (in Applications: Utilities) or an application such as NoName Scriptware's CacheOutX.

In Console, delete any log listed in your user folder's Library: Logs folder by highlighting it from the left-hand Logs column and pressing Command-delete. After you confirm your action, that log file vanishes. Your Mac automatically re-creates it the next time the system or the program needs to write something to the log.


Automate Your Maintenance

Why: OS X comes with a set of Unix scripts that run automatically. They delete and archive unnecessary data created through normal use of your machine.

When: You don't have to lift a finger—the scripts run daily, weekly, and monthly, as long as your machine is awake at their scheduled run times.

Who: Heavy users of the command line.

OS X is designed to make basic maintenance tasks invisible to you. The operating system regularly cleans up the little files that can clog your machine—from system logs to FTP logs to firewall logs. But there's a catch. OS X's cleanup scripts are set to run at specific times. The daily script runs at 3:15 a.m., the weekly script runs at 4:30 a.m. on Saturdays, and the monthly script runs at 5:30 a.m. on the first day of the month. Apple probably chose these times because you're not likely to be using your machine during the wee hours, so you probably won't be bothered by the CPU draw or the drive noise. Unfortunately, those times are also when most of our machines are powered off or sleeping, so the scripts can't execute.

Most people won't see problems if these scripts don't run regularly, but a few will. To find out if you're vulnerable, take a closer look at each script.

The daily script cleans up the tmp directory, where many programs and installers store files that aren't permanently required. iChat, for instance, keeps copies of images you've sent in the tmp folder. (Your machine empties this folder when you restart.)

However, the daily script also backs up your NetInfo database, an essential file with information on your users, services, and devices. If you don't regularly back up this file in some other way, I suggest running the daily script. (Note that recovering this file from a backup is very complicated. Go to this article for a how-to that's not for the faint of heart.)

The daily script also creates a network-interface status report and a free-disk-space report, and rotates the system.log files by creating multiple compressed backup copies.

The weekly script updates the locate and whatis databases (two files that are very useful when you spend a lot of time in Terminal); archives older secondary system logs, such as FTP; and archives Web-server logs. It also restarts your Web server.

The monthly script runs a user time-accounting script (not much to it when you're the only user on your machine) and rotates installer log files.

You can look for reported errors in the output of these scripts by opening the Console program (Applications: Utilities), clicking on the /var/log line in the Logs column (click on the Logs button in the toolbar if you can't see this column), and then selecting daily.out, weekly.out, or monthly.out. The contents of the file display to the right.

If you've decided that running the scripts is important, but you don't want to keep your Mac on and awake at the times they run, see "Run, Scripts, Run!" for tips on changing the automatic run times.

Keep Hard Drives Healthy

Why: An unhealthy hard drive is a nightmare. SMART (Self-Monitoring Analysis and Reporting Technology) lets you perform a routine checkup that identifies potential drive failures before they happen, so you have time to update backups and look for replacement drives.

When: You (or an automated application) should check SMART indicators daily.

Who: Everyone.

The hard drive or drives inside your Mac are critically important—if the hard drive fails, the Mac won't boot, and you could lose all your files. While there's nothing you can do to physically maintain your drives, there are some tools that sniff out disk weaknesses, and there are a couple of ways to recover data when you do have trouble.

SMART Status Indicators The SMART hard drives in newer Macs diagnose their own health, and they note any problems they find with internal drives on an IDE/ATA or SATAbus.

There are two ways to check the status of your Mac's SMART indicators. If you're using the machine locally, launch Disk Utility (Applications: Utilities) and click on the top-level indicator for your drive in the left-hand column. In the bottom of the window, you'll see the words SMART status, and next to that, you'll see the word verified. If you don't see SMART status, your Mac doesn't have the technology. If you see the phrase but it's not accompanied by verified, you should back up your hard drive and then replace it—it will likely experience a failure soon.

If you prefer to use Terminal, or if you connect remotely to Macs—for instance, if you have a Mac in your home that you're using as a server—you can also check the status of the drives from Terminal. In Terminal, type diskutil info disk0 | grep SMART , assuming that the Mac has only one hard drive. If the Mac has more than one hard drive, type diskutil list to see which drive numbers are assigned to each drive, and then repeat the first command with the proper number.

Manually checking SMART indicators gets old fast. If you're comfortable in the command line, you can add a new cron task that executes this command on a regular basis and writes the output to a text file; you can also create an AppleScript that displays a dialog box and then set the AppleScript to run at login each day. Or you could let a third-party application, such as Alsoft's $80 DiskWarrior (see Best Current Price ), Micromat's $98 TechTool Pro 4, or Julian Mayer's free SMARTReporter, inspect the drives and alert you if there's an error.

Advanced Maintenance and Repair SMART indicators don't catch everything. Despite your best efforts, you might power up your machine one day and see the dreaded blinking question mark.

Your first step should be to boot from the OS X Install CDs. Next, select Open Disk Utility from the Installer menu (next to the Apple menu). If your boot drive shows up in the left-side drive list, select it, and click on Repair Disk—then sit back and cross your fingers. Disk Utility may be able to repair the disk; if it does, restart and hope the drive works as usual. Then back up important files and consider investing in a new drive.

If Disk Utility can't repair the drive, it's time for DiskWarrior or TechTool Pro 4. DiskWarrior is primarily a directory-repair tool. Its directory-rebuilding feature has returned seemingly dead drives to the land of the living. TechTool Pro also recovers data from dead drives, through a different mechanism. In addition, it can monitor and test a number of other aspects of your system, such as CPU, memory, and power supply. Both are capable tools; which to use is really a matter of per-sonal preference.

If you can't make the drive work with either of these programs, it has probably suffered a physical failure of some sort. If you're willing to dole out serious dough, companies like DriveSavers Data Recovery can often recover data from even badly damaged drives.

Construct a Maintenance Toolbox

Why: Maintaining your Mac doesn't have to be a burden. There's software that can handle it with ease, and some programs even throw in additional system-tweaking features.

When: There's no sense in waiting to download helper applications.

Who: See the "Managing Mac Maintenance" chart for an easy-to-scan list of the applications and their abilities. Out of that list, every Mac user should have at least three: OnyX, SMARTReporter, and DiskWarrior.

OnyX For general system maintenance, Titanium Software's OnyX is tough to beat. It's free, it has a clean interface, and its help system is easy to understand. OnyX's features go well beyond basic maintenance: the program lets you erase caches, logs, browser cookies, and even Safari's cached bookmark icons with a few mouse clicks. Throw in the ability to run a Terminal command, browse log files, and view Unix manual (man) pages, and you've got a maintenance winner.

SMARTReporter Julian Mayer's SMARTReporter checks SMART status indicators. While many programs can do this (including Apple's Disk Utility), I prefer SMARTReporter's reporting capabilities. With its intuitive interface, you'll have your drives set up for regular monitoring in no time. You specify the testing interval and the actions to take if a test fails. You can even control SMARTReporter's appearance in your menu bar—a solid green or red disk icon, or just a small green or red dot that indicates the status of the most recent test.

DiskWarrior When your hard drive appears to be dead, you need a drive-repair utility. And DiskWarrior's ability to resuscitate drives is unmatched. Using a proprietary and patented technique, DiskWarrior builds a new directory for your drive. Once this new directory is built, DiskWarrior lets you mount it as a new hard drive, so you can check it for errors and even copy files off of it. If everything looks good, DiskWarrior then writes its new directory onto your drive. DiskWarrior can't save you from hardware failures that render the drive unusable, but for nearly everything else, it's an invaluable data-saving tool.

什么是plist 文件?

OS X uses .plist files to store application- and system-related preference information. These files are text files saved in the XML format, which follows a set layout. So it's easy to determine whether a file is corrupted: if it doesn't adhere to the set XML layout, it's corrupted.

There are two ways to check XML preference files. In OS X 10.2 and later, you can use the Unix utility plutil. Just open Terminal and type the following: sudo plutil -s ~/Library/ Preferences/*.plist —and then press enter and provide your password when asked.

In the preceding code, -s tells plutil to suppress output of a successful test, so if you see output, you'll know that it's from an error. You need to use sudo because some preference files, such as those from Micromat's TechTool, are owned by the system even though they reside in the Preferences folder in your user folder.

You can check the top-level system preferences by repeating this command with /Library/Preferences as the folder location.

An application may create a file that fails Apple's test but is not corrupt. If you see a file or two listed for applications that seem to work just fine, you can safely ignore the warnings. If you find a truly corrupted preference file (and don't have a corruption-free backup), quit the application, trash the file, and start over with the application settings.

一个比较完整的关于Open Fireware的说明

Booting Mac OS X

This page contains a brief description of the Mac's firmware (analogous to the PC BIOS in many respects), the bootloader, and the typical Mac OS X boot up sequence. There are significant differences between how older (68k, "Old World" PowerMacs) and newer (everything currently, but essentially "New World" machines with Open Firmware 3.x that load ROM from a file) boot. The discussion here applies to the newer systems.

The firmware is not part of Mac OS X, but it plays an important role in the operation of the machine, and is useful in debugging. Hence, we discuss it here.

Open Firmware

Background

Open Firmware (IEEE-1275 Standard for Boot Firmware: Core Requirements and Practices) is a non-proprietary, platform (CPU and system) independent boot firmware. Similar to a PC's BIOS, Open Firmware is stored in ROM and is the first stored program to be executed upon power-up.

An Open Firmware implementation is based on the Forth programming language, in particular, the FCode dialect (FCode is an ANS Forth compliant dialect that supports compilation of FCode source to bytecode). Apple and Sun are two prominent computer system makers that use implementations of Open Firmware in their systems (Sun's trademark is called OpenBoot). The Open Firmware Working Group's home page is hosted at various places, including Apple and Sun.

Thus, the firmware is implemented in Forth, and stored in the ROM as FCode bytecode. Device drivers that are required during system startup are also implemented similarly. Such drivers usually exist in the expansion ROM of expansion cards that are needed before the operating system has loaded.

Interaction

You can enter Open Firmware by pressing the key combination cmd-opt-O-F just as you power on a Macintosh. The cmd key is the one with the Apple logo, and the opt (option) key is the same as the alt key. You should see a welcome message and some other verbiage, and should be dropped into a prompt like the following:

ok 0 >

You can continue booting the machine by typing mac-boot, or shut it down by typing shut-down.

Even though this Forth "shell" supports reasonable (for a BIOS) command line editing (you can use ctrl-a to go to the beginning of a line, ctrl-e to go to the end, ctrl-u to erase a line, the up-arrow key for history, etc.), you would find it more convenient (particularly if you are trying to write any code in the firmware) to access a Mac's Open Firmware from another (arbitrary) computer, over the network. Here is the command sequence to do this (everything is typed at the Open Firmware prompt, unless stated otherwise):

0 > dev /packages/telnet

Note that upon success, Open Firmware prints the string "ok" on the same line as you press <return>. In the examples on this page, if you see ok, remember that it is printed by Open Firmware and you are not supposed to type it in (it's not a valid Open Firmware word anyway).

If your Mac's Open Firmware includes the telnet package, you would see:

0 > dev /packages/telnet ok

If you do get an ok, you can run a TELNET server on it:

" enet:telnet,10.0.0.1" io

This would run a TELNET server on the machine with IP address 10.0.0.1 (you can and should choose any appropriate address). Thereafter, you can connect to Open Firmware on this machine using a TELNET client - say, from a Windows machine. See The Towers of Hanoi in Open Firmware for a programming example.

Note that current (at least G4 and above) Apple computers come with Ethernet ports that are auto-sensing and self-configuring, so you do not need a cross-over cable to connect it directly to another computer (no hub is required, etc.).

Examples

1. The following command prints the device tree:

0 > dev / ls ff880d90: /cpus ff881068: /PowerPC,750@0 ff881488: /l2-cache ff882148: /chosen ff882388: /memory@0 ff882650: /openprom ff882828: /client-services ... More [<space>,<cr>,q,a] ? _

2. The following command gives you information about installed RAM:

0 > dev /memory .properties ok name memory device_type memory reg 00000000 10000000 10000000 10000000 slot-names 00000003 SODIMM0/J25LOWER SODIMM1/J25UPPER ... dimm-types DDR SDRAM DDR SDRAM dimm-speeds PC2700U-25330 PC2700U-25330 ...

The machine in the above command (a PowerBook G4 15, although that is not relevant) has two PC2700 DDR SDRAM chips installed. The two pairs of numbers against reg are specify the starting address and size of the chips. Thus, the first RAM chip starts at address 0x0000000 and has a size 0x10000000 (which is 256 MB). The second chip starts at 0x1000000 (256 MB) and has a size 256 MB. The total RAM is thus 512 MB.

If you need to reduce the installed RAM size (as seen by Mac OS X) for any reason, without actually having to remove a RAM stick (or you want to simulate an arbitrary size that's less than the total installed RAM), you can actually delete the reg entry using the delete-property command, and specify your own reg. Referring to the previous example of the 512 MB PowerBook, the following command essentially disables the second RAM stick (note that this change is not written to NVRAM - it is transient - once you reboot, the other chip will be detected and used as before):

0 > " reg" delete-property ok 0 > 0 encode-int 10000000 encode-int encode+ " reg" property ok

It must be kept in mind though that the reg properties can change from machine to machine, or more likely with architectural changes (for example, the format changed with the PowerMac G5). A less adventurous and more appropriate way to limit visible RAM is to use the maxmem boot argument, such as at the shell prompt:

# nvram boot-args="maxmem=128"

3. The following command sequence shows you various information on the machine's CPU(s):

0 > dev / ok 0 > dev /cpus ok 0 > ls ff886d58: /PowerPC,G4@0 ff8871f8: /l2-cache ok 0 > dev PowerPC,G4@0 ok 0 > .properties name cpu reg 00000000 cpu-version 80020101 state running clock-frequency 4a817c7b bus-frequency 09ef21aa ...

The rest of the output contains various cache sizes, the processor's graphics capabilities (Altivec, support for certain instructions, ...), and so on. You can think of this as analogous to /proc/cpuinfo on Linux.

4. The following command lists files in the root directory of the disk (partition) referred to by the "alias" hd

0 > dir hd:\ Size/ GMT File/Dir bytes date time Name 6148 12/25/ 3 4:25:25 .DS_Store 156 9/12/ 3 20:41:59 .hidden 589824 12/25/ 3 6:45: 6 .hotfiles.btree ...

5. The following command expands the alias hd, and gives you the complete path of the device in the tree (type devalias by itself to see a list of current aliases, along with what they refer to):

0 > devalias hd /pci@f4000000/ata-6@d/disk@0 ok

6. You can load a file (kernel) using the load command, and boot it using the boot command. As stated earlier, mac-boot and shut-down are predefined to boot the machine normally, or shut it down, respectively. You can get and set variables (options) using the printenv and setenv commands. These variables are stored in the non-volatile memory (NVRAM) of Open Firmware. For example, if you want your email address to be used as the "OEM banner", you should do the following:

0 > setenv oem-banner you@your.email.address 0 > setenv oem-banner? true

You do not actually need to drop into Open Firmware to set the NVRAM variables. You can access (get and set) these from within Mac OS X via the nvram command line utility.

To sum up, Open Firmware is a powerful tool for controlling, debugging, and exploring the computer.

Operation

When an Open Firmware equipped Macintosh (all current Apple systems at the time of this writing) is powered on, hardware is diagnosed (by some POST code) and initialized. The first entity to control the CPU thereafter is the firmware. Open Firmware (which runs with interrupts disabled) builds a device tree, probes slots for devices, queries PCI devices and assigns them address space appropriately, and then looks for the default boot device (unless one was specified explicitly). The following "snag" keys let the user specify a boot device as the system is powered on:

C device referred to by the 'cd' alias, a CD-ROM drive D device referred to by the 'hd' alias, a hard disk drive N device referred to by the 'enet' alias, a network card Z device referred to by the 'zip' alias, a ZIP drive

It is worth noting that pressing T while your Mac powers on would boot it into what's called the FireWire Target Disk Mode. Essentially, your Mac becomes a fancy external FireWire disk drive.

You can also specify the complete pathname of a device, or have the machine boot over the network using TFTP:

boot enet:<server IP>,<file>,<my IP>;<subnet>,;<gateway IP>

If Open Firmware fails to find a boot device, a blinking folder is displayed.

Open Firmware then loads a file of type tbxi (ToolBox ROM Image, for historical reasons) from the system partition. Note that this would have been the file called "Mac OS ROM" in the System Folder on Mac OS 9, while OS X loads /System/Library/CoreServices/BootX, which is the bootloader as well. BootX is then executed and Control is then passed to it.

Note that Open Firmware can directly load ELF, XCOFF and "bootinfo" (any supported format with an XML header) binaries, but not Mach-O, the native executable format on Mac OS X. BootX can load Mach-O binaries.

Bootloader

BootX (/System/Library/CoreServices/BootX) is the default bootloader on Mac OS X.

BootX is also the name of an open source bootloader (different from Apple's BootX) that allows dual-booting Mac OS and Linux on "Old World" machines.

BootX can load kernels from various filesystems: HFS+, HFS, UFS, ext2, and TFTP (network, abstracted to look like a filesystem). In addition to Mach-O, BootX can also load ELF kernels, although Mac OS X does not use this feature. To reiterate, BootX can load ELF kernels from an ext2 partition!

The "Old World" Macs had various issues with the implementation of Open Firmware, which in turn caused many booting problems for Apple engineers, and even more problems for the PowerPC Linux port. Now, Apple had access to the firmware's source. They solved most of the problems either via NVRAM patches, or by integrating required changes into BootX itself (in the instances where the changes could not be implemented as patches). As BootX matured, Apple added support for ext2 and ELF with the goal of making the platform more amenable to PowerPC Linux.

The sequence of events when BootX starts executing (after being handed control by Open Firmware) is described below:

  • BootX first initializes the Open Firmware client interface (that it would use to talk to the firmware), and retrieves the firmware version.
  • It then creates a pseudo-device called sl_words ('sl' implies secondary loader) in the firmware, and defines various FORTH words in it (it is here that code for the spinning cursor is set up).
  • BootX looks up the options device in the firmware, which contains various variables (that you can see and set using the printenv and setenv commands in Open Firmware).

0 > dev /options .properties name options little-endian? false real-mode? false auto-boot? true diag-switch? false ... boot-command mac-boot ...

  • BootX looks up the chosen device, which contains handles for entities such as the boot input/output devices, memory, the MMU, the PMU, the CPU, the PIC, etc. For example, the following command at the Open Firmware prompt shows you the contents of chosen:

0 > dev /chosen ok 0 > .properties name chosen stdin ffbc6e40 stdout ffbc6600 memory ffbdd600 mmu ... ...

  • BootX initializes handles to the MMU and memory using chosen.
  • BootX initializes handles to the boot display and the keyboard (if present).
  • BootX checks if the "security mode" is "none", or
  • BootX checks if the "verbose" (cmd-v) or "single user" (cmd-s) flags were specified, and sets the "output level" accordingly.
  • BootX checks if the system is booting in "Safe Mode".
  • BootX claims memory for various purposes.
  • BootX finds all displays and sets them up. It does this by searching for nodes of type "display" in the device tree. The primary display is referred to by the screen alias. For example, you can try this at the Open Firmware prompt:

0 > dev screen ok 0 > .properties name ATY,Bee_A compatible ATY,Bee width 00000400 height 00000300 linebytes 00000400 depth 00000008 display-type 4c434400 device_type display character-set ISO859-1 ...

  • While opening the display(s), BootX also sets the screen color to the familiar whitish gray.
  • BootX looks up the boot device, boot arguments, etc., and determines where to get the kernel from (via a network device, from a block device, etc.), whence the path to the kernel file (mach_kernel) is constructed. If booting from a block device (which is the usual case), the path to the kext cache (see kextcache(8)) is calculated, along with the extensions directory (usually /System/Library/Extensions).

Mac OS X uses a few kinds of "kext" (kernel extension) caches to speed up loading of kexts. Kernel caches are kept in the directory /System/Library/Caches/com.apple.kernelcaches. The cache files are named kernelcache.XXXXXXXX, where the suffix is a 32-bit adler checksum (the same algorithm as used by Gzip).

  • At this point, BootX draws the Apple logo splash screen, and starts the spinning cursor. If booting from a network device, a spinning globe is drawn instead.
  • Depending on various conditions, BootX tries to retrieve and load the kernel cache file.
  • The next step is to "decode" the kernel. If the kernel header indicates a compressed kernel, BootX tries to decompress it (typical LZSS compression is used, as you compress this kind of data once but expand it many times). Since the kernel binary can potentially be a "fat" binary (code for multiple architectures residing in the same binary), BootX checks if it indeed is (fat), and if so, "thins" it (figures out the PowerPC code).
  • BootX attempts to decode the file (possibly "thinned") as a Mach-O binary. If this fails, BootX also tries to decode it as ELF.
  • If the above fails, BootX gives up, draws the failed boot picture, and goes into an infinite loop.
  • If BootX is successful so far, it saves filesystem cache hits, misses and evicts, sets up various boot arguments and values (such as whether this is a graphical or verbose boot, whether there are some flags to be passed to the kernel, the size of installed RAM), and also calls a recursive function to flatten the device tree.
  • Finally, BootX "calls" the kernel, immediately before which it "quiesces" Open Firmware, an operation as a result of which any asynchronous tasks in the firmware, timers, or DMA get stopped, etc.

System Startup

Mac OS X user level startup is neither pure BSD style, nor SYSV style, although the presence of /etc/rc indicates a BSD heritage. In fact, various things are unsurprisingly similar to NEXTSTEP.

The next section, XNU: The Kernel, describes some of the things the kernel does as it comes up. Mac OS X System Startup continues with a description of (mostly) user-level startup.

BootCache

Mac OS X uses a boot-time optimization (effectively a smart readahead) called "BootCache" that monitors the pattern of incoming read requests to a block device (the boot disk), and sorts the pattern into a "playlist" (it also measures the cache hit rate and stores the request pattern into a "history list" for being adaptive in future).

The loadable (sorted) read pattern is stored in /var/db/BootCache.playlist. Once this is loaded, the cache comes into effect.

Note that this feature requires at least 128 MB of physical RAM before it is enabled (automatically).

/System/Library/Extensions/BootCache.kext is the location of the kernel extension implementing the cache while Contents/Resources/BootCacheControl within that directory is the user-level control utility (it lets you load the playlist, among other things). The effectiveness of BootCache can be gauged from the following: in a recent update to "Panther", a reference to BootCacheControl was broken. BootCache is started (via the control utility) in /etc/rc, and a prefetch tag is inserted (unless the system is booting in safe mode). /etc/rc looks for BootCacheControl in the "kext" directory, as well as in /usr/sbin, and finds it in the former (it doesn't exist in the latter). However, another program (possibly loginwindow.app) accesses /usr/sbin/BootCacheControl directly, and does not find it. For what it's worth, making BootCacheControl available in /usr/sbin, say via a symlink, reduces the boot time (measured from clicking on the "Restart" confirmation button to the point where absolutely everything has shown up on the system menu) from 135 seconds to 60 seconds on one of my machines!

Magical Macintosh Key Sequences

It's pretty sad that there are so many "hidden" things in an OS that's supposed to be so easy to use. I hadn't thought about it before, but the sheer volume of them has surprised me. I knew of the existence of a lot of these shortcuts myself, but I'd never tried to think of them all at once until I started compiling this page. Now that I have many of them in one place (there's more to be added - I think there always will be), I find myself wondering about ease of use. Anyway, enjoy.

http://davespicks.com/writing/programming/mackeys.html

Contents

On Boot
After display of Happy Mac icon
As Finder starts
In Finder
On disk mount
After startup
In the sleep/restart dialog
In other dialogs
On keyboards with a function key
Clicks
Control Strip
 

On Boot

Key CombinationEffect
mouse down Eject removable media ( I think Boot ROMs prior to 2.4f1 excluded the CD drive )
opt Bring up OF system picker on New World machines - boot to 9 on pre-New World machines
F8Bring up Mac OS X boot partition selector (DTKs only?)
cmd-periodWhen OF system picker is active, open the CD tray
cmd-opt Hold down until 2nd chime, will boot into Mac OS 9 ?
cmd-x (or just x?) Will boot into Mac OS X if 9 and X are on the same partition and that's the partition you're booting from.
cmd-opt-n-d prevent native drivers from loading (System 7 until 9.x?)
cmd-opt-shift-delete Bypass startup drive and boot from external (or CD). This actually forces the system to NOT load the driver for the default volume, which has the side effect mentioned above. For SCSI devices it searches from highest ID to lowest for a partition with a bootable system. Not sure about IDE drives.
cmd-opt-shift-delete-# Boot from a specific SCSI ID # (# = SCSI ID number)
cmd-opt-p-r Zap PRAM. Hold down until second chime.
cmd-opt-n-v Clear NV RAM. Similar to reset-all in Open Firmware.
cmd-opt-o-f Boot into open firmware
cmd-opt-t-v Force Quadra AV machines to use TV as a monitor
cmd-opt-x-o Boot from ROM (Mac Classic only)
cmd-opt-a-v Force an AV monitor to be recognized as one
c Boot from CD. If set to boot to X and no CD is present, may boot to 9.
d Force the internal hard disk to be the startup device
n Hold down until Mac logo, will attempt to boot from network server (using BOOTP or TFTP)
r Force PowerBooks to reset the screen
t Put FireWire machine into FireWire Target Disk mode
z Attempt to boot using the devalias zip from first bootable partition found
ctl-cmd-shift-powerReset power manager (with computer off)
shift (Classic only) Disable Extensions
shift (OS X, 10.1.3 and later) Disables login items. Also disables non-essential kernel extensions (safe boot mode)
cmd (Classic only) Boot with Virtual Memory off
cmd-v (OS X only) show console messages (verbose mose) during boot. Also invokes Safe Mode
cmd-s (OS X only) boot into single user mode
cmd-opt-c-i(Mac IIci only) Set date to 20 Sep 1989 to get a graphical easter egg
cmd-opt-f-x(Mac IIfx only) Set date to 19 Mar 1990 to get a graphical easter egg
cmd-opt-shift-tab-deleteErase startup disk under 7.1(?)
Back to Contents
 

After display of Happy Mac icon

Key CombinationEffect
space (Classic only) Invoke Extensions Manager
shift (Classic only) Disable Extensions including MacsBug
shift-opt (Classic only) Disable exetensions, except MacsBug
ctrl (Classic only) Break into MacsBug as soon as it is loaded
Back to Contents
 

At login window

Key CombinationEffect
shift (10.x only) Disable auto-login, forcing login window
 

As Finder Starts

Key CombinationEffect
cmd-opt (whenever Classic Finder sees a new disk) Rebuild Desktop
opt (Mac OS 9) Do not open Finder windows
shift (Mac OS X) Do not launch startup items. Do not open Finder windows when launching Finder. The windows' states aren't changed to closed, as they will be reopened if you reboot again.
shift (Mac OS 9) Do not launch anything from the "Startup Items" folder.
Back to Contents
 

In Finder

opt-click close box (or cmd-opt-w) Close all open finder windows (except popup windows)
cmd-shift-opt-w Close all open finder windows (including popup windows)
cmd-right arrow Open folder in list view
cmd-opt-right arrow Recursively open folder and nested folders in list view
cmd-left arrow Close folder in list view
cmd-opt-left arrow Recursively close folder and nested folders in list view
cmd-up arrowOpen parent folder. On Mac OS X, when nothing is selected and no windows are open, open User directory
cmd-opt-up arrowOpen parent folder, closing current folder
cmd-opt-shift-up arrowMake desktop the active window, select parent volume
cmd-down arrowOpen selected item. On Mac OS X, when nothing is selected and no windows are open, open the desktop folder
cmd-opt-down arrowOpen selected item, closing current folder
cmd-opt-oOpen selected item, closing current folder
opt-double-clickOpen selected item, closing current folder
opt-click(In disclosure triangle) expand or collapse all folders within that window
tabselect next icon alphabetically
shift-tabselect previous item alphabetically
cmd-deletemove selection to trash
cmd-shift-deleteempty trash
spacewhile navigating, opens folder under mouse immediately (with spring-loaded folders enabled)
 
In Finder Window Menu
cmd-selectClose window
cmd-shift-selectPut away popup window
cmd-opt-selectExpand selected window and close all others
ctl-selectExpand selected window and collapse all others
ctl-opt-selectActivate selected window and expand all others
Back to Contents
 

On disk mount

cmd-opt (whenever Classic Finder sees a new disk) Rebuild Desktop
opt (Mac OS 9) Add session numbers (;1, ;2, etc) to ISO-9660 CD filenames
opt (Mac OS X) Show each session on an ISO-9660 CD as a volume
cmd-opt-iForce-mount ISO-9660 partition of a CD, rather than a Mac partition
Back to Contents
 

After startup

Key CombinationEffect
 
On machines with a power key
power Bring up dialog for shutdown, sleep or restart (see next table)
cmd-ctrl-power Unconditionally reboot (sometimes referred to as "control flower power" to easily remember) (dirty reboot - may corrupt disk)
ctrl-cmd-opt-power Fast shutdown
cmd-power Bring up debugger (if debugger installed). Really old macs (mac ii era) needed Paul Mercer's debugger init to do this, then it got folded into the firmware, around 040 timeframe.
cmd-opt-power Put late model PowerBooks & Desktops to sleep
cmd-opt-ctrl-power (PowerBook 500) Reset Power Manager
shift-fn-ctrl-power (PowerBook G3, G4) Reset Power Manager
 
On machines without a power key
ctrl-ejectBring up dialog for shutdown, sleep or restart (see next table)
cmd-ctrl-eject Unconditionally reboot
ctrl-cmd-opt-eject Fast shutdown
cmd-eject Bring up debugger (if debugger installed). Really old macs (mac ii era) needed Paul Mercer's debugger init to do this, then it got folded into the firmware, around 040 timeframe.
cmd-opt-eject Put late model PowerBooks & Desktops to sleep
 
On all machines
cmd-opt-esc Force quit current app
cmd-shift-0 Put late model PowerBooks & Desktops to sleep No longer work in OS X. On Macs with three floppy drives (Mac SE) they eject the third floppy disk.
cmd-shift-1 or 2 Eject internal or external floppy. Not sure which is which on dual floppy machines (Mac SE, Mac II, etc.)
cmd-shift-3 Screen shot
cmd-shift-4 Abstract user defined area screen shot (hold control while selecting to direct it to the clipboard on Mac OS 9)
cmd-shift-capslock-4 (Classic only) User selectable window screen shot
cmd-ctl-shift-3 Screen shot to clipboard
cmd-ctl-shift-4 Abstract user defined area screen shot to clipboard
cmd-ctl-shift-capslock-4 (Classic only) User selectable window screen shot to clipboard (classic only)
cmd-tab Switch apps (possible to change key in Mac OS 8-9)
cmd-shift-tabSwitch apps in reverse order
cmd-space Switch keyboards/script systems (if more than one is installed)
cmd-opt-space switch through all keyboards in keyboards menu
opt-f3, opt-f4 or opt-f5bring up the system preferences (Mac OS X only - maybe powerbooks only? only if system preferences isn't already running)
cmd-f1toggle between video mirroring and extended desktop mode (works on Ti Powerbooks)
opt-f1open the displays preference (10.2 and later)
cmd-f2auto-detect a newly-connected display (works on Ti Powerbooks)
opt-f2open the displays preference (10.2 and later)
opt-f3, f4, or f5open the Sounds preference (10.2 and later)
opt-f8, f9, or f10open the Keyboard and Mouse preference (10.2 and later)
f12Eject CD/DVD (must be held down on 10.1.2 or later). If the device can be dismounted, it is. If not, nothing happens.
f14dim display (cubes/g4 iMacs/others?)
f15brighten display (cubes/g4 iMacs/others?)
cmd-ctl-shift-0Spin down HD (when possible) on machines running OS 9
cmd-`cycle through current application's windows (Mac OS X 10.2 only?)
cmd-~cycle through current application's windows (reverse order) (Mac OS X 10.2 only?)
opt-"Empty Trash"Emptry trash without locked file or contents summary alert. Empties locked items, as well
cmd-opt-D(Mac OS X only) toggle dock
cmd-opt (when opening chooser)(Mac OS 9 only) rebuild chooser cache of printer driver information
 
(See Universal Access System Preference for more on following)
cmd-opt-ctl-8(Mac OS X, 10.2 or later) Turn on "Inverse Mode" via accessbility.
cmd-opt-8(Mac OS X, 10.2 or later) Turn on "Zoom Mode" via accessbility.
cmd-opt-plus(Mac OS X, 10.2 or later) Zoom In via accessbility.
cmd-opt-minus(Mac OS X, 10.2 or later) Zoom Out via accessbility.
Back to Contents
 

In the sleep/restart dialog

Key Effect
S Sleep
R Restart
esc cancel
cmd-. (period) cancel
Return or Enter Shut Down
PowerCancel (9.2.x only?)
Back to Contents
 

In other dialogs

KeyAction
escCancel
command-. (period)Cancel
enterDefault button
returnDefault button (if there are no text fields that use return
cmd-dDon't save (in save/cancel/don't save dialog)
cmd-rReplace (in "Do you want to replace this file" dialog, Mac OS X only)
Back to Contents
 

On keyboards with a function key

Key Combination Effect
fn-backspace forward delete
fn-left arrowhome
fn-right arrowend
fn-up arrowpage up
fn-down arrowpage down
Back to Contents
 

Clicks

click / modifierEffect
option-click in another applicationSwitch to that application and hide previous app
cmd-drag (window)Drag window without bringing it to front (requires application support to work behind dialogs)
cmd-drag (window background)Pan contents of window with hand (Finder)
cmd-opt-drag (window background)Option may be needed to pan contents of window with hand (Finder) on 10.3 and later
cmd-drag (Mac OS X)Rearrange menu extras
opt-drag (file)Copy file
cmd-opt-drag (file)Make alias of file
cmd-click window titlePop-up menu showing path to current folder/document (in some applications)
option-windowshadeWindowshade all windows of application (classic only)
option-zoomZoom window to full-screen
option-yellowDock all windows of application (Mac OS X only)
option-greenZoom window to fill screen (in some applications)
 
Mac OS X only - items in dock
cmd-clickReveal in Finder
cmd-opt-clickActivate app and hide other apps
ctl-click (or click and hold)contextual menu
cmd-drag into dockFreeze current dock items from moving so icon can be dropped onto an app
cmd-opt-drag into dockForce application you're dropping onto to open dropped item
Back to Contents
 

Control Strip

opt-drag control strip Move control strip
opt-drag CS module within stripreorders CS modules
opt-drag CS module to trashuninstalls a module
opt-drag CS module elsewherewhatever dragging the module file itself would
Back to Contents

Friday, June 1, 2007

Mac版的FileZilla

FileZilla最新的版本(3beta)已经增加了对mac的支持:

http://sourceforge.net/project/showfiles.php?group_id=21558&package_id=206762

添加afp的share point

在xserve1上添加一个share point:

sudo sharing -a /Applications/Gate
sudo sharing -e Gate -g 100

name:           Gate
path:           /Applications/Gate
        afp:    {
                name:   Gate
                shared: 1
                guest access:   1
                inherit perms:  0
        }
        ftp:    {
                name:   Gate
                shared: 1
                guest access:   0
        }
        smb:    {
                name:   Gate
                shared: 1
                guest access:   0
                inherit perms:  0
                oplocks:        0
                strict locking: 0
                directory mask: 493
                create mask:    420
        }


重启xserve1后,在xserve2上mount:

 mount_afp afp://xserve1.local/Gate /Volumes/Gate/