目前分類:Linux (90)

瀏覽方式: 標題列表 簡短摘要

Understanding Bash fork() bomb ~ :(){ :|:& };:

by VIVEK GITE

Bluelove1968 發表在 痞客邦 留言(0) 人氣()

7 個致命的 Linux 命令

Bluelove1968 發表在 痞客邦 留言(0) 人氣()

《Linux下的安全工具》

 
一、摘要
資訊科技的進步帶給人們極大的方便,尤其是企業更需要資訊科技的幫助。但是相對
之下,安全的議題就更為重要了。如果企業的資料被竊取或是系統被入侵而導致的阻斷服
務等等損失,皆是難以估計的。然而人們總是等到系統被駭客入侵或接收到安全事件報告
時,才會去注意到安全環境的重要性。為了進一步強化系統的安全性,本文介紹了一些在
Linux 環境下,如在強化系統、系統監控、網路監控上重要常用的安全工具。

二、安全工具簡介
1.Nmap
Nmap 是一套免費的開放原始碼工具,它可以探測網路或安全稽核。俗語說的好:「
水可載舟,亦可覆舟」,Nmap 也常常被當作駭客進行入侵偵測的基本工具。Nmap 可
以探測網路上的主機有開啟什麼樣的服務,正在執行的作業系統版本,以及是否有使
用封包過濾器或防火牆。對一個系統管理者來說 Nmap 提供了系統基本安全測試,可
以使得我們知道現有網路設備提供怎樣的資訊給入侵者,以及如何對這些弱點進行更
新。至於對於一位有心的入侵者,Nmap 更提供了許多有力的資訊。

Nmap 可以在 http://www.insecure.org/nmap/ 取得,而其更新的版本提供了更強大
的功能。Nmap 可以針對一個網段進行掃瞄,也可針對單一主機進行更高階的掃瞄,
例如 stealth scanning,即想要得到對方主機資訊同時也不希望在對方主機上留下
任何掃瞄的資訊所使用的方式。Nmap 也可以使用 SYN Scan,這種掃瞄技巧通常稱為
half-open scanning,因為我們通常並不是真的去建立一個連線,只是讓對方以為我
們要建立連線。有時候在掃瞄的時候,連 SYN Scan 都不夠秘密而被某些防火牆或是
filter 監控紀錄,0便會使用其他比較特殊的掃瞄方式,送出一些定義未明的封包來
做掃瞄如 Stealth FIN, Xmas Tree, 或 Null scan。Nmap 除了利用 TCP 協定之外
,也利用了 UDP 協定來掃瞄,許多進階的掃瞄技術都可以參考 Nmap 的指令說明。

2.Nessus
在介紹完 Nmap 之後,我們繼續介紹一另個功能強大、免費、執行速度快的弱點掃瞄
軟體。系統管理者可以搭配 Nmap 掃瞄出系統所開的服務之後,再依照所設定要掃瞄
的項目去逐一掃瞄系統上所有的服務。Nessus 是針對伺服器作業系統以及所提供服
務的弱點所設計出來的掃瞄的軟體,而 Nessus 其實可以視為一種攻擊工具,掃瞄程
式以 NASL 寫成 script,而每種弱點都寫成一隻 plugin,這種 plugin 的架構在維
護更新攻擊測試程式是迅速方便的。

Nessus 可以在 http://www.nessus.org 中找到免費的原始碼,而目前的 plugin 種
類眾多,有Backdoors, CGI abuses, Denial of Service, Finger abuses,
Firewalls, FTP, Gain a shell remotely, Gain root remotely, General, Misc.,
NIS, Port scanners, Remote file access, RPC, SMTP problems, Useless
services, Windows。而且在 Nessus 的網站上會定期的發布最新的 plugin 提供下
載,而 Nessus 的掃瞄也可是自動化的(cron jobs)。在掃瞄的結果方面,Nessus 提
供了很詳細的資訊,會將弱點分成低、中、高,三個等級,並且也有描述解決方式,
供管理者方便去更新軟體漏洞。Nessus 是一種 client-server 的架構,server 負
責對所欲測試的電腦或網段進行攻擊,client 則是負責監看掃瞄的結果。Nessus 不
會拘泥於 IANA 所定的埠號來決定服務的項目,它不會因為 FTP server 開啟不是 21
port 的服務就識別不出來此為 FTP 服務。

