1. 程式人生 > >(原)記一次CentOS7 磁盤空間大小異常的解決過程

(原)記一次CentOS7 磁盤空間大小異常的解決過程

數據 並且 程序 ges mounted prim isp 也不會 顯示

環境:kvm
系統:CentOS7
故障描述:10g的ssd,可使用大小僅有2g
解決過程:

? ? 某次重裝系統後,安裝軟件總提示磁盤空間不足,檢查之下發現僅有2G空間,實則明明是10G的ssd,以下為排錯過程:

1、df -h查看vda1大小為2.7G

#df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 2.7G 2.4G 236M 91% /
devtmpfs 234M 0 234M 0% /dev
tmpfs 244M 0 244M 0% /dev/shm
tmpfs 244M 4.5M 240M 2% /run
tmpfs 244M 0 244M 0% /sys/fs/cgroup
tmpfs 49M 0 49M 0% /run/user/0

2、fdisk查看vda1一共9959232個block,大小應為9959232KB=9.725.8GB

#fdisk -l
Disk /dev/vda: 10.7 GB, 10737418240 bytes, 20971520 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: 0x000f3770
?? Device Boot????? Start???????? End????? Blocks?? Id? System
/dev/vda1?? *??????? 2048??? 19920511? ???9959232?? 83? Linux
/dev/vda2??????? 19920512??? 20969087????? 524288?? 82? Linux swap / Solaris

3、嘗試能否通過新建分區解決的時候,發現了另一個bug,居然能看到主機的真實磁盤大小!

#fdisk /dev/vda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): u
Changing display/entry units to cylinders (DEPRECATED!).

Command (m for help): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p
Partition number (3,4, default 3): 3
First cylinder (1306-20805, default 1306): 
Using default value 1306
Last cylinder, +cylinders or +size{K,M,G} (1306-20805, default 20805): 
Using default value 20805
Partition 3 of type Linux and of size 149.4 GiB is set? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

//剩余149.4G,加上我自己的10G,這塊SSD的大小應該是160G的,當然僅此而已了,想要盜用還是不可能的,至少我辦不到。囧

Command (m for help): q

fdisk -l? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

//雖然fdisk看到的vda3貌似很厲害的樣子

Disk /dev/vda: 10.7 GB, 10737418240 bytes, 20971520 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: 0x000f3770

Device Boot Start End Blocks Id System
/dev/vda1 * 2048 19920511 9959232 83 Linux
/dev/vda2 19920512 20969087 524288 82 Linux swap / Solaris
/dev/vda3 20969088 334232324 156631618+ 83 Linux

4、partprobe的時候果然報錯了哈哈哈

#partprobe 
Error: Can‘t have a partition outside the disk!

5、fdisk看到的vda1大小正常,並且也沒有多余的可用空間來新建分區,說明問題不是出在磁盤空間分配上,此路不通。

所以刪除那個奇葩的vda3,嘗試resize方法

#resize2fs /dev/vda1
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/vda1 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 2
The filesystem on /dev/vda1 is now 2489808 blocks long.

6、fdisk數據並無變化,但df顯示磁盤空間終於正常了,安裝程序也不會再提示磁盤空間不足,故障排除。

fdisk -l

Disk /dev/vda: 10.7 GB, 10737418240 bytes, 20971520 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: 0x000f3770

Device Boot Start End Blocks Id System
/dev/vda1 * 2048 19920511 9959232 83 Linux
/dev/vda2 19920512 20969087 524288 82 Linux swap / Solaris

# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 9.3G 2.4G 6.6G 27% /
devtmpfs 234M 0 234M 0% /dev
tmpfs 244M 0 244M 0% /dev/shm
tmpfs 244M 4.5M 240M 2% /run
tmpfs 244M 0 244M 0% /sys/fs/cgroup
tmpfs 49M 0 49M 0% /run/user/0

個人blog:https://www.moonshadows.cn/

(原)記一次CentOS7 磁盤空間大小異常的解決過程