Wednesday, May 30, 2007

MAC上使用automount自动加载网络文件夹

1. 使用Login Items in the Account section of System Preferences

"Adding a volume to your startup items used to work, but I think that
was back in the days of 10.1. It has since stopped working with 10.3
and 10.4 at least"

An AppleScript to mount:

mount volume "afp://username:password@servername/volume"

Save it as an application and put into Login Items.

2. 使用NetInfo,

Static vs. dynamic mounting

When you mount a sharepoint statically, it is mounted during startup
and available immediately when you click on its icon. You can assign
statically mounted sharepoints specific directories within the
/Network directory (that blue globe you see sitting next to all the
other volumes on your system). Dynamic sharepoints always reside in
/Network/Servers/server_name. They do not actually mount when the
computer is started up, instead, they mount on the fly when you
request information from them (e.g., when you double-click on its
icon). Static sharepoints have the advantage of being assigned to
specific directories within /Network and being available immediately.
Dynamic sharepoints have the advantage of using less server resources
when the sharepoint is not being used. Apple recommends having User
home directories served on dynamically mounted sharepoints, while
statically mounting other resources, such as a Library folder.

Here's what to do

1. Launch NetInfo Manager; it is located in the
/Applications/Utilities folder.
2. Authenticate by clicking on the lock in the lower left corner.
3. Click on the /mounts directory.
4. Click on "New+" icon. An item named "new_directory" will appear.
5. Double-click on the value "new_directory" for the "name"
property and change it to "servername:/sharepoint". You can use the IP
address, the hostname or the fully qualified hostname in place of
servername.
6. Select "New Property" from the "Directory" menu. Set the
property name to "vfstype". Set the value to "url" if this is an AFP
sharepoint or "nfs" if this is an NFS sharepoint.
7. Skip this step for statically mounted NFS sharepoints.
Otherwise, select "New Property" from the "Directory" menu. Set the
property name to "opts". If this is a dynamically mounting NFS
sharepoint, set the value to "net". Follow the instructions below for
static and dynamic AFP sharepoints:

Special steps for AFP sharepoints only:

+ Set the "opts" value to:
url==afp://;AUTH=NO%20USER%20AUTHENT@servername/sharepoint

+ If this sharepoint will mount dynamically, click on the
opts property and select "Insert Value" from the "Directory" menu. Set
the value to "net".

8. Select "New Property" from the "Directory" menu. Set the
property to "dir". If this sharepoint will mount dynamically, set the
value to "/Network/Servers/". If this is a statically mounted
sharepoint, set the value to "/Network/sharepoint".
9. Select "Save Changes" from the "Domain" menu and restart the
computer. Verify that the sharepoint mounted correctly in the
appropriate location in the /Network directory.

Alternatively, you can use the application SharePoints AutoMounter to
setup these settings, though it only sets up dynamic mounts.

Note that you must have guest access enabled on an AFP sharepoint in
order to automount it. See the Mac OS 10.2 Server Administrator's
guide for more details on setting up sharepoints.

Tuesday, May 29, 2007

在Mac上使用NFA

第一步:启动NFS Server

The tools to get NFS up and running are built-in to every copy of Mac OS X but their configuration can be a little arcane, so I'm going to describe how NFS can be set up using a little utility called "NFSManager" by Marcel Bresink. NFSManager comes in the form of an 826KB download, and the demonstration version of the program is fully functional.

本地下载:NFSManager.dmg

Perhaps Marcel's own description best describes what NFSManager is and does:

NFSManager is a small tool for easy access to the NFS features of Mac OS X. As an operating system with a Unix core, Mac OS X is able to support the Network File System (NFS) protocol according to internet specification RFC 1094. NFS is the accepted industry standard for sharing files between Unix systems.Although NFS is a built-in component of Mac OS X, users cannot access this feature without special knowledge and use of the command-line. NFSManager solves this problem by providing an easy-to-use Aqua interface for the definition of NFS connections.

There are two pieces of NFS terminology that we'll need to be familiar with before we continue: "mounts" and "exports". Mounts are folders or files that we retrieve from other machines on the network and which we access from the local machine. To create and use mounts we will be using an NFS client. Exports are folders or files that we make available to other machines on the network. To create and share exports we will be using an NFS server. Both client and server are included with Mac OS X.

Setting up an export