3.TCPWrappers
當我們關閉系統上的所有服務時,可以確保系統在安全機制上不易被入侵,但是這卻
是不可能的,因為我們一定會在系統上執行一些服務,例如 FTP 或 Telnet。而
TCPWrapper 就是一個簡單易用的網路存取控制工具,主要的功能在紀錄並攔截由
inetd 管理的 TCP 服務,一旦有連線被建立得時候,TCPWrapper 會由 inetd 所啟
動。如 BBS一樣,server 端會送訊息給 client 端,TCPWrapper 也具有 DNS 反查
的功能,比對連線 IP 和主機名稱,可以檢查是否相符,供日後分析。TCPWrappers
支援簡單形式的存取控制,可以對每個服務或主機或結合二者來進行控制,存取控制
也可以限制使用者連到適當的服務,例如當在國內時,gopher 或 www 資料庫會顯示
當地的語言,如果是連線到國外就顯示英文。

但是 TCPWrappers 還是有一些缺點,例如它對於 IP Spoofing 的攻擊沒有辦法有效
的阻擋,因為 TCPWrappers 對 IP 所採用的認證機制,而這正好讓駭客利用 IP
Spoofing 的技術進行入侵。而比較好的防治辦法就是在防火牆上設定規則,有可能
類似 IP Spoofing 的封包就加以攔截。另一個缺點是,TCPWrapper 對 UDP 的支援
較少,而有些功能不適用於 UDP 服務,故伺服器會接收來源不名的封包。

4.Tripwire
Tripwire 其實是一種入侵偵測系統 (IDS),但是由於它對於檔案監控的強大功能,
使得大多數的系統管理者使用此功能勝於其入侵偵測的功能。Tripwire 與其它偵測
入侵系統軟體不同的是,它並非用來偵測系統的異常或被誤用,而是專注在系統的完
整性上。系統管理者必須對 Tripwire 加以認識的是,一般的偵測系統大都以過濾
syslog 或稽核追蹤,來找出可能被攻擊的證據,而 Tripwire 卻是將焦點集中在偵
測系統檔案是否被未經授權者竄改。Tripwire 會針對檔案系統做完整稽核的保護,
可以很快地發現檔案以及目錄是否遭到修改,以及利用電子郵件通知管理者,以便管
理者能很快地將遭受攻擊的檔案做復原。Tripwire 採用的技術為數位簽章,就是對
所欲監控的文件或檔案,產生一份簽章,而以後在稽核文件的時候也對同一份文件產
生簽章,用來比對是否一致,才可知道是否被竄改了。

Tripwire 可以追縱系統上所安裝、移除或修改的軟件,對於惡意的程式碼、探測器
(sniffers)、木馬 (trojans) 或任何後加於系統的軟件都能有效的控制。Tripwire
也可以用來當作電腦鑑識 (forensics)的功能,它提供有利的證據對於想要告發的入
侵者。

5.Logcheck
記錄和稽核各系統每日所發生的事件是必須做的事,這樣一來可以使系統管理員更有
效地做稽核追蹤來發現異常事件,早一步阻止入侵和被破壞。但是每日的日誌檔案實
在是太多了,系統管理員根本無法從這些大量的檔案去檢查,太浪費時間與成本了。
而 Logcheck 可以自動地將正常的日誌檔案刪除,一些有問題的日誌檔案將會被郵寄
給系統管理原來審核。Logcheck 會處理來自於由系統 daemons、TCPWrappers、log
daemons 所產生的日誌檔案。Logcheck 利用一個叫 logtail 的程式記住上次讀過日
誌檔案的位置,然後下一次在從此位置繼續讀取新的日誌檔案。

Logcheck 的通知沒有那麼即時,但是相對於 swatch (即時的日誌監控工具) 它更適
合於分散式日誌文件系統。因為它不必為每個日誌文件建立一個處理序。

6. Snort
Snort 為一個免費開放原始碼的網路入侵偵測系統,它能執行即時的流量分析和封
包偵測,具有網路資料即時分析、報告以及日誌的能力。它也能執行通訊協定分析
、內容搜尋與比對、以及可使用來偵測各種攻擊,例如:CGI 攻擊、緩衝區溢出、
異常埠的掃瞄、作業系統特徵攻擊…等等,可以將警告資訊寫到 syslog、或特定的
文件檔;如果有人試著 telnet 或是 ftp 你的機器時,你可將這些動作紀錄或是設
定用 Winpopup 的方式告知其他 windows 的機器。

