Tuesday, May 06, 2008

Adding extra disk to OpenBSD the fast way

This is to add an extra disk to OpenBSD system, in a simple and quick way. if you'd like to know more details and what we're doing by these commands, please go to OpenBSD faq "disk setup" page: http://www.openbsd.org/faq/faq14.html.

tested on openbsd 4.2.

NOTE: THIS  IS FOR LEARNING ONLY. DO NOT TRY ON YOUR PRODUCTION SERVER!!

1. power off your box

2. attache your disk to your computer

3. boot

4. login as root

5. check dmesg for the disk you just add.
     For a 2nd IDE disk, usually it's wd1; for 2nd SCSI disk, it's sd1 etc

6. run command: `fdisk -i wd1`, assuming it's 2nd IDE disk, brand new.

7. run command: `disklabel -E wd1`

8. under the disklabel command prompt, enter `a a` to add your first partition, accept all default setting in the following 3 prompt, the "offset" sector, end sector and fs type. this will make the whole disk as one partition "a"

9. enter 'q' to exit disklabel command and save your setting

10. run `newfs /dev/wd1a` to make new file system on the newly created partition.

11. make a directory, under which you want to mount the new partition to. `mkdir /vol0`.

12. run `mount /dev/wd1a /vol0`

13. you should be able to cd into /vol0 directory and do whatever you normally can do.
if you want to have this partition mounted automatically at every reboot, edit the "/etc/fstab" file, append to it the line `/dev/wd1a /vol0 ffs 1 1`

DONE.

Saturday, May 03, 2008

WAFL(Write Anywhere File Layout) 实现(1)


1. Overview

WAFL is a UNIX compatible file system optimized for network file access. In many ways WAFL is similar to other UNIX file systems such as the Berkeley Fast File System (FFS) and TransArc's Episode file system. WAFL is a block-based file system that uses inodes to describe files. It uses 4 KB blocks with no fragments.
Each WAFL inode contains 16 block pointers to indicate which blocks belong to the file. Unlike FFS, all the block pointers in a WAFL inode refer to blocks at the same level. Thus, inodes for files smaller than 64 KB use the 16 block pointers to point to data blocks. Inodes for files larger than 64 MB point to indirect blocks which point to actual file data. Inodes for larger files point to doubly indirect blocks. For very small files, data is stored in the inode itself in place of the block pointers.

一: 概览

WAFL是一个和UNIX兼容的文件系统,并专门为网络访问做了优化。在很多方面WAFL 都和Berkeley FFS文件系统以及TransArc的Episode文件系统很相似。WAFL是基于 磁盘块(block)的,它使用inodes来描述文件。它的block是4KB大,没有分片 (fragments)。

每一个WAFL inode(索引节点)包含16个block指针来表明哪些块属于这个文件。 和FFS不一样的是,所有的块指针都指向同一个层次的块,因此,对于小于64KB的 文件,inode的块指针直接指向数据块;对于大于64MB的文件,指针指向间接的 块,这些间接块则包含指向实际数据块的指针;对于更大的文件,这种间接块则会 再增加一级。而对于非常小的文件,数据则直接存储在inode里面那些存放块指针 的位置。

2. Meta-Data Lives in Files

Like Episode, WAFL stores meta-data in files. WAFL's three meta-data files are the inode file, which contains the inodes for the file system, the block-map file, which identifies free blocks, and the inode-map file, which identifies free inodes. The term map is used instead of bit map because these files use more than one bit for each entry. The block-map file's format is described in detail below.

2. 元数据存在于文件中

和Episode一样,WAFL把元数据存放于文件中。WAFL的三个元数据文件是inode文 件,包含文件系统的inode数据;block-map(块映射)文件,它标明空闲块;inode- map文件,标明空闲的inode。这里使用了map而不是bit map是因为这些文件为每个 条目使用了多于一个bit的空间。Block-map文件的格式细节如下图所示。

           ___________
           | |        |   root Inode
           |
           |________________________________________________
           | |     000    | |     000     | |    000       |            inode file

           |
           |____________   ____________     ___________  ____________
           |      _    _|  |___________|   | _____   __| |           |  all other files

           block-map file  inode-map file  all other files in the file system

           Figure 1: The WAFL file system is a tree of blocks with the
           root inode, which describes the inode file, at the top, and
           meta-data files and regular files underneath.           
           图1:WAFL文件系统是一个树状块,包含描述其他inode文件的位于顶
           部的root inode和 下面的其他的元数据文件和常规文件

Keeping meta-data in files allows WAFL to write meta-data blocks anywhere on disk. This is the origin of the name WAFL, which stands for Write Anywhere File Layout. The write-anywhere design allows WAFL to operate efficiently with RAID by scheduling multiple writes to the same RAID stripe whenever possible to avoid the 4-to-1 write penalty that RAID incurs when it updates just one block in a stripe.

将元数据放在文件里面让WAFL可以将元数据块写在磁盘的任何位置。这也是WAFL的 名称的由来—--任意可写文件格式。这种任意可写的设计让WAFL在RAID上的运行非 常有效,当它更新条带上的某一个块的时候,可以规划(schedule)多次写操作到 RAID条带,在任何可能的情况下避免RAID 4-to-1写操作带来的低效。

----待续---- --to be continued---