【原创】Ubuntu 24自动分区后的根目录扩展

安装了一台Ubuntu 24服务器,发现根目录只有不到100G。
再安装了一台,发现还是同样的问题。

查看分区挂载情况

root@DeepSeek:~# df -h
Filesystem                         Size  Used Avail Use% Mounted on
tmpfs                              772M  1.1M  771M   1% /run
efivarfs                           150K   72K   74K  50% /sys/firmware/efi/efivars
/dev/mapper/ubuntu--vg-ubuntu--lv   98G   44G   50G  47% /
tmpfs                              3.8G   16K  3.8G   1% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
/dev/nvme0n1p2                     2.0G   97M  1.7G   6% /boot
/dev/nvme0n1p1                     1.1G  6.2M  1.1G   1% /boot/efi
tmpfs                              772M   12K  772M   1% /run/user/1000

/dev/mapper/ubuntu–vg-ubuntu–lv 挂载在根目录,只有98G

检查磁盘空间

root@DeepSeek:~# fdisk -l
Disk /dev/nvme0n1: 476.94 GiB, 512110190592 bytes, 1000215216 sectors
Disk model: SAMSUNG MZVLQ512HALU-000H1              
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: 64428F08-2785-4574-A705-2AE6B40F81AD

Device           Start        End   Sectors   Size Type
/dev/nvme0n1p1    2048    2203647   2201600     1G EFI System
/dev/nvme0n1p2 2203648    6397951   4194304     2G Linux filesystem
/dev/nvme0n1p3 6397952 1000212479 993814528 473.9G Linux filesystem


Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 100 GiB, 107374182400 bytes, 209715200 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/nvme0n1: 476.94 GiB,磁盘近500G

接下来将剩余部分全部合并到根目录

查看当前的卷组(VG)

root@DeepSeek:~# 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               <473.89 GiB
  PE Size               4.00 MiB
  Total PE              121315
  Alloc PE / Size       25600 / 100.00 GiB
  Free  PE / Size       95715 / <373.89 GiB
  VG UUID               Uc9TNh-gnfD-OC8N-053Q-VCBg-5UQm-jfuNKc

得到信息:Free PE / Size 95715 / <373.89 GiB。

查看当前逻辑卷(LV)

root@DeepSeek:~# lvdisplay
  --- Logical volume ---
  LV Path                /dev/ubuntu-vg/ubuntu-lv
  LV Name                ubuntu-lv
  VG Name                ubuntu-vg
  LV UUID                2KBkqE-fdaV-rAkI-x1aR-JOIT-X3eZ-DH00pL
  LV Write Access        read/write
  LV Creation host, time ubuntu-server, 2025-02-26 07:34:44 +0000
  LV Status              available
  # open                 1
  LV Size                100.00 GiB
  Current LE             25600
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:0

扩展逻辑卷

root@DeepSeek:~# 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 <473.89 GiB (121315 extents).
  Logical volume ubuntu-vg/ubuntu-lv successfully resized.

扩展文件系统

先检查文件系统

root@DeepSeek:~# df -T
Filesystem                        Type     1K-blocks     Used Available Use% Mounted on
tmpfs                             tmpfs       790120     1112    789008   1% /run
efivarfs                          efivarfs       150       72        74  50% /sys/firmware/efi/efivars
/dev/mapper/ubuntu--vg-ubuntu--lv ext4     102626232 45178732  52188236  47% /
tmpfs                             tmpfs      3950600       16   3950584   1% /dev/shm
tmpfs                             tmpfs         5120        0      5120   0% /run/lock
/dev/nvme0n1p2                    ext4       1992552    98732   1772580   6% /boot
/dev/nvme0n1p1                    vfat       1098632     6288   1092344   1% /boot/efi
tmpfs                             tmpfs       790120       12    790108   1% /run/user/1000

从 /dev/mapper/ubuntu–vg-ubuntu–lv ext4 102626232 45178732 52188236 47% /
得知 文件系统为 ext4

扩展文件系统

root@DeepSeek:~# resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
resize2fs 1.47.0 (5-Feb-2023)
Filesystem at /dev/mapper/ubuntu--vg-ubuntu--lv is mounted on /; on-line resizing required
old_desc_blocks = 13, new_desc_blocks = 60
The filesystem on /dev/mapper/ubuntu--vg-ubuntu--lv is now 124226560 (4k) blocks long.

检查挂载情况

root@DeepSeek:~# df -h
Filesystem                         Size  Used Avail Use% Mounted on
tmpfs                              772M  1.1M  771M   1% /run
efivarfs                           150K   72K   74K  50% /sys/firmware/efi/efivars
/dev/mapper/ubuntu--vg-ubuntu--lv  466G   44G  403G  10% /
tmpfs                              3.8G   16K  3.8G   1% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
/dev/nvme0n1p2                     2.0G   97M  1.7G   6% /boot
/dev/nvme0n1p1                     1.1G  6.2M  1.1G   1% /boot/efi
tmpfs                              772M   12K  772M   1% /run/user/1000

可以看到 /dev/mapper/ubuntu–vg-ubuntu–lv 466G 44G 403G 10% /
根目录获得全部剩余空间。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

赵庆明老师

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值