Snort 有三種主要模式:封包嗅探器、封包記錄器或成熟的侵入探測系統。遵循開
發/自由軟體最重要的慣例,Snort 支援各種形式的插件、擴充和定製,包括資料庫
或是 XML 記錄、統計的異常探測等。封包有效載荷探測是 Snort 最有用的一個特
點,這就意味著很多額外種類的敵對行d可以被探測到。 Snort 使用一個較彈性規
則的語言來描述需要收集或略過的流量,以及一個使用模組化 plugin 架構的偵測
引擎。Snort 有三個主要的使用方式,它可以直接被當作如 tcpdump 一樣的封包嗅
探器,或當做網路流量的封包日誌,或當作一個完整的網路入侵偵測系統。Snort
屬於一種輕量級的網路入侵偵測系統 (NIDS),它容易安裝設定,它目前可以偵測超
過1100種潛在的安全弱點。

三、其他安全工具
因為篇幅的關係,沒辦法繼續介紹其他有用的安全工具。在此簡列一些常用的安全工
具:

工具名稱(工具作用)
Sxid(檢查系統中的 suid,sgid 以及沒有主人的文件)
skey(一次性密碼工具)
logrotate(日誌循環工具)
logcheck(日誌管理工具)
swatch(日誌管理工具,比 logcheck 即時)
Ssh(openssh)(提供安全的連線認證)
openssl(提供加密的資料傳送和認證)
Portsentry(反掃瞄工具,監視自己的udp和tcp連接埠)
gnupg(對單個文件進行加密以及建立數位簽章)
hostsentry(基於主機的入侵偵測,將連線記入日誌)
ipchains(Linux發行版內建的封包過濾形防火牆)
CFS和TCFS(密碼文件系統和透明的密碼文件系統實作目錄下所有文件加密,基於 NFS)
Anti-sniff(反嗅探工具,檢查網路中是否有探測器)
Freeswan(在 linux 實作 VPN 的工具)
Syslog-ng(替代 syslog 的日誌文件系統)
Scandns(進行 dns 檢查追蹤的工具)
Whisker Cgi(掃瞄器)
Snoopy(透過追蹤 execve 系統呼叫記錄執行的指令)
Linux kernel patch(核心的安全修正檔,防止緩衝區溢位等)
krnsniff(一個基於核心的監聽模組)
iptable(用來替代ipchains的封包過濾防火牆)
Imsafe(透過追蹤系統呼叫來偵測緩衝區溢位等問題)
Iplog(對來往的封包進行日誌記錄)
Solaris designer(核心修正檔,防止緩衝區溢位等)
Stackguard(作為修正檔修補gcc,防止緩衝區溢位)
DTK(Honey port欺騙式防禦)
Antiroute(阻止和記錄基於路由的追蹤)

(資料來源:http://www2.tw.ibm.com/developerWork...ctTutorial.do?
tutorialId=268)

四、結論
沒有一個系統是完美無缺的,根據資料顯示 Linux 最新版的內核升級距上次升級不
到二個月,由此可知系統漏洞實在是無可避免的。我們所能做的就是儘量維護系統的安全
,時時關心最新安全漏洞以及安全新聞,定時的將系統或應用程式更新,以防被入侵。而
本篇也介紹了一些常用的安全工具,雖然不一定能確保系統能百分之百安全,但是讓一般
使用者也能知道如何做到防範您的Linux系統安全。

參考資料:
1.Bobby S. Wen, Security Tools in Linux Distributions,Linux Journal 2002
2.TCPWrippers工具簡介
http://www.cert.org.tw/
http://www.sunfreeware.com/README.tcpwrappers
3.Tripwire工具簡介
http://securitypronews.com/securityp...-Tripwire.html
http://www.tripwire.org/qanda/index.php#1
http://www2.tw.ibm.com/developerWork...tutorialId=268
3.Logcheck工具簡介
Securing and Optimizing Linux: RedHat Edition -A Hands on Guide, Chapter 14.
Software -Security/Monitoring, Logcheck.
http://www.linuxsecurity.com/docs/Se...p14sec114.html
http://www.freeos.com/articles/3540/
4.Nmap工具簡介
http://www.insecure.org/nmap/index.html
http://www.insecure.org/nmap/nmap_doc.html
5.Snort工具簡介
http://www.snort.org/about.html
http://www.geekcomix.com/cgi-bin/cla...ction_To_Snort
6.Nessus工具簡介
http://www.nessus.org/intro.html
http://www.nessus.org/features.html


