Linux運維實戰(zhàn)之磁盤分區(qū)、格式化及掛載(一)
在網(wǎng)絡(luò)系統(tǒng)中,磁盤和文件系統(tǒng)管理是兩個非常基本、同時也是非常重要的管理任務(wù),特別是文件系統(tǒng)管理,因為它與用戶權(quán)限和整個網(wǎng)絡(luò)系統(tǒng)的安全息息相關(guān)。本次博文的主題是關(guān)于Linux系統(tǒng)中磁盤分區(qū)、格式化及掛載,下次博文我們再詳細討論文件系統(tǒng)管理。
在操作系統(tǒng)中,磁盤管理屬于設(shè)備管理的范疇。一塊硬盤安裝到主機之后稱為 裸設(shè)備, 若要能夠在Linux系統(tǒng)中使用必須對其進行如下步驟: 分區(qū)=>格式化(創(chuàng)建文件系統(tǒng))=>掛載 我們先來談?wù)凩inux系統(tǒng)中的設(shè)備類型。
一、Linux系統(tǒng)中的設(shè)備類型:
Linux沿襲Unix的風格,將所有設(shè)備認成是一個文件。
設(shè)備文件分為兩種: 1、塊設(shè)備文件(b):
通常稱為“隨機設(shè)備”。所謂“ 塊設(shè)備 ”是指對其信息的存取以“塊”為單位,如通常的光盤、硬盤、軟盤、磁帶等,塊長取 512 、 1024 或 4096 字節(jié)。塊設(shè)備可以直接通過塊設(shè)備特別文件來訪問。為了提高數(shù)據(jù)的傳輸效率,塊設(shè)備驅(qū)動程序內(nèi)部采用塊緩沖技術(shù)。
2、字符設(shè)備文件(c):
通常稱為“線性設(shè)備”。所謂“ 字符設(shè)備 ”是指在I/O傳輸中 以字符為單位進行傳輸 的設(shè)備,如鍵盤,打印機等。不過需要注意的是以字符為單位并不一定意味著是以字節(jié)為單位,因為有的編碼規(guī)則規(guī)定,一個字符占16bit,合2個字節(jié)。
設(shè)備文件一般存放在 /dev 目錄下:
/dev/hd [a-t]:IDE設(shè)備
/dev/sd[a-z]:SCSI設(shè)備
/dev/fd [0-7]:標準軟驅(qū)
/dev/md[0-31]:軟raid設(shè)備
/dev/loop[0-7]:本地回環(huán)設(shè)備
/dev/ram[0-15]:內(nèi)存
/dev/null:無限數(shù)據(jù)接收設(shè)備 , 相當于回收站
/dev/zero:無限零資源,有點像冒泡機
/dev/tty[0-63]:虛擬終端
/dev/ttyS[0-3]:串口
/dev/lp[0-3]:并口
/dev/console:控制臺
/dev/fb[0-31]:framebuffer
/dev/cd rom -> /dev/hd c
/dev/modem -> /dev/ttyS[0-9]
/dev/pilot -> /dev/ttyS[0-9]
/dev/console:控制臺
Tips:控制臺和虛擬終端的區(qū)別與聯(lián)系:
控制臺就好比電視機上的按鈕,終端好比遙控板,他們的目的都是控制電視機,但是控制臺必須在本地,而終端可以在遠端,系統(tǒng)只有一個控制臺,叫 console ,其他的都是終端
二、Linux系統(tǒng)中的磁盤及分區(qū):
1、磁盤基礎(chǔ):
日常生活和工作中,常見的磁盤種類有以下幾種:
(1)IDE(ATA)硬盤:
集成 磁盤 電子接口,Integrated Device Electronics,并行傳輸數(shù)據(jù), 最大的理論傳輸速率為133MB/s
SATA:全稱是Serial Advanced Technology Attachment(串行高級技術(shù)附件,一種基于行業(yè)標準的串行硬件驅(qū)動器接口)就是我們現(xiàn)在經(jīng)常所說的SATA; 常見的理論傳輸速率:300MB/s, 600MB/s, 6Gb/s
(2)SCSI硬盤:
Small Computer System Interface, UltraSCSI 標準傳輸速率為320MB/s 常見轉(zhuǎn)速:10000 RPM, 15000RPM
SAS:串行版的SCSI硬盤,最大傳輸速率:6Gbps
(3)SSD硬盤:
Disk固態(tài)硬盤(Solid State Disk)用固態(tài)電子存儲芯片陣列而制成的硬盤,由控制單元和存儲單元(FLASH芯片、DRAM芯片)組成。固態(tài)硬盤的接口規(guī)范和定義、功能及使用方法上與普通硬盤的完全相同,在產(chǎn)品外形和尺寸上也完全與普通硬盤一致。
(4)USB硬盤:
常見USB接口規(guī)范:1.1, 2.0, 3.0
2、Linux系統(tǒng)中的磁盤分區(qū)
(1)磁盤分區(qū)基礎(chǔ):
首先問大家一個問題: 磁盤為什么需要分區(qū)?如果沒有分區(qū),我們要在一個磁盤上安裝兩個以上的操作系統(tǒng)是無法辦到的。因此,每一個分區(qū)可以當做獨立的文件系統(tǒng)來使用以便于安裝多個操作系統(tǒng),這就是磁盤需要分區(qū)的原因。
Linux中不同類型的硬盤和分區(qū)文件名不同:IDE硬盤和分區(qū)文件名:
Linux對連接到IDE接口的硬盤使用/dev/hdxy的方式命名,其中hd表示硬盤為IDE類型,x表示硬盤序號,x的值可以是a、b、c、d。 y為分區(qū)號;如第二塊IDE硬盤的第二個分區(qū)系統(tǒng)中文件名為hdb2
SATA或者SCSI硬盤和分區(qū)文件名:
連接到SCSI接口的設(shè)備使用ID號進行區(qū)別,SCSI設(shè)備ID號為0~15,SCSI接口卡本身的ID號是7。Linux對連接到SCSI接口卡的硬盤使用/dev/sdx的方式命名,x的值可以是a、b、c、d等,即ID號為0的SCSI硬盤名為/dev/sda,ID號為1的SCSI硬盤名為/dev/sdb,以此類推。LINUX對SCSI硬盤最多支持15個分區(qū)。
說明:
a、所有使用USB接口的移動存儲設(shè)備,不論是移動硬盤、優(yōu)盤,還是USB光驅(qū),都一律使用/dev/sdxx的設(shè)備文件。光驅(qū)(光盤)的設(shè)備文件一般默認為/dev/cdrom,這個就與光驅(qū)的接口無關(guān)了。
b、一個硬盤最多可以有4個(主+擴展)分區(qū),其中,擴展分區(qū)只能有一個(如圖中的/dev/hda2為擴展分區(qū),/dev/hda5為擴展分區(qū)中劃分的邏輯分區(qū)),分區(qū)的形式只能有兩種:
P+P+P+P P+P+P+E //P表示主分區(qū),E表示擴展分區(qū)( 擴展分區(qū) 保存的是磁盤的二級分區(qū)表,它指向具體的邏輯分區(qū),因此擴展分區(qū)不能寫東西,這是我個人的理解哈) 因1~4號己被保留,所以第1個邏輯分區(qū)的代號由5號開始,以此順序增加到磁盤號,若未劃分/dev/sda3,/dev/sda4分區(qū),則這兩個代號是空的被保留下來的代號。 邏輯分區(qū)和主分區(qū)沒有關(guān)系,只與MBR的空間有關(guān)系
MBR(Main/Master Boot Record)知識點:引導扇區(qū)在每個分區(qū)里都存在,但我們常說的 主引導扇區(qū) 是硬盤的第一物理扇區(qū)。它位于磁盤的 0磁頭0柱面1扇區(qū) 且由兩個部分組成: 主引導記錄MBR+ 硬盤分區(qū)表DPT , 其中主引導記錄的作用就是檢查分區(qū)表是否正確以及確定哪個分區(qū)為引導分區(qū),并在程序結(jié)束時把該分區(qū)的啟動程序(也就是操作系統(tǒng)引導扇區(qū))調(diào)入內(nèi)存加以執(zhí)行。
在總共512字節(jié)的主引導扇區(qū)里其中 MBR 占 446個字節(jié) (偏移0-- 偏移1BDH), DPT 占 64個字節(jié) (偏移1BEH--偏移1FDH),最后兩個字節(jié)“55,AA”(偏移1FEH偏移1FFH)是分區(qū)的結(jié)束標志,稱為 “魔數(shù)(MagicNumber)”, 表示當前分區(qū)是否可引導( 5A表示可引導 )。也就是說 主引導扇區(qū)=MBR+DPT+MagicNumber ,大致的結(jié)構(gòu)如下圖: 0000 |------------------------------------------------| | | | | | Main Boot Record | | | | | | 主引導記錄(446字節(jié)) | | | | | | | 01BD | | 01BE |------------------------------------------------| | | 01CD | 分區(qū)信息 1(16字節(jié)) | 01CE |------------------------------------------------| | | 01DD | 分區(qū)信息 2(16字節(jié)) | 01DE |------------------------------------------------| | | 01ED | 分區(qū)信息 3(16字節(jié)) | 01EE |------------------------------------------------| | | 01FD | 分區(qū)信息 4(16字節(jié)) | |------------------------------------------------| | 01FE | 01FF | | 55 | AA | |------------------------------------------------|
(2)Linux下的磁盤分區(qū):
命令名稱:fdisk
命令所在路徑:/sbin/fdisk
執(zhí)行權(quán)限:root
功能描述:磁盤分區(qū)相關(guān)操作,最多支持15個分區(qū)
語法: fdisk [option] [DEVICE]
常用選項:
-l:查看當前磁盤分區(qū)的詳細情況
范例:
[root@Centos ~]# fdisk -l #查看磁盤的分區(qū)情況,不帶參數(shù)顯示的是當前主機上所有的磁盤分區(qū)情況 Disk /dev/sda: 107.4 GB, 107374182400 bytes #當前主機只有一塊磁盤,容量107.4GB 255 heads, 63 sectors/track, 13054 cylinders #此處顯示該硬盤的具體參數(shù):共255個磁頭,每個磁道63個扇區(qū),共13054個柱面 Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes #此處顯示扇區(qū)大小,每個扇區(qū)512個字節(jié) I/O size (minimum/optimal): 512 bytes / 512 bytes #I/O大小,說明讀寫一個數(shù)據(jù)最小需要512字節(jié) Disk identifier: 0x00097863 Device Boot Start End Blocks Id System /dev/sda1 * 126 204800 83 Linux #第一個分區(qū),按柱面劃分,從第一個柱面開始,到26個柱面結(jié)束 Partition 1 does not end on cylinder boundary. #此處的警告說明該分區(qū)沒有包含整個柱面(一個柱面一定要屬于一個分區(qū),否則就會給出警告) /dev/sda2 2691 524288 82 Linux swap / Solaris #第二個分區(qū),分區(qū)類型為“交換分區(qū)” Partition 2 does not end on cylinder boundary. /dev/sda3 91 13055 104127488 83 Linux #第三個分區(qū),分區(qū)類型為Linux分區(qū)fdisk 是交互式命令,其下有許多子命令 , 說明如下:
[root@Centos ~]# fdisk /dev/sda #fdisk的參數(shù)是設(shè)備名稱而非分區(qū)名 WARNING: DOS-compatible mode is deprecated. It's strongly recommended toswitch off the mode (command 'c') and change display units to sectors (command 'u'). Command (m for help): m#交互式命令,提示鍵入“m”以獲取幫助 Command action #可以看到,fdisk有如下這么多的子命令 a toggle a bootable flag #設(shè)定可啟動標記 b edit bsd disklabel c toggle the dos compatibility flag d delete a partition #刪除一個分區(qū) l list known partition types #各分區(qū)類型所對應的System ID m print this menu n add a new partition#新建一個分區(qū) o create a new empty DOS partition table p print the partition table #顯示當前的分區(qū)信息 q quit without saving changes #不保存退出 s create a new empty Sun disklabel t change a partition's system id #修改指定分區(qū)的System IDu change display/entry units v verify the partition table w write table to disk and exit #保存退出 x extra functionality (experts only)我們重點來看下“l”子命令,用于列出Linux支持的分區(qū)所對應的 System ID :
[root@Centos ~]# fdisk /dev/sda WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units tosectors (command 'u'). Command (m for help): l 0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris1 FAT12 39 Plan 982 Linux swap / So c1 DRDOS/sec (FAT- 2 XENIX root 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT- 3 XENIX usr 40 Venix 80286 84 OS/2 hidden C: c6 DRDOS/sec (FAT- 4 FAT16 <32M 41 PPC PReP Boot 85 Linux extended c7 Syrinx 5 Extended42 SFS 86 NTFS volume set da Non-FS data 6 FAT16 4d QNX4.x87 NTFS volume set db CP/M / CTOS / . 7 HPFS/NTFS 4e QNX4.x 2nd part 88 Linux plaintext de Dell Utility 8 AIX 4f QNX4.x 3rd part 8e Linux LVM df BootIt 9 AIX bootable 50 OnTrack DM 93 Amoebae1 DOS access a OS/2 Boot Manag 51 OnTrack DM6 Aux 94 Amoeba BBT e3 DOS R/Ob W95 FAT32 52 CP/M 9f BSD/OSe4 SpeedStorc W95 FAT32 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi eb BeOS fse W95 FAT16 (LBA) 54 OnTrackDM6 a5 FreeBSD ee GPT f W95 Ext'd (LBA) 55 EZ-Drivea6 OpenBSD ef EFI (FAT-12/16/10 OPUS 56 Golden Bow a7 NeXTSTEPf0 Linux/PA-RISC b 11 Hidden FAT12 5c Priam Edisk a8 Darwin UFS f1 SpeedStor 12 Compaq diagnost 61 SpeedStor a9 NetBSDf4 SpeedStor 14 Hidden FAT16 <3 63 GNU HURD or Sys ab Darwin boot f2 DOS secondary 16 Hidden FAT16 64 Novell Netware af HFS / HFS+ fb VMware VMFS 17 Hidden HPFS/NTF 65 Novell Netware b7 BSDI fs fc VMware VMKCORE 18 AST SmartSleep 70 DiskSecure Mult b8 BSDI swap fd Linux raid auto 1b Hidden W95 FAT3 75 PC/IX bb Boot Wizard hid fe LANstep 1c Hidden W95 FAT3 80 Old Minix be Solaris boot ff BBT 1e Hidden W95 FAT1其中常用的類型為:
82:Linux swap交換分區(qū)
83:Linux分區(qū)
8e:Linux邏輯卷
fd:Soft Raid
下面我們來進行常規(guī)的分區(qū)操作哈!
首先來查看下當前主機的分區(qū)情況:
[root@Centos ~]# fdisk /dev/sda WARNING: DOS-compatible mode is deprecated. It's strongly recommended toswitch off the mode (command 'c') and change display units to sectors (command 'u'). Command (m for help): p Disk /dev/sda: 107.4 GB, 107374182400 bytes 255 heads, 63 sectors/track, 13054 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00097863 Device Boot Start End Blocks Id System /dev/sda1 * 126 204800 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 2691 524288 82 Linux swap / Solaris Partition 2 does not end on cylinder boundary. /dev/sda3 91 13055 104127488 83 Linux #這里可以看到該主機上已經(jīng)沒有尚未劃分的磁盤空間既然沒有多余的磁盤空間來創(chuàng)建分區(qū),那我們先來刪除其中一個分區(qū):
Disk /dev/sda: 107.4 GB, 107374182400 bytes 255 heads, 63 sectors/track, 13054 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00097863 Device Boot Start End Blocks Id System /dev/sda1 * 126 204800 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 2691 524288 82 Linux swap / Solaris Partition 2 does not end on cylinder boundary. /dev/sda3 91 13055 104127488 83 Linux Command (m for help): d #刪除一個分區(qū) Partition number (1-4): 4 #根據(jù)前面的內(nèi)容,主分區(qū)+擴展分區(qū)的數(shù)目只能是4個 Warning: partition 4 has empty type #顯示第4個分區(qū)不存在哈 Command (m for help): d Partition number (1-4): 3 #刪除第3個分區(qū) Command (m for help): p #驗證結(jié)果,可以看到sda3分區(qū)被刪除了 Disk /dev/sda: 107.4 GB, 107374182400 bytes 255 heads, 63 sectors/track, 13054 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00097863 Device Boot Start End Blocks Id System /dev/sda1 * 126 204800 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 2691 524288 82 Linux swap / Solaris Partition 2 does not end on cylinder boundary.創(chuàng)建擴展分區(qū):
[root@Centos ~]# fdisk /dev/sda Command (m for help): n #創(chuàng)建一個新分區(qū) Command action e extended #鍵入e鍵創(chuàng)建擴展分區(qū) p primary partition (1-4) #鍵入p鍵創(chuàng)建主分區(qū) e #我們要創(chuàng)建擴展分區(qū)哈 Partition number (1-4):3 #分區(qū)號我們就選3哈 First cylinder (91-13054, default 91): #選擇起始柱面,默認是91 Using default value 91 Last cylinder, +cylinders or +size{K,M,G} (91-13054, default 13054): +10G #選擇結(jié)束柱面,這里可以用+K,+M,+G的方法輸入 Command (m for help): p #驗證結(jié)果 Disk /dev/sda: 107.4 GB, 107374182400 bytes 255 heads, 63 sectors/track, 13054 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00097863 Device Boot Start End Blocks Id System /dev/sda1 * 126 204800 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 2691 524288 82 Linux swap / Solaris Partition 2 does not end on cylinder boundary. /dev/sda3 911396 10483258 5 Extended #可以看到創(chuàng)建了擴展分區(qū)哈創(chuàng)建邏輯分區(qū):(擴展分區(qū)創(chuàng)建好了之后不能拿來直接使用哈,要想使用還需要創(chuàng)建邏輯分區(qū))
Command (m for help): n Command action l logical (5 or over) #鍵入“l”創(chuàng)建邏輯分區(qū)(提示分區(qū)號從5開始哈) p primary partition (1-4) l First cylinder (91-1396, default 91): Using default value 91 Last cylinder, +cylinders or +size{K,M,G} (91-1396, default 1396): +200G Value out of range. #提示超出范圍了哈 Last cylinder, +cylinders or +size{K,M,G} (91-1396, default 1396): +5G Command (m for help): p Disk /dev/sda: 107.4 GB, 107374182400 bytes 255 heads, 63 sectors/track, 13054 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00097863 Device Boot Start End Blocks Id System /dev/sda1 * 126 204800 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 2691 524288 82 Linux swap / Solaris Partition 2 does not end on cylinder boundary. /dev/sda3 911396 10483258 5 Extended /dev/sda5 91 744 5246036+ 83 Linux #創(chuàng)建了邏輯分區(qū)哈,可以看到分區(qū)號是sda5重要說明 :
(1)分區(qū)創(chuàng)建好了之后,用 fdisk -l 命令可以查看分區(qū)情況,但需要注意的是:雖然fidsk命令列出了所有的分區(qū)情況,不代表新分區(qū)就可以被操作系統(tǒng)識別了,文件系統(tǒng)是內(nèi)核的功能(即軟件能識別新分區(qū)但內(nèi)核并不能識別),可以用" cat /proc/partitions "命令查看,若要內(nèi)核能識別需要把分區(qū)變化情況同步到內(nèi)核。
(2) 要特別注意 :分區(qū)及格式化操作會永久地破壞目前存在于該分區(qū)上的任何數(shù)據(jù),操作時需要特別小心(操作前對原有數(shù)據(jù)做備份)!
查看內(nèi)核識別的分區(qū)信息:
[root@Centos dev]# fdisk -l #查看當前系統(tǒng)所有的磁盤分區(qū)情況 Disk /dev/sdb: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x0aeb57a8 Device Boot Start End Blocks Id System /dev/sdb1 1 262 2104483+ 83 Linux #sdb硬盤只有一個分區(qū)哈 Disk /dev/sda: 107.4 GB, 107374182400 bytes 255 heads, 63 sectors/track, 13054 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00097863 Device Boot Start End Blocks Id System /dev/sda1 * 126 204800 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 2691 524288 82 Linux swap / Solaris Partition 2 does not end on cylinder boundary. /dev/sda3 91 13055 104127488 83 Linux [root@Centos dev]# cat /proc/partitions #查看內(nèi)核識別的分區(qū)信息 major minor #blocks name #所有的分區(qū)都能被內(nèi)核識別哈,只有這樣才能格式化分區(qū)操作哈;如果不能被內(nèi)核識別,則我們可以讓內(nèi)核重新讀取DPT 8 16 10485760 sdb 8 17 2104483 sdb1 80 104857600 sda 81 204800 sda1 82 524288 sda2 83 104127488 sda3 讓內(nèi)核重新讀取硬盤分區(qū)表:RHEL5:partprobe [DEVICE]
說明:RHEL5上該命令的執(zhí)行能夠成功,但RHEL6上可能不行,需要重新啟動系統(tǒng)
[root@Centos ~]# partprobe /dev/sda #提示需要重啟系統(tǒng)所有分區(qū)才能被內(nèi)核識別(其實windows系統(tǒng)也是這樣的,分區(qū)完之后會提示用戶重啟系統(tǒng)以便內(nèi)核讀取) Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy).As a result, it may not reflect all of your changes until after reboot.?RHEL6:partx -a [PARTITION] DEVICE
[root@Centos ~]# partx -a /dev/sdb #不帶分區(qū)選項表示讀取指定硬盤的所有分區(qū) BLKPG: Device or resource busy #顯示設(shè)備繁忙無法添加分區(qū)哈 error adding partition 1我們手動添加來試試哈!
[root@Centos dev]# partx -a sdb1 /dev/sdb #手動添加成功了哈 [root@Centos dev]#三、Linux系統(tǒng)中文件系統(tǒng)的創(chuàng)建(磁盤格式化):
Tips:只有內(nèi)核能夠識別硬盤分區(qū)信息之后,我們才能夠?qū)τ脖P格式化,格式化的過程也就是創(chuàng)建文件系統(tǒng)的過程, 文件系統(tǒng)通常由內(nèi)核提供 !
1、Linux系統(tǒng)所支持的文件系統(tǒng)類型:
以管理員身份登錄,查看" /lib/modules/ 2.6 . 32 - 358 .el6.x86_64/kernel/fs/ ”目錄
[root@Centos ~]# ls /lib/modules/2.6.32-358.el6.x86_64/kernel/fs/ autofs4 cachefiles configfs dlm exportfs ext3 fat fuse jbd jffs2 mbcache.ko nfs_common nls ubifs xfs btrfs cifscramfs ecryptfs ext2 ext4 fscache gfs2 jbd2 lockd nfs nfsdsquashfs udf可以看到Linux支持這么多的文件系統(tǒng)哈,下面我們對常用的文件系統(tǒng)類型做一個簡單介紹。
(1)minix 是Minix操作系統(tǒng)使用的文件系統(tǒng),是Linux最先使用的文件系統(tǒng)。它有許多缺點:分區(qū)只能小于64MB,只支持短文件名,單一的時間戳,等等。在軟盤和動態(tài)磁盤領(lǐng)域仍然有用。
(2)ext 是對Minix的擴展。已完全被ext2取代,內(nèi)核最終將不會支持它。
(3)ext2 是Linux使用的,性能很好的文件系統(tǒng),用于固定文件系統(tǒng)和可活動文件系統(tǒng)。它是作為ext文件系統(tǒng)的擴展而設(shè)計的。ext2在Linux所支持的文件系統(tǒng)中,提供最好的性能(在速度和CPU使用方面),簡短的說,ext2是Linux的主要文件系統(tǒng)。
(4)ext3 是對ext2增加日志功能后的擴展。是RHEL5中默認使用的文件系統(tǒng)類型。它向前、向后兼容ext2,意為ext2不用丟失數(shù)據(jù)和格式化就可以轉(zhuǎn)換為ext3,ext3也可以轉(zhuǎn)換為ext2 而不用丟失數(shù)據(jù)(只要重新安裝該分區(qū)就行了),強烈推薦使用這種文件系統(tǒng)。
(5)ext4
為第4代擴展文件系統(tǒng),是RHEL6中默認使用的文件系統(tǒng)類型,屬于典型的日志型文件系統(tǒng)。其特點是保持有磁盤存取記錄的日志數(shù)據(jù),便于恢復,性能和穩(wěn)定性更加出色。
(6)ReiserFS/JFS
仍然在完善的帶日志文件系統(tǒng),特別適合小文件的文件系統(tǒng)
(7)ISO9660文件系統(tǒng)
該文件系統(tǒng)中光盤所使用的標準文件系統(tǒng),Linux對該文件系統(tǒng)也有很好的支持,不僅能讀取光盤和光盤ISO映像文件,而且還支持在Linux環(huán)境中刻錄光盤。
(8)NFS文件系統(tǒng) NFS即網(wǎng)絡(luò)文件系統(tǒng),用于在UNIX系統(tǒng)間通過網(wǎng)絡(luò)進行文件共享,用戶可將網(wǎng)絡(luò)中NFS服務(wù)器提供的共享目錄掛載到本地的文件目錄中,從而實現(xiàn)操作和訪問NFS文件系統(tǒng)中的內(nèi)容。
(9)swap文件系統(tǒng)
swap文件系統(tǒng)用于Linux的交換分區(qū)。在Linux中,使用整個交換分區(qū)來提供虛擬內(nèi)存,其分區(qū)大小一般應是系統(tǒng)物理內(nèi)存的2倍,在安裝Linux操作系統(tǒng)時,就應創(chuàng)建交換分區(qū), 它是Linux正常運行所必需的,其類型必須是swap,交換分區(qū)由操作系統(tǒng)自行管理。
2、創(chuàng)建文件系統(tǒng)(格式化分區(qū)):
配置文件/etc/mke2fs.conf可以定義文件系統(tǒng)類型,下面進行簡單說明:
[root@Centos ~]# cat /etc/mke2fs.conf [defaults] #默認選項 base_features = sparse_super,filetype,resize_inode,dir_index,ext_attr #默認創(chuàng)建的文件系統(tǒng)是ext2;#若 base_features = has_journal,extent,huge_file,flex_bg,uninit_bg,dir_nlink,extra_isize 則默認創(chuàng)建ext4文件系統(tǒng) blocksize = 4096 #默認塊大小,對于大文件塊越小越好 inode_size = 256inode_ratio = 16384 [fs_types] ext3 = { features = has_journal } ext4 = { features = has_journal,extent,huge_file,flex_bg,uninit_bg,dir_nlink,extra_isize inode_size = 256 } ext4dev = { features = has_journal,extent,huge_file,flex_bg,uninit_bg,dir_nlink,extra_isize inode_size = 256 options = test_fs=1 } small = { blocksize = 1024 inode_size = 128 inode_ratio = 4096 }舉例說明:
[root@Centos dev]# mkfs -t ext3 /dev/sdb1 #用ext3文件系統(tǒng)格式化sdb1分區(qū) mke2fs 1.41.12 (17-May-2010) Filesystem label= OS type: Linux Block size=4096 (log=2)#塊大小為4096B Fragment size=4096 (log=2) Stride=0 blocks, Stripe style="color: #800080">0 blocks 131648 inodes, 526120 blocks 26306 blocks (5.00%) reserved for the super user #默認分區(qū)的5%的空間預留給管理使用的塊First data block=0 Maximum filesystem blocks=54106521617 block groups32768 blocks per group, 32768 fragments per group 7744 inodes per group Superblock backups stored on blocks:32768, 98304, 163840, 229376, 294912 Writing inode tables: done Creating journal (16384 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 39 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@Centos dev]# mke2fs -b 2048 /dev/sdb1 #調(diào)整分區(qū)sdb1的塊大小為2048B mke2fs 1.41.12 (17-May-2010) Filesystem label= OS type: Linux Block size=2048 (log=1) #可以看到塊大小變成了2048B了哈 Fragment size=2048 (log=1) Stride=0 blocks, Stripe style="color: #800080">0 blocks 131560 inodes, 1052240 blocks 52612 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=53896806465 block groups16384 blocks per group, 16384 fragments per group 2024 inodes per group Superblock backups stored on blocks:16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816 Writing inode tables: done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 20 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.3、查看/調(diào)整文件系統(tǒng)參數(shù):
舉例說明:
[root@Centos dev]# tune2fs -l /dev/sdb1 #查看sdb1分區(qū)的超級塊信息 tune2fs 1.41.12 (17-May-2010) Filesystem volume name: <none> Last mounted on:<not available> Filesystem UUID:8f9d5e47-c3e2-441f-b29f-e0a9dd508632 #UUID Filesystem magic number: 0xEF53 #文件系統(tǒng)魔數(shù) Filesystem revision #: 1 (dynamic) Filesystem features: ext_attr resize_inode dir_index filetype sparse_super Filesystem flags: signed_directory_hash Default mount options: (none) Filesystem state: clean Errors behavior:Continue Filesystem OS type: Linux Inode count: 131560 Block count: 1052240 #總共塊的數(shù)目 Reserved block count: 52612 Free blocks: 1031020 Free inodes: 131549 First block: 0 Block size: 2048 #塊大小 Fragment size: 2048 Reserved GDT blocks: 512 Blocks per group: 16384 Fragments per group: 16384 Inodes per group: 2024 Inode blocks per group: 253 Filesystem created: Wed Feb 26 14:13:10 2014#文件系統(tǒng)創(chuàng)建日期 Last mount time:n/a Last write time:Wed Feb 26 14:13:10 2014 Mount count: 0 Maximum mount count: 20 Last checked: Wed Feb 26 14:13:10 2014 Check interval: 15552000 (6 months) Next check after: Mon Aug 25 14:13:10 2014 Reserved blocks uid: 0 (user root) #預留空間所給的用戶是管理員 Reserved blocks gid: 0 (group root) First inode: 11 Inode size: 256 Required extra isize: 28 Desired extra isize: 28 Default directory hash: half_md4 Directory Hash Seed: 7b570d3a-1fe3-4d12-a9c3-3a5811e8cbe4設(shè)定卷標/查看卷標、UUID和文件系統(tǒng)類型:
[root@Centos ~]# e2label /dev/sdb1 MYDATA #設(shè)定sdb1的卷標為MYDATA [root@Centos ~]# blkid /dev/sdb1 #UUID、文件系統(tǒng)類型和卷標 /dev/sdb1: UUID="284c3316-e0f8-4a87-8d49-72ab1c9964ae" TYPE="ext4" LABEL="MYDATA"文件系統(tǒng)創(chuàng)建完之后,我們還需要掛載分區(qū)才能夠正常使用新創(chuàng)建好的分區(qū)。
相關(guān)文章:
1. Solaris與Windows/Linux的簡單區(qū)別2. 如何在電腦PC上啟動Windows11和Linux雙系統(tǒng)3. 在 XP系統(tǒng)下虛擬機Linux文件共享4. Linux和Mac上的UGNX界面5. SWsoft公司推出Windows版Linux服務(wù)器軟件6. 在Ubuntu/Linux環(huán)境下使用MySQL開放/修改3306端口和開放訪問權(quán)限7. 紅帽RH133課程概要――Red Hat Linux 系統(tǒng)管理8. mysql8.0.23 linux(centos7)安裝完整超詳細教程9. linux 查看文件系統(tǒng)類型實例方法10. 基于Linux的性能監(jiān)測比拼和實現(xiàn)攻略
