安装 Ubuntu Server 系统后磁盘空间 98G 没有全部使用的解决方法

在安装 Ubuntu Server 22.04.2 LTS 系统的过程中,使用了一块 1T 空间的硬盘,安装时使用 Ubuntu 系统默认的 lvm 进行磁盘管理,所使用的空间只有 98G,仅为总磁盘空间的 10%,如果要把剩余的空间全部使用起来,需要做如下处理

首先使用 df -h 命令查看磁盘目录状态,看到磁盘没有被 100% 全部利用。

wan@wan:~$ df -h
Filesystem                         Size  Used Avail Use% Mounted on
tmpfs                              393M  772K  392M   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv   98G  6.2G   87G   7% /
tmpfs                              2.0G     0  2.0G   0% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
/dev/sda2                          2.0G  131M  1.7G   8% /boot
/dev/sda1                          1.1G  6.1M  1.1G   1% /boot/efi
tmpfs                              393M  4.0K  393M   1% /run/user/1000

使用 fdisk -l 命令可以看到是 1TB 的硬盘

wan@wan:~$ fdisk -l
Disk /dev/sda: 1 TiB, 1099511627776 bytes, 2147483648 sectors
Disk model: Virtual disk
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: 219E2044-9C56-41A0-8509-DA525EE765CD

Device       Start        End    Sectors    Size Type
/dev/sda1     2048    2203647    2201600      1G EFI System
/dev/sda2  2203648    6397951    4194304      2G Linux filesystem
/dev/sda3  6397952 2147481599 2141083648 1020.9G Linux filesystem


Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 1020.95 GiB, 1096231682048 bytes, 2141077504 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

使用 sudo vgdisplay 命令查看现有存在的卷组

wan@wan:~$ sudo vgdisplay
  --- Volume group ---
  VG Name               ubuntu-vg
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  2
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <1020.95 GiB
  PE Size               4.00 MiB
  Total PE              261362
  Alloc PE / Size       25600 / 100.00 GiB
  Free  PE / Size       235762 / <920.95 GiB
  VG UUID               JSTFe2-1keY-T6x8-l8aq-ccrb-jjWe-wVtkg9

可以看到卷组中 Free PE / Size 235762 / <920.95 GiB,这些空间就是需要利用起来的部分。

扩展硬盘方法

扩展现有逻辑卷

/dev/mapper/ubuntu--vg-ubuntu--lv 逻辑卷扩展至 100% 的硬盘空间

使用命令:sudo lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv 回车执行

wan@wan:~$ sudo lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
  Size of logical volume ubuntu-vg/ubuntu-lv changed from 100.00 GiB (25600 extents) to <1020.95 GiB (261362 extents).
  Logical volume ubuntu-vg/ubuntu-lv successfully resized.

注意:此处的/dev/mapper/ubuntu--vg-ubuntu--lv,目录为手动执行 df -h 命令中返回/目录对应的 Filesystem 内容。

此时,还没有生效,如果用 df -h 命令查询,还是原来的状态。

重新计算逻辑卷大小

使用命令:sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv 回车执行

wan@wan:~$ sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
resize2fs 1.46.5 (30-Dec-2021)
Filesystem at /dev/mapper/ubuntu--vg-ubuntu--lv is mounted on /; on-line resizing required
old_desc_blocks = 13, new_desc_blocks = 128
The filesystem on /dev/mapper/ubuntu--vg-ubuntu--lv is now 267634688 (4k) blocks long.

再次查看硬盘使用情况

wan@wan:~$ df -h
Filesystem                         Size  Used Avail Use% Mounted on
tmpfs                              393M  772K  392M   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv 1005G  6.2G  957G   1% /
tmpfs                              2.0G     0  2.0G   0% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
/dev/sda2                          2.0G  131M  1.7G   8% /boot
/dev/sda1                          1.1G  6.1M  1.1G   1% /boot/efi
tmpfs                              393M  4.0K  393M   1% /run/user/1000

至此,整个硬盘空间都可以 100% 利用了。

实际应用过程

实际中只需要执行两段命令即可。

sudo lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv

执行过后,使用 df -h 命令,即可查看已使用全部空间。

参考资料:

  • https://www.bilibili.com/read/cv23646901
  • https://mx.moonjer.com/2021/11/22/310.html
  • https://blog.csdn.net/asdcls/article/details/122905148
  • https://blog.csdn.net/u013593031/article/details/131814048
  • https://blog.csdn.net/weixin_45789404/article/details/132921498
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。
任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。
如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
Linux 相关

Linux下WEB管理面板

2023-6-25 1:39:33

Linux 相关

Ubuntu系统时间更改

2023-11-2 22:33:25

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
有新私信 私信列表
搜索