ubuntu20.04 service版本硬盘部分未挂载,实际容量不对,sda3部分未使用

发布于 2024年03月09日

现象:在安装完ubuntu20.04的服务器版本以后,发现一个固态被分成了3部分,并且一分部固态容量消失了!

root@mylinux:/dev# fdisk -l
Disk /dev/loop0: 63.24 MiB, 66301952 bytes, 129496 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 /dev/loop1: 63.28 MiB, 66347008 bytes, 129584 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 /dev/loop2: 91.85 MiB, 96292864 bytes, 188072 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 /dev/loop3: 49.64 MiB, 52031488 bytes, 101624 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 /dev/loop4: 67.25 MiB, 70508544 bytes, 137712 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 /dev/sda: 111.81 GiB, 120034123776 bytes, 234441648 sectors
Disk model: KINGSTON SA400S3
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: BBF8C9A2-2432-46D4-A91A-02B5AB21DF03

Device       Start       End   Sectors   Size Type
/dev/sda1     2048   2203647   2201600   1.1G EFI System
/dev/sda2  2203648   5349375   3145728   1.5G Linux filesystem
/dev/sda3  5349376 234438655 229089280 109.2G Linux filesystem

Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 54.63 GiB, 58644758528 bytes, 114540544 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

可以看到,三部分sda1,sda2,sda3,但是用指令df -h看到的实际容量不符合!.

root@mylinux:~# df -h
Filesystem                         Size  Used Avail Use% Mounted on
udev                               1.9G     0  1.9G   0% /dev
tmpfs                              384M  1.5M  383M   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv   54G   15G   36G  30% /
tmpfs                              1.9G     0  1.9G   0% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
tmpfs                              1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/loop1                          64M   64M     0 100% /snap/core20/1778
/dev/loop0                          64M   64M     0 100% /snap/core20/1738
/dev/loop2                          92M   92M     0 100% /snap/lxd/24061
/dev/loop3                          50M   50M     0 100% /snap/snapd/17883
/dev/sda2                          1.5G  205M  1.2G  15% /boot
/dev/loop4                          68M   68M     0 100% /snap/lxd/21835
/dev/sda1                          1.1G  5.3M  1.1G   1% /boot/efi
tmpfs                              384M     0  384M   0% /run/user/1000

我的固态是120G,明显少了几十G容量

继续输入命令:

root@mylinux:/dev# lsblk
NAME                      MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
loop0                       7:0    0  63.2M  1 loop /snap/core20/1738
loop1                       7:1    0  63.3M  1 loop /snap/core20/1778
loop2                       7:2    0  91.9M  1 loop /snap/lxd/24061
loop3                       7:3    0  49.6M  1 loop /snap/snapd/17883
loop4                       7:4    0  67.2M  1 loop /snap/lxd/21835
sda                         8:0    0 111.8G  0 disk
├─sda1                      8:1    0   1.1G  0 part /boot/efi
├─sda2                      8:2    0   1.5G  0 part /boot
└─sda3                      8:3    0 109.2G  0 part
  └─ubuntu--vg-ubuntu--lv 253:0    0  54.6G  0 lvm  /

OK,可以看到,sda3一共有109g,其中一部分被分成了ubuntu–vg-ubuntu–lv,逻辑卷54G。并且被挂载到了根目录下“/”,但是sda3并没有被完全使用,109-54=55G,没有被挂载到任何目录下

此时如果使用挂载指令:

root@mylinux:/dev# mount /dev/sda3  /
mount: /: unknown filesystem type 'LVM2_member'.

会有mount: /: unknown filesystem type 'LVM2_member’的提示,其实就是因为部分被分成了逻辑卷,所以无法挂载。

解决方案:我们可以选择直接增大逻辑卷的大小,将sda3完全占用即可

指令:

lvextend -l +100%FREE /dev/mapper/ubuntu–vg-ubuntu–lv
root@mylinux:/dev# lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
  Size of logical volume ubuntu-vg/ubuntu-lv changed from <54.62 GiB (13982 extents) to 109.23 GiB (27964 extents).
  Logical volume ubuntu-vg/ubuntu-lv successfully resized.

然后刷新:

resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
root@mylinux:/dev# resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
resize2fs 1.45.5 (07-Jan-2020)
Filesystem at /dev/mapper/ubuntu--vg-ubuntu--lv is mounted on /; on-line resizing required
old_desc_blocks = 7, new_desc_blocks = 14
The filesystem on /dev/mapper/ubuntu--vg-ubuntu--lv is now 28635136 (4k) blocks long.

现在用df -h查看硬盘使用情况:

root@mylinux:/dev# df -h
Filesystem                         Size  Used Avail Use% Mounted on
udev                               1.9G     0  1.9G   0% /dev
tmpfs                              384M  1.5M  383M   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv  108G   15G   88G  15% /
tmpfs                              1.9G     0  1.9G   0% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
tmpfs                              1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/loop1                          64M   64M     0 100% /snap/core20/1778
/dev/loop0                          64M   64M     0 100% /snap/core20/1738
/dev/loop2                          92M   92M     0 100% /snap/lxd/24061
/dev/loop3                          50M   50M     0 100% /snap/snapd/17883
/dev/sda2                          1.5G  205M  1.2G  15% /boot
/dev/loop4                          68M   68M     0 100% /snap/lxd/21835
/dev/sda1                          1.1G  5.3M  1.1G   1% /boot/efi
tmpfs                              384M     0  384M   0% /run/user/1000
root@mylinux:/dev# lsblk -l
NAME                  MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
loop0                   7:0    0  63.2M  1 loop /snap/core20/1738
loop1                   7:1    0  63.3M  1 loop /snap/core20/1778
loop2                   7:2    0  91.9M  1 loop /snap/lxd/24061
loop3                   7:3    0  49.6M  1 loop /snap/snapd/17883
loop4                   7:4    0  67.2M  1 loop /snap/lxd/21835
sda                     8:0    0 111.8G  0 disk
sda1                    8:1    0   1.1G  0 part /boot/efi
sda2                    8:2    0   1.5G  0 part /boot
sda3                    8:3    0 109.2G  0 part
ubuntu--vg-ubuntu--lv 253:0    0 109.2G  0 lvm  /

可以看到根目录下,硬盘大小恢复到了109G,解决!



评论