fdisk 對硬碟進行分割 (partition)﹔
mke2fs 對分割槽進行格式化 (format)﹔
e2label 更改磁碟的表頭資料﹔
fsck, badblocks 對檔案系統進行檢驗(可不做)﹔
mkdir 在 Linux 系統上建立掛載點,即建立要掛載的目錄﹔
mount 進行掛載。
[root@dywOffice ~]# fdisk [-l] [裝置名稱] 參數說明: -l :直接列出硬碟裝置的 partition table #範例: #範例一:列出硬碟的 partition table [root@dywOffice ~]# fdisk -l Disk /dev/hda: 80.0 GB, 80032038912 bytes 255 heads, 63 sectors/track, 9730 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/hda1 * 1 254 2040223+ 83 Linux /dev/hda2 255 9730 76115970 5 Extended /dev/hda5 255 457 1630566 82 Linux swap / Solaris /dev/hda6 458 584 1020096 83 Linux /dev/hda7 585 1603 8185086 83 Linux /dev/hda8 1604 2240 5116671 83 Linux /dev/hda9 2241 5427 25599546 83 Linux /dev/hda10 5428 9730 34563816 83 Linux #範例二:分割 hda 磁碟 [root@dywOffice ~]# fdisk /dev/hda %*<== 不可加編號*) The number of cylinders for this disk is set to 9730. There is nothing wrong with that, but this is larger than 1024, and could in certain setups cause problems with: 1) software that runs at boot time (e.g., old versions of LILO) 2) booting and partitioning software from other OSs (e.g., DOS FDISK, OS/2 FDISK) Command (m for help): m Command action a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition %*<== 刪除 partition*) l list known partition types %*<== 列出已知的檔案系統型態*) m print this menu %*<== 顯示此手冊 *) n add a new partition %*<== 加入新的 partition*) o create a new empty DOS partition table p print the partition table %*<== 列出目前的磁碟分割狀態 *) q quit without saving changes %*<== 不儲存離開 fdisk *) s create a new empty Sun disklabel t change a partition's system id %*<== 改變檔案系統 id *) u change display/entry units v verify the partition table %*<== 確認 partition table*) w write table to disk and exit %*<== 寫入 partition table 並退出 (危險)*) x extra functionality (experts only) ### fdisk 注意事項: # fdisk 最主要的工作為修改 partition tables。 # 硬碟分割錯誤時,只要在 format 前將 partition tables 復原就可將資料救回。 # fdisk 是針對整顆硬碟,所以其後接裝置名稱而非某個 partition (例如 hda 而非 hda1)。 # fdisk 後悔時直接按下 q 取消剛剛的動作。 # 一個硬碟最大的邏輯磁區可以達到 63 號(包含 1 至 4 的 primary partition)。
[root @test /root ]# mke2fs [-b block-size][-c][-i bytes-per-inode][-j][-L volume-label] 參數: -b :設定 block 的大小,目前支援 1k, 2k, 4k bytes。 -c :檢查錯誤磁碟 -i :設定 inode 值 -j :預設為 ext2 檔案格式,若加入 -j 選項時格式化為 ext3。 -L :設定磁區的 label (表頭名稱) #範例: #範例一:以 mke2fs 預設的條件( ext2 )格式化 /dev/hda5,且名稱為 csie。 [root @test /root]# mke2fs -L "csie" /dev/hda5 #範例二:以 mke2fs 預設的條件( ext2 )格式化 /dev/hda5,且過程中檢查硬碟。 [root @test /root]# mke2fs -c /dev/hda5 #範例三:以 mke2fs 將 /dev/hda5 格式化為 ext3,且 block 為 2048 bytes, inode 為 256 bytes。 [root @test /root]# mke2fs –j -b 2048 -i 256 /dev/hda5
[root @test /root ]# e2label [/dev/hd...] [label_name] #範例:將檔案系統 /dev/hda1 表頭設定為 CsieHome [root @test /root]# e2label /dev/hda1 CsieHome
[root@linux ~]# fsck [-AtCary] 裝置名稱 參數: -t :指定檢查 filesystem 的 type。 -A :依據 /etc/fstab 的內容,將所有的裝置都掃瞄一次 -a :自動修復檢查到的有問題的磁區,不用一直按 y -r :要讓使用者決定是否需要修復,與 -a 剛好相反 -y :與 -a 類似,但某些 filesystem 僅支援 -y 這個參數 -C :在檢驗過程中,使用長條圖顯示進度 #範例: #範例一:顯示個別的 filesystem 的檢驗程式 [root@dywOffice ~]# ll /sbin/fsck* -rwxr-xr-x 1 root root 18616 Aug 22 2006 /sbin/fsck* -rwxr-xr-x 1 root root 11320 Jun 2 04:48 /sbin/fsck.cramfs* -rwxr-xr-x 1 root root 147908 Aug 22 2006 /sbin/fsck.ext2* -rwxr-xr-x 1 root root 147908 Aug 22 2006 /sbin/fsck.ext3* -rwxr-xr-x 1 root root 23364 Jun 2 04:48 /sbin/fsck.minix* #範例二: 檢驗裝置 /dev/hdb5 [root@linux ~]# fsck -C -t ext3 /dev/hdb5 fsck 1.37 (21-Mar-2005) e2fsck 1.37 (21-Mar-2005) logical: clean, 11/181056 files, 21706/361446 blocks # 每個掛載點都會有一個預設目錄 lost+found。 # fsck 若發現任何錯誤的檔案,就會將該檔案的資料存到目錄 lost+found。 # 通常只有 root 且系統有問題的時候才使用 fsck,在正常狀況下使用,可能會造成對檔案的危害。 # 執行 fsck 時被檢查的 partiton 必須在卸載狀態。
[root@linux ~]# badblocks -[sv] 裝置名稱 參數: -s :在螢幕上列出進度 -v :可以在螢幕上看到進度 #範例: [root@dywOffice ~]# badblocks -sv /dev/hda6 Checking blocks 0 to 1020096 Checking for bad blocks (read-only test): done Pass completed, 0 bad blocks found.
練習題
mke2fs -L "csie" /dev/hda5
mke2fs -c /dev/hda5
mke2fs -b 2048 /dev/hda5
mke2fs -i 256 /dev/hda5
mke2fs -j /dev/hda5
e2label /dev/hda1 CsieHome
fsck -a /dev/hda1
或 fsck -y /dev/hda1
fsck -A
fsck -t ext3 /dev/hda1
fsck -C /dev/hda1
/home/lost+found
下。