前言:
識別磁盤、
磁盤構(gòu)成喜庞、
文件系統(tǒng)诀浪、
link(軟鏈接、硬鏈接)延都、
fdisk 使用雷猪、
gdisk 使用
導(dǎo)圖
磁盤和文件系統(tǒng)
識別硬盤
一般添加磁盤完成后,如果想要能夠識別晰房,需要重啟電腦求摇,不過這里也可以通過命令的方式識別
# echo "- - -" >> /sys/class/scsi_host/host0/scan
# echo "- - -" >> /sys/class/scsi_host/host1/scan
# echo "- - -" >> /sys/class/scsi_host/host2/scan
# fdisk -l
磁盤的構(gòu)成
硬盤的物理構(gòu)成:
扇區(qū)(sector)、磁道(track)殊者、磁頭与境、柱面(cylinder)分區(qū):
就是記錄每一個分區(qū)的起始柱面和結(jié)束柱面。文件系統(tǒng):
是操作系統(tǒng)用于明確存儲設(shè)備(常見的是磁盤)或分區(qū)上的文件的方法和數(shù)據(jù)結(jié)構(gòu)猖吴;
即在存儲設(shè)備上組織文件的方法摔刁。
基本概念
- block
數(shù)據(jù)存儲的最小單元 - inode
索引節(jié)點,全局唯一編號海蔽,除了記錄文件的屬性外共屈,同時還具有指針功能,指向文件內(nèi)容放置的塊党窜;
(里面保存的是文件的權(quán)限拗引,所有者,所屬主等基本信息)
文件系統(tǒng)
boot block (boot sector)(待補充)
它位于分區(qū)上的第一個塊幌衣,占用1024字節(jié)矾削,只有裝了操作系統(tǒng)的主分區(qū)和裝了操作系統(tǒng)的邏輯分區(qū)才有。group description(組描述)(待補充)
ext文件系統(tǒng)為每一個塊組信息使用32字節(jié)描述,這32個字節(jié)稱為塊組描述符怔软,
所有塊組的塊組描述符組成塊組描述符表GDT(group descriptor table)垦细。superblock(超級塊)(待補充)
記錄整個文件系統(tǒng)相關(guān)信息block bitmap(塊位圖)(待補充)
此處記錄block是否使用inode bitmap(inode位圖)(待補充)
此處記錄inode是否使用inode table(inode表)(待補充)
為每個inode的數(shù)據(jù)存放區(qū)
在ext文件系統(tǒng)上,將這些物理上存儲inode的block組合起來挡逼,在邏輯上形成一張inode表(inode table)來記錄所有的inode括改。block group(待補充)
data block(數(shù)據(jù)塊)
為每個block的數(shù)據(jù)存放區(qū)
軟鏈接和硬鏈接:
鏈接:硬鏈接和軟鏈接(符號鏈接),多個文件指向同一個iNode家坎,硬鏈接嘱能;
符號連接,指向的是源文件的路徑虱疏,而不是文件塊
硬鏈接
硬鏈接:在某個目錄下的block中增加一個文件關(guān)聯(lián)數(shù)據(jù)惹骂,不會用到inode與磁盤空間
只能對文件進行創(chuàng)建,為了避免循環(huán)引用不能跨文件系統(tǒng)做瞪,
可以在不同目錄下創(chuàng)建硬鏈接可以增加文件被連接的次數(shù)
軟鏈接
軟連接(符號鏈接):建立一個獨立的文件对粪,這個文件會讓數(shù)據(jù)的讀取指
向它連接的文件內(nèi)容可以對目錄創(chuàng)建可以跨文件系統(tǒng)
不會增加被鏈接文件的鏈接次數(shù)
其大小為指定路徑所包含的字符個數(shù)
磁盤分區(qū)
硬盤分區(qū)格式 | 說明 |
---|---|
MBR分區(qū) | <div style="width: 400pt">位于0扇區(qū),他一共512字節(jié)装蓬,前446字節(jié)是grub引導(dǎo)程序著拭,中間64字節(jié)是分區(qū)表,最后2個字節(jié)是結(jié)束符號每個分區(qū)需要16個字節(jié)表示牍帚,因此主分區(qū)和擴展分區(qū)一共只能有4個分區(qū)儡遮,超過4個的分區(qū)只能從擴展分區(qū)上再設(shè)置邏輯分區(qū)來表示。每個分區(qū)的大小無法超過2T暗赶。 |
GPT格式 | <div style="width: 400pt">打破了MBR的限制鄙币,可以設(shè)置多達128個分區(qū),分區(qū)的大小突破了2T空間的限制蹂随。支持高達 18EB(1EB=1024PB十嘿,1PB=1024TB)的卷大小,允許將主磁盤分區(qū)表和備份磁盤分區(qū)表用于冗余岳锁,還支持唯一的磁盤和分區(qū) ID (GUID)绩衷。 |
fdisk(創(chuàng)建MBR分區(qū))
- 語法
# fdisk /dev/sdX
命令 | 說明 |
---|---|
a | 設(shè)置引導(dǎo)扇區(qū) |
b | 編輯bsd磁盤標簽 |
c | 切換dos兼容性標志 |
d | 刪除分區(qū) |
g | 創(chuàng)建一個新的空GPT分區(qū)表 |
G | 創(chuàng)建一個IRIX(SGI)分區(qū)表 |
l | 列出已知的分區(qū)類型 |
m | 打印此菜單 |
n | 添加一個新分區(qū) |
o | 創(chuàng)建一個新的空DOS分區(qū)表 |
p | 打印分區(qū)表 |
q | 退出而不保存更改 |
s | 創(chuàng)建一個新的空Sun disklabel |
t | 更改分區(qū)的系統(tǒng)ID |
u | 更改顯示/輸入單位 |
v | 驗證分區(qū)表 |
w | 將表寫入磁盤并退出 |
x | 額外功能(僅限專家) |
- 創(chuàng)建分區(qū)
# fdisk /dev/sda
命令(輸入 m 獲取幫助):n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
分區(qū)號 (1-4,默認 1):1
起始 扇區(qū) (2048-41943039浸锨,默認為 2048):
將使用默認值 2048
Last 扇區(qū), +扇區(qū) or +size{K,M,G} (2048-41943039,默認為 41943039):+2G
分區(qū) 1 已設(shè)置為 Linux 類型版姑,大小設(shè)為 2 GiB
- 查看分區(qū)
# fdisk /dev/sda
命令(輸入 m 獲取幫助):p
磁盤 /dev/sda:21.5 GB, 21474836480 字節(jié)柱搜,41943040 個扇區(qū)
Units = 扇區(qū) of 1 * 512 = 512 bytes
扇區(qū)大小(邏輯/物理):512 字節(jié) / 512 字節(jié)
I/O 大小(最小/最佳):512 字節(jié) / 512 字節(jié)
磁盤標簽類型:dos
磁盤標識符:0x82ff3e4f
設(shè)備 Boot Start End Blocks Id System
/dev/sda1 2048 4196351 2097152 83 Linux
- 保存分區(qū)
命令(輸入 m 獲取幫助):w
The partition table has been altered!
Calling ioctl() to re-read partition table.
正在同步磁盤。
- 刪除分區(qū)
命令(輸入 m 獲取幫助):d
分區(qū)號 (1,2剥险,默認 2):1
分區(qū) 1 已刪除
gdisk(創(chuàng)建GPT分區(qū))
命令 | 說明 |
---|---|
b | 將GPT數(shù)據(jù)備份到文件 |
c | 更改分區(qū)的名稱 |
d | 刪除分區(qū) |
i | 在分區(qū)上顯示詳細信息 |
l | 列出已知的分區(qū)類型 |
n | 添加一個新分區(qū) |
o | 創(chuàng)建一個新的空GUID分區(qū)表(GPT) |
p | 打印分區(qū)表 |
q | 退出而不保存更改 |
r | 恢復(fù)和轉(zhuǎn)換選項(僅限專家) |
s | 排序分區(qū) |
t | 更改分區(qū)的類型代碼 |
v | 驗證磁盤 |
w | 將表寫入磁盤并退出 |
x | 額外功能(僅限專家) |
? | 打印此菜單 |
- 創(chuàng)建分區(qū)
# gdisk /dev/sdb
GPT fdisk (gdisk) version 0.8.10
Partition table scan:
MBR: not present
BSD: not present
APM: not present
GPT: not present
Creating new GPT entries.
Command (? for help): n
Partition number (1-128, default 1): 1
First sector (34-41943006, default = 2048) or {+-}size{KMGTP}:
Last sector (2048-41943006, default = 41943006) or {+-}size{KMGTP}: +2G
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300):
Changed type of partition to 'Linux filesystem'
- 查看分區(qū)
Command (? for help): p
Disk /dev/sdb: 41943040 sectors, 20.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): B428B7A5-EBDF-4644-A35F-37942EC0C7EF
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 41943006
Partitions will be aligned on 2048-sector boundaries
Total free space is 37748669 sectors (18.0 GiB)
Number Start (sector) End (sector) Size Code Name
1 2048 4196351 2.0 GiB 8300 Linux filesystem
- 保存分區(qū)
Command (? for help): w
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sdb.
The operation has completed successfully.
- 刪除分區(qū)
Command (? for help): d
Partition number (1-2): 1
parted
- 設(shè)置 磁盤分區(qū)表格式
設(shè)定為 MER格式:mklabel msdos
設(shè)定為 GPT格式:mklabel gpt
(parted) mklabel msdos
警告: The existing disk label on /dev/sda will be destroyed and all data on this disk
will be lost. Do you want to continue?
是/Yes/否/No? yes
(parted) mklabel gpt
警告: The existing disk label on /dev/sda will be destroyed and all data on this disk
will be lost. Do you want to continue?
是/Yes/否/No? yes
- 創(chuàng)建分區(qū)
(parted) mkpart
分區(qū)名稱聪蘸? []? disk1
文件系統(tǒng)類型? [ext2]? ext4
起始點? 0M
結(jié)束點健爬? 5G
警告: The resulting partition is not properly aligned for best performance.
忽略/Ignore/放棄/Cancel? i
- 查看分區(qū)
parted) print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sda: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system 標志
1 512B 10.0GB 10.0GB primary
- 刪除分區(qū)
(parted) rm
分區(qū)編號控乾? Number