Setting up an export is quite easy with NFSManager. After clicking on the padlock and entering our administrator password we just use the "Add" button under the "Exports" pane. Most of the options in the ensuing dialog are self-explanatory. We select the item that we wish to share across our network. We can choose to make it available to any machines (this is called sharing with the "world") or we can specify particular machines or subnets. We can also opt to change the user access privileges by granting root access (universal, read-everything privileges) or running as user "nobody" (for restricted access privileges). We can grant write access if we so desire, or keep things "read only". Finally we can export entire filesystems at a time if we wish.

Once we've set things up we just close the export window and save the changes.

Setting up a mount

Establishing a mount is much the same as creating an export. We once again use the "add" button, this time under the "Mounts" pane. Under "Directory to import" we enter a description of the server and share that we wish to mount of the form: "server:/share". As an example, if I want to share the "/home" directory from an NFS server on my network located at "192.168.0.1" then I will enter the following string in the space provided:
192.168.0.1:/home

There are two ways of setting up mounts. If we set them up using the "Display as server connection" option then we'll have to reboot in order to see them. They will appear in the Finder under "Network/Servers". Alternatively, we can specify "Static Mounts" and these will appear without a reboot. In this case we need to specify a path were we wan the files to appear. The default path is "/mnt".

Conclusion

Once you've set up your mounts and exports you need only select "Activate changes" from the NFS menu in NFSManager. Your static mounts and exports will become instantly available. It's beyond the scope of this article to talk about how to set up other Unix boxes on your network -- the steps required will vary depending on the OS in use; Linux, FreeBSD, Solaris, or others.

It is quite easy nevertheless to test out your Mac OS X setup by connecting to another Mac OS X machine nearby, or easier still, by using the "localhost" feature of Mac OS X. Using this feature you can run an NFS server on your own machine and connect to it from that same machine by specifying "localhost" as the server when preparing a Mount. For example, in testing my own machine I exported my "Library" folder and then mounted it over NFS by specifying "localhost:/Library" when I added the mount. Having verified that this was working I was then able to go to another machine on my network -- a FreeBSD server -- and mount the Library folder on that machine too.

Thanks to the power of NFS, Mac OS X is interoperable with an entire flotilla of Unix operating systems in a way that was never possible under Mac OS 9. Steve Jobs's announcement that SMB capabilities will be built into Mac OS X 10.1 is another critical support in making Mac OS X the most advanced operating system in the world today. And all this from an operating system that is still in its beginning stages -- imagine what we'll be able to do five years from now...

Above from: http://www.macobserver.com/tips/hotcocoa/2001/20010723.shtml

Another useful link: http://mactechnotes.blogspot.com/2005/09/mac-os-x-as-nfs-server.html

AFS不是AFP

什么是AFS文件系统?

  .AFS Andrew File System的缩写,他是一种分散式的文件系统( Distributed File System)可以将分散在不同机器上磁盘空间组合成一个共有的磁盘空间,让使用者能够在不同的机器上使用相同的文件系统来管理自己的文件 .

 

AFS 的运行模式

  .AFS 采用C/S(Client/Server)的工作模式,Client 发送请求到Server提取文件,Server Machine 提供文件给请求的Client

 

   Client Machine上的某个Porcess第一次需要某个文件资料时 ,Client Machine上的一个名叫Cache Manager Process,便会负责找出存放有该文件的Server(他会从 CellServ配置文件中找到 VLDB服务器,在经由 VLDB找到相应文件存放的Server), 使用 RPC通信协议来取回文件存储于自己的Cache中,之后就可以直接读写于 Cache中的资料了,这期间Cache Manager会适时的和 Server Machine通信来更新资料,有了Cache Manager的帮助使得网络的负荷减轻,因为当我们读写一个在其他机器上的资料时,不再需要每次都经由网络去读取,而由 Cache Manage判断在Cache 的资料是否和Server Machine上所存的相同,若相同,就直接使用Cache 上的资料, 如此一来 节省了部分读取文件时所需要的传送,更减少了原本Server 上的磁盘I/O负荷。

 

OpenAFS 基本原理

   OpenAFS 试图免除安装和管理用于使不同文件系合作的的痛苦。OpenAFS 也能使不同文件系 更有效地合作。尽管 UNIX 及其引人注目的后 Plan 9 的最初目 是文件,但是商业现实指出,与其底重构代的网 文件系 ,不如添加另一个分布式文件系统层

