本文主要是介绍Ubuntu增加一块硬盘添加到卷组并扩展逻辑卷,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
在虚拟机里给Ubuntu增加一块硬盘,跟物理机的操作一样,只是硬盘的盘符为vda和vdb罢了。
首先看下新增加的硬盘,识别出来了:
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
loop0 7:0 0 63.9M 1 loop /snap/core20/2318
loop1 7:1 0 63.4M 1 loop /snap/core20/1974
loop2 7:2 0 111.9M 1 loop /snap/lxd/24322
loop3 7:3 0 87M 1 loop /snap/lxd/29351
loop4 7:4 0 53.3M 1 loop /snap/snapd/19457
loop5 7:5 0 38.8M 1 loop /snap/snapd/21759
sr0 11:0 1 2.7M 0 rom
vda 252:0 0 20G 0 disk
├─vda1 252:1 0 953M 0 part /boot/efi
├─vda2 252:2 0 1.8G 0 part /boot
└─vda3 252:3 0 17.3G 0 part
└─ubuntu--vg-ubuntu--lv 253:0 0 17.3G 0 lvm /
vdb 252:16 0 10G 0 disk
尝试加载
sudo vgextend ubuntu-vg /dev/vdb
说没有vgextend这个命令
也许vdb还需要格式化一下。
分区:
fdisk /dev/vdb
后面有点乱,就又重新做了一遍。
再来操作一遍
先看看硬盘信息
sudo fdisk -l
Disk /dev/loop5: 38.83 MiB, 40714240 bytes, 79520 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/vda: 20 GiB, 21474967552 bytes, 41943296 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 151A0432-2D62-4909-9CA7-73BF5B861A92
Device Start End Sectors Size Type
/dev/vda1 2048 1953791 1951744 953M EFI System
/dev/vda2 1953792 5623807 3670016 1.8G Linux filesystem
/dev/vda3 5623808 41940991 36317184 17.3G Linux filesystem
Disk /dev/vdb: 10 GiB, 10737549312 bytes, 20971776 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 0D4478B6-ED80-7743-B8EA-E9DC3B8A51C7
Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 17.32 GiB, 18593349632 bytes, 36315136 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
新加入的是/dev/vdb
对vdb进行分区
sudo fdisk /dev/vdbWelcome to fdisk (util-linux 2.37.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.Command (m for help): n
Partition number (1-128, default 1):
First sector (2048-20971742, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-20971742, default 20971742): Created a new partition 1 of type 'Linux filesystem' and of size 10 GiB.Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
再次查看分区
sudo fdisk -l
Disk /dev/vdb: 10 GiB, 10737549312 bytes, 20971776 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 0D4478B6-ED80-7743-B8EA-E9DC3B8A51C7Device Start End Sectors Size Type
/dev/vdb1 2048 20971742 20969695 10G Linux filesystem
新建物理卷
sudo pvcreate /dev/vdb1Physical volume "/dev/vdb1" successfully created.
查看卷
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
loop5 7:5 0 38.8M 1 loop /snap/snapd/21759
sr0 11:0 1 2.7M 0 rom
vda 252:0 0 20G 0 disk
├─vda1 252:1 0 953M 0 part /boot/efi
├─vda2 252:2 0 1.8G 0 part /boot
└─vda3 252:3 0 17.3G 0 part └─ubuntu--vg-ubuntu--lv 253:0 0 17.3G 0 lvm /
vdb 252:16 0 10G 0 disk
└─vdb1 252:17 0 10G 0 part
然后,首先看看我们的卷名:
sudo vgs
VG #PV #LV #SN Attr VSize VFree
ubuntu-vg 2 1 0 wz--n- 27.31g <10.00g
也就是vg名为ubuntu-vg(这里是添加之后,因为添加之前忘记保存vgs的输出了,所以里面有10G空余空间)
把/dev/vdb1添加到ubuntu-vg
使用下面命令把/dev/vdb1添加到ubuntu-vg :
sudo vgextend ubuntu-vg /dev/vdb1
如果重复添加,会报错:
sudo vgextend ubuntu-vg /dev/vdb1
Physical volume '/dev/vdb1' is already in volume group 'ubuntu-vg'
Unable to add physical volume '/dev/vdb1' to volume group 'ubuntu-vg'
/dev/vdb1: physical volume not initialized.
添加之后,查看
sudo vgs
VG #PV #LV #SN Attr VSize VFree
ubuntu-vg 2 1 0 wz--n- 27.31g <10.00g
可以看到有10G的空间未分配
使用lvextend扩充逻辑卷
把所有未分配空间分配上:
sudo lvextend -r -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
查看分配结果,可以看到空间大了10G:
skywalk@ub12:~$ sudo vgs
VG #PV #LV #SN Attr VSize VFree
ubuntu-vg 2 1 0 wz--n- 27.31g 0
skywalk@ub12:~$ df -h
Filesystem Size Used Avail Use% Mounted on
tmpfs 392M 1.1M 390M 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv 27G 16G 11G 61% /
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
/dev/vda2 1.7G 149M 1.5G 10% /boot
/dev/vda1 952M 6.1M 946M 1% /boot/efi
tmpfs 392M 4.0K 391M 1% /run/user/1001
tmpfs 392M 4.0K 391M 1% /run/user/1000
总结
添加一块硬盘,需要三步:
1 新硬盘分区
2 新硬盘创建物理卷并扩展到vs里
3 扩展逻辑卷的可用空间
这篇关于Ubuntu增加一块硬盘添加到卷组并扩展逻辑卷的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!