linux文件系統
文件系統:Filesystem(基于內核的軟件)
磁盤分區是以柱面(一個個磁道)來分的.
每一個分區就是一個文件系統!
UNIX:FresBSD
Partition:
獨立的文件系統
文件的數據:
元數據(metadata):屬性信息,單獨存放!
數據(data)
inode:文件權限、屬主屬組、文件類型、磁盤塊指向
cp:同樣的數據存儲了兩次,有兩個inode號
mv:文件數據沒動,映射關系改變(在同一個分區之內)
rm:對應關系,inode號為空,磁盤塊內的數據沒變,表示為空!
ln:
硬鏈接:不同的文件路徑的文件指向的是同一個inode,刪除硬連接跟原文件沒關系,不能跨分區存在!不能連接到目錄上,避免循環引用
軟連接:刪除原文件軟連接不可用,軟連接可以對目錄創建,可以跨分區,
ln:
ln [OPTION]... [-T] TARGET LINK_NAME (1st form)
-s 軟鏈接
ls -i 顯示inode號
Linux文件 系統:
ext2
ext3
ext4
xfs
reiserfs
jfs
iso9660
swap
vfat
ntfs
GFS2
OCFS2 orical數據庫文件系統
NFS
VFS:Virtual FileSystem 虛擬文件系統
du:估算文件空間使用量的!
-s 僅顯示統計
-S顯示個別目錄的大小
-h 單位換算
df:顯示磁盤相關信息
-h 單位換算
-i 顯示inode信息
fdisk:
-l 列出當前系統磁盤分區情況
gzip:壓縮文件
-d 解開壓縮文件
-f 強制壓縮文件
-c 輸出重定向,不動原文件
使用例子:
gzip -c File > Gzip.gz 輸出重定向Gzip
-t 測試壓縮文件是否正確
-# (1-9)指定壓縮比 默認為6,壓縮比越大,壓縮越慢
gunzip:解壓縮文件
zcat File.gz 只能壓縮文件,不能壓縮目錄
bzip File
.bz2
-d 解壓縮
-k 直接保留原文件
bunzip2 File.bz2 = bzip2 -d File.bz2
bzcat File.bz2
zip:
zip 指定文件名.zip + 需要壓縮的文件名
unzip File.zip
tar 文件歸檔工具
-c 創建歸檔文件
-f 指定文件名
-x 從歸檔文件中還原文件
-t 列出文件內容
-v 顯示詳細過程
-z 指定通過gzip處理歸檔文件
常用
tar -zcvf 創建歸檔壓縮文檔并顯示過程 (擴展名為tar.gz)
tar -zxvf 展開歸檔文檔并顯示過程 (擴展名為tar.gz)
tar -jcvf 創建歸檔壓縮文檔并顯示過程 (擴展名為tar.bz2)
tar -jxvf 展開歸檔文檔并顯示過程 (擴展名為tar.bz)
分區:
Boot Sector : bootloader + fat + 封裝碼
512 = 446 + 64 +2(封裝碼)
64 :每16個字節可以引導一個主分區!最多4個主分區,多采用3+1(一主三擴展)
linux 如何識別磁盤設備:
/dev/
IDE(ATA):hd
SATA:sd
SCSI:sd
USB:sd
SAS:sd
a,b,c,d
/dev/hda
/dev/hab
...
/dev/sda
掛載卸載
/media 掛載便攜式設備
/mnt 常用掛載目錄
fdisk:
fdisk /dev/sda
m 獲得幫助
p 獲得分區表
n 新建分區
e 新建擴展分區
p 新建主分區
n 新建邏輯分區
d:刪除分區
l 查看id號
t 修改分區的id
w 保存修改并退出
q 放棄修改并退出
fdisk 最多只能創建15個分區
partprobe /dev/sda 重新掃描分區
[root@localhost wangzhen]# fdisk
Usage: fdisk [-l] [-b SSZ] [-u] device
E.g.: fdisk /dev/hda (for the first IDE disk)
or: fdisk /dev/sdc (for the third SCSI disk)
or: fdisk /dev/eda (for the first PS/2 ESDI drive)
or: fdisk /dev/rd/c0d0 or: fdisk /dev/ida/c0d0 (for RAID devices)
...
[root@localhost wangzhen]# fdisk /dev/sda
The number of cylinders for this disk is set to 6527.
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 刪除一個分區
l list known partition types 顯示分區id號
m print this menu 幫助菜單
n add a new partition 一個新的分區域
o create a new empty DOS partition table
p print the partition table 顯示分區表
q quit without saving changes 放棄保存并退出
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
w write table to disk and exit 保存并退出
x extra functionality (experts only)
Command (m for help): p
Disk /dev/sda: 53.6 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 38 305203+ 83 Linux
/dev/sda2 39 6462 51600780 83 Linux
/dev/sda3 6463 6527 522112+ 82 Linux swap / Solaris
fdisk 默認只支持到15個數字!
partprobe 重新掃描分區
sfdisk 保存備份分區表
格式化:(高級格式化)
mkfs -t ext2 /dev/sdb1
mkfs -L + Lables 卷標
mkfs 默認不支持ntfs 格式
e2label /dev/sdb1 顯示卷標
e2label /dev/sdb1 LABLE 設置卷標
mke2fs 創建文件系統
mke2fs /dev/sdb2
-j 帶日志類型的文件類型
-L 設置卷標
-b(1024|2048|4096<默認>)
-c 檢測磁盤是否有壞道
-i inode比率(byte/inode)
默認每128個字節創建一個inode條目,決定inode的個數!