1983 Carnegie Mellon University 程人 员开发 AFS。此后不久,大学成立了一家叫做 Transarc 的公司来出售基于 AFS 的服1998 IBM Transarc,并使 AFS 一个放源 码产品,叫做 OpenAFS。但是,故事并未就此束,因 OpenAFS 衍生了其他的分布式文件系,如 Coda Arla 些我将在后面到。存在 针对所有主要操作系的各 机,及大量的过时文档 料。Gentoo.org 使 OpenAFS Linux 可用做出了特 别贡献,即使其他机构在需要分布式文件系统时似乎仍然是指 NFS

 

OpenAFS 如何行管

    NFS 是位置无的,它把本地目 映射到 程文件系位置。OpenAFS 户隐 藏了文件位置。因可能所有的源文件都以写副本的形式保存在制到的不同文件服 器位置上,必 保持制的副本同此要使用一 称作 Ubik 的技 ,它源于单词"ubiquitous (无所不在)",是欧拼写法。Ubik 程使 AFS 文件系上的文件、目和卷 (volume) 保持同,但是通常运行三个以上文件服程的系统获 益最多。系管理人可以将一个 AFS 站点的几个 AFS cell ―― 个以前的 AFS 被保留在 OpenAFS 文件系语义中了。管理人将决定 AFS cell 的数目,以及 cell 使存器和文件 站点内的其他 AFS cell 可用的程度。

 

AFS 中的几个名词解释

     Cell:一个管理单元,由一个Group 或一个管理单位所负责管理建筑的基本单元,通常是由许多文件及目录所组成的一个结构,不同的Cell可以组合成为一个 AFS File Space

通常是一个主服务器和几个附加服务器组成一个Cell 每个Cell共用自己的VLDB

 

    Partition :一般常使用电脑的人,对于硬盘上的Partiton一定不会陌生,对于一个分散文件系统而言,这个系统管理既然是文件,必会和硬盘扯上关系,使得 AFS对于硬盘同样可以分Partition ,但是AFS中的分区必须是/vicepXX 这样的形式 XX可以是 a-zz中的任意组合或单个字母。

 

    Volumes :在每个Partition上可以再分更小的单元,我们称之为Volumes ,对于使用者而言,并不需要太注意Volumes到底是做什么的,因为使用者使用AFS ,只是想好好好使用自己的文件,而不必要理会Volume或者Partition ,这两者都只是AFS对于硬盘空间的管理,适用者所需要的AFS 的系统管理都已经帮你弄好了

AFS 管理人 cell 划分 然卷可以随硬分区 (co-extensive),但大多数管理人都不会将整个分区只分一个卷。AFS 实际上是由一个 独的、称作 Volume Manager UNIX 型的程管理的。您可以以一的方式从 UNIX 文件系安装卷。但是,您可以将 AFS 卷从一个文件服器移 到另一个文件服 ―― 是由一个 UNIX 型的程来管理的 ―― 但是 UNIX 不能从一个分区实际地移 到另一个分区上。AFS Volume Location Manager 跟踪卷和目的位置,并留意制的卷和目。因此, 当文件服 器非期地停止操作,用 根本无需担心,因 AFS 会把用到另一个文件服器机器上的 制卷,而用 可能都不会注意到。

从来不 AFS 器上的文件行操作。他操作已 由客存管理器从文件服 器中取出的文件。Cache Manager 是居留在客机操作系 内核中的一只非常有趣的猛 。(您可以在 2.4 版本以上的任何内核中运行 Cache Manager)。

 

 

Mount Point:分散文件系统的最大特色是,不需要专门的指定一部机器作为文件的存储,相反的,任何一部机器都可以使存储文件的 Server,也可以成为提出要求存取某个文件的Client ,那么,文件都分散存储在不同的机器上,使用者要如何存取它所需要的文件呢?

前面提过Volume 的概念,让我们从Volume的概念出发,各位可以将 Volume视做一个箱子,负责存一个目录文件,当你下达了CD 命令更换目前所在的目录,有两种情况会发生,第一种情况是,所更换的目录仍在同一个Volume,第二种情况是,需要换到另一个 Volume中,此时便需要一个指标来指示,所要更换的目录是在哪一个Volume ,好到该Volume所在处取出该 Volume的资料,这个指标便成为Mount Points

    简单一点来说, AFS系统是利用Mount Points 的概念,不漏痕迹的取回使用者所需要的文件或目录资料

 


