硬盘布局与引导

FILE SYSTEM

A Linux filesystem contains files that are arranged on a disk or other block storage device in directories. As with many other systems, directories on a Linux system may contain other directories called subdirectories. Unlike a system such as Microsoft® Windows® with a concept of separate file systems on different drive letters (A:, C:, etc.), a Linux filesystem is a single tree with the / directory as its root directory.

You might wonder why disk layout is important if the filesystem is just one big tree. Well, what really happens is that each block device, such as a hard drive partition, CD-ROM, or floppy disk, actually has a filesystem on it. You create the single tree view of the filesystem by mounting the filesystems on different devices at a point in the tree called a mount point.

一个Linux文件系统包含包含被安排在磁盘或者其他块存储设备目录里的文件,像很多其他的系统一样,Linux系统上的目录可能包含其他的目录,被称作子目录。一个Linux文件系统是一棵树把/目录作为它的根目录,而不像如微软Windows的以不同的驱动器字母(A:,C:等等)来分割文件系统的思想。

你可能惊讶如果文件系统只有一棵大树为什么硬盘布局还是重要的,好,实际的情况是像硬盘分区,CD-ROM或者软驱每一个块设备都有一个文件系统。通过将不同设备上的文件系统 挂装(mounting) 在树型结构中的某一个叫做挂装点(mount point) 的点上,就创建了文件系统的单一树型视图。

Usually, the kernel starts this mount process by mounting the filesystem on some hard drive partition as /. You may mount other hard drive partitions as /boot, /tmp, or /home. You may mount the filesystem on a floppy drive as /mnt/floppy, and the filesystem on a CD-ROM as /media/cdrom1, for example. You may also mount files from other systems using a networked filesystem such as NFS. There are other types of file mounts, but this gives you an idea of the process. While the mount process actually mounts the filesystem on some device, it is common to simply say that you "mount the device," which is understood to mean "mount the filesystem on the device."

 

通常,首先核心将一些的硬盘的分区挂载为/。你也可能挂载了其他的硬盘分区,比如/boot,/tmp或者/home。你可能也把软驱的文件系统挂载为/mnt/floppy。也可以把CD-Rom的文件系统挂载为/media/cdrom1 例如你也可以使用像NFS的网络文件系统把其他系统挂载过来。还有其他文件挂装类型,但是您只要理解这个过程就行了。挂装过程实际上是挂装某一设备上的文件系统,但是常常说“挂装这个设备”,这就表示“挂装这个设备上的文件系统”。

 

Now, suppose you have just mounted the root file system (/) and you want to mount a CD-ROM, /dev/sr0, at the mount point /media/cdrom. The mount point must exist before you mount the CD-ROM over it. When you mount the CD-ROM, the files and subdirectories on the CD-ROM become the files and subdirectories in and below /media/cdrom. Any files or subdirectories that were already in /media/cdrom are no longer visible, although they still exist on the block device that contained the mount point /media/cdrom. If the CD-ROM is unmounted, then the original files and subdirectories become visible again. You should avoid this problem by not placing other files in a directory intended for use as a mount point.

 

  现在,假设你已经挂载了根文件系统,你想要在/media/crdom上挂载CD-ROM,/dev/sr0。在你把CD-ROM挂载过来之前这个挂载点必须是存在的。在挂载cd-rom时,CD-ROM中的子目录变为/media/cdrom底下的子目录。所有的文件和已经在media/cdrom中的子目录就不在是可见的了。尽管他们仍然存在于包含挂载点/media/cdrom块设备上。如果cdrom被卸载了,以前的文件和子目录就又可以看到了。  在打算使用挂载点的目录中,不放置任何文件就可以避免这个问题。

。。。。。

。。。。。

 

Connect with Ian

Before we get into LILO and GRUB, let's review how a PC starts or boots. Code called BIOS (for Basic Input Output Service) is stored in non-volatile memory such as a ROM, EEPROM, or flash memory. When the PC is turned on or rebooted, this code is executed. Usually it performs a power-on self test (POST) to check the machine. Finally, it loads the first sector from the master boot record (MBR) on the boot dive.

 

在我们开始LILO和GRUB之前,让我们来回顾一下PC是怎么启动的。被称为BIOS的代码存储在非易失性的存储器中,如ROM,EEPROM或者flash memory。当PC打开或者重启时,代码就执行了。通常执行POST来检查机器。最后,装载启动盘上主引导记录的第一个扇区。

 

As discussed in the article "Learn Linux 101: Hard disk layout," the MBR also contains the partition table, so the amount of executable code in the MBR is less than 512 bytes, which is not very much code. Note that every disk, even a floppy, contains executable code in its MBR, even if the code is only enough to put out a message such as "Non-bootable disk in drive A:". This code that is loaded by BIOS from this first sector is called the first stage boot loader or the stage 1 boot loader.

 

正如在前面文章中所讨论的,MBR也包含了分区表,所以MBR中执行代码的数量小于512字节,没有太多的代码。注意每个MBR中都包含可执行代码,甚至是软盘。即使代码只够输出一个Non-bootable disk in drive a:消息。这个代码是通过BIOS从被称为第一个装载的。

 

The standard hard drive MBR used by MS DOS, PC DOS, and Windows® operating systems checks the partition table to find a primary partition on the boot drive that is marked as active, loads the first sector from that partition, and passes control to the beginning of the loaded code. This new piece of code is also known as the partition boot record. The partition boot record is actually another stage 1 boot loader, but this one has just enough intelligence to load a set of blocks from the partition. The code in this new set of blocks is called the stage 2 boot loader. As used by MS-DOS and PC-DOS, the stage 2 loader proceeds directly to load the rest of operating system. This is how your operating system pulls itself up by its bootstraps until it is up and running.

This works fine for a system with a single operating system. What happens if you want multiple operating systems, say OS/2, Windows XP, and three different Linux distributions? You could use some program (such as the DOS FDISK program) to change the active partition and reboot. This is cumbersome. Furthermore, a disk can have only four primary partitions, and the standard MBR can have only one active primary partition; it cannot boot from a logical partition. But our hypothetical example cited five operating systems, each of which needs a partition. Oops!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值