Bluelove1968 發表在 痞客邦 留言(0) 人氣()

[HowTo] Linux 用兩張網卡作不同子網路設定

在 Linux 下要使用兩張網卡時,是可直接設定不同的 IP Address,但必須同屬於一個子網路,因為 Default Gateway 預設只能有一個,

Bluelove1968 發表在 痞客邦 留言(0) 人氣()

Fedora 7 upgrade Fedora 8

由於 W6A 無法用 Fedora 8 DVD 安裝,決定用升級方式處理。打開終端機,按照步驟升級。

  1. su -
  2. yum update
  3. yum clean all
  4. rpm -Uhv ftp://download.fedora.redhat.com/pub/fedora/linux/releases/8/Fedora/i386/os/Packages/fedora-release-8-3.noarch.rpm
  5. rpm -Uhv ftp://download.fedora.redhat.com/pub/fedora/linux/releases/8/Fedora/i386/os/Packages/fedora-release-notes-8.0.0-3.noarch.rpm
  6. yum upgrade
  7. reboot

升級過程蠻久,有點耐心等待吧。

Bluelove1968 發表在 痞客邦 留言(0) 人氣()

YUM & APT 套件管理調校

YUM, 全名 Yellowdog Updater Modified

Bluelove1968 發表在 痞客邦 留言(0) 人氣()

  • Sep 12 Wed 2007 01:38
  • find

find

find is one of the most useful Linux/Unix tools around, but most people use only a fraction of its power. Many Linux/Unix questions seen online can be solved using the find command alone; it's simply a matter of becoming familiar with its options.

The power of find lets you do anything from finding all your .jpg files to seeing "all of Michael's files that have the execute bit set and have been modified since yesterday." When combined with xargs, a properly wielded find command can make many common tasks ten times easier.

Bluelove1968 發表在 痞客邦 留言(0) 人氣()

本人安裝有多個作業系統,有XP,多個版本核心的LINUX,使用GRUB的過程中有過多種情況發生,下面和大家討論解決的方法。

Bluelove1968 發表在 痞客邦 留言(0) 人氣()

在 RedHat9下架設 PPPOE-Server

前提 :已經安裝好linux作業系統(桌面或是工作站)。

  因為在安裝的時候會對安裝的軟體套件進行選擇,所以首先要查看原有系統是否已經安裝了rp-pppoe。

  在終端程式下輸入以下命令:
   # rpm –q rp-pppoe

Bluelove1968 發表在 痞客邦 留言(0) 人氣()

Linux-DNS-HOWTO

①簡介
DNS就是Domain Name System,它能夠把形如www.21php.com這樣的域名轉換為211.152.50.35這樣的IP地址;沒有DNS,瀏覽21php.com 這個網站時,就必須用211.152.50.35這麼難記的數字來存取。提供DNS服務的就是DNS伺服器。DNS伺務器可以分為三種,高速緩存伺器 (Cache-only server)、主伺器(Primary Name server)、輔助伺器(Second Name Server)。

DNS的詳細原理、工作流程、術語、概念,限於篇幅,這裡就不說了。可以閱讀專門的文章,如DNS-HOWTO加以瞭解。

②配置主DNS伺
首先我們做以下假設:A伺器為21php.com的主域名伺器,其IP地址為11.0.0.1,B伺器為21php.com的輔助域名伺器,其IP地址為11.0.0.2;

下面我們配置伺務器11.0.0.1為21PHP.COM的主DNS伺

Linux下的dns功能是通過bind軟件實 現的。bind軟件安裝後,會產生幾個固有檔案,分為兩類,一類是配置檔案在/etc目錄下,一類是dns 記錄檔案在/var/named目錄下。加上其他相關檔案,共同設置dns伺器。下面是所有和dns設置相關檔案的列表與說明。

位於/etc目錄下的有:hosts,host.conf,resolv.conf,named.boot,named.conf。

1、「hosts」檔案,定義了主機名和ip地址的對應,其中也有將要運行dns這台電腦的ip地址和主機名。內容:
127.0.0.1 localhost.localdomain localhost

Bluelove1968 發表在 痞客邦 留言(0) 人氣()

Linux Kernel Thread