AFP:档案分享协议 (Apple Filling Protocol)

它是 Apple 主要用来进行网路上档案分享的专有网路通讯协定。它基于 ASP 顶层,其主要为认证用户和 Macintosh HFS 文档系统提供服务。


The Apple Filing Protocol (AFP) is a layer 6 ( presentation layer) network protocol that offers file services for Mac OS X and Classic Mac OS. In Mac OS X, AFP is one of several file services supported including Server Message Block (SMB), Network File System (NFS), File Transfer Protocol (FTP), and WebDAV. It currently supports Unicode file names, POSIX and access control list permissions, UNIX quotas, resource forks, named extended attributes, and advanced file locking. In Mac OS 9 and earlier, AFP was the primary protocol for file services.

Monday, May 28, 2007

一篇比较Mac的BT软件的文章

The number of user-friendly, appealing BitTorrent clients available for the platform are very few in comparison to the number of those available for Windows.

In this article we will highlight the most popular Mac BitTorrent applications and compare their features.

Mac OS X is heralded as the most appealing operating system on the market and one of the most capable as well thanks to its BSD (Unix) core.
Sadly, the number of user-friendly, appealing BitTorrent clients available for the platform are very few in comparison to the number of those available for Windows.

In this article we will highlight the most popular Mac BitTorrent applications and compare their features.

BitTorrent OSXLet's start with the granddaddy of them all, Bram Cohen's self-titled BitTorrent application. It's gotten kind of confusing since he named the protocol, his company and his application all BitTorrent. BitTorrent OSX is a very (and I mean very) basic application. It's as feature-full as Safari's download box and that's not saying much. Now some people wouldn't mind something like that, but if you're looking for simplicity Transmission is a much better choice. BitTorrent OSX also takes an age to start up on my MacBook Pro.

Transmission is my current Mac B.T. client of choice. Transmission It's an Open Source project, maintained by the developer of the popular Mac DVD ripping application, HandBrake. Transmission does its job well. A neat feature it offers is the ability to view download and upload rates in the dock, so I don't even have to open up the program to check how my downloads are going. Another great thing Transmission does is copy the .torrent file to its support folder, then trash the original file from my desktop thereby leaving no mess of files behind for me to clean up. Now just like everything Transmission has its flaws, the biggest of which is that Demonoid, a leading BitTorrent directory has banned it on ocassion! They say it doesn't adhere to set standards.

AzureusAzureus is a cross-platfrom BitTorrent client written in Java. It's slightly slower than all the other native Mac B.T. applications, but has features none of the others can boast of. Therefore it remains one of the most popular clients, even on the Mac. The one reason I have both Azureus and Transmission installed at any given time is because Transmission doesn't allow me to select which files I want from a particular torrent. We call the feature 'Selective Downloading' and Azureus is sadly the only popular Mac B.T. client that lets me do that! There are also a number of great plug-ins for Azureus that let you do all sorts of things like subscribe to RSS feeds with .torrent enclosures.

Tomato Torrent Tomato Torrent is a very plain alternative, seriously lacking in eye-candy and begging for a new icon (and maybe a new name too). It's based on the official BitTorrent client. I think it desrves a mention because I know a few people who swear by it. It comes with an AppleScript file that you can place in folders you want to download to. When you want to download a torrent to a specific folder, you just drag the .torrent file onto the piece of AppleScript to initiate the transfer. One pro is that it's an extremely light client that hogs very little RAM. It's the closet thing to uTorrent on the Mac.

