Linux单磁盘扩容
Ubuntu 18.04
物理卷操作命令:pvcreate,pvscan,pvdisplay.
卷组操作命令:vgcreate,vgdisplay.
逻辑卷操作命令:lvcreate,lvdisplay.
查看文件挂载情况
df -h
Filesystem Size Used Avail Use% Mounted on
udev 7.9G 0 7.9G 0% /dev
tmpfs 1.6G 4.3M 1.6G 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv 98G 27G 67G 29% /
tmpfs 7.9G 0 7.9G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 7.9G 0 7.9G 0% /sys/fs/cgroup
/dev/sda2 976M 219M 690M 25% /boot
tmpfs 1.6G 0 1.6G 0% /run/user/1000
查看块存储
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 1M 0 part
├─sda2 8:2 0 1G 0 part /boot
└─sda3 8:3 0 199G 0 part
└─ubuntu--vg-ubuntu--lv 253:0 0 99.5G 0 lvm /
sr0 11:0 1 945M 0 rom
显示逻辑卷
sudo lvdisplay
--- Logical volume ---
LV Path /dev/ubuntu-vg/ubuntu-lv
LV Name ubuntu-lv
VG Name ubuntu-vg
LV UUID prkI6m-Fjwq-sRpL-Hi5r-hEjL-D0R7-MjdwsR
LV Write Access read/write
LV Creation host, time ubuntu-server, 2020-12-15 16:56:13 +0800
LV Status available
# open 1
LV Size 99.50 GiB
Current LE 25472
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
显示卷组
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 <199.00 GiB
PE Size 4.00 MiB
Total PE 50943
Alloc PE / Size 25472 / 99.50 GiB
Free PE / Size 25471 / <99.50 GiB
VG UUID 2O2PDL-3f4O-RnDU-M1gn-gPgR-D3nI-QglF5V
第一个就是我的 /dev/mapper/ubuntu–vg-ubuntu–lv 这个磁盘
第二个是 这个磁盘可以扩容的大小 也就是剩余可以扩容多少
显示物理卷
sudo pvdisplay
--- Physical volume ---
PV Name /dev/sda3
VG Name ubuntu-vg
PV Size <199.00 GiB / not usable 0
Allocatable yes
PE Size 4.00 MiB
Total PE 50943
Free PE 25471
Allocated PE 25472
PV UUID IKrdJU-oXZ3-Y3L1-jqPT-7oaK-1wMt-E7lmLy
-------显示磁盘信息
sudo fdisk -l
Disk /dev/sda: 200 GiB, 214748364800 bytes, 419430400 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
Disklabel type: gpt
Disk identifier: 9C8BD67A-5C02-4206-BE43-94DFFE591660
Device Start End Sectors Size Type
/dev/sda1 2048 4095 2048 1M BIOS boot
/dev/sda2 4096 2101247 2097152 1G Linux filesystem
/dev/sda3 2101248 419428351 417327104 199G Linux filesystem
Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 99.5 GiB, 106837311488 bytes, 208666624 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
--------
ll /dev/mapper/ubuntu--vg-ubuntu--lv
lrwxrwxrwx 1 root root 7 Jun 22 14:02 /dev/mapper/ubuntu--vg-ubuntu--lv -> ../dm-0
lapis@master03:/$ ll /dev/ubuntu-vg/ubuntu-lv
lrwxrwxrwx 1 root root 7 Jun 22 14:02 /dev/ubuntu-vg/ubuntu-lv -> ../dm-0
--------
物理卷/dev/sda3 有199G
卷组ubuntu-vg 有199G
逻辑卷ubuntu-lv 99G
所以要给逻辑卷扩容
sudo lvextend /dev/ubuntu-vg/ubuntu-lv
sudo lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
扩容命令
sudo lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
Size of logical volume ubuntu-vg/ubuntu-lv changed from 99.50 GiB (25472 extents) to <199.00 GiB (50943 extents).
Logical volume ubuntu-vg/ubuntu-lv successfully resized.
---
sudo fdisk -l
Disk /dev/sda: 200 GiB, 214748364800 bytes, 419430400 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
Disklabel type: gpt
Disk identifier: 9C8BD67A-5C02-4206-BE43-94DFFE591660
Device Start End Sectors Size Type
/dev/sda1 2048 4095 2048 1M BIOS boot
/dev/sda2 4096 2101247 2097152 1G Linux filesystem
/dev/sda3 2101248 419428351 417327104 199G Linux filesystem
这里变大了
Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 199 GiB, 213670428672 bytes, 417325056 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
--- Volume group ---
VG Name ubuntu-vg
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
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 <199.00 GiB
PE Size 4.00 MiB
Total PE 50943
Alloc PE / Size 50943 / <199.00 GiB
Free PE / Size 0 / 0
VG UUID 2O2PDL-3f4O-RnDU-M1gn-gPgR-D3nI-QglF5V
这里为0了
sudo pvdisplay
--- Physical volume ---
PV Name /dev/sda3
VG Name ubuntu-vg
PV Size <199.00 GiB / not usable 0
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 50943
Free PE 0
Allocated PE 50943
PV UUID IKrdJU-oXZ3-Y3L1-jqPT-7oaK-1wMt-E7lmLy
这里为0了
sudo lvdisplay
--- Logical volume ---
LV Path /dev/ubuntu-vg/ubuntu-lv
LV Name ubuntu-lv
VG Name ubuntu-vg
LV UUID prkI6m-Fjwq-sRpL-Hi5r-hEjL-D0R7-MjdwsR
LV Write Access read/write
LV Creation host, time ubuntu-server, 2020-12-15 16:56:13 +0800
LV Status available
# open 1
LV Size <199.00 GiB
Current LE 50943
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
这里变为<199了
df -h
Filesystem Size Used Avail Use% Mounted on
udev 7.9G 0 7.9G 0% /dev
tmpfs 1.6G 4.3M 1.6G 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv 98G 27G 67G 29% /
tmpfs 7.9G 0 7.9G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 7.9G 0 7.9G 0% /sys/fs/cgroup
/dev/sda2 976M 219M 690M 25% /boot
tmpfs 1.6G 0 1.6G 0% /run/user/1000
这里没有变
重新计算磁盘大小
sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
resize2fs 1.44.1 (24-Mar-2018)
Filesystem at /dev/mapper/ubuntu--vg-ubuntu--lv is mounted on /; on-line resizing required
old_desc_blocks = 13, new_desc_blocks = 25
The filesystem on /dev/mapper/ubuntu--vg-ubuntu--lv is now 52165632 (4k) blocks long.
df -h
Filesystem Size Used Avail Use% Mounted on
udev 7.9G 0 7.9G 0% /dev
tmpfs 1.6G 4.3M 1.6G 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv 196G 27G 161G 14% /
tmpfs 7.9G 0 7.9G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 7.9G 0 7.9G 0% /sys/fs/cgroup
/dev/sda2 976M 219M 690M 25% /boot
tmpfs 1.6G 0 1.6G 0% /run/user/1000
现在变大了
Linux单磁盘扩容
最新推荐文章于 2023-09-07 14:51:21 发布