Written by dahuja76 - 2006-10-08 06:34
LINUX KERNEL SERIES

Author:Dinesh Ahuja

Bluelove1968 發表在 痞客邦 留言(0) 人氣()

Linux Kernel Threads in Device Drivers

Purpose

This examples shows how to create and stop a kernel thread.
The driver is implemented as a loadable module. In the init_module() routine five kernel threads are created. This kernel threads sleep one second, wake up, print a message and fall asleep again. On unload of the module (cleanup_module), the kernel threads are killed.
The example has been tested with Linux kernel 2.4.2 on Intel (uni processor only) and Alpha platform (COMPAQ Personal Workstation 500au (uni processor), DS20 and ES40 (SMP).

A version for the 2.2 kernel can be found here. Note: depending on the context of the creator of the threads the new threads may inherit properties from the parent you do not want to have. The new version avoids this by having keventd create the threads. The 2.2. kernel do not have a keventd, so this approach is not implementable there.

Functions in example

  • start_kthread: creates a new kernel thread. Can be called from any process context but not from interrupt. The functions blocks until the thread started.
  • stop_kthread: stop the thread. Can be called from any process context but the thread to be terminated. Cannot be called from interrupt context. The function blocks until the thread terminated.
  • init_kthread: sets the environment of the new threads. Is to be called out of the created thread.
  • exit_kthread: needs to be called by the thread to be terminated on exit

Creation of new Thread

A new thread is created with kernel_thread(). The thread inherits properties from its parents. To make sure that we do not get any weired properties, we let keventd create the new thread.
The new thread is created with start_kthread() . It uses a semaphore to block until the new thread is running. A down() blocks the start_kthread() routine until the corresponding up() call in init_kthread() is executed.
The new thread must call init_kthread() in order to let the creator continue.

Stop of new Thread

stop_kthread() sets a flag that the thread uses to determine whether do die or not and sends a SIGKILL to the thread. This signal causes the thread to be woken up. On wakeup it will check for the flag and then terminate itself by calling exit_kthread and returning from the thread function. With a semaphore the stop_kthread() function blocks until the thread terminated.

Initialization of new Thread

Within the new created thread, init_kthread() needs to be called. This function sets a signal mask, initialises a wait queue, the termination flag and sets a new name for the thread. With a up() call it notifies the creator that the setup is done.

Exit of new Thread

When the thread receives the notification to terminate itself, is calls the exit_kthread() function. It notifies the stop_kthread() function that it terminated with an up() call.

The new Thread itself

The new thread is implemented in the example_thread() function. It runs an endless loop (for(;;)). In the loop it falls asleep with the interruptible_sleep_on_timeout() function. It comes out of this function either when the timeout expires or when a signal got caught.
The "work" in the thread is to print out a message with printk.

Kernel Versions

The example has been tested on 2.4.2.

Example Device Driver Code

The example consists of four files: kthread.h, kthread.c, thread_drv.c and a Makefile

kthread.h

#ifndef _KTHREAD_H

Bluelove1968 發表在 痞客邦 留言(0) 人氣()

GoogleTalk是基於開放原始碼的IM技術Jabber,可以用支持Jabber協定的其它客戶端直接登錄這項服務。在Linux下可以使用Gaim來使用google的服務.

Bluelove1968 發表在 痞客邦 留言(0) 人氣()

在 Linux 上使用 NTFS

Linux kernel 對 NTFS 的支援非常有限
主要的原因當然是因為微軟不公開 NTFS 的檔案系統格式
因此,我們想要在 NTFS 底下建立、刪除或變更檔案的大小都是很困難且有風險的, 僅僅可以去覆蓋原本已存的檔案 (而原檔案大小不變)

1.NTFS Driver
1.1.ntfs driver (read-only)
原本的 http://linux-ntfs.sourceforge.net/ 已搬到 http://www.linux-ntfs.org/
原來的 Linux-NTFS project 提供了 ntfs (read-only) 的 driver 以及 NTFS 相關的工具程式 (ntfsprogs)
但這些工具程式都是有風險性的

使用方式:
$ mount -t ntfs /dev/hda1 /XP

1.2.ntfs-3g driver (read-write)
http://www.linux-ntfs.org/ 的 Linux-NTFS project 最近發表了 ntfs-3g driver
http://sourceforge.net/mailarchive/forum.php?thread_id=23836054&forum_id=2697
號稱提供了一個更快速更安全的 open source driver,雖然目前還在 beta 階段,不過根據一些使用者的實際測試結果,成功率很高,也有不錯的效能

使用方式:
$ ntfs-3g /dev/hda1 /XP -o silent,umask=0,locale=zh_TW.UTF-8

1.3.captive-ntfs driver (read-write)
http://www.jankratochvil.net/project/captive/ 的 captive-ntfs driver
算是最早支援 “寫入” NTFS 的 open source driver
原理是使用 Wine 的方式透過原本的 Microsoft Windows ntfs.sys driver

使用方式:
$ mount -t captive-ntfs /dev/hda1 /XP

1.4.Paragon NTFS for Linux Driver (read-write)
http://www.ntfs-linux.com/ 的 Paragon NTFS for Linux Driver
這是商業版本的 driver,號稱可以完全讀寫 NTFS

2.在 Windows 上讀寫 ext2/ext3
因為 NTFS 的種種限制,與其冒著風險來寫入 NTFS,不如來個反其道而行
在 Windows 上來讀寫 ext2/ext3

2.1.Ext2IFS
http://www.fs-driver.org/index.html
提供在 Windows NT4.0/2000/XP 上完整存取 Linux Ext2 (read access and write access)
Linux Ext3 的存取部份請參考 FAQ: http://www.fs-driver.org/faq.html

2.2.Explore2fs
http://www.chrysocome.net/explore2fs
Explore2fs 是圖形化介面的工具,幾乎可以存取大部份 ext2/ext3 檔案系統
目前主要是支援讀取部份
Beta 版本的 Virtual Volumes (Explore2fs 2 預覽版) 則預計要支援:

Supported by all versions of Windows (Vista is still Work In Progress)
Reads and Writes LVM2 (Multiple slices is still Work In Progress)
Reads and Writes EXT2/EXT3
Reads and Writes Win32 filesystems (via Win32 API)
Reads software RAID0 and RAID1
VFS allows mounting on subdirectories
VFS abstraction allows multiple filesystems to be supported
VFS abstraction allows network filesystems like ftp & http be supported
Command line interface
GUI
Accessable in native namespace
NT Kernel driver to enable IFS to read LVM2

3.實測結果
底下為我個人的測試結果,測試的準確性可能會受硬碟內外圈及 Cache 等因素的影響因此,數據僅供參考以 “read” 來說,ntfs driver 的效果最好,速度跟 ntfs-3g 差不多,captive-ntfs 則慢了點而在 “write” 部份,ntfs-3g 的表現的確不錯,captive-ntfs 的表現就慢很多很多

測試主機:

Acer Veriton 7800GX 桌機
Intel 945G Chipset
CPU P4-3.0G (HT)
RAM 512Mb
SATA WDC WD800JD-22LS 80G 7200RPM HDD
$ ls -l ubuntu-6.06-desktop-i386.iso
-rw-r--r-- 1 root root 731744256 Jun 20 11:47 ubuntu-6.06-desktop-i386.iso
我的 SATA 硬碟的分割如下:

$ df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda2             10080520   6868316   3212204  69% /
/dev/sda5              8064272   5883248   2181024  73% /SL
/dev/fuse             20490872   5294168  15196704  26% /XP
/dev/sda3             37571064  12375192  23287352  35% /var/ftp
/dev/shm                253496         0    253496   0% /dev/shm
我以 ubuntu-6.06-desktop-i386.iso 731744256 (約 700Mb) 大檔複製來做測試

Write 部份:
3.1.Use ntfs-3g driver

$ time cp ubuntu-6.06-desktop-i386.iso /XP/
(連測三次的結果)

real    1m43.250s
user    0m0.224s
sys     0m3.432s

real    1m13.189s
user    0m0.152s
sys     0m3.600s

real    1m2.355s
user    0m0.152s
sys     0m3.424s
3.2.Use captive-ntfs driver

$ time cp ubuntu-6.06-desktop-i386.iso /XP/
(因為實在太慢了,我只測了兩次就測不下去了)

real    46m24.915s
user    0m0.848s
sys     0m6.800s

real    39m43.023s
user    0m0.800s
sys     0m6.488s
至於 Paragon NTFS Dirver 因為要 $$ 買,所以沒去測

Read 部份:
3.3.Use ntfs-3g driver

$ time cp /XP/ubuntu-6.06-desktop-i386.iso /var/ftp/
(連測三次的結果)

real    0m36.037s
user    0m0.100s
sys     0m3.860s

real    0m37.327s
user    0m0.160s
sys     0m3.464s

real    0m37.831s
user    0m0.132s
sys     0m3.796s
3.4.Use ntfs driver

$ time cp /XP/ubuntu-6.06-desktop-i386.iso /var/ftp/
(連測三次的結果)

real    0m30.422s
user    0m0.180s
sys     0m6.392s

real    0m31.072s
user    0m0.128s
sys     0m6.500s

real    0m29.892s
user    0m0.156s
sys     0m6.212s
3.5.Use captive-ntfs driver

$ time cp /XP/ubuntu-6.06-desktop-i386.iso /var/ftp/
(連測三次的結果)

real    1m58.328s
user    0m0.144s
sys     0m3.612s

real    1m57.597s
user    0m0.104s
sys     0m3.272s

real    2m21.475s
user    0m0.172s
sys     0m4.348s

Bluelove1968 發表在 痞客邦 留言(0) 人氣()

到目前為止和 Windows相容性最高的 Linux作業系統問世

Bluelove1968 發表在 痞客邦 留言(0) 人氣()

SuSe 10.1

Bluelove1968 發表在 痞客邦 留言(0) 人氣()

Device Numbers

郭慶賢

2005/04/09

Bluelove1968 發表在 痞客邦 留言(0) 人氣()

 
 
如 何 開 發 Linux Device Driver?

 

Bluelove1968 發表在 痞客邦 留言(0) 人氣()

在Linux上用兩張網路卡做網路流量管控

Bluelove1968 發表在 痞客邦 留言(0) 人氣()

壓縮檔案系統

eg. 有片光碟片,裡面都是資料,現在要把全部放入硬碟,以
方便隨時查閱,也會分享給別人看,甚至可能會全部 copy 給別人,
你會如何做?


    代碼:

        # cat  /dev/cdrom > /mnt/data.iso
        # mount -t iso9660 -o loop /mnt/data.iso /mnt/data/
 
如果,你有一個空的partition,比光碟容量大一點點,要全部放進去的話,可以這麼做
 
    代碼:

        # dd if=/mnt/data.iso of=/dev/hdax
        # mount -t iso9660 /dev/hdax /mnt/data
 

怎麼製作 ext2 的檔案系統

    代碼:

        # mke2fs /dev/hdax
        # mount -t ext2 /dev/hdax /mnt/tmp
 

如何製作軟碟開機片

    代碼:

        #!/bin/sh
        echo "create 4,096KB "
        dd if=/dev/zero of=/tmp/tmp_loop bs=1k count=4096
        losetup /dev/loop0 /tmp/tmp_loop
        mke2fs -m 0 /dev/loop0
        mount -t ext2 /dev/loop0 /mnt/tmp

    代碼:

        #!/bin/sh
        #先把一些你需要的檔案copy進入 /mnt/tmp
        umount /mnt/tmp
        losetup -d /dev/loop0
        echo "建立 ramdisk image : initrd.img"
        dd conv=sync if=/tmp/tmp_loop | gzip -9 > /tmp/initrd.img.gz
 
看initrd.img.gz 的內容

    代碼:

        # gunzip /tmp/initrd.img.gz
        # mount -t ext2 -o loop /tmp/initrd.img /mnt/tmp
 
 
上面程式有看到 gzip ,好像有談到縮壓了,沒錯,這是很普通嵌入
式所應用的縮壓方式,但是,我們不用這個方式,因為,要應用時,
要先做一個 ramdisk ,然後把檔案 gunzip 到 ramdisk 上,才能使
用,有什麼缺點呢?舉個例子來說明,假設總共要8MB,縮壓後只要
4MB,你 flash 有 4MB 剛好放得下,記憶體有 16MB ,那開機後
要劃 8MB 的 ramdisk 給解開的檔案系統用,記憶體就憑空少了
8MB,所以這並不是一個很好的方法。當然,也有好處,一切唯讀,
隨便重開機也不會掛,重開機一切恢復正常。



「cramfs」
 
    代碼:

        # mkdir /tmp/tmp_root
        # copy你所要的檔案到 /tmp/tmp_root
        # mkcramfs /tmp/tmp_root.img /tmp/tmp_root
        # mount -t cramfs -o loop /tmp/tmp_root.img /mnt/tmp
 
你會發覺,/mnt/tmp 和 /tmp/tmp_root 的內容是相同的,用 du 去查,
大小也差不多,但是,/tmp/tmp_root.img 的大小卻小很多,而且
也不用另外解開才能讀,不會另外再佔一個非壓縮的空間唷!
說明一下,mkcramfs 主要目的就是做一個壓縮的檔案系統,它做法是
直接把一個目錄轉成一個檔案系統,你可以直接做用 mount 的方式來
掛載,就如同前面的 iso9660 、 ext2 的使用方式。放入嵌入式系統
時,也不用另外再把有限的記憶體割一塊來放檔案系統了。另外,
你或許要重編 kernel 才可支援 cramfs。

這有什麼限制?當然有,最大限制就是,它是一個唯讀的,你對它寫
入是無效的,由於要即時解壓縮,效能上也會差一點點,但不會影響
很大。

那有沒有像 Windows 一樣的,可以對某些檔案、目錄壓縮,也可以
即時寫入的?有的,要 patch C library 及 Kernel。       


cramfs 有一些很重要的限制要注意:
一、檔案最大限制為 16MB。
二、檔案系統最大上限為 256MB。
三、所有檔案的 timestamps 都是 1970/01/01 。
其他的請參考 kernel source 的文件 /usr/src/linux/Documentation/filesystems/cramfs.txt

用 squashfs 比較沒有限制,而且壓縮比較好。現在要算squashfs + lzma 最棒了.
squashfs default use gzip, but you can try to patch it to use lzma,
of course you have to change mksquashfs to use lzma too.



   Cramfs - cram a filesystem onto a small ROM

cramfs is designed to be simple and small, and to compress things well.

It uses the zlib routines to compress a file one page at a time, and
allows random page access.  The meta-data is not compressed, but is
expressed in a very terse representation to make it use much less
diskspace than traditional filesystems.

You can't write to a cramfs filesystem (making it compressible and
compact also makes it _very_ hard to update on-the-fly), so you have to
create the disk image with the "mkcramfs" utility.


