Linux磁盘分区问题

当前fdisk查看的磁盘分区比实际df出来的磁盘分区大,实际磁盘分区不可用。

[SME@search-10 ~]$ df -Th
Filesystem     Type     Size Used Avail Use% Mounted on
devtmpfs       devtmpfs   94G     0   94G   0% /dev
tmpfs         tmpfs     94G     0   94G   0% /dev/shm
tmpfs         tmpfs     94G   18M   94G   1% /run
tmpfs         tmpfs     94G     0   94G   0% /sys/fs/cgroup
/dev/sda3     ext4      7.6G  2.6G  4.6G  36% /
/dev/sda2     ext4      2.0G 389M  1.5G  22% /boot
/dev/sda4     ext4      1.7T   60K  1.6T   1% /home/search
tmpfs         tmpfs     19G     0   19G   0% /run/user/0
tmpfs         tmpfs     19G     0   19G   0% /run/user/1006

[SME@search-10 ~]$ sudo fdisk -l
Disk /dev/sda: 2.6 TiB, 2876997894144 bytes, 5619136512 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 262144 bytes / 786432 bytes
Disklabel type: gpt
Disk identifier: 40992439-8FB1-4EF3-AF5D-0B180C07EA05

Device         Start       End   Sectors Size Type
/dev/sda1        2048       4095       2048   1M BIOS boot
/dev/sda2        4096    4198399    4194304   2G Linux filesystem
/dev/sda3     4198400 2101350399 2097152000 1000G Linux filesystem
/dev/sda4  2101350400 5619003391 3517652992  1.7T Microsoft basic data
/dev/sda5  5619003392 5619136478     133087   65M Linux filesystem

由于是根分区,无法重新格式化,且重新通过分配之后,重启也无法获得扩展,如下所示:

[SME@search-10 ~]$ sudo fdisk /dev/sda

Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p
Disk /dev/sda: 2.6 TiB, 2876997894144 bytes, 5619136512 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 262144 bytes / 786432 bytes
Disklabel type: gpt
Disk identifier: 40992439-8FB1-4EF3-AF5D-0B180C07EA05

Device         Start       End   Sectors Size Type
/dev/sda1        2048       4095       2048   1M BIOS boot
/dev/sda2        4096    4198399    4194304   2G Linux filesystem
/dev/sda3     4198400 2101350399 2097152000 1000G Linux filesystem
/dev/sda4  2101350400 5619003391 3517652992  1.7T Microsoft basic data
/dev/sda5  5619003392 5619136478     133087   65M Linux filesystem

Command (m for help): d
Partition number (1-5, default 5): 3

Partition 3 has been deleted.

Command (m for help): p
Disk /dev/sda: 2.6 TiB, 2876997894144 bytes, 5619136512 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 262144 bytes / 786432 bytes
Disklabel type: gpt
Disk identifier: 40992439-8FB1-4EF3-AF5D-0B180C07EA05

Device         Start       End   Sectors Size Type
/dev/sda1        2048       4095       2048   1M BIOS boot
/dev/sda2        4096    4198399    4194304   2G Linux filesystem
/dev/sda4  2101350400 5619003391 3517652992  1.7T Microsoft basic data
/dev/sda5  5619003392 5619136478     133087   65M Linux filesystem

Command (m for help): n
Partition number (3,6-128, default 3):
First sector (4198400-2101350399, default 4198400):
Last sector, +sectors or +size{K,M,G,T,P} (4198400-2101350399, default 2101350399):

Created a new partition 3 of type 'Linux filesystem' and of size 1000 GiB.
Partition #3 contains a ext4 signature.

Do you want to remove the signature? [Y]es/[N]o: Y

The signature will be removed by a write command.

Command (m for help): p
Disk /dev/sda: 2.6 TiB, 2876997894144 bytes, 5619136512 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 262144 bytes / 786432 bytes
Disklabel type: gpt
Disk identifier: 40992439-8FB1-4EF3-AF5D-0B180C07EA05

Device         Start       End   Sectors Size Type
/dev/sda1        2048       4095       2048   1M BIOS boot
/dev/sda2        4096    4198399    4194304   2G Linux filesystem
/dev/sda3     4198400 2101350399 2097152000 1000G Linux filesystem
/dev/sda4  2101350400 5619003391 3517652992  1.7T Microsoft basic data
/dev/sda5  5619003392 5619136478     133087   65M Linux filesystem

Filesystem/RAID signature on partition 3 will be wiped.

Command (m for help): w
The partition table has been altered.
Syncing disks.

[SME@search-10 ~]$ sudo partprobe /dev/sda
Warning: The disk CHS geometry (11017914,255,2) reported by the operating system does not match the geometry stored on the disk label (22095,255,63).
Error: Can't have overlapping partitions.

于是,尝试使用resize2fs,如下所示:

[SME@search-10 ~]$ sudo resize2fs /dev/sda3
resize2fs 1.45.6 (20-Mar-2020)
Filesystem at /dev/sda3 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 125
The filesystem on /dev/sda3 is now 262144000 (4k) blocks long.

[SME@search-10 ~]$ df -Th
Filesystem     Type     Size Used Avail Use% Mounted on
devtmpfs       devtmpfs   94G     0   94G   0% /dev
tmpfs         tmpfs     94G     0   94G   0% /dev/shm
tmpfs         tmpfs     94G   18M   94G   1% /run
tmpfs         tmpfs     94G     0   94G   0% /sys/fs/cgroup
/dev/sda3     ext4     985G  2.6G 942G   1% /
/dev/sda2     ext4      2.0G 389M  1.5G  22% /boot
/dev/sda4     ext4      1.7T   60K  1.6T   1% /home/search
tmpfs         tmpfs     19G     0   19G   0% /run/user/0

结果成功扩展了分区。

Monthly Archives

Pages

Powered by Movable Type 7.9.4

About this Entry

This page contains a single entry by Cnangel published on August 31, 2022 10:38 PM.

一句话编程技巧 was the previous entry in this blog.

[转]c++使用宏检测类是否包含某个函数或者变量属性 is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.