【新分区】
查看硬盘分区大小及挂载情况
fdisk -l && lsblk
对新硬盘进行分区
fdisk /dev/sdb2
创建新分区
n
直接按Enter,按默认分区就可以
分区完成,写入分区
w
格式化分区
mkfs -t ext4 /dev/sdb2
创建挂载点并挂载
mkdir -p /data_disk && mount -t ext4 /dev/sdb2 /data_disk && df -h
更新fstab
vim /etc/fstab /dev/sdb2 /data_disk ext4 defaults 0 0
【分区扩容】
如果分区仍有空余容量,需要扩展已有卷的容量,查看lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS fd0 2:0 1 4K 0 disk loop0 7:0 0 63.3M 1 loop /snap/core20/1822 loop1 7:1 0 111.9M 1 loop /snap/lxd/24322 loop2 7:2 0 49.8M 1 loop /snap/snapd/18357 sr0 11:0 1 1.8G 0 rom vda 252:0 0 100G 0 disk ├─vda1 252:1 0 1G 0 part /boot/efi ├─vda2 252:2 0 2G 0 part /boot └─vda3 252:3 0 96.9G 0 part └─ubuntu--vg-ubuntu--lv 253:0 0 48.5G 0 lvm /
查看扩容前的硬盘信息(ubuntu--vg-ubuntu--lv只有48G,其中ubuntu--vg为卷组名、vg-ubuntu--lv为逻辑卷名)
df -h
Filesystem Size Used Avail Use% Mounted on tmpfs 197M 1.1M 196M 1% /run /dev/mapper/ubuntu--vg-ubuntu--lv 48G 5.1G 40G 12% / tmpfs 981M 0 981M 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock /dev/vda2 2.0G 126M 1.7G 7% /boot /dev/vda1 1.1G 6.1M 1.1G 1% /boot/efi tmpfs 197M 4.0K 197M 1% /run/user/1000 tmpfs 197M 4.0K 197M 1% /run/user/0
查看卷组信息,Free PE即:未被使用的物理扩展(Physical Extents, PE)的数量,Size即:该扩展对应的容量大小;
目前Free PE显示12409则代表剩余可扩展的数量
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 <96.95 GiB PE Size 4.00 MiB Total PE 24818 Alloc PE / Size 12409 / 48.47 GiB Free PE / Size 12409 / 48.47 GiB VG UUID 0XH1EX-SgUO-PcfZ-rK1f-qPTl-qWVC-QVnUbV
扩展逻辑卷ubuntu-lv容量+12409
lvextend -l +12409 /dev/ubuntu-vg/ubuntu-lv
Size of logical volume ubuntu-vg/ubuntu-lv changed from 48.47 GiB (12409 extents) to <96.95 GiB (24818 extents). Logical volume ubuntu-vg/ubuntu-lv successfully resized.
查看逻辑卷信息
lvdisplay
--- Logical volume --- LV Path /dev/ubuntu-vg/ubuntu-lv LV Name ubuntu-lv VG Name ubuntu-vg LV UUID MAhKCo-72Pb-iioJ-cRe0-aigh-8Xs0-pf2VNR LV Write Access read/write LV Creation host, time ubuntu-server, 2024-11-03 00:23:20 +0800 LV Status available # open 1 LV Size <96.95 GiB Current LE 24818 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0
扩展文件系统
resize2fs /dev/ubuntu-vg/ubuntu-lv
resize2fs 1.46.5 (30-Dec-2021) Filesystem at /dev/ubuntu-vg/ubuntu-lv is mounted on /; on-line resizing required old_desc_blocks = 7, new_desc_blocks = 13 The filesystem on /dev/ubuntu-vg/ubuntu-lv is now 25413632 (4k) blocks long.
查看扩容后的硬盘信息(ubuntu--vg-ubuntu--lv已有96G)
df -h
Filesystem Size Used Avail Use% Mounted on tmpfs 197M 1.1M 196M 1% /run /dev/mapper/ubuntu--vg-ubuntu--lv 96G 5.1G 86G 6% / tmpfs 981M 0 981M 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock /dev/vda2 2.0G 126M 1.7G 7% /boot /dev/vda1 1.1G 6.1M 1.1G 1% /boot/efi tmpfs 197M 4.0K 197M 1% /run/user/1000 tmpfs 197M 4.0K 197M 1% /run/user/0
查看/etc/fstab
cat /etc/fstab
# /etc/fstab: static file system information. # # Use 'blkid' to print the universally unique identifier for a # device; this may be used with UUID= as a more robust way to name devices # that works even if disks are added and removed. See fstab(5). # # <file system> <mount point> <type> <options> <dump> <pass> # / was on /dev/ubuntu-vg/ubuntu-lv during curtin installation /dev/disk/by-id/dm-uuid-LVM-0XH1EXSgUOPcfZrK1fqPTlqWVCQVnUbVMAhKCo72PbiioJcRe0aigh8Xs0pf2VNR / ext4 defaults 0 1 # /boot was on /dev/vda2 during curtin installation /dev/disk/by-uuid/6519c946-733a-40a3-80a4-ba34535bf37b /boot ext4 defaults 0 1 # /boot/efi was on /dev/vda1 during curtin installation /dev/disk/by-uuid/1F30-BA35 /boot/efi vfat defaults 0 1 /swap.img none swap sw 0 0
其中扩容的逻辑卷挂载信息0XH1EXSgUOPcfZrK1fqPTlqWVCQVnUbVMAhKCo72PbiioJcRe0aigh8Xs0pf2VNR
/dev/disk/by-id/dm-uuid-LVM-0XH1EXSgUOPcfZrK1fqPTlqWVCQVnUbVMAhKCo72PbiioJcRe0aigh8Xs0pf2VNR / ext4 defaults 0 1
即:
# 卷组 UUID vgs --noheadings --options vg_uuid ubuntu-vg | sed 's/-//g'
0XH1EXSgUOPcfZrK1fqPTlqWVCQVnUbV
# 逻辑卷 UUID lvs --noheadings --options lv_uuid ubuntu-vg/ubuntu-lv | sed 's/-//g'
MAhKCo72PbiioJcRe0aigh8Xs0pf2VNR
最新回复 (0)