那天下午,陽(yáng)光透過(guò)辦公室的窗戶(hù)灑在桌面上,我剛剛處理完一個(gè)棘手的bug,正享受著一杯茶的寧?kù)o時(shí)光。然而,這份寧?kù)o很快被一陣急促的電話(huà)鈴聲打破。
“我們?cè)谧鎏摂M機(jī)磁盤(pán)擴(kuò)容,遇到一個(gè)奇怪的問(wèn)題,你能幫忙看看嗎?”電話(huà)那頭的聲音透著焦急。
我調(diào)整了一下?tīng)顟B(tài),心中略顯興奮?;貜?fù)道:“別擔(dān)心,我馬上來(lái)?!?/p>
一、故障描述
在使用不同的磁盤(pán)分區(qū)工具(如`fdisk`和`parted`)時(shí),發(fā)現(xiàn)它們顯示的分區(qū)類(lèi)型不一致。這種情況看似微小,但實(shí)際上可能引發(fā)一系列嚴(yán)重問(wèn)題,影響數(shù)據(jù)安全和系統(tǒng)穩(wěn)定性。
# fdisk -l /dev/sda
Disk /dev/sda: 64.4 GB, 64424509440 bytes, 125829120 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
/dev/sda1 1 104857599 52428799+ ee GPT
# parted -s /dev/sda unit s print
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 125829120s
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 2048s 411647s 409600s fat16 EFI System Partition boot
2 411648s 2508799s 2097152s xfs
3 2508800s 104855551s 102346752s
二、初步排查
# which fdisk /usr/sbin/fdisk # rpm -qf /usr/sbin/fdisk util-linux-2.23.2-59.el7.x86_64
2.查看版本
# fdisk -v fdisk from util-linux 2.23.2
3.查看分區(qū)表
# fdisk -lu /dev/sda Disk /dev/sda: 64.4 GB, 64424509440 bytes, 125829120 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x00000000 Device Boot Start End Blocks Id System /dev/sda1 1 104857599 52428799+ ee GPT # fdisk -lu /dev/sda Disk /dev/sda: 64.4 GB, 64424509440 bytes, 125829120 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dosDisk identifier: 0x00000000 Device Boot Start End Blocks Id System /dev/sda1 1 104857599 52428799+ ee GPT # parted -s /dev/sda unit s print Model: VMware Virtual disk (scsi) Disk /dev/sda: 125829120s Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 2048s 411647s 409600s fat16 EFI System Partition boot 2 411648s 2508799s 2097152s xfs 3 2508800s 104855551s 102346752s lvm
三、試錯(cuò)與分析
在初步排查中,發(fā)現(xiàn)`fdisk`的版本較舊(`util-linux 2.23.2`)。通常情況下,較新的工具版本會(huì)修復(fù)舊版本中的一些已知問(wèn)題。因此,首先想到的是通過(guò)升級(jí)`util-linux`來(lái)解決問(wèn)題,期望新版本能夠正確處理分區(qū)顯示問(wèn)題。
# rpm -Uvh util-linux-2.23.2-65.el7_9.1.x86_64.rpm --force --nodeps warning: util-linux-2.23.2-65.el7_9.1.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY Preparing... ################################# [100%] Updating / installing... 1:util-linux-2.23.2-65.el7_9.1 ################################# [ 50%] Cleaning up / removing... 2:util-linux-2.23.2-59.el7 ################################# [100%]
但是很遺憾,升級(jí)后`fdisk`的顯示仍然異常。
# fdisk -l Disk /dev/sda: 64.4 GB, 64424509440 bytes, 125829120 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dosDisk identifier: 0x00000000 Device Boot Start End Blocks Id System /dev/sda1 1 104857599 52428799+ ee GPT
1.查看扇區(qū)
2.備份mbr
dd if=/dev/sda of=sda_mbr.data bs=512 count=1
3.清空mbr
dd if=/dev/zero of=/dev/sda bs=512 count=1
# dd if=/dev/zero of=/dev/sda bs=512 count=1
1+0 records in
1+0 records out
512 bytes (512 B) copied, 0.000450755 s, 1.1 MB/s
然而,不幸的是,再次分區(qū)表丟失。
# fdisk -l /dev/sda Disk /dev/sda: 64.4 GB, 64424509440 bytes, 125829120 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes # parted /dev/sda print Error: /dev/sda: unrecognised disk label Model: VMware Virtual disk (scsi) Disk /dev/sda: 64.4GB Sector size (logical/physical): 512B/512B Partition Table: unknown Disk Flags:
四、故障分析
如果你已經(jīng)有了答案,不妨一起來(lái)看看我的分析。
五、故障模擬
為了驗(yàn)證這一假設(shè),我模擬了在GPT環(huán)境下擴(kuò)展分區(qū)的情況,果然復(fù)現(xiàn)了相同的故障。
##擴(kuò)容sda之后##
六、故障原因
至此,故障原因也就很清晰了。在創(chuàng)建GUID分區(qū)表(GPT)時(shí),系統(tǒng)會(huì)同時(shí)創(chuàng)建一個(gè)MBR(msdos)分區(qū)表,其中包含一個(gè)覆蓋整個(gè)磁盤(pán)或高達(dá)2TB的0xEE(GPT)分區(qū),稱(chēng)為MBR保護(hù)分區(qū)。這個(gè)分區(qū)用于提醒舊命令和實(shí)用程序磁盤(pán)確實(shí)已分區(qū)。
正常gpt分區(qū) 通過(guò)hexdump查看,200是主分區(qū)開(kāi)始,033ffe00 是secondary (backup) 分區(qū)。
</pre>