Usage Notes
-----------

File sizes are limited to less than 16MB.

Maximum filesystem size is a little over 256MB.  (The last file on the
filesystem is allowed to extend past 256MB.)

Only the low 8 bits of gid are stored.  The current version of
mkcramfs simply truncates to 8 bits, which is a potential security
issue.

Hard links are supported, but hard linked files
will still have a link count of 1 in the cramfs image.

Cramfs directories have no `.' or `..' entries.  Directories (like
every other file on cramfs) always have a link count of 1.  (There's
no need to use -noleaf in `find', btw.)

No timestamps are stored in a cramfs, so these default to the epoch
(1970 GMT).  Recently-accessed files may have updated timestamps, but
the update lasts only as long as the inode is cached in memory, after
which the timestamp reverts to 1970, i.e. moves backwards in time.

Currently, cramfs must be written and read with architectures of the
same endianness, and can be read only by kernels with PAGE_CACHE_SIZE
== 4096.  At least the latter of these is a bug, but it hasn't been
decided what the best fix is.  For the moment if you have larger pages
you can just change the #define in mkcramfs.c, so long as you don't
mind the filesystem becoming unreadable to future kernels.


For /usr/share/magic
--------------------

0   ulelong   0x28cd3d45   Linux cramfs offset 0
>4   ulelong   x      size %d
>8   ulelong   x      flags 0x%x
>12   ulelong   x      future 0x%x
>16   string   >\0      signature "%.16s"
>32   ulelong   x      fsid.crc 0x%x
>36   ulelong   x      fsid.edition %d
>40   ulelong   x      fsid.blocks %d
>44   ulelong   x      fsid.files %d
>48   string   >\0      name "%.16s"
512   ulelong   0x28cd3d45   Linux cramfs offset 512
>516   ulelong   x      size %d
>520   ulelong   x      flags 0x%x
>524   ulelong   x      future 0x%x
>528   string   >\0      signature "%.16s"
>544   ulelong   x      fsid.crc 0x%x
>548   ulelong   x      fsid.edition %d
>552   ulelong   x      fsid.blocks %d
>556   ulelong   x      fsid.files %d
>560   string   >\0      name "%.16s"


Hacker Notes
------------

See fs/cramfs/README for filesystem layout and implementation notes.
 

Bluelove1968 發表在 痞客邦 留言(0) 人氣()

1 2345