Bits on Wheels Bits on Wheels is a slightly out-dated (last updated Sep. '05), yet popular Mac BitTorrent client. It claims to be "the first 100% native BitTorrent client for the Macintosh" as it is written in Objective-C and Cocoa.

Bits on Wheels is freeware but not Open Source. One of its main features is a visual 3D Swarm with which you can observe what's actually going on under the hood, how many seeders and leechers you're connected to and the bits transferring between everyone. Bits on Wheels is very OSeXy (heh!), it's how I'd imagine the default OS X BitTorrent downloader to look if there was one. bits on wheels sawrmIf not to use the first native OS X B.T. client, I'd download it just to fly around in 3D chasing bits.

Conclusion
Clearly, feature-wise Azureus is the winner. Bits on Wheels and Transmission are both great alternatives to BitTorrent OSX. If only Bits on Wheels would be updated more often and Transmission become standards-compliant and both of them allow Selective Downloading, they might start taking back some market share. And lets not forget the light weighted tomato. Tomato Torrent could use a few more features and better interface, but it too is a great BitTorrent client.

Worthy Mentions
AcquisitionAcquisition is a Mac p2p program like Limewire that accesses popular file-sharing networks like Gnutella to search for files. It also doubles as a BitTorrent client. Although I have never been able to achieve superior download speeds that I do with Transmission or Azureus, it's iTunes-integration is sweet.

From version 9 Opera the popular cross-platform browser has implemented a simple, built-in BitTorrent client. It's supposedly "targeted at novice users."

.torrents are OSeXy.

http://torrentfreak.com/mac-bt-clients/

Thursday, May 17, 2007

Install X11 in xserve1 在服务器上安装x11

xserve1上安装的是Mac OS X Server 10.4.9,但是没有X11,所以想装一个。

下载了X11User.pkg,但是运行的时候提示已经有更新的版本安装了,但是怎么搜索系统也找不到X11。

一个解释说,Panther X11是基于Xfree86 4.3.0,而Tiger X11是基于Xfree86 4.4.0,如果下载的X11User.pkg是Panther版本的话,就会有这个问题。

解决办法:只能从Tiger的光盘安装,而不能通过下载。

Tuesday, May 15, 2007

从xserve1连到其他xserve

1. ssh到xserve2

2. 打开xserve2的ARD/VNC:
 Activate Remote Desktop Sharing, enable access privileges for all users, restart ARD Agent:
$ sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -activate -configure -access -on -restart -agent -privs -all

3. 把vncpasswd.pl通过sftp传到xserve2

4. 运行 perl vncpasswd.pl mypasswod 生成命令,运行

5. 重启:sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -restart -agent

6. 在xserve1上运行Chicken of VNC, 用10.0.0.2登陆xserve2

Thursday, May 10, 2007

给mac装一个sha1sum工具

下载:http://www.microbrew.org/tools/md5sha1sum/

本地:


$ setenv CC "/usr/bin/gcc"
$ ./configure
$ make

然后在当前目录下出现可执行文件 md5sum和sha1sum,而后者实际上是一个指向前者的link。。。但运行两个程序得到不同的结果,都是正确的。。。

Mac OS X的启动【转载】

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!

<<< Architecture of Mac OS X

NetInfo手册

NetInfo的使用与管理手册:UnderstandingUsingNetInfo.pdf

Wednesday, May 9, 2007

Mac里的用户及其他

There are multiple user accounts in every UNIX system. Most of these accounts are associated with actual, human users. For example, you created an account when you supplied a username and password upon installing Mac OS X. Every process and application is associated with a user. So when you start an application after logging in, that application will be associated with your username.

UNIX systems also have accounts that are not associated with any person logging into the system; rather, they are built into the system. Five accounts are installed by default in Mac OS X: daemon, nobody, root, unknown, and www. To understand the full significance of these accounts, you'll need to understand UNIX permissions, which will be discussed shortly. For now, keep in mind that www is the account used by the built-in web server, unknown and nobody provide minimal permissions, and daemon runs system services that need some permissions.

The root account is very special — it has no restrictions. Any application or process running with the privileges of the root user can read, write, or delete any file on the system; stop or start any application on the system; or do anything else it pleases. There is nothing the root user cannot do. Consequently, guarding access to the root account is very, very important.

In addition to users, UNIX has a concept of groups. A UNIX group is a collection of individual accounts. In the UNIX file permission scheme, which will be discussed shortly, you can grant permissions to a group. This provides a way of allowing a selected set of users to have identical access to files, directories, and applications, while denying access to other users. Individual user accounts belong to a default group and may be given membership in other groups.

If you've worked with file sharing in previous versions of the Mac OS, what you've read so far about users and groups should be familiar. Like the older versions of Mac OS, each object in UNIX systems (a file or folder) is owned by a user and is associated with a group. For each object, specific permissions can be granted to the owner, to the group, and to everyone else.

There are three basic permissions: read, write, and execute. The meanings of read and write are fairly straightforward; execute, however has different meanings depending on whether the object is a file or a directory. For a file, execute means the file is executable (that is, it's an application or a script), but if the object is a directory, execute means that the class (owner, group, or everyone) has permission to search the directory.

You can view the permissions associated with any file by opening up the Terminal application and using the ls command.

G4-OSX 1% ls -Fla
total 32
drwx------ 9 eric users 512 Mar 1 15:01 ./
drwxr-xr-x 16 eric users 2048 Mar 11 18:06 ../
drwxr-x--- 3 eric users 512 Jan 12 13:02 Apple/
drwxr-xr-x 2 eric users 512 Feb 19 15:15 OpenBSD/
-rw-r--r-- 1 eric users 2525 Mar 1 15:01 file_listings
-rw-r--r-- 1 eric users 2408 Mar 1 15:00 file_listings.2
lrwxr-xr-x 1 eric users 15 Jan 12 12:54 symbolic_link_example@ -> Apple
drwxr-xr-x 3 eric users 512 Feb 4 11:22 foobar/
drwxr-xr-x 2 eric users 512 Jan 18 18:02 honeynet/
drwxr-xr-x 3 eric users 512 Feb 2 13:56 ipf_howto/
drwxr-xr-x 3 eric users 512 Feb 16 23:20 upgrades/
G4-OSX 2%=20

The collection of letters and hyphens furthest to left indicates exactly what each element is and the permissions for that element. The first column of each line indicates the element's type: d for directory, - for a regular file, and l for a symbolic link, which is essentially the same as an alias in Mac OS 9.x. The next three columns (rwx) show the permissions for the owner, the next three for the group associated with the file, and the last three for everyone. A - in any position indicates a lack of that permission. For example, rw- indicates read and write permissions, but no execute permission, and r-x indicates read and execute permission, but no write access.

For the third listing above (Apple/), you can look at the permissions (drwxr-x — -) and know that this is a directory (the first letter is d) that has read, write, and execute permissions for the owner ( rwx), read and execute permissions for the group (r-x) and no permissions for everyone ( — -).

The owner (eric) and the group (users) are both shown here, as well as the file size in bytes, the last modified date, and the filename. Also shown are the current directory (symbolized by a single dot) and the parent directory (symbolized by two dots).

UNIX Networking

UNIX systems are designed to be used in network environments. Frequently, UNIX systems host network services, such as Web servers, file sharing, and database servers. Although there's no need to run these services on your Mac OS X box, you do have the option. You can run, for example, the Apache Web server with PHP and Perl and the MySQL database server in your development environment.

UNIX systems natively speak the various protocols of what is commonly referred to as the TCP/IP suite. Each network service will be associated with the IP address assigned to your machine. Additionally, each service will be associated with a TCP or UDP port. Ports are a feature of TCP and UDP that allow many processes on a single host access to TCP and UDP services simultaneously. Ports are numeric in the range of 1 to 65535, some of which are, by convention, assigned to specific services. For example, the HTTP services is commonly assigned to TCP port 80. There are a number of such assigned ports, but there are a far greater number of unassigned ports — that is, ports that are not commonly bound to a service or application.

The combination of an IP address and a port makes a socket, and a pair of sockets define a connection. Applications that provide network services listen for connections on a socket. For example, a secure web server commonly listens on the socket formed by the IP address of the server and TCP port 443.

The more sockets that are active on your machine, the greater the opportunity for an intruder to break into your box. More on this later.


What Are All Those Processes?

Mac OS X: What Are All Those Processes?

A short list of background processes and daemons

By Gordon Davisson

Copyright (c) 2005, Westwind Computing inc.

Mac OS X (like any unixish OS) always has a number of things going on in the background -- processes that take care of business behind the scenes. Normally, you won't even notice them, unless you use something like Activity Monitor (ProcessViewer under 10.2 or before) or the ps or top commands to look at the process list. If you do notice them, you may wonder what on earth they're all there for. This list is here to answer that question.

Note: this list is far from complete. If you see processes on your Mac that aren't on this list, it doesn't mean there's something wrong or that you've been hacked; just that I'm not as dilligent as I could be in maintaining the list.

System Processes (mostly owned by root):

Process Its function
AppleFileServer The personal file sharing (AFP over IP) server. It should only be present if file sharing is enabled (in the System Preferences' Sharing pane).
autodiskmount Responsible for mounting removable disks and media.
automount Automatically mounts and unmounts network (NFS and AFP) file systems as they are accessed / left idle.
configd Maintains dynamic configuration information about the computer and its environment (mainly the network).
CrashReporter Logs information about program crashes. It can be configured (via editing /etc/hostconfig in OS X 10.0, and the Console utility's preferences on OS X 10.1) to log crashes in ~/Library/Logs.
cron Runs various scheduled programs and scripts, mostly to perform perodic maintenance on the computer. Note: in Mac OS X, this is set to run system maintenance late at night; if the computer is turned off every night, the maintenance may never get done. Either leave the computer on overnight occasionally, or use something like Brian R. Hill's program MacJanitor to perform maintenance manually. In Mac OS X 10.4 it was mostly replaced by launchd, but is kept around for compatibility.
DirectoryService This process acts as a central clearinghouse for "Directory" information -- mainly users/groups/authentication, and service location (e.g. file servers, printers, etc). It gathers information from a variety of plugins (NetInfo, LDAP, Active Directory, NIS, Bonjour/Rendesvous/, AppleTalk, SMB) and hands it out to whatever program requested it.
DesktopDB Keeps track of information on currently known applications and their document types. Used by the Finder to associate documents with the appropriate application.
distnoted Provides distributed notifications services.
dynamic_pager Assists the kernel with managing swap files for virtual memory.
ftpd Handles incoming FTP (File Transfer Protocol) connections. This process is created dynamically by xinetd (or inetd in earlier versions of OS X), so it should only appear when someone is actually connected to your computer.
httpd This is Apache, the web server that ships with OS X. It should only be present if web sharing is enabled (in the System Preferences' Sharing pane). It is normal for there to be several of these running, one owned by root, the rest by www.
init (10.0-10.3 only)
The master of the computer from the BSD/unix point of view. This is responsible for creating (via the /etc/rc* scripts and StartupItems) and looking after many of the other background processes. In Mac OS X 10.4 it was replaced by launchd.
inetd (10.0-10.3 only)
Responsible for starting and looking after some internet services (mainly FTP and telnet) provided by this computer. As of version 10.2 this was functionally replaced by xinetd (which was then replaced by launchd), but was kept around through Mac OS X 10.3 for compatibility.
ipconfigd (10.0-10.1.1 only)
Automatically configures the network. Now merged into configd (since OS X 10.1.2, if I'm reading right).
KernelEventAgent Handles notifications about file system status (e.g. "A server you are using is no longer available. Do you want to continue trying to contact it?" and "Your startup disk is almost full. You need to make more space available on your startup disk by deleting files.")
kextd Responsible for loading and unloading kernel extensions (e.g. device drivers) as they are needed.
launchd (v10.4 and later)
This process replaces init and mach_init, and takes over most of the functions of cron and xinetd.
lookupd Handles looking up information from network information services such as NetInfo and DNS, and acts as a bridge to allow unix/BSD/posix programs to get information from DirectoryService.
mach_init (10.0-10.3 only)
The Mach kernel's bootstrap port server. This is the first process created during bootup, and creates the BSD init process (which then creates everything else). In Mac OS X 10.3, it's also used to create several daemons that used to be created via StartupItems. In Mac OS X 10.4, it's replaced by launchd.
mDNSResponder The multicast DNS (a component of Bonjour/Rendezvous) responder; this advertises network services (such as AFP file sharing) provided by this computer, as well as the computer's self-chosen ".local" name.
Note: this runs under the pseudo-user "nobody" (presumably for security reasons).
netinfod Serves out NetInfo data. There will be one of these processes for each NetInfo domain served from the computer (normally just one, for the local domain). ProcessViewer/Activity Monitor won't tell you which daemon process serves which NetInfo domain, but the ps command will.
nfsiod Services asynchronous requests to an NFS server. It is normal for there to be several of these.
nibindd Finds, creates, and destroys NetInfo servers (i.e. netinfod). This process will only exist if you have something beyond the standard local NetInfo domain set up.
notifyd Passes event notifications between processes.
ntpd Synchronizes the Mac's clock with network time servers.
pitond The Retrospect backup client (only present if you've installed Retrospect Client).
pmTool This is actually a user process that happens to run as root. Activity Monitor uses it to collect information on running processes.
portmap Dynamically assigns RPC (network Remote Procedure Call) services (such as NetInfo and NFS) to TCP/UDP ports.
slpd The Service Location Protocol (SLP) responder; this advertises network services (such as AFP file sharing) provided by this computer. SLP has been functionally replaced by Bonjour/Rendezvous, but is kept active for compatibility with older computers on the network.
slpdLoad This process frequently shows up as a Zombie in ProcessViewer's listing (with semirandom owner, parent, and statistics) under early versions of OS X. Don't worry, it's harmless, just a little confused.
(More technically: a zombie process is one that has finished (i.e. died), but whose parent process has not received notification of its death. In order to keep process information around until the parent process is notified, the zombie's entry is left in the process table even though the process itself is gone. A bit morbid, perhaps, but since it doesn't consume resources, it's not really a problem.)
sshd The secure shell server -- listens for and handles incoming SSH (encrypted remote login) connections. It was added in version 10.0.1 and should only be present if "Allow remote login" is enabled (in the System Preferences' Sharing pane).
Note: In 10.3, sshd no longer runs continuously to listen for incoming ssh connections. Instead, xinetd (v10.3) or launchd (v10.4) does the listening, and only starts sshd when it's actually needed.
syslogd Logs and/or dispatches system status and error messages.
telnetd Handles incoming telnet (remote login) connections. It's enabled by the "Allow remote login" option in the System Preferences' Sharing pane of Mac OS X 10.0; in later versions it's disbled, and SSH is used instead (although telnetd can be reenabled manually by editing the /etc/inetd.conf file). This process is created dynamically by inetd, so it should only appear when someone is actually telnetted into your computer.
update Responsible for keeping disks synchronized with the file system cache, to keep data loss to a minimum in case of a crash.
xinetd Responsible for starting and looking after some internet services (mainly ssh, FTP and telnet) provided by this computer. This is essentially an extended version of inetd. In Mac OS X 10.4 it was mostly replaced by launchd, but is kept around for compatibility.

User processes (generally owned by the current user):

Process Its function
ATSServer The Apple Type Solution Server; responsible for managing the available fonts and making them available to applications.
Dock Maintains and displays the Dock.
DocklingServer Keeps docklings' status and displays up to date.
Finder The Finder.
hdid Handles mounted disk image (.img and .dmg) files.
LaunchCFMApp Applications in the old-style Macintosh format (Code Fragment Manager format, aka CFM, aka PEF) will show up in Process Viewer under this name. LaunchCFMApp is actually a wrapper program provided for compatibility with this old application format; Process Viewer just can't see through the wrapper to the actual application inside.
(Note: the distinction between the old (CFM) and new (mach-o) formats is not the same as the distinction betweem the old (Carbon) and new (Cocoa) application environments. Many of the Carbon apps you're likely to run into on OS X are in mach-o format.)
loginwindow This is only partly a user process -- it starts before anyone logs into the computer, and is responsible for displaying the login screen (or not, if autologin is set), validating login attempts, and setting up the user environment (launching the Finder, Dock, any login apps, etc) at login. It also acts as a process monitor for user processes, restarts the Finder or Dock if they crash, and implements the Force Quit Applications window. Finally, it handles the logout, restart, and shutdown procedures.
pbs The pasteboard server; analogous to the clipboard under Mac OS 9.
pmTool a background process that Activity Monitor uses to collect information on running processes.
Note that this process runs as root (despite being part of a user-level program).
SystemUIServer (OS X 10.1 and later)
Maintains the Menu Items in the right end of the menu bar.
TruBlueEnvironment
or "(null)"
The Classic (OS 9 compatibility) environment. This single process includes OS 9 and all running classic applications. The name derives from an early Apple code-name for the Classic environment: "the Blue Box".
For some reason, Activity Monitor (under Mac OS X v10.3) has trouble reading this process's name, and tends to display it as "(null)".
WindowServer (aka Window Manager) Responsible for managing the computer's display and mediating between the various Applications and other processes that want to display information on it. It also does the grunt work of launching new user applications, so most user processes are actually its children in the process hierarchy.
http://www.westwind.com/reference/OS-X/background-processes.html