本文最新網址位於 XFCE 設鍵盤快速鍵
XFCE 要設鍵盤快速鍵
於 設定 -> 視窗管理程式 -> 鍵盤 -> 新增 -> 再來就看自己要如何設定了.
再來就會發現自己 ~/.theme 下會有 自己剛剛新增的那個名字.
之後要換機器或環境. 把這個帶著走就可以囉 :)
本文最新網址位於Xwindow ICON 預設路徑
Xwindow 每次要找 ICON 時. 總是會不知道在哪裡 ... :(
還是記一下好了.. 預設: /usr/share/pixmaps/
而平常自己的 MAC 的 ICON 通常都會放在 ~/.icon 裡面.
今天幹了件很蠢的事情~.. 想要將 a電影.srt 改成跟 電影.avi 同名字.
於是就下了 mv a電影.srt 電影.avi ... 當按下 enter 時清醒了過來...
發現到那 avi 已經被我清掉了.. 變 srt 了... :~
於是就有這篇文章的由來.... 嗚... :~
雖然是寫說檔案刪除的回復救援, 但事實上我沒有成功救回來.. XD
主要是因為還要 mount -ro 而且我砍的檔案是在 "/". 很麻煩~ :(
而且也並不是那麼重要的檔案~ 大不了就那影片別看罷了... :p
但是看了這麼多~ 來做點小筆記比較好.. 希望未來不會需要用到這篇...
先簡單看一下幾種常用的 filesystem - Linux日誌式文件系统面面觀
(這篇下面有許多相關文件蠻不錯的)
說明系統rm, mv 等等動作是做何種事情, 流程, 該如何救回來 - UNIX系统被删文件的恢复策略
簡易說明實作步驟: Linux檔系統的反刪除方法
實作搶救的心得:[chat] 搶救過去!!!! (ext2 undelete)
救援主要就是靠 debugfs 這個程式.
debugfs 的程式就兩個 file, 大約共 500 行. 有興趣的就於下處去看看吧~(kernel 2.6.11)
/usr/src/linux/fs/debugfs/
以下都是轉載自原網站, 怕原網站資料遺失就頭痛了~ :(
發信人: thhsieh (居士), 信區: SM
標 題: [Sys] 搶救過去!!!! (ext2 undelete)
發信站: 冷月流蘇BBS驛站 (Mon Feb 1 17:21:11 1999) , 轉信
本系的 BBS 系統真是多災多難 (嗯 .... 其實是因為我的疏忽,才會這麼多災
多難 ....) ,繼這幾日系統時間不正確,造成許多人的 ID 被誤砍後,又一次
因系統設定上的問題,將 BBS 的重要備份檔給殺了。這件事是學弟發現後告訴
我的,當我上站來一見到他的 mail, 當真是欲哭無淚,差點沒去撞牆。那個備
分檔有多重要呢? 這麼說吧! 所有等待我們恢復舊信件的使用者資料全在裏頭。
那時已是週六晚 11:00 左右,我一邊想著要編一套說辭向大家解釋無法替大家
恢復舊信件與設定了,一邊還在想是否能夠挽回局面。大家知道, UNIX like
的系統是很難像 M$ 的系統一樣,做到 undelete 的,所有網管前輩都曾再三
警告我們,要小心! 小心! 砍檔之前三思而後行,砍了之後再後悔也沒用。雖
然我已漸漸做到砍檔三思而後行,但之次誤砍事件是系統在背景中定時執行的,
等到我找出原因時已是檔案被砍後一個多小時。
我憑著一點點的印象,想起在網路上,有人討論過在 Linux ext2 filesystem
中 undelete 的可能性,但我所見到的多半是負面的答案,但好像真的有人做過
這件事,於是我第一個所做的,就是馬上將該檔案原來所在的 partition mount
成 read-only, 禁止任何的寫入動作,不是怕再有檔案被誤砍 (因為已沒什麼可
砍的了) ,而是怕有新檔案寫進來,新資料可能會覆蓋到舊資料原本存在的磁區
(block) 。我們現在唯一個指望,就是企圖將檔案原來存在的磁區一個個找回來,
並且「希望」這些磁區上的舊資料都還在,然後將這些磁區串成一個檔案。
終於被我找到了!! 原來這方面的技術文件就存在我自己的系統中 :-))
/usr/doc/HOWTO/mini/Ext2fs-Undeletion.gz
於是我就按照這份文件的指示一步步來,總算將一個長達 8MB 的壓縮檔救回了
99%, 還有一個長達 1.1 MB 的壓縮檔完整無缺地救了回來。感謝上帝、 Linux
的設計者、寫那篇文件的作者、曾經討論過此技術的人、以及 Linux 如此優秀
的 ext2 filesystem, 讓我有機會搶救過去。現在,我將我的搶救步驟做一個整
理讓大家參考,希望有派得上用場的時候 (喔! 不,最好是希望大家永遠不要有
機會用到以下的步數 :-)))
************************************************************************
在此嚴正聲明!! 寫這篇文章的目的,是給那些處於萬不得已情況下的人們,有
一個挽回的機會,並不意味著從此我們就可以大意,砍檔不需要三思。前面提
到,我有一個檔案無法 100% 救回,事實上,長達 8MB 的檔案能救回 99% 已是
幸運中的幸運,一般的情況下若能救回 70% - 80% 已經要愉笑了。所以,不要
指望 undelete 能救回一切。預防勝於治療! 請大家平時就養成好習慣,砍檔前
請三思!!!
************************************************************************
我們能救回的機會有多大? 在 kernel-2.0.X 系列中 (本站所用的 kernel 是
2.0.33) ,取決以下兩點:
1. 檔案原來所在的磁區是否沒有被覆寫?
2. 檔案是否完全連續?
第一點我們可以與時間競賽,就是當一發現檔案誤砍時,要以最快的速度 umount
該 filesystem, 或將該 filesystem remount 成唯讀。就這次的情況而言,檔案
誤砍是在事發一個小時後才發現的,但由於該 filesystem 寫入的機會很少 (我
幾乎可確定一天才只有一次,做 backup),所以第一點算是過關了。
第二點真的是要聽天由命了,就本站所使用的 kernel, 必須要在假設「長檔案」所
佔的 block 完全連續的情況下,才有可能完全救回來! 一個 block 是 1024 bytes,
長達 8 MB 的檔案就有超過 8000 個 block。在經常讀寫的 filesystem 中,可以
想見長檔案很難完全連續,但在我們的系統中,這一點似乎又多了幾分指望。同時,
Linux ext2 如此精良的 filesystem, 能做到前 7950 多個 block 都連續,這一點
也功不可沒。
好了,以下我就講一下我的步驟。
1. mount filesystem readonly:
該檔案的位置原來是在 /var/hda/backup/home/bbs 下,我們系統的 filesystem
組態是:
root@bbs:/home/ftp/rescue# df
Filesystem 1024-blocks Used Available Capacity Mounted on
/dev/sda1 396500 312769 63250 83% /
/dev/sda3 777410 537633 199615 73% /home
/dev/hda1 199047 36927 151840 20% /var/hda
/dev/hda2 1029023 490998 485710 50% /home/ftp
因此 /var/hda 這個 filesystem 要馬上 mount 成 readonly (以下請用 root 身
份):
mount -o remount,ro /var/hda
當然也可以直接 umount 它,但有時候可能有某些 process 正在此 filesystem
下運作,您可能無法直接 umount 它。因此我選擇 mount readonly。但您也可以
用:
fuser -v -m /usr
看一下目前是那些 process 在用這個 filesystem, 然後一一砍掉,再 umount。
2. 執行
echo lsdel | debugfs /dev/hda1 | less
看一下該 filesystem 最近被砍的 inode (檔案) 有那些 (為什麼是 /dev/hda1?
請見上頭的 df 列表)? 在這裏要說一下,在 UNIX like 的系統中,所有的檔案都
有一個 inode 指向它, inode 中記錄了檔案的重要資訊,如大小、時間、屬性等
等。就我們的系統而言,其列示如下:
debugfs: 92 deleted inodes found.
Inode Owner Mode Size Blocks Time deleted
.................................................................
29771 0 100644 1255337 14/ 14 Sat Jan 30 22:37:10 1999
29772 0 100644 5161017 14/ 14 Sat Jan 30 22:37:10 1999
29773 0 100644 8220922 14/ 14 Sat Jan 30 22:37:10 1999
29774 0 100644 5431 6/ 6 Sat Jan 30 22:37:10 1999
請注意! inode 裏頭不會記錄檔案的檔名,檔名是記錄在該檔案所在的目錄的
data block 中,故在此我們見不到。因此,我們必須要在檔案大小、被砍時間
等資訊中判斷出要救回的檔案是那一個。在此,我們要救回 29773 這個 inode。
3. 執行
echo "stat <29773>" | debugfs /dev/hda1
列出該 inode 的所有資訊,如下:
debugfs: stat <29773>
Inode: 29773 Type: regular Mode: 0644 Flags: 0x0 Version: 1
User: 0 Group: 0 Size: 8220922
File ACL: 0 Directory ACL: 0
Links: 0 Blockcount: 16124
Fragment: Address: 0 Number: 0 Size: 0
ctime: 0x36b31916 -- Sat Jan 30 22:37:10 1999
atime: 0x36aebee4 -- Wed Jan 27 15:23:16 1999
mtime: 0x36adec25 -- Wed Jan 27 00:24:05 1999
dtime: 0x36b31916 -- Sat Jan 30 22:37:10 1999
BLOCKS:
123134 123136 123137 123138 123140 131404 131405 131406 131407 131408 131409 131
410 131411 131668
TOTAL: 14
現在的重點是,必須將該 inode 所指的檔案,所指的 block 全部找回來。在這裏,
列出的資訊顯示只有 14 個 block? 不對啊! 應該要有 8000 多個 block 才對啊!
在這裏要談一下 UNIX like filesystem 的「奧密」了。上頭所列的前 12 個 block
是真正指到檔案資料的 block, 稱之為 direct block 。第 13 個稱為第一階
indirect block, 第 14 個稱為第二階 indirect block 。什麼意思? 該檔的資料
所在的 block 位置如下:
123134
123136
123137
123138
......
131409
131410
131411 =========> 131412
131413
131414 (第一階,共 256 個)
......
131667
131668 =========> 131669 ==========> 131670
131671
131672 (共 256 個)
......
131925
131926 ==========> 131927
131928
131929 (共 256 個)
......
132182
132183 ==========> 132184
132185 (共 256 個)
......
各位明白嗎? 第 13 個 (131411) 與第 14 個 block 其實不是 data, 而是 index,
它指出接下來的 block 的位置。由於一個 block 的大小是 1024 bytes, 一個 int
在 32 位元系統中是 4 bytes, 故一個 block 可以記錄 256 筆資料。以 131411
block 為例,它所記錄的資料即為 (在檔案未砍前):
131412 131413 131414 .... 131667 (共 256 筆)
而這 256 個 block 就真正記錄了檔案資料,所以我們稱為第一階。同理,第二階
就有兩個層 index, 以 131668 來說,它可能記錄了:
131669 131926 132182 .... (最多有 256 筆)
而 131669 的 block 記錄為:
131670 131671 131672 .... 131925 (共 256 筆)
而這 256 個 block 才是真正儲存檔案資料的。而我們要的,就是這些真正儲存檔
案資料的 block 。
理論上,我們只要將這些 index block 的內容全部讀出來,然後照這些 index 把
所有的 block 全部讀到手,就能 100% 救回檔案 (假設這些 block 全部沒有被新
檔案覆寫的話)。工程很大,但是可行。不幸的是,在 kernel-2.0.33, 其設計是,
如果該檔案被砍了,則這些 index block 全部會規零,因此我所讀到的是
0 0 0 0 0 ..... (共 256 筆)
哇! 沒辦法知道這些 data block 真正所在的位置。所以,在此我們做了一個很大
的假設: 整個檔案所在的 block 是連續的! 也就是我上頭的例子。這也就是為什
麼說,只有連續 block (是指後頭的 indirect block) 的檔案才能完整救回,而
這一點就要聽天由命了。
4. 好了,現在我們只好假設所有的檔案處於連續的 block 上,現在請用
http://archie.ncu.edu.tw
去找這個工具: fsgrab-1.2.tar.gz, 並將它安裝起來。因為步驟很簡單,故在此
我就不多談。我們要用它將所需的 block 全部抓出來。它的用法如下:
fsgrab -c count -s skip device
其中 count 是只要 (連續) 讀幾個, skip 是指要從第幾個開始讀,例如我要從
131670 開始連續讀 256 個,就這樣下指令:
fsgrab -c 256 -s 131670 /dev/hda1 > recover
現在我們就開始救檔案吧! 以上頭的資料,我們必須用以下的指令來救:
(注意到頭開的 12 個 block 並沒有完全連續!!!)
fsgrab -c 1 -s 123134 /dev/hda1 > recover
fsgrab -c 3 -s 123136 /dev/hda1 >> recover
fsgrab -c 1 -s 123140 /dev/hda1 >> recover
fsgrab -c 7 -s 131404 /dev/hda1 >> recover
這是開頭的 12 個 block, 對於第一階 indirect, 就資料來看好像是連續的 :-))
fsgrab -c 256 -s 131412 /dev/hda1 >> recover
注意要跳過 131411, 因為它是 index block。對於第二階 indirect, 我們 *假設*
它們都是連續的:
fsgrab -c 256 -s 131670 /dev/hda1 >> recover
fsgrab -c 256 -s 131927 /dev/hda1 >> recover
fsgrab -c 256 -s 132184 /dev/hda1 >> recover
............................................
要一直做,直到 recover 的大小超過我們所要救回的檔案大小 (8220922) 為止。
要注意在這裏我們已很小心地跳過那些 index block (如 131668, 131669, 131926,
132183, ....) 了。
5. 最後一步,就是把檔案「剪」出來,並看看我們救回多少了。在這裏我們可以用
split 這個工具,假設我們重覆上述步驟,弄出來的 recover 檔大小為 8294400,
而我們要的大小是 8220922, 那就這樣下指令:
split -b 8220922 recover rec
則會做出兩個檔,一個是 recaa, 大小是 8220922, 另一個是 recab 則是剩下的大
小,後者是垃圾,扔了即可。現在我們可以檢查這個檔案是不是「完整」的那個被
誤砍的檔案了。由於我們的那個檔案是 .tar.gz 的格式,於是我們這個方法來檢查:
mv recaa recaa.tar.gz
zcat recaa.tar.gz > recaa.tar
如果沒有錯誤訊息,那表示成功了! 完全救回來了。但不幸的是,我們沒有成功,
將弄出的 recaa.tar 改名再 gzip 之後,與原來的 recaa.tar.gz 比一下大小,發
現少了 1%, 表示說該檔原來所在的 block 中最後有 1% 是不連續的 (或者被新寫
入的檔案覆寫了),但這已是不幸中的大幸了。
=============================================================================
對於在 undelete 時 *必需* 假設所有 block 連續的問題,那份 HOWTO 文件說 Linus
與其他 kernel 設計者正著手研究,看能否克服這個困難,也就是在檔案砍掉時,不要
將 index block 規零。我剛剛試一下 kenrel-2.2.0 的環境,發現已做到了!! 以下是
一個已砍的檔案的 inode data (由 debugfs 所讀出):
debugfs: Inode: 36154 Type: regular Mode: 0600 Flags: 0x0 Version: 1
User: 0 Group: 0 Size: 2165945
File ACL: 0 Directory ACL: 0
Links: 0 Blockcount: 4252
Fragment: Address: 0 Number: 0 Size: 0
ctime: 0x36b54c3b -- Mon Feb 1 14:39:55 1999
atime: 0x36b54c30 -- Mon Feb 1 14:39:44 1999
mtime: 0x36b54c30 -- Mon Feb 1 14:39:44 1999
dtime: 0x36b54c3b -- Mon Feb 1 14:39:55 1999
BLOCKS:
147740 147741 147742 147743 147744 147745 147746 147747 147748 147769 147770 157
642 157643 157644 157645 157646 157647 157648 157649 157650 157651 157652 157653
157654 157655 157656 157657 157658 157659 157660 157661 157662 157663 157664 15
7665 157666 157667 157668 157669 157670 157671 157672 157673 157674 157675 15767
6 157677 157678 157679 157680 157681 157682 157683 157684 157685 157686 157687 1
............................................................................
9745 159746 159747 159748 159749 159750 159751 159752 159753 159754 159755 15975
6
TOTAL: 2126
真是太完美了!! 這意味著在 kernel-2.2.X 的環境下,我們不必假設所有的 block 都
連續,而且可以百分之百找回所有砍掉的 block! 因此上述的第二個風險就不存在了。
以上資料,謹供參考。
參考文件: Ext2fs-Undeletion Mini HOWTO
1. 引导块
位于文件卷最开始的第一扇区,这512字节是文件系统的引导代码,为根文件系统所特有,其他文件系统这512字节为空。
2. 超级块
位于文件系统第二扇区,紧跟引导块之后,用于描述本文件系统的结构。如i节点长度、文件系统大小等,其结构存放于/usr/include/sys/filsys.h中,其结构如下:
struct filsys
{
ushort s_isize; /*磁盘索引节点区所占用的数据块数*/
daddr_t s_fsize; /*整个文件系统的数据块数*/
short s_nfree; /*在空闲块登录表中当前登记的空闲块数目*/
daddr_t s_free[NICFREE]; /*空闲块登记表*/
short s_ninode; /*空闲索引节点数*/
ino_t s_inode[NICINOD]; /*空闲节点登记表*/
char s_flock; /*加锁标志位*/
char s_ilock; /*节点加锁标志位*/
char s_fmod; /*超级块修改标志*/
char s_ronly; /*文件系统只读标志*/
time_t s_time; /*超级块上次修改的时间*/
short s_dinfo[4]; /*设备信息*/
daddr_t s_tfree; /*空闲块总数*/
ino_t s_tinode; /*空闲节点总数*/
char s_fname[6]; /*文件系统名称*/
char s_fpack[6];
long s_fill[13]; /*填空位*/
long s_magic; /*指示文件系统的幻数*/
long s_type; /*新文件系统类型*/
};
3. i节点表
i节点表存放在超级块之后,其长度是由超级块中的s_isize字段决定的,其作用是用来描述文件的属性、长度、属主、属组、数据块表等,其数据结构在/usr/include/sys/ino.h中,如下:
struct dinode
{
ushort di_mode;
short di_nlink;
ushort di_uid;
ushort di_gid;
off_t di_size;
char di_addr[40];
time_t di_atime;
time_t di_mtime;
time_t di_ctime;
};
4. 目录结构
UNIX所有文件均存放于目录中,目录本身也是一个文件。目录存放文件的机制如下:首先,目录文件本身也象普通文件一样,占用一个索引节点,其次,由这个索引节点得到目录内容的存放位置,再次,从其内容中取出一个个的文件名和它对应的节点号,从而访问一个文件。目录结构如下:
索引节点号(2字节) .(本目录)(14字节)
索引节点号(2字节) ..(父目录)(14字节)
索引节点号(2字节) 文件名(14字节)
索引节点号(2字节) 文件名(14字节)
索引节点号(2字节) 文件名(14字节)
由上可知文件名是依靠目录来描述的,文件的内容和其他信息则由索引节点来描述。
二、文件的删除过程
UNIX下删除一个文件的过程很简单,那就是释放索引节点表和文件占用的数据块,清空文件占用的索引节点,但不清除文件内容。但删除文件与删除目录的处理不尽相同,不同命令删除文件的过程也不相同。
1. 删除一个文件
UNIX 删除一个文件的具体步骤是:根据文件i节点的地址表逐一释放文件占用的磁盘数据块,然后清空相应的节点,最后释放i节点。
2. 删除一个目录
删除一个目录的过程:首先逐一删除目录里的所有文件,然后删除目录。目录本身也是一个文件,故删除方法与删除文件一致。
3. 几种不同的删除命令
.rm 命令
一般删除命令,删除过程上述已说明。
.mv命令
格式:mv 文件1 文件2
处理过程是将文件2的数据块释放,然后将文件1的名称改为文件2,再释放文件2所占的i节点。
. > 命令
格式:>文件名
若产生一个新文件,>命令仅仅申请一个i节点,而不写入任何文件内容;若清空一个已经存在的文件,则释放文件所占的数据块,并将文件长度清零。
三、被删文件的恢复策略
要恢复被删除的文件,只能根据删除后留下的东西去做文章。文件被删除后留下了什么呢?由上述分析可知:其一、留下了文件的内容;其二、留下了“现场”。文件的恢复策略只能从这两个方面来分析。以下谈几种恢复策略。
1.根据磁盘现场进行恢复
如果文件被删除,现场未被破坏(即文件被删除后硬盘未发生过写操作),而且假定只删除了一个文件,那么可根据系统的分配算法进行恢复。因为系统建立一个文件时,必定根据某一特定的分配算法决定文件占用的数据块位置。而当该文件被删除后,它所占用的数据块被释放,又回到系统的分配表中,这时如果重新建立一个文件,系统根据原来的分配算法分配出的数据块必定跟该文件原来占用的数据块一致,而且我们知道,UNIX文件最后一数据块尾部多出的字节是全部置0的,据此只要调用系统的数据分配算法,在系统中一块块的申请数据块,因为UNIX文件最后一个数据块尾部多出的字节全部为0,所以,只要发现一个分配出的数据块中尾部全为0,即可认为文件结束,由此可确定文件长度和内容,进而实现恢复。方法如下:
⑴申请一个索引节点,即向系统申请创建一个新文件名而不写入任何内容。如:#>/tmp/xx
⑵调用系统分配数据块算法getnextfreeblock()得到一个数据块号,记入某一地址表变量中。
⑶读出这个数据块,判断其尾部是否全部连续为0,若不是,则回到(2),若是,则进行(4)。
⑷首先用系统函数fstat得到/tmp/xx的i节点号,然后将(2)步所得的地址表写入索引节点的地址表中(注意间址问题),并根据数据块个数和最后一块中有效数据长度计算出文件大小,写入i节点的di_size字段。
⑸回写系统的索引节点表即可。
需要说明的是,第一,系统分配数据块的算法因不同的UNIX版本而不同;第二,有的UNIX如SCO UNIX 5.0版,其空闲数据块的分配和回收是使用一种动态链表的数据结构来实现的,它们的文件恢复更加容易,只要在空闲链表中的表尾去寻找即可,笔者另行描述。
2. 根据内容恢复。
若现场已被破坏,即硬盘发生过写操作,那么只好根据内容来恢复。而且,由于UNIX是一个多进程、多用户系统,它每一次开关机或硬件、通讯故障等都会记录系统日志、.sh_history等,硬盘现场被破坏可能性极大。因此讨论按内容恢复的方法具有更大的实用价值。笔者经过实际探索得出下列四种恢复策略供参考。
⑴关键字搜索法
如果知道被删除的文件内容中若干字节的内容,而且该文件长度又不超过一个磁盘块,那么可以在整个文件系统中搜索这一字节串,得出一个文件所在的数据块,将它们的块号填入一个i节点,即可恢复一个文件,搜索文件系统的算法很简单,说明如下:
a. #df -k 确定文件系统的设备文件名(如/dev/root)
b.用下述函数搜索,若成功,返回数据块号,反之返回-1。其中fsname是文件系统的设备名,如/dev/root,comp()参数是实现搜索条件的函数。
long searchfs(char *fsname , int comp())
{
FILE *fp;
char buf[1024];
long i=0;
fp=fopen(fsname,"r");
while (!feof(fp))
{
fread(buf,1024,1,fp);
if (comp()) /* 检查是否符合搜索条件 */
return i; /* 若成功返回块号 */
i++;
}
fclose(fp);
return -1; /* 未找到符合条件的块,返回-1*/
}
⑵精确长度搜索法
如果知道被删除文件的精确长度(字节数),那么可根据一个数据块的大小,计算出文件的最后一个数据块中数据的精确长度,该数据块中其他字节必然是全0。根据这一条件,通过搜索整个文件系统,找出其中符合条件的数据块,若出现多个块符合要求,则还需要根据其他条件区分。但不管怎样,根据精确长度分析也是恢复数据的一个策略。
⑶内容关联法
如果知道文件内容中存在某种可实现的关联,例如文件的校验和,或者文件内容的某种上下文关系,那么也可通过搜索整个文件系统,通过反复尝试寻找符合关联条件的磁盘数据块,进而恢复一个文件。
⑷环境比较法
如果知道删除文件所在的文件系统的安装过程,那么,另行找一台完全相的机器,按原来完全相同的步骤安装相同版本的UNIX和相应的其他软件,可以想象,新的机器环境会与原来的环境基本相同,比较两个机器上相同文件系统的内容,可以推断出被删除文件的大致位置,至少可以大大减少查找的范围,一旦查找的范围足够小时,可以用逐个观察和尝试的方法结合其他条件恢复数据,降低恢复的难度,增加恢复的可靠性。
UNIX系统下文件系统恢复的具体实现依赖于不同操作系统和不同版本的具体文件系统结构和磁盘块分配算法。本文试图总结出一种一般性的思路和策略,限于篇幅,不能详细讨论它们的具体实现过程。
摘自:http://linux.softhouse.com.cn
Linux檔系統的反刪除方法
作為一個多用戶、多工的作業系統,Linux下的檔一旦被刪除,是難以恢復的。儘管刪除命令只是在檔節點中作刪除標記,並不真正清除檔內容,但是其他用戶和一些有寫盤動作的進程會很快覆蓋這些資料。不過,對於家庭單機使用的Linux,或者誤刪檔後及時補救,還是可以恢復的。
1.Ext2檔系統結構的簡單介紹
在Linux所用的Ext2檔系統中,檔是以塊為單位存儲的,默認情況下每個塊的大小是1K,不同的塊以塊號區分。每個檔還有一個節點,節點中包含有檔所有者,讀寫許可權,檔類型等資訊。對於一個小於12個塊的檔,在節點中直接存儲檔資料塊的塊號。如果檔大於12個塊,那麼節點在12個塊號之後存儲一個間接塊的塊號,在這個間接塊號所對應的塊中,存儲有256個檔資料塊的塊號(Ext2fs中每個塊號佔用4位元組,這樣一個塊中所能存儲的塊號就是 1024/4=256)。如果有更大的檔,那麼還會在節點中出現二級間接塊和三級間接塊。
2。恢復被誤刪檔的方法
大多數Linux發行版都提供一個debugfs工具,可以用來對Ext2檔系統進行編輯操作。不過在使用這個工具之前,還有一些工作要做。
首先以唯讀方式重新掛載被誤刪的檔所在分區。使用如下命令:(假設文件在/usr分區)
mount –r –n –o remount /usr
-r表示唯讀方式掛載;-n表示不寫入/etc/mtab,如果是恢復/etc上的檔,就加上這個參數。如果系統說xxx partion busy,可以用fuser命令查看一下是哪些進程使用這個分區上的檔:
fuser –v –m /usr
如果沒有什麼重要的進程,用以下命令停掉它們:
fuser -k –v –m /usr
然後就可以重新掛載這些檔系統了。
如果是把所有的檔統一安裝在一個大的/分區當中,可以在boot提示符下用linux single進入單用戶模式,儘量減少系統進程向硬碟寫入資料的機會,要不乾脆把硬碟掛在別的機器上。另外,恢復出來的資料不要寫到/上面,避免破壞那些有用的資料。如果機器上有dos/windows,可以寫到這些分區上面:
mount –r –n /dev/hda1 /mnt/had
然後就可以執行debugfs:(假設Linux在 /dev/hda5)
#debugfs /dev/hda5
就會出現debugfs提示符debugfs:
使用lsdel命令可以列出很多被刪除的檔的資訊:
debugfs:lsdel
debugfs: 2692 deleted inodes found.
Inode Owner Mode Size Blocks Time deleted
164821 0 100600 8192 1/ 1 Sun May 13 19:22:46 2001
…………………………………………………………………………………
36137 0 100644 4 1/ 1 Tue Apr 24 10:11:15 2001
196829 0 100644 149500 38/ 38 Mon May 27 13:52:04 2001
debugfs:
列出的檔有很多(這裏找到2692個),第一欄位是檔節點號,第二欄位是檔所有者,第三欄位是讀寫許可權,接下來是檔大小,佔用塊數,刪除時間。然後就可以根據檔大小和刪除日期判斷那些是我們需要的。比如我們要恢復節點是
196829的文件:
可以先看看檔資料狀態:
debugfs:stat <196829>
Inode: 196829 Type: regular Mode: 0644 Flags: 0x0 Version: 1
User: 0 Group: 0 Size: 149500
File ACL: 0 Directory ACL: 0
Links: 0 Blockcount: 38
Fragment: Address: 0 Number: 0 Size: 0
ctime: 0x31a9a574 -- Mon May 27 13:52:04 2001
atime: 0x31a21dd1 -- Tue May 21 20:47:29 2001
mtime: 0x313bf4d7 -- Tue Mar 5 08:01:27 2001
dtime: 0x31a9a574 -- Mon May 27 13:52:04 2001
BLOCKS:
594810 594811 594814 594815 594816 594817
………………………………….
TOTAL: 38
然後就可以用dump指令恢復檔:
debugfs:dump <196829> /mnt/hda/01.sav
這樣就把檔恢復出來了。退出debugfs:
debugfs:quit
另一種方法是手工編輯inode:
debugfs:mi <196829>
Mode [0100644]
User ID [0]
Group ID [0]
Size [149500]
Creation time [0x31a9a574]
Modification time [0x31a9a574]
Access time [0x31a21dd1]
Deletion time [0x31a9a574] 0
Link count [0] 1
Block count [38]
File flags [0x0]
Reserved1 [0]
File acl [0]
Directory acl [0]
Fragment address [0]
Fragment number [0]
Fragment size [0]
Direct Block #0 [594810]
…………………………….
Triple Indirect Block [0]
使用mi指令後每次顯示一行資訊以供編輯,其他行可以直接按回車表示確認,把deletion time改成0(未刪除),Link count改成1。改好後退出debugfs:
debugfs:quit
然後用fsck檢查/dev/hda5
fsck /dev/hda5
程式會說找到丟失的資料塊,放在lost+found裏面。這個目錄裏的檔就是我們要的東東。
Now all O.K. Good Luck.
EXT3 Recovery - Score one for the fleshlings
/var was unmountable.
I removed /var from fstab and booted the machine on a /var dir off the root so I could work on it remotely.
Here's what happened next. I fsck a variety of ways, fsck.ext3 etc.. each reported the same:
fsck /dev/ida/c0d0p7
fsck 1.27 (8-Mar-2002)
e2fsck 1.27 (8-Mar-2002)
Group descriptors look bad... trying backup blocks...
fsck.ext2: Invalid argument while checking ext3 journal for /var
Tried downgrading to ext2 to bypass the hosed journal issues:
tune2fs -O ^has_journal /dev/ida/c0d0p7
tune2fs 1.27 (8-Mar-2002)
tune2fs: Invalid argument while reading journal inode
No good. Tried mounting as ext2 read only:
mount -t ext2 /dev/ida/c0d0p7 /mnt -o ro
mount: wrong fs type, bad option, bad superblock on /dev/ida/c0d0p7,
or too many mounted file systems
Nada. Tried some more stuff... tune2fs, and debugfs to try to fix / disable the journal, then decided I'd better back up the partition... should have done that first! ;P
e2fsck -c /dev/ida/c0d0p7
e2fsck 1.27 (8-Mar-2002)
Group descriptors look bad... trying backup blocks...
e2fsck: Invalid argument while checking ext3 journal for /var
[root@adrock init.d]# tune2fs -j /dev/ida/c0d0p7
tune2fs 1.27 (8-Mar-2002)
The filesystem already has a journal.
[root@adrock init.d]# debugfs -w /dev/ida/c0d0p7
debugfs 1.27 (8-Mar-2002)
/dev/ida/c0d0p7: Can't read an inode bitmap while reading inode bitmap
debugfs: quit
[root@adrock init.d]# dd if=/dev/ida/c0d0p7 of=/big/var.bak.dd
530368+0 records in
Still hosed, but now I have a backup of the burnination. And now for the FIX!!!
mke2fs -S /dev/ida/c0d0p7
mke2fs 1.27 (8-Mar-2002)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
66528 inodes, 265184 blocks
13259 blocks (5.00%) reserved for the super user
First data block=1
33 block groups
8192 blocks per group, 8192 fragments per group
2016 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801, 221185
Writing superblocks and filesystem accounting information: done
That did it! mke2fs re-wrote all of the superblocks and group descriptors and I was able to mount in RO mode and copy off the data. After that I was able to fsck and remount the original parition with no problems!
I found some great info on the RedHat ext3 mailing list archive which led me to this fix. Big thanks to the guys on that list!
以下兩頁的說明, 一頁說有支援 ext3, 一頁說沒有 :(
DEBUGFS、debugfs(8) - Linux man page
本文最新網址位於套件管理工具比較
比較一下現在市面上幾種套件管理工具
(debian - apt , gentoo - emerge , freebsd - prots)
深入內容中有 emerge, apt, ports 的語法比較(也可以說是語法教學吧)
以下轉載自: Gentoo/Debian/FreeBSD套件管理memo
以關鍵字搜尋軟體
Gentoo: emerge -s
輸出會有這個 pkg 的簡介 , 關鍵字都可以用正規表示式
Debian: apt-cache search
FreeBSD: make search name=
ports_glob
安裝軟體
Gentoo: emerge
Debian: apt-get install
FreeBSD: portinstall
移除軟體
Gentoo: emerge unmerge
Debian: apt-get remove
FreeBSD: pkg_deinstall
升級單一軟體
Gentoo: emerge -u
Debian: ?
FreeBSD: portupgrade
察看升級全系統會動到哪些套件:
Gentoo: emerge -puDv world
Debian: apt-get -u dist-upgrade
FreeBSD: portupgrade -arnv
升級全系統
Gentoo: emerge -u --deep world
Debian: apt-get dist-upgrade
FreeBSD: make world ; portupgrade -ar
查詢系統裝了哪些軟體
Gentoo: emerge -pe world 或 qpkg -I -v
Debian: dpkg --get-selections
FreeBSD: pkg_info
查詢某檔案屬於哪個軟體
Gentoo: qpkg -f
(need gentoolkit)
Debian: dpkg -S
FreeBSD: pkg_info -W
查詢某個套件安裝了什麼檔案
Gentoo: qpkg -l
Debian: ?
FreeBSD: pkg_info -L
查詢有沒有裝這個關鍵字的套件
Gentoo: qpkg -I | grep
Debian: dpkg -qa | grep
FreeBSD: pkg_info | grep
找哪些 pkg "簡介" 裡含有你要找的關鍵字:
Gentoo: emerge -S <關鍵字>
輸出方式和前者一樣, 關鍵字都可以用正規表示式
Debian: apt-cache search
FreeBSD: make search key=
不管相依性強制移除某套件
Gentoo: emerge -C
Debian:
FreeBSD: pkg_delete -f
全系統重新編譯
Gentoo: emerge -e world
Debian: ?
FreeBSD: make world ; portupgrade -arf
========
補充:
qpkg -f
ps: emerge gentoolkit first.
--
gentoo 裡:
查詢某個套件安裝了什麼檔案:
qpkg -l
查詢有沒有裝這個關鍵字的套件:
qpkg -I
不管相依性強制移除某套件:
emerge -C
--
仔細看一下 man emerge
要找一個 pkg 的 "名稱":
emerge -s <關鍵字>
輸出會有這個 pkg 的簡介
找哪些 pkg "簡介" 裡含有你要找的關鍵字:
emerge -S <關鍵字>
輸出方式和前者一樣
更厲害的是上面的關鍵字都可以用正規表示式!!
--
emerge -f
好處在於當你emerge 兩個package以上的時候,可以先把source給抓回來,不過需要再emerge
emerge -p
看要裝些什麼東西,
小弟認為這兩個指令對撥接使用者很重要,尤其 -f .一來可以大略知道下載時間,二來可以隨時中斷,然後在續傳(感謝偉大的wget)
--
升級單一軟體
Gentoo: emerge -u
Debian: apt-get install
FreeBSD: portupgrade
查詢某個套件安裝了什麼檔案
Gentoo: qpkg -l
credit to paar@gentoo.org.tw
Debian: dpkg -L
FreeBSD: pkg_info -L
全系統重新編譯
Gentoo: emerge -e world
Debian: apt-get update;apt-get upgrade
FreeBSD: make world ; portupgrade -arf
HOW TO OPTIMIZE AND ACCELERATE YOUR SYSTEM
讓你的 Gentoo 加速~ 要如何最佳化自己的系統呢?..
從以下幾點來做. 深入的就看看 這篇文章 吧~
0. How to make tests without being in danger
1. Optimization of the init scripts
2. Using rc-update
3. Cflags and ldflags
4. Using hdparm
5. Should you.. prelink?
6. Managing the Swap
7. Ccache
8. Distcc
9. USE's
10. Modifying ebuilds and injecting packages
11. Halt vs Suspend
12. Xdelta - Deltup
13. NPTL
14. GCC
15. Filesystems [data safety vs speed]
16. i/o and tasks schedulers
17. Useful Scripts
以下轉載自: HOW TO OPTIMIZE AND ACCELERATE YOUR SYSTEM
also known as how to fly with gentoo
This is guide is a sum of a lot of posts here in the forum and some investigations i have done in my boxes by trying out several programs and options. Some of them are completely safe, but some other could damage your system. Please make backups of your important data, try this guide in testing boxes, and then move the optimizations to the production boxes.
This improvements will obviously have a greater effect on a old computer, if you have a very good computer this will have a minor impact, as your system should already be pretty fast Wink
INDEX
0. How to make tests without being in danger
1. Optimization of the init scripts
2. Using rc-update
3. Cflags and ldflags
4. Using hdparm
5. Should you.. prelink?
6. Managing the Swap
7. Ccache
8. Distcc
9. USE's
10. Modifying ebuilds and injecting packages
11. Halt vs Suspend
12. Xdelta - Deltup
13. NPTL
14. GCC
15. Filesystems [data safety vs speed]
16. i/o and tasks schedulers
17. Useful Scripts
0. How to make tests without being in danger
To test new ebuilds and try new configurations I did an instalation inside a chroot to be completely safe. There's is a guide HERE to make a similar thing, and be able to test this howto without damaging your system. You could also use vmware or uml, but this seems a fastest way.
Once I did the chroot install, I made a compressed image, so that everytime I broke the sub-system with my tests i can extract it and go on testing with a new installed system (and my system keeps clean).
1. Optimization of the init scripts
Some of the operations performed when you boot the system are not always needed. Let's modify the scripts so that we only do them if they are really needed.
/etc/init.d/modules
change:
Code:
ebegin "Calculating module dependencies"
/sbin/modules-update &>/dev/null
eend $? "Failed to calculate dependencies"
for:
Code:
if [ /etc/modules.d -nt /etc/modules.conf ]
then
ebegin "Calculating module dependencies"
/sbin/modules-update &>/dev/null
eend $? "Failed to calculate dependencies"
else
einfo "Module dependencies are up-to-date"
fi
Doing this, modules-update will only run if it愀 really needed because you made changes in the system.
/etc/init.d/localmount
change:
Code:
mount -at nocoda,nonfs,noproc,noncpfs,nosmbfs,noshm >/dev/null
for:
Code:
mount -aFt nocoda,nonfs,noproc,noncpfs,nosmbfs,noshm >/dev/null
The will start all the local mounts at the same moment, not one after the other.
/etc/init.d/bootmisc
change:
Code:
if [ -x /sbin/env-update.sh ]
then
ebegin "Updating environment"
/sbin/env-update.sh >/dev/null
eend 0
fi
for:
Code:
if [ -x /sbin/env-update.sh ]
then
if [ /etc/env.d -nt /etc/profile.env ]
then
ebegin "Updating environment"
/sbin/env-update.sh >/dev/null
eend 0
else
einfo "Environment up-to-date"
fi
fi
Doing this, env-update will only run if it愀 really needed because you made changes in the system.
/etc/conf.d/rc
change:
Code:
RC_PARALLEL_STARTUP="no"
for:
Code:
RC_PARALLEL_STARTUP="yes"
This will start all the services at the same moment, not one after the other.
note: could some devel explain if this tweaks are dangeorus, and if not why they are not in portage by default?
2. Using rc-update
Managing the runlevels is very easy thanks to rc-update, that makes easy this job:
to see how we have currently configured the boot runlevels:
Code:
# rc-update show
to remove a service from the system start:
Code:
# rc-update del aplicacion runlevel
note: change runlevel for boot or default (you could also create more), if you omit the runlevel it will search in all of them and remove the service.
to add an application:
Code:
# rc-update add application runlevel
I have some service in the boot runlevel and some in the default runlevel, please note that some services need to be started after some other (this means that some services depends on some other.
You can check the depends editing the /etc/init.d/service file and checking the first lines, where the depends are declared. For example, if you want to start sshd, you will need the net services started before.
I have recently created a new runlevel (battery) where i added all i want to have running when i don愒 have AC. Then, with acpid's help I configured the runlevel so that when i unplug the AC, it changes to battery runlevel, and the when i plug it again it gets back to default runlevel. This way, when I switch to the battery level i use speedfreq, hdparm and iwconfig to reduce the power consumption of the hardisk, the wireless card and the processor.
You can check the actual runlevel using rc-status:
Code:
# rc-status
Runlevel: battery
acpid started
alsasound started
domainname started
gpm started
hdparm.battery started
local started
metalog started
speedfreq.battery started
vixie-cron started
wireless.baterry started
more information about the RC- HERE.
For those who boot directly into X (xdm, gdm, kdm,..) i have read that you can put xdm and it's dependencies in boot runlevel, so that it will load X while loading the rest of services in the background. If someone have this running please comment so that the rest can use it.
3. cflags and ldflags
CFLAGS (you can set them at /etc/make.conf) are parameters we pass to gcc when we compile a package when emerging it. You can be more or less risky here, in THIS webpage and THIS one there is a lot of info on recommended configurations for CFLAGS. My CFLAGS for my pentium4 box are the following:
Code:
CHOST="i686-pc-linux-gnu"
CFLAGS="-march=pentium4 -mcpu=pentium4 -O3 -pipe -fforce-addr -falign-functions=4 -fprefetch-loop-arrays -fomit-frame-pointer"
note: cflags changed a little bit in gcc 3.4.X and -mcpu is deprecated, you should use -mtune instead. Moreover, pentium-m is accepted for centrino laptops. The CFLAGS of my centrino laptop are the following:
Code:
CFLAGS="-O3 -march=pentium-m -mtune=pentium-m -pipe -ftracer -fomit-frame-pointer -ffast-math -momit-leaf-frame-pointers"
As for the CXXFLAGS, -fvisibility-inlines-hidden has been reported as a good flag to improve the C++ compiles (thx teutzz).
Frepo has also been reported as a good cxxflag, but it does not perform very well on my system.
The ldflags are also interesting, they are discussed HERE and HERE. Ldflags are optimizations for the dinamyc loader (ld), so it's more or less the same way prelink would go. I am using them already and didn't have any problem when emerging new packages:
Code:
LDFLAGS="-Wl,-O1 -Wl,--enable-new-dtags -Wl,--sort-common -s"
Something more "stable" would be
Code:
LDFLAGS="-Wl,-O1"
note: those in the ldflags are "L", not "1" (in the -W)
note: some users reported errors using ldflags, if you have problems compiling a package try to remove them (and post ldflags/package in this thread).
NOTE: Cflags and Ldflags are and will be always a subject in which everybody has his opinion. The best way is to test them yourself, do somebenchmarks, and keep the flags you find optimal for your system. Also check the differents posts in the forums talking about this so that you can get an idea. A useful program to determine what cflags you should use, is ACOVEA (already in portage), which is a benchmarking tool that will do several tests on your machine (the standard test will run for more than 15 hours) to help you pick the best cflags for your machine. See THIS thread for acovea scripts and results.
4. Using hdparm
Another important application is hdparm. It allows us to configure our hard disk parameters, so get the maximum performance:
Code:
# emerge hdparm
# rc-update add hdparm default
See /etc/conf.d/hdparm
see actual configuration:
Code:
# hdparm -i /dev/hda
testing the speed:
Code:
# hdparm -Tt /dev/hda
In my computer I modifified /etc/conf.d/hdparm to get the maximum of my hard disk:
Code:
hda_args="-d1 -X69 -c1"
cdrom0_args="-d1"
If you need more information the man page is pretty good
Code:
# man hdparm
Also check THIS for a little tutorial.
5. Should you.. prelink?
Prelink is a powerful application, it allows us to pre-link the libraries needed for a binary before using it. So instead of looking for which libraries the binary will need when we launch it, prelink will modify the binary addind a little descriptions of the libs it nees to run. This get rid of the search for shared libraries everytime we launch the binary, so it makes it faster.
Important: Everytime that you upgrade the libraries that are needed for the binaries, (for example glibc) you have to re-run prelink on the system.
This is a little optimization that we will thank when launching big applications like KDE (moreover, if you prelink your system KDE will not need to launch kdeinit, so it will also run faster). The little binaries are already pretty fast, so will not appreciate the difference.
Requirements: it is a must to have compiled the binaries with binutils-2.13.90.0.xx and gcc-3.2 or higher, and also have installed glibc-2.3.1-r2 or higher. The size of the binaries will be bigger with prelink, and to run the process you need enough free space on the hard disk.
Way to go:
Code:
# emerge prelink
Find config file at /etc/prelink.conf
Code:
# prelink -afmR
This is the common use of prelink, that will prelink ALL the binaries, and also will look if the binaries were already prelinked, and prelink them again if needed.
It is possible that you get some errors when running prelink, because some binaries can not be prelinked (the ones compressed with upx, for example).
More information HERE, and/or man prelink.
6. Managing the swap
In this section I just wanted to mention some things that can help us.
First of all, if you have two harddisks it is better to put the swap partition on the second disk (having the root partition in the first one) as this will improve the read/write times.
Also you should NOT use a file as swap. I tried it once in an old computer, deleted the swap partition and set a file as ./swap of 256 MB.� and modified fstab. This method is slower, as it has to find the file, open the file, find were it was writting to it, writte to it, save, and close the
file. With a partition in the disc this process is pretty much faster.
Another concept to know about is swappiness (kernel 2.6+). When an application needs memory and the RAM is full, there are two options: or the RAM gets empties a little bit cleaning out old used memory, or swap memory gets used (slower than ram). In the new kernels, you can set a variable to define if the kernel should empty some ram or use the swap partition.
/etc/sysctl.conf
Code:
vm.swappiness = 40
This value can be between 0 and 100. Close to 0 will mean that the kernel should empty some ram, and a higher value close to 100 will tell the kernel to use the swap memory more often.
The default value is 60. I set this to 25 in my laptop, so that i can reduce the disk access. You can use 惠ree -m� to see the stats of your memory useage.
7. Ccache
ccache is an application (included en portage and on by default when emerging (if you emerge ccache)) that acts as a cache for the compiler.
With this little prog we will be able to compile in a faster way when compiling packages, specially with the big make's (you could think that using a cache when compiling has no use, but it speeds up some instructions like the make clean)
Just emerge it and set the default cache size (read the einfo after the emerge), and it will be on by default. You can check it with:
Code:
# emerge info | grep ccache
ccache version 2.3 [enabled]
You can check the ccache stats by doing:
Code:
# ccache -s
8. Distcc
distcc is an application that will make our life easier when installing gentoo in several computers, or if our computer is very slow but have another fast computer. It can be combined with ccache, optimizing the compiling time. I won't explaint this
feature a lot, because it's not used by everyone. Just that you know about it, because you can use cross-compiling with different computers with different processors, they will just share the compiling tasks.
More information HERE.
9. USE's
The USE flags are a useful tool that gentoo provides us with to configure our packages as we want them.
For example, imagine that you want to compile apache:
Code:
# emerge -pv apache
[ebuild N ] net-www/apache-2.0.50 -debug -doc -ipv6 +ssl 6,197 kB
The (+/-) options that appear after the name of the program we are going to install (-v flag) are the USE vars we can use to configure the package we are installing. If, for example, we don't want our apache to use ssl, we can do this:
Code:
# USE="-ssl" emerge -pv apache
[ebuild N ] net-www/apache-2.0.50 -debug -doc -ipv6 -ssl 6,197 kB
We can see that ssl is now off, and apache won't be compiled with ssl support.
In this example we set the USE var directly on the propmt, but this is not the correct way to do it if you want the system to remember the USE flags everytime you compile that package. You can set your USE flags in the /etc/make.conf file, or also use /etc/portage/package.use to set them for
individual packages.
It is the same for the "x86" flag (to tell portage to use the latest version available of every package), it's not recommended to just set the flag on the prompt, you should set it on /etc/make.conf to use it for all the packages, or set it individually:
Code:
# echo "app-editors/nano ~x86" >> /etc/portage/package.keywords
It is important to take a look at the USE flags of the packages before installing them, so that we can turn off features we won't be needing saving space and sometimes dependencies.
For example, if we want to emerge the console irc client BitchX, portage want to install xmms, X, and some other dependencies that could be useless for some of us. Setting -xxms and -X for xmms in the /etc/portage/package.use will allow us to install BitchX without the xmms and X support, and we won't need to install all those packages.
You can see that this is a powerful tool to use when emerging, it gives us a lot of control of how the packages will be installed in our system.
You have a little description of the USE flags in /usr/portage/profiles/use.desc
10. Modifying ebuilds and injecting packages
Always keep a backup of your files before modifying them (also note that emerge sync will fix if you mess an ebuild).
獨hat's injecting a package and what's the use of it?
Remember that time when you wanted to install package X, and as a dependency portage asked to install package Y? For example, a lot of users manage the kernel manually instead of using portage to do it (gentoo-sources, gentoo-dev-sources, vanilla-sources, and so on). Then, when you emerge some package that needs the kernel-sources (like alsa, or ipw2X00) installed portage will try to install some kernel-sources. Why would you do that if you already have your kernel at /usr/src?
note: injecting has been deprecated, now you should use package.provided and virtuals as explained
- using package.provided:
package.provided tells portage that a package is installed (even if it's not)
You can use this file to put all the packages you want to tell portage you installed by hand.
Code:
echo "sys-kernel/ck-sources" >> /etc/portage/profile/package.provided
package.provided doesn't affect virtuals, virtuals are used to tell portage what packages should install for a given category:
For example, you could tell portage that you want to satisfy x11 with xorg, and not xfree anymore (which is not a valid example anymore, but it is useful to understand the use of it)
Code:
echo "virtual/x11 x11-base/xorg-x11" >> /etc/portage/profile/virtuals
more information on this and /etc/portage management -> man portage
11. Halt vs Suspend
Have you never asked yourself why you shutdown you computer, when you can suspend it to ram or disk?
If you suspend to ram, it has the handicap that it will still need AC input in order to keep the system alive. But suspending to disk is very useful (specially for laptops), because the laptop will "shutdown", but we will keep our sesion.
Doing it this way we avoid to boot all the system services everytime (it not an instant recuperation from the "sleep", but seems faster).
I have used swsusp2 in my laptop and works fine, but you have to patch the kernel sources. You can find info in THIS post on how to do this. Try it and you won't regret.
12. Xdelta - Deltup
In THIS post Deltup is discussed, because a new version is available. The point is that everytime portage needs to download a file, deltup will look for an older version of the file (/usr/portage/distfiles) and try to download only the
difference between the two files, and create the new file on-the-fly.
This can be a big improvement for all those 56k users who keep their /usr/portage/distfiles in order to only download patches when new "revisions" are released, because this can lower the mb to download everytime they want to emerge new versions of the installed packages.
13. Native POSIX Thread Library
This library, know as NPTL, can improve our system, because it's up to 4 times faster than the standard LinuxThreads when creating new threads. You *should* use 2.6 linux headers, and a new version of glibc and gcc (~x86). To use ntpl you just have to recompile glibc with the USE flag
"nptl" turned on.
note: in order to use nptl you need gcc 3.x or higher installed.
HERE you can get more information and benchmarkings.
14. GCC
GCC is very important, specially in a distro like gentoo in which the users look to optimize their system by compiling theirselves the packages they install. Using an actual version of gcc has some advantages, because all the code we create when compiling will be more optimized (from version 3.4.x you can already use the -march=pentium-m for the centrino
processors).
To install the latest gcc, just emerge gcc with ~x86 turned on (rmember to change your profile also):
Code:
# echo "sys-devel/gcc ~x86" >> /etc/portage/package.keywords
# emerge -u gcc
15. Filesystems [data safety vs speed]
After trying out some filesystems, i use reiser4 because it's the fastest filesystem available. I think that it is very useful to use a fast filesystem, but you have to keep backups of your data just in case you have corruption issues.
Also point that, after using ext2, ext3, reiserfs, xfs, reiserfs and som other encripted filesystems i have never had corruption issues with my data. Just keep backups of your data and you will be all set.
Note that you need a version of the kernel with the reiser4 patches, so it will have to be a development patched release.
To convert your / partition to reiser4 you will need a livecd with reiser4 support like THIS one, and install a kernel with that support also.
NOTA: Some people have problems because they can't find the Reiser4 submenu in the Filesystems tree of the kernel, make sure that you have deactivated the option "use 4kb for kernel stacks instead of 8kb) under the kernel hacking submenu, and then you will find the Reiser4 option.
16. i/o and tasks schedulers
coming soon
17. Useful Scripts and tips
There are some useful scripts in the forums and the portage tree to manage our system:
1- esearch
This one is included in the portage tree (you can just emerge esearch), and it's an utility to search trought the portage package database. The good thing is that it's very fast (faster than emerge -sS).
Note that after every emerge sync we have to update de esearch database by running eupdatedb, or you can just use esync to update the portage tree (esync will emerge sync, and then show a list with the changes (new packages) from the last sync).
2- eix
The same concept as esearch, but it's faster (and it is also faster to update the package database).
It's a young project, but works pretty fine.
More info HERE.
3- Cruft
This script from will generate a list with all the files in our system that could be deleted because they don't belong to any installed package. You have to be careful when using it, because it can generase false positives.
Usage:
Code:
# ./cruft > cruft.log
Then you can check the list, and remove from it the files you want to keep.
Then you can run this command to get rid of the files:
Code:
# cat cruft.log | xargs rm -rf
You could also just take a look at the list and delete them yourself.
More info HERE.
4- Stale
Interesting script that will help us to keep /usr/portage/distfiles with an optimal size. The script will search in that dir, and delete (when invoked with the --nopretend option) the old files, not the actual ones.
For example, if we have libtool-1.3.5.tar.gz and libtool-1.5.2.tar.gz, it would delete libtool-1.3.5.tar.gz
It gets messed with files like font-arial-iso-8859-1 and font-arial-iso-8859-2, in which the numeration doesn't not correspond to the versioning of the package (the same with gtk and glib in their versions 1.x and 2.x)
More info HERE.
5- Porthole
Portage frontend made in python (+gtk), that offers us a visual way to configure portage, and it makes easier to configure the packages and emerges. It's already in portage, so you just have to "emerge porthole".
6- kuroo
Another portage frontend, this one is made with Qt (for the kde-lovers). It's a young project, but works fine.
More info HERE.
You can also find more useful scripts and programs related to Portage in THIS thread.
7- portage cdb
This is not a script itself, but it's a nice tip to improve the portage speed. Try it, you wont be disappointed!
8- mounting / in ram
very nice article, worth a read Smile http://forums.gentoo.org/viewtopic-t-296892.html
-under construction-
_________________
gentoo sex is updatedb; locate; talk; date; cd; strip; look; touch; finger; unzip; uptime; gawk; head; emerge --oneshot condom; mount; fsck; gasp; more; yes; yes; yes; more; umount; emerge -C condom; make clean; sleep
以下轉載自: 弱點掃瞄強大工具 Nessus
Nessus 是一款免費,經常更新且全功能的遠端弱點掃瞄強大工具, 支援各種平台如 Linux, BSD, Solaris 等. 它具備多執行緒, 採 plugin 基礎元件模式, 以良好的 GTK 介面來設計, 目前有超過1000個以上的弱點偵察能力. 另外, Nessus 有強大的報表功能, 能以多種格式輸出 (HTML, LaTeX, ASCII), 不僅可以指出問題所在, 更提示修補之道. 也有 Windows 版本喔.
國內也有廠商做類似的弱點掃瞄工具, 要價數10~60萬, 但功能未必及於 Nessus.
下載位址:
http://www.nessus.org/download/
TNC mirror:
ftp://ftp.tnc.edu.tw/pub/security-tools/nessus/nessus-installer-2.2.4.sh
htop - interactive processes viewer
一個類似 top 的工具. 不過顏色標示清楚, 且有圖形化(文字介面的圖形化).
看起來簡單、清楚又方便. 看系統 loading 的好工具.
可以去 http://htop.sourceforge.net/ 看看 Screenshots.
小小的工具. 但是很實用 ~ :)
Policyd is an anti-spam plugin for Postfix (written in C) that does greylisting, sender (envelope or SASL) based throttling (on messages and/or volume per defined time unit) and Spamtrap monitoring / blacklisting.
另一種防 Spam 的東東 - DomainKeys
網域認證鑰匙 DomainKeys
DomainKey Implementor's Tools and Library for email servers & clients (SourceForge)
一般預設的 shell command.(PS1='\u@\h:\w\$ ')
如果你打的字打到下一行去. 系統會自動的換到下一行去顯示文字.
但是如果自己要再加一些怪怪的東西, 一些控制碼(加顏色等等)..
就會遇到文字太長他不會自動換到下一行去的問題..
這時後 只要去修改 .bashrc 或 .bash_profile
在 PS1 = 前面加 \[ 於最後面加 \] 括起來.
ex: export PS1='\[\u@\h:\e[32m\w\e[0m$ \]'
這樣子就可以了.
(不用擔心 [ ] 這個會出現在自己的 command line)
[] 只是把那整個括起來的意思罷了. [] 不會顯示出來的 :)
Apache2 httpd.conf 設定檔的翻譯.
以下轉載自: Apache2的httpd.conf翻译
提交人: neosnake 时间: 四, 01/20/2005 - 15:04
Apache2的httpd.conf翻译
摘自http://www.linuxaid.com.cn/forum/
#
# 基于 NCSA 服务的配置文件。
#
#这是Apache服务器主要配置文件。
#它包含服务器的影响服务器运行的配置指令。
#参见以取得关于这些指令的详细信息
#
#不要只是简单的阅读这些指令信息而不去理解它。
#这里只是做了简单的说明,如果你没有参考在线文件,你就会被警告。
#
#这些配置指令被分为下面三个部分:
#1. 控制整个Apache服务器行为的部分(即全局环境变量)
#2. 定义主要或者默认服务参数的指令,也为所有虚拟主机提供默认的设置参数
#3. 虚拟主机的设置参数
#
#配置和日志文件名:如果你指定的文件名以“/”开始(win32下以“dirver:/”),
#服务器将使用绝对路径,如果文件名不是以“/”开始的,那么它将把ServerRoot
#的值附加在文件名的前面,例如,对“logs/foo.log",如果ServerRoot的值
#为“/usr/local/apache2”,则该文件应为“/usr/local/apache2/logs/foo.log”
#
##第一区:全局环境参数
#
#这里设置的参数将影响整个Apache服务器的行为;
#例如Apache能够处理的并发请求的数量等。
#
#ServerRoot:指出服务器保存其配置、出错和日志文件等的根目录。
#
#注意!如果你想要将它指定为NFS或其它网络上的位置,
#请一定要去阅读与LockFile有关的文档(可能在
#)。
#这将会使你自己也能解决很多问题。
#
#路径的结尾不要添加斜线。
#
ServerRoot "/usr/loacl/apache2"
#
#串行访问的锁文件必须保存在本地磁盘上
#
#LockFile logs/accept.lock
#ScoreBoardFile:用来保存内部服务进程信息的文件。
#如果未指明(默认),记分板(scoreboard)将被保存在一个匿名的共享内存段中,
#并且它不能被第三方软件所使用。
#如果指定了,要确保不能使用两个Apache使用同一个记分板文件,
#这个记分板文件必须保存在本地磁盘上。
#
#ScoreBoardFile logs/apache_runtime_status
#
#PidFile:记录服务器启动进程号的文件。
#
PidFile logs/httpd.pid
#
#Timeout:接收和发送前超时秒数
#
Timeout 300
#
#KeepAlive:是否允许稳固的连接(每个连接有多个请求),
#设为"Off"则停用。
#
KeepAlive On
#
#MaxKeepAliveRequests:在稳固连接期间允许的最大请求数,
#设为0表示无限制接入。
#我们推荐你将其设为一个较大的值,以便提高性能
MaxKeepAliveRequests 100
#
#KeepAliveTimeout:在同一个连接上从同一台客户上接收请求的秒数
#
KeepAliveTimeout 15
##
##Server-Pool大小设定(针对MPM的)
##
# prefork MPM
# StartServers:启动时服务器启动的进程数
# MinSpareServers:保有的备用进程的最小数目
# MaxSpareServers:保有的备用进程的最大数目
# MaxClients:服务器允许启动的最大进程数
# MaxRequestsPerChild:一个服务进程允许的最大请求数
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 150
MaxRequestPerChild 0
# worker MPM
# StartServers:服务器启动时的服务进程数目
# MaxClients:允许同时连接的最大用户数目
# MinSpareThreads:保有的最小工作线程数目
# MaxSpareThreads:允许保有的最大工作线程数目
# ThreadsPerChild:每个服务进程中的工作线程常数
# MaxRequestsPerChild:服务进程中允许的最大请求数目
StartServers 2
MaxClients 150
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 0
# perchild MPM
# NumServers:服务进程数量
# StartThreads:每个服务进程中的起始线程数量
# MinSpareThreads:保有的最小线程数量
# MaxSpareThreads:保有的最大线程数量
# MaxThreadsPerChild:每个服务进程允许的最大线程数
# MaxRequestsPerChild:每个服务进程允许连接的最大数量
NumServers 5
StartThreads 5
MinSpareThreads 5
MaxSpareThreads 10
MaxThreadsPerChild 20
MaxRequestsPerChild 0
# WinNT MPM
# ThreadsPerChild:服务进程中工作线程常数
# MaxRequestsPerChild:服务进程允许的最大请求数
ThreadsPerChild 250
MaxRequestsPerChild 0
# BeOS MPM
# StartThreads:服务器启动时启动的线程数
# MaxClients:可以启动的最大线程数(一个线程等于一个用户)
# MaxRequestsPerThread:每个线程允许的最大请求数
StartThreads 10
MaxClients 50
MaxRequestsPerThread 10000
# NetWare MPM
# ThreadStachSize:为每个工作线程分配的堆栈尺寸
# StartThreads:服务器启动时启动的线程数
# MinSpareThreads:用于处理实发请求的空闲线程数
# MaxSpareThreads:空闲线程的最大数量
# MaxThreads:在同一时间活动的最大线程数
# MaxRequestPerChild:一个线程服务请求的最大数量,
# 推荐将其设置为0,以实现无限制的接入
ThreadStackSize 65536
StartThreads 250
MinSpareThreads 25
MaxSpareThreads 250
MaxThreads 1000
MaxRequestPerChild 0
# OS/2 MPM
# StartServers:启动的服务进程数量
# MinSpareThreads:每个进程允许的最小空闲线程
# MaxSpareThreads:每个进程允许的最大空闲线程
# MaxRequestsPerChild:每个服务进程允许的最大连接数
StartServers 2
MinSpareThreads 5
MaxSpareThreads 10
MaxRequestsPerChild 0
#
# Listen:允许你绑定Apache服务到指定的IP地址和端口上,以取代默认值
# 参见指令
# 使用如下命令使Apache只在指定的IP地址上监听,
# 以防止它在IP地址0.0.0.0上监听
#
# Listen 12.34.56.78:80
Listen 80
#
# 动态共享支持(DSO)
#
# 为了能够使用那些以DSO模式编译的模块中的函数,你必须有相应的“LoadModule”行,
# 因此,在这里包含了这些指令,以便能在使用它之前激活。
# 那些静态编译的模块不需要在这里列出 (即以“httpd -l”列出的模块)
#
# 示例:
# LoadModule foo_module modules/mod_foo.so
#
#
# ExtendedStatus:当调用“server-status”时,控制Apache是产生“全”状态
# 信息(ExtendedStatus On),还是产生基本信息(ExtendedStatus Off)。
# 默认为off
#
# ExtendedStatus On
### 第二区:“主”服务配置
#
# 这一区建立被 “主” 服务器用的指令值,以回应那些不被
# 定义处理的任何请求。
# 这些数值也提供默认值给后面定义的容器。
# 如果中有定义,那么这里定义的指令值将被
# 中的定义所覆盖。
#
#
# 如果你想使httpd以另外的用户或组来运行,你必须在开始时以root方式启动
# 然后再将它切换为你想要使用的用户或组。
#
# User/Group:运行httpd的用户和组
# 在SCO (ODT3)上使用“User nouser”和“Group nogroup”
# 在HPUX上,你可能不能以nobody身份使用共享内存,建议创建一个www用户。
# 注意一些核心(kernel)在组ID大于60000时拒绝setgid(Group)或semctl(IPC_SET),
#节在这些系统上不要使用“Group #-1”。
#
User nobody
Group #-1
#
# ServerAdmin:你的邮件地址,当发生问题时Apache将向你发出邮件。
# 作为一个出错文档,这个地址显示在server-generated页上,
# 例如:admin@your-domain.com
#
ServerAdmin kreny@sina.com
#
# ServerName指定Apache用于识别自身的名字和端口号。
# 通常这个值是自动指定的,但是我们推荐你显式的指定它以防止启动时出错
#
# 如果你为你的主机指定了一个无效的DNS名,server-generated重定向将不能工作。
# 参见UseCanonicalName指令
#
# 如果你的主机没有注册DNS名,在这里键入它的IP地址
# 无论如何,你必须使用它的IP地址来提供服务,
# 这里使用一种容易理解的方式重定向服务
ServerName www.dalouis.com:80
#
# UseCanonicalName:决定Apache如何构造URLS和 SERVER_NAME 和 SERVER_PORT 的指令。
# 当设置为 “Off”时,Apache会使用用户端提供的主机名和端口号。
# 当设置为“On”,Apache会使用ServerName指令的值。
#
UseCanonicalName Off
#
# DocumentRoot:你的文档的根目录。默认情况下,所有的请求从这个目录进行应答。
# 但是可以使用符号链接和别名来指向到其他的位置。
#
DocumentRoot "/home/redhat/public_html"
#
# Apache可以存取的每个目录都可以配置存取权限(包括它的子目录)。
#
# 首先,我们配置一个高限制的特征。
# 这将禁止访问文件系统所在的目录,并添加你希望允许访问的目录块。
# 如下所示
Order Deny,Allow
Deny from all
#
# 注意从这里开始你一定要明确地允许哪些特别的特征能够被使用。
# - 所以,如果Apache没有象你所期待的那样工作的话,
# 请检查你是否在下面明确的指定它可用。
#
#
# 这将改变到你设置的DocumentRoot
#
#
# Options:这个指令的值可以是“None”,“All”,或者下列选项的任意组合:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# 注意,“MultiViews”必须被显式的指定,“Options All”不能为你提供这个特性。
#
# 这个指令既复杂又重要,请参见
#“http://httpd.apache.org/docs-2.0/mod/core.html#optioins”以取得更多的信息。
#
Options FollowSymLinks
#
# AllowOverride控制那些被放置在.htaccess文件中的指令。
# 它可以是“All”,“None”,或者下列指令的组合:
# Options FileInfo AuthConfig Limit
#
AllowOverride None
#
# 控制谁可以获得服务。
#
Order allow,deny
Allow from all
#
# UserDir:指定在得到一个~user请求时将会添加到用户home目录后的目录名。
#
UserDir public_html
# 为防止在UserDir指令上的漏洞,对root用户设置
# 象“./”这样的UserDir是非常有用的。
# 如果你使用Apache 1.3或以上版本,我们强烈建议你
# 在你的服务器配置文件中包含下面的行
UserDir disabled root
#
# 下面是一个使用UserDir指令使一个站点的目录具有只读属性的示例:
#
#
# AllowOverride FileInfo AuthConfig Limit Indexes
# Options MultiViews Indexes SymLinksIfOwnerMatch IncludeNoExec
#
# Order allow,deny
# Allow from all
#
#
# Order deny,allow
# Deny from all
#
#
#
# DirectoryIndex:定义请求是一个目录时,Apache向用户提供服务的文件名
#
# index.html.var文件(一个类型映象文件)用于提供一个文档处理列表,
# 出于同样的目的,也可以使用MultiViews选项,但是它会非常慢。
#
DirectoryIndex index.php index.html index.html.var
#
# AccessFileName:在每个目录中查询为目录提供附加配置指令的文件的文件名。
# 参见AllowOverride指令。
#
AccessFileName .htaccess
#
# 下面的行防止.htaccess和.htpasswd文件被Web客户查看。
#
Order allow,deny
Deny from all
#
# Typeconfig:定义在哪里查询mime.types文件。
#
TypeConfig conf/mime.types
#
# DefaultType:定义当不能确定MIME类型时服务器提供的默认MIME类型。
# 如果你的服务主要包含text或HTML文档,“text/plain”是一个好的选择;
# 如果大多是二进制文档,诸如软件或图像,你应使用
# “application/octer-stream”来防止浏览器象显示文本那样显示二进制文件。
#
DefaultType text/plain
#
# mod_mime_magic允许服务器从自己定义自己类型的文件中使用不同的线索(hints),
# 这个MIMEMagicFile指令定义hints定义所在的文件。
#
MIMEMagicFile conf/magic
#
# HostnameLookups:指定记录用户端的名字还是IP地址,例如,本指令为on时
# 记录主机名,如www.apache.org;为off时记录IP地址,204.62.129.132。
# 默认值为off,这要比设为on好得多,因为如果设为on则每个用户端请求都将会
# 至少造成对 nameserver 进行一次查询。
#
HostnameLookups Off
#
# EnableMMAP:控制是否进行内存转储(如果操作系统支持的话)。
# 默认为on,如果你的服务器安装在网络文件系统上(NFS),请关闭它。
# 在一些系统上,关闭它会提升系统性能(与文件系统类型无关);
# 具体情况请参阅http://httpd.apache.org/docs-2.0/mod/core.html#enablemmap
#
# EnableMMAP off
#
# EnableSendfile:控制是否使用sendfile kernel支持发送文件
# (如果操作系统支持的话)。默认为on,如果你的服务器安装在网络文件系统
# (NFS)上,请你关闭它。
# 参见http://httpd.apache.org/docs-2.0/mod/core.html#enablesendfile
#
# EnableSendfile off
#
# ErrorLog:错误日志文件定位。
# 如果你没有在内定义ErrorLog指令,这个虚拟主机的错误信息
# 将记录在这里。如果你在那儿定义了ErrorLog,这些错误信息将记录在你所
# 定义的文件里,而不是这儿定义的文件。
#
ErrorLog logs/error_log
#
# LogLevel:控制记录在错误日志文件中的日志信息数量。
# 可能的值包括:debug,info,notice,warn,error,crit,alert,emerg。
#
LogLevel warn
#
# 下面的指令为CustomLog指令定义格式别名。
#
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
# 你需要安装了mod_logio.c模块才能使用%I和%O。
# LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
#
# 指定接入日志文件的定位和格式(一般日志格式)。
# 如果你没有在内定义这个指令,传输信息将记录在这里,
# 如果你定义了这个指令,则记录在你指定的位置,而不是这儿定义的位置。
#
CustomLog logs/access_log common
#
# 如果你想要记录agent和referer信息,可以使用下面的指令
#
# CustomLog logs/referer_log referer
# CustomLog logs/agent_log agent
#
# 如果你想要使用一个文件记录access,agent和referer信息,
# 你可以如下定义这个指令:
#
# CustomLog logs/access_log combined
#
# ServerTokens
# 这个指令定义包含在HTTP回应头中的信息类型。默认为“Full”,
# 这表示在回应头中将包含模块中的操作系统类型和编译信息。
# 可以设为列各值中的一个:
# Full | OS | Minor | Minimal | Major | Prod
# Full传达的信息最多,而Prod最少。
#
ServerTokens Full
#
# 随意的添加包含服务器版本和虚拟主机名字一行信息到server-generated输出页中
# (内部错误文档,FTP目录列表,mod_status和mod_info输出等等,除了CGI错误
# 或自定义的错误文档以外)。
# 设为“EMail”将包含一个指向ServerAdmin的mailto:连接。
# 可以为如下值:On | Off | EMail
#
ServerSignature On
#
# Aliases:在这时添加你需要的别名,格式如下:
# Alias 别名 真实名
#
# 注意,如果你在别名的未尾包含了“/”,那么在URL中也需要包含“/”。
# 因此,“/icons”不是这个示例中的别名。
# 如果别名中以“/”结尾,那么真实名也必须以“/”结尾,
# 如果别名中省略了结尾的“/”,那么真实名也必须省略。
#
# 我们使用别名“/icons/”来表示FancyIndexed目录列表,如果你不使用、
# FancyIndexing,你可以注释掉它。
#
# Alias /icons/ "/usr/local/apache2/icons/"
#
# Options Indexes MultiViews
# AllowOverride None
# Order allow,deny
## Allow from all
#
#
# 这将改变ServerRoot/manual。这个别名提供了手册页所在的位置,
# 即使你改变了你的DocumentRoot。如果你对有无手册页并不在意的话,
# 你可以注释掉它。
#
Alias /manual "/usr/loacl/apache2/manual"
Options Indexes FollowSymLinks MultiViews IncludesNoExec
AddOutputFilter Includes html
Order allow,deny
Allow from all
#
# ScriptAlias:指定包含服务脚本的目录。
# ScriptAliases 本质上与Aliases一样,除了这里的文档在请求时做为程序处理处理以外。
# 尾部的“/”规则与Alias一样
#
ScriptAlias /cgi-bin/ "/usr/loacl/apache2/cgi-bin/"
# 这里是添加php 4支持的指令
AddType application/x-httpd-php .php
LoadModule php4_module modules/libphp4.so
#
# 添加mod_cgid.c设置,mod_cgid提供使用cgid进行通讯的UNIX套接字的
# 脚本接口路径。
#
# Scriptsock logs/cgisock
#
# 将"/usr/local/apache2/cgi-bin"改为你的ScriptAliased指定的CGI目录,
# 如果你配置了的话。
#
AllowOverride None
Options None
Order allow,deny
Allow from all
#
# Redirect允许你告诉客户端使用存在于服务器名字空间中的文档,
# 而不是现在的,这帮助客户定位那些改变了位置的文档。
# 例如:
# Redirect permanent /foo http://www.example.com/bar
#
# 控制server-generated目录列表显示的指令
#
#
# IndexOptions:控制server-generated目录列表显示特征。
#
IndexOptions FancyIndexing VersionSort
#
# AddIcon* 指令告诉服务器不同扩展名的图象文件如何显示,
# 只适用于FancyIndexed指令
#
AddIconByEncoding (CMP,/icons/compressed.gif) x-compress x-gzip
AddIconByType (TXT,/icons/text.gif) text/*
AddIconByType (IMG,/icons/image2.gif) image/*
AddIconByType (SND,/icons/sound2.gif) audio/*
AddIconByType (VID,/icons/movie.gif) video/*
AddIcon /icons/binary.gif .bin .exe
AddIcon /icons/binhex.gif .hqx
AddIcon /icons/tar.gif .tar
AddIcon /icons/world2.gif .wrl .wrl.gz .vrml .vrm .iv
AddIcon /icons/compressed.gif .Z .z .tgz .gz .zip
AddIcon /icons/a.gif .ps .ai .eps
AddIcon /icons/layout.gif .html .shtml .htm .pdf
AddIcon /icons/text.gif .txt
AddIcon /icons/c.gif .c
AddIcon /icons/p.gif .pl .py
AddIcon /icons/f.gif .for
AddIcon /icons/dvi.gif .dvi
AddIcon /icons/uuencoded.gif .uu
AddIcon /icons/script.gif .conf .sh .shar .csh .ksh .tcl
AddIcon /icons/tex.gif .tex
AddIcon /icons/bomb.gif core
AddIcon /icons/back.gif ..
AddIcon /icons/hand.right.gif README
AddIcon /icons/folder.gif ^^DIRECTORY^^
AddIcon /icons/blank.gif ^^BLANKICON^^
#
# DefaultIcon 为那些没有显式定义图标的文件提供处理
#
DefaultIcon /icons/unknown.gif
#
# AddDescription允许你在server-generated索引后放置一个简短的说明。
# 只对FancyIndexed指令有效。
# 格式:AddDescription "说明" 文件名
#
# AddDescription "GZIP compressed document" .gz
# AddDescription "tar archive" .tar
# AddDescription "GZIP compressed tar archive" .tgz
#
# ReadmeName指定服务器默认查找的README文件的名字,并添加到目录列表中
#
# HeaderName指定目录列表前缀文件的文件名
ReadmeName README.html
HeaderName HEADER.html
#
# IndexIgnore指定目录索引忽略并且不包含在列表中的文件名集合,
# 支持shell类型的通配符。
#
IndexIgnore .??* *~ *# HEADER* README* RCS CVS *,v *,t
#
# AddEncoding允许你在信息传送中使用(Mosaic/X 2.1+)解压缩信息,
# 注意:不是所有的浏览器都支持这个选项。
# 尽管名字相似,但是下列的指令与上面的FancyIndexing定制指令不同。
#
AddEncoding x-compress Z
AddEncoding x-gzip gz tgz
#
# DefaultLanguage和AddLanguage允许你指定文档的语言。
# 这使你可以让用户用容易理解的语言浏览文档。
#
# 指定默认的语言,这意味着所有没有指定语言的包都将使用该语言。
# 多数情况下,你也许并不想设置它,除非你确信这样做是正确的。
# 通常,不使用确定的语言比使用错误的语言要好。
#
# DefaultLanguage nl
#
# 注意1:作为语言关键字的词缀毫无疑问是不能一样的--采用波兰
# 文的文档(网络标准语言代码是pl)将希望使用“AddLanguage pl .po”
# 来避免与perl脚本的一般词缀产生二义性。
#
# 注意2: 下面的例子举例说明在一些范例中语言的二字符缩写与它的国家
# 的二字符缩写不相同,例如 “Danmark/dk” 和 “Danmark/da” 的比较.
#
# 注意3: 在 “ltz” 的情况下我们使用三字符词缀,违犯了 RFC的规定,
# 运行中将修复它并使用RFC1766标准取得参考数据。
#
# Danish (da) - Dutch (nl) - English (en) - Estonian (et)
# French (fr) - German (de) - Greek-Modern (el)
# Italian (it) - Norwegian (no) - Norwegian Nynorsk (nn) - Korean (ko)
# Portugese (pt) - Luxembourgeois* (ltz)
# Spanish (es) - Swedish (sv) - Catalan (ca) - Czech(cz)
# Polish (pl) - Brazilian Portuguese (pt-br) - Japanese (ja)
# Russian (ru) - Croatian (hr)
#
AddLanguage da .dk
AddLanguage nl .nl
AddLanguage en .en
AddLanguage et .et
AddLanguage fr .fr
AddLanguage de .de
AddLanguage he .he
AddLanguage el .el
AddLanguage it .it
AddLanguage ja .ja
AddLanguage pl .po
AddLanguage ko .ko
AddLanguage pt .pt
AddLanguage nn .nn
AddLanguage no .no
AddLanguage pt-br .pt-br
AddLanguage ltz .ltz
AddLanguage ca .ca
AddLanguage es .es
AddLanguage sv .sv
AddLanguage cz .cz
AddLanguage ru .ru
AddLanguage tw .tw
AddLanguage zh-tw .tw
AddLanguage hr .hr
# LanguagePriority允许你在会话过程中优先使用一些语言。
#
# 以优先次序递减的方式列出它们。我们或多或少地采用按字母排列顺序的方式
# 排列它们。也许你想要改变这个顺序。
LanguagePriority en da nl et fr de el it ja ko no pl pt pt-br ltz ca es sv tw
#
# ForceLanguagePriority 允许你为MULTIPLE CHOICES(Prefer)[在通讯的情况下]
# 或NOT ACCEPTABLE(Fallback)[没有可接受的语言匹配的情况]提供一个结果页。
#
ForceLanguagePriority Prefer Fallback
#
# 为发送出的所有页指定默认的字符集,这总是一个好主意,并且为你的
# web站点的国际化打开了大门,这不正是你曾经想要的吗。同样地,指定
# 默认字符集有一些小的损害,如一个使用iso-8859-1(latin1)标准命令
# 的页面,除非以别的方式指定例如你仅仅以显式方式声明它。
# 也有一些与那些总是鼓励你使用默认字符集的javascropt和URL语法有关
# 的浏览器安全原因。
#
#AddDefaultCharset ISO-8859-1
AddDefaultCharse GB2312
#
# 一般以文件扩展名的方式使用字符集。也许你想要避免与语言扩展发生
# 碰撞,除非你在每次改变后都做了很好的测试。
# 参见http://www.iana.org/assignments/character-sets以取得字符集
# 的名字列表和它们各自的RFCs。
#
AddCharset ISO-8859-1 .iso8859-1 .latin1
AddCharset ISO-8859-2 .iso8859-2 .latin2 .cen
AddCharset ISO-8859-3 .iso8859-3 .latin3
AddCharset ISO-8859-4 .iso8859-4 .latin4
AddCharset ISO-8859-5 .iso8859-5 .latin5 .cyr .iso-ru
AddCharset ISO-8859-6 .iso8859-6 .latin6 .arb
AddCharset ISO-8859-7 .iso8859-7 .latin7 .grk
AddCharset ISO-8859-8 .iso8859-8 .latin8 .heb
AddCharset ISO-8859-9 .iso8859-9 .latin9 .trk
AddCharset ISO-2022-JP .iso2022-jp .jis
AddCharset ISO-2022-KR .iso2022-kr .kis
AddCharset ISO-2022-CN .iso2022-cn .cis
AddCharset Big5 .Big5 .big5
# 对于俄语,使用了多个字符集(如何使用主要依靠客户端):
AddCharset WINDOWS-1251 .cp-1251 .win-1251
AddCharset CP866 .cp866
AddCharset KOI8-r .koi8-r .koi8-ru
AddCharset KOI8-ru .koi8-uk .ua
AddCharset ISO-10646-UCS-2 .ucs2
AddCharset ISO-10646-UCS-4 .ucs4
AddCharset UTF-8 .utf8
# 下面的字符集没有映射到一个特定的标准(iso)上,但是它们在浏览器
# 中被广泛的支持。注意那些大写字母。
# (它不应该,但是它是为兼容一些浏览器而做)
#
# 参见http://www.iana.org/assianments/character-sets以取得
# 它们的列表。但是浏览器支持较少。
#
AddCharset GB2312 .gb2312 .gb
AddCharset utf-7 .utf7
AddCharset utf-8 .utf8
AddCharset big5 .big5 .b5
AddCharset EUC-TW .euc-tw
AddCharset EUC-JP .euc-jp
AddCharset EUC-KR .euc-kr
AddCharset shift_jis .sjis
#
# AddType允许你为指定的文件类型添加或覆盖mime.types文件中配置的MIME
#
AddType application/x-tar .tgz
AddType image/x-icon .ico
#
# AddHandler允许你映射确定的文件扩展名到“handlers”:
# 与文件类型无关的行为。这既能编译到服务器中也可以添加到Action指令
# 中(看下面)。
# 为了在ScriptAliased指令指定的以外使用CGI脚本:
#(要使它可用,你还需要在Options中添加“ExecCGI”。
#
# AddHandler cgi-script .cgi
#
# 对于那些包含他们自己的HTTP头的文件
#
# AddHandler send-as-is asis
#
# 对于server-parsed imagemap文件:
#
# AddHandler imap-file map
#
# agemap 文件:
#
#AddHandler imap- 文件映像
#
# 对于类型映像:(转移资源)
#(这是默认的设定以允许Apache的“It Worked”页能多种语言分发)。
#
AddHandler type-map var
#
# 过滤器允许你在将它发送到客户端前进行处理。
#
# 为了在服务器端分析包含(SSI)的.shtml文档:
# (要执行这个指令,你还需要在Options指令中添加“Includes”。)
#
# AddType text/html .shtml
# AddOutputFilter INCLUDES .shtml
#
# Action让你定义当调用匹配的媒体文件时将要执行的脚本。这将减少
# 那些经常使用的CGI脚本的URL路径名的重复输入。
# 格式:Action media/type /cgi-script/location
# 格式:Action handler-name /cgi-script/location
#
#
# 可配置的错误应答有三种风格:
# 1)plain text 2)local redirects 3) external redirects
#
# 一些示例:
# ErrorDocument 500 "The server made a boo boo."
# ErrorDocument 404 /missing.html
# ErrorDocument 404 "/cgi-bin/missing_handler.pl"
# ErrorDocument 402 http://www.example.com/subscription_info.html
#
#
# 综合应用这些指令,我们可以创建一个国际化的出错应答。
#
# 我们使用Alias来重定向任意/error/HTTP_.html.var应答到
# 我们的多语言错误消息集合。使用正确的文本替代它。
#
# 通过加入下面的行,你就能够改变这些消息的显示,而不必改变
# HTTP_.html.var文件。
#
# Alias /error/include/ "/your/include/path/"
#
# 以将/usr/local/apache2/error/include/下的文件拷贝到/your/inclue/path/下
# 开始,你可以创建你自己的文件集合,甚至是其于每个虚拟主机的。
# 不管你的ServerSignature如何设置,默认的包含文件将显示你的
# Aapche版本号和你的ServerAdmin邮件地址
#
# 国际化的错误文档需要mod_alias,mod_include和mod_negotiation三个
# 模块。要激活它们,取消下面30行的注释符号
# Alias /error/ "/usr/local/apache2/error/"
#
#
# AllowOverride None
# Options IncludesNoExec
# AddOutputFilter Includes html
# AddHandler type-map var
# Order allow,deny
# Allow from all
# LanguagePriority en de es fr it nl sv
# ForceLanguagePriority Prefer Fallback
#
#
# ErrorDocument 400 /error/HTTP_BAD_REQUEST.html.var
# ErrorDocument 401 /error/HTTP_UNAUTHORIZED.html.var
ErrorDocument 403 /error.php
# ErrorDocument 404 /error/HTTP_NOT_FOUND.html.var
# ErrorDocument 405 /error/HTTP_METHOD_NOT_ALLOWED.html.var
# ErrorDocument 408 /error/HTTP_REQUEST_TIME_OUT.html.var
# ErrorDocument 410 /error/HTTP_GONE.html.var
# ErrorDocument 411 /error/HTTP_LENGTH_REQUIRED.html.var
# ErrorDocument 412 /error/HTTP_PRECONDITION_FAILED.html.var
# ErrorDocument 413 /error/HTTP_REQUEST_ENTITY_TOO_LARGE.html.var
# ErrorDocument 414 /error/HTTP_REQUEST_URI_TOO_LARGE.html.var
# ErrorDocument 415 /error/HTTP_SERVICE_UNAVAILABLE.html.var
# ErrorDocument 500 /error/HTTP_INTERNAL_SERVER_ERROR.html.var
# ErrorDocument 501 /error/HTTP_NOT_IMPLEMENTED.html.var
# ErrorDocument 502 /error/HTTP_BAD_GATEWAY.html.var
# ErrorDocument 503 /error/HTTP_SERVICE_UNAVAILABLE.html.var
# ErrorDocument 506 /error/HTTP_VARIANT_ALSO_VARIES.html.var
#
# 下面的命令更改标准的HTTP应答行为以处理己知的浏览器问题。
#
BrowserMatch "Mozilla/2" nokeepalive
BrowserMatch "MSIE 4\.0b2;" nokeepalive downgrade-1.0 force-response-1.0
BrowserMatch "RealPlayer 4\.0" force-response-1.0
BrowserMatch "Java/1\.0" force-response-1.0
BrowserMatch "JDK/1\.0" force-response-1.0
#
# 下面命令关闭对那些没有尾部“/”的目录的非GET请求的重定向,
# 这些命令修复了微软的采用DAV方法不能正确处理重定向的WEB文件夹的问题。
# Apple下的DAV文件系统和Gnome下的VFS对DAV的支持也是采用这样的方法
# 进行处理的。
#
BrowserMatch "Microsoft Data Access Internet Publishing Provider" redirect-carefully
BrowserMatch "^WebDrive" redirect-carefully
BrowserMatch "^WebDAVFS/1.[012]" redirect-carefully
BrowserMatch "^gnome-vfs" redirect-carefully
#
# 允许你使用URL:http://servername/server-status来通过mod_status生
# 成并报告服务器状态信息。改变.example.com为你自己的域名。
#
#
# SetHandler server-status
# Order deny,allow
# Deny from all
# Allow from .example.com
#
#
# 允许使用URL:http://servername/server-info来远程报告服务器配置信息
# (需要mod_info.c支持)。改变“.example.com”为你自己的域名。
#
#
# SetHandler server-info
# Order deny,allow
# Deny from all
# Allow from .example.com
#
#
# 代理服务器命令,去掉下面的行使代理服务可用。
#
#
# ProxyRequests On
#
# Order deny,allow
# Deny from all
# Allow from .example.com
#
#
# 安装或关闭HTTP/1.1“通道”头处理。
# (“Full”添加服务器版本信息,“Block”移掉所有输出“通道”头信息。
# 可以设为下面各选项之一:Off | On | Full | Block
#
# ProxyVia On
# 最好为代理服务安装高速缓冲,去掉下面几行的注释符号:
# (没有CacheRoot则不缓冲)
#
# CacheRoot "/usr/local/apache2/proxy"
# CacheSize 5
# CacheGcInterval 4
# CacheMaxExpire 24
# CacheLastModifiedFactor 01
# CacheDefaultExpire 1
# NoCache a-domain.com another-domain.edu joes.garage-sale.com
#
# 代理命令结束。
#
# 附加的特定模块配置。
#
Include conf/ssl.conf
## 第三区:虚拟主机
#
# VirtualHost:你可以通过设置虚拟主机容器以实现在你的主机上保有多个
# 域名/主机名。大多数配置信息只使用基于名字的虚拟主机,因此服务器
# 不必担心IP地址的问题,下面的命令以*号代替虚拟主机名。
#
# 在你试着配置你的虚拟主机以前,请参见
# URL:http://httpd.apache.org/docs-2.0/vhosts/>以取得更多的信息。
#
# 你可以使用命令行选项“-S”来检验你的虚拟主机配置。
#
# 使用基于名字的虚拟主机。
#
# NameVirtualHost *
#
# 虚拟主机示例:
# 几乎所有的Apache命令都可以在虚拟主机容器中使用。
# 第一个虚拟主机区是用于向服务名未知的请求进行应答的配置。
#
#
# ServerAdmin webmaster@dummy-host.example.com
# DocumentRoot /www/docs/dummy-host.example.com
# ServerName dummy-host.example.com
# ErrorLog logs/dummy-host.example.com-error_log
# CustomLog logs/dummy-host.example.com-access_log commom
#
本文最新 url Apache 1.x版 部份參數說明(I) 38, 39 就是其它兩部份.
非常棒的一份文件. Part I ~ III
一定要轉載過來好好學習.
以下轉載自: apache 部份參數說明
AllowOverride 的屬性功能
AllowOverride Limit 允許蓋掉原聯結屬性得範圍
AllowOverride Authconfig 可做密碼設定:如:藏密
AllowOverride Options 可將該目錄之Options 功能覆蓋
AllowOverride FileInfo 可將該目錄之任何文件型態覆蓋,如:DefaultType,ErrorType
AllowOverride Indexs 可將該目錄之顯式列印功能覆蓋,如:AddIcon,HeaderName.ReadName
Options的屬性功能
Indexs 當無index.html可用列印目錄方式顯式,如:center3 homepage 若用 -Indexs 則看不見 listing
FollowSymLinks 加一屬性如+FollowSymLinks可允許使用symbol link 時,依舊可瀏覽
ExecCGI 當為 +ExecCGI可執行 CGI SCRIPT
Includes 可執行Server site include,若為 +Includes
IncludesNOEXEC 可執行Server site include,若為 +Includes,但不可執行CGI
None 沒有任何功能可用
All 均可
總之,以 +, - 符號可加或刪減其功能,若未給符號,則只有初步功能
Limit的屬性功能
GET 限定取得文件法,如:<Limit GET>
POST 限定cgi post方法,如:<Limit POST>
order 限定拒絕或允許的次序
deny 限定拒絕範圍,如:deny from all 或 deny from .mycompany.com
allow 限定允許範圍,如:allow from all 或 allow from 192.153.22
AuthConfig 之方法 & .htaccess 範例
<Files index.html>
#與Directory同,但在 .htaccess 只能用他 AuthName Members-only 設定僅 Member 才可入,僅為名稱 AuthType Basic 解碼方法 AuthUserFile /home1/users/center/center21/public_html/wwwclass/bau
#密碼表位置(絕對位置) AuthGroupFile /home1/users/center/center21/public_html/wwwclass/group
#同群表位置
<Limit GET>
#限制取件
require user center21
#bau的密碼表有很多user,但....
order allow,deny
#先允許在拒絕
allow from all
#允許全部
</Limit>
<Files>
密碼表之產生方法
找到及取得htpasswd程式
執行htpasswd -c filename username (第一次,以後僅htpasswd filename username)
修改需要的 user (在 require 後)
require用法
require user center21 center3
require group cc cv ee
都會啟動httpd以隨畤提供服務。
# inted:需要時才臨時啟動,監聽所有進入本機請求的port,然後核對port所對應的服務
以決定要用哪一個服務,再執行httpd,當請求完結就將httpd結束。
# 語法:Port [編號]
# 說明:指定 httpd 服務的閘道,一般是 80,
# 2000 以後的 URL 就必須寫成 http://xx.xx.xx.xx:2000/
# 語法:HostNameLookups [on/off]
# 說明:設定要不要把自動搜尋 HostName 的功能打開