Ubuntu增加一块硬盘添加到卷组并扩展逻辑卷

2024-08-21 09:44

本文主要是介绍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增加一块硬盘添加到卷组并扩展逻辑卷的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1092809

相关文章

Ubuntu中远程连接Mysql数据库的详细图文教程

《Ubuntu中远程连接Mysql数据库的详细图文教程》Ubuntu是一个以桌面应用为主的Linux发行版操作系统,这篇文章主要为大家详细介绍了Ubuntu中远程连接Mysql数据库的详细图文教程,有... 目录1、版本2、检查有没有mysql2.1 查询是否安装了Mysql包2.2 查看Mysql版本2.

新特性抢先看! Ubuntu 25.04 Beta 发布:Linux 6.14 内核

《新特性抢先看!Ubuntu25.04Beta发布:Linux6.14内核》Canonical公司近日发布了Ubuntu25.04Beta版,这一版本被赋予了一个活泼的代号——“Plu... Canonical 昨日(3 月 27 日)放出了 Beta 版 Ubuntu 25.04 系统镜像,代号“Pluc

Java常用注解扩展对比举例详解

《Java常用注解扩展对比举例详解》:本文主要介绍Java常用注解扩展对比的相关资料,提供了丰富的代码示例,并总结了最佳实践建议,帮助开发者更好地理解和应用这些注解,需要的朋友可以参考下... 目录一、@Controller 与 @RestController 对比二、使用 @Data 与 不使用 @Dat

SpringBoot项目使用MDC给日志增加唯一标识的实现步骤

《SpringBoot项目使用MDC给日志增加唯一标识的实现步骤》本文介绍了如何在SpringBoot项目中使用MDC(MappedDiagnosticContext)为日志增加唯一标识,以便于日... 目录【Java】SpringBoot项目使用MDC给日志增加唯一标识,方便日志追踪1.日志效果2.实现步

最新Spring Security实战教程之表单登录定制到处理逻辑的深度改造(最新推荐)

《最新SpringSecurity实战教程之表单登录定制到处理逻辑的深度改造(最新推荐)》本章节介绍了如何通过SpringSecurity实现从配置自定义登录页面、表单登录处理逻辑的配置,并简单模拟... 目录前言改造准备开始登录页改造自定义用户名密码登陆成功失败跳转问题自定义登出前后端分离适配方案结语前言

Spring组件初始化扩展点BeanPostProcessor的作用详解

《Spring组件初始化扩展点BeanPostProcessor的作用详解》本文通过实战案例和常见应用场景详细介绍了BeanPostProcessor的使用,并强调了其在Spring扩展中的重要性,感... 目录一、概述二、BeanPostProcessor的作用三、核心方法解析1、postProcessB

Ubuntu中Nginx虚拟主机设置的项目实践

《Ubuntu中Nginx虚拟主机设置的项目实践》通过配置虚拟主机,可以在同一台服务器上运行多个独立的网站,本文主要介绍了Ubuntu中Nginx虚拟主机设置的项目实践,具有一定的参考价值,感兴趣的可... 目录简介安装 Nginx创建虚拟主机1. 创建网站目录2. 创建默认索引文件3. 配置 Nginx4

Java逻辑运算符之&&、|| 与&、 |的区别及应用

《Java逻辑运算符之&&、||与&、|的区别及应用》:本文主要介绍Java逻辑运算符之&&、||与&、|的区别及应用的相关资料,分别是&&、||与&、|,并探讨了它们在不同应用场景中... 目录前言一、基本概念与运算符介绍二、短路与与非短路与:&& 与 & 的区别1. &&:短路与(AND)2. &:非短

Ubuntu 22.04 服务器安装部署(nginx+postgresql)

《Ubuntu22.04服务器安装部署(nginx+postgresql)》Ubuntu22.04LTS是迄今为止最好的Ubuntu版本之一,很多linux的应用服务器都是选择的这个版本... 目录是什么让 Ubuntu 22.04 LTS 变得安全?更新了安全包linux 内核改进一、部署环境二、安装系统

linux下多个硬盘划分到同一挂载点问题

《linux下多个硬盘划分到同一挂载点问题》在Linux系统中,将多个硬盘划分到同一挂载点需要通过逻辑卷管理(LVM)来实现,首先,需要将物理存储设备(如硬盘分区)创建为物理卷,然后,将这些物理卷组成... 目录linux下多个硬盘划分到同一挂载点需要明确的几个概念硬盘插上默认的是非lvm总结Linux下多