Hetzner 使用 LVM 合并硬盘空间

Hetzner 使用 LVM 合并硬盘空间

Table of Contents

背景

由于原始硬盘容量无法满足业务需求,遂额外加购硬盘。起初使用的是 RAID0 方案合并硬盘空间,但是由于 RAID0 的特性限制,最终可用容量为最小硬盘容量乘以总硬盘数。如果硬盘大小不同则不可避免有大量的容量浪费。且 RAID0 本身有高风险,如果一枚硬盘物理损坏则全部数据丢失,无法找回。

<!–more–>

开干

前往 Rescue System, 删除 RAID 并格式化盘符

mdadm --remove /dev/md0
mdadm --remove /dev/md1
mdadm --remove /dev/md2

mdadm --stop /dev/md0
mdadm --stop /dev/md1
mdadm --stop /dev/md2

mkfs.ext4 /dev/nvme0n1
mkfs.ext4 /dev/nvme1n1
mkfs.ext4 /dev/nvme2n1

通过 installimage 安装操作系统。在安装配置文件中修改和添加分区信息

...
SWRAID 0 ## 关闭 RAID
...

## 编写分区
PART  /boot  ext3  512M
PART  lvm    vg0   all

LV   vg0   swap   swap  swap  32G
LV   vg0   root   /     ext4  all

进入正常系统后,列出本机中的物理硬盘,记录硬盘名

fdisk -l

Disk /dev/nvme0n1: 1.86 TiB, 2048408248320 bytes, 4000797360 sectors
Disk model: SAMSUNG MZVL22T0HBLB-00B00
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: dos
Disk identifier: 0xacf2949f

Device         Boot   Start        End    Sectors  Size Id Type
/dev/nvme0n1p1         2048    1050623    1048576  512M 83 Linux
/dev/nvme0n1p2      1050624 4000795311 3999744688  1.9T 8e Linux LVM

Disk /dev/nvme1n1: 476.94 GiB, 512110190592 bytes, 1000215216 sectors
Disk model: SAMSUNG MZVLB512HBJQ-00000
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/nvme2n1: 476.94 GiB, 512110190592 bytes, 1000215216 sectors
Disk model: SAMSUNG MZVLB512HBJQ-00000
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/mapper/vg0-swap: 32 GiB, 34359738368 bytes, 67108864 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/mapper/vg0-root: 1.83 TiB, 2013504995328 bytes, 3932626944 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

添加其他物理卷至 LVM

pvcreate /dev/nvme1n1 /dev/nvme2n1

将其他物理卷扩展至卷组 vg0

vgextend vg0 /dev/nvme1n1 /dev/nvme2n1

将剩余空间添加至逻辑卷并整理

lvextend -l +100%FREE /dev/mapper/vg0-root
resize2fs /dev/mapper/vg0-root

查询可用空间

df -hl

Filesystem            Size  Used Avail Use% Mounted on
tmpfs                 6.3G  940K  6.3G   1% /run
/dev/mapper/vg0-root  2.8T  1.9G  2.6T   1% /
tmpfs                  32G     0   32G   0% /dev/shm
tmpfs                 5.0M     0  5.0M   0% /run/lock
/dev/nvme0n1p1        488M   89M  374M  20% /boot
tmpfs                 6.3G     0  6.3G   0% /run/user/0

fdisk -l

Disk /dev/nvme0n1: 1.86 TiB, 2048408248320 bytes, 4000797360 sectors
Disk model: SAMSUNG MZVL22T0HBLB-00B00
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: dos
Disk identifier: 0xacf2949f

Device         Boot   Start        End    Sectors  Size Id Type
/dev/nvme0n1p1         2048    1050623    1048576  512M 83 Linux
/dev/nvme0n1p2      1050624 4000795311 3999744688  1.9T 8e Linux LVM

Disk /dev/nvme1n1: 476.94 GiB, 512110190592 bytes, 1000215216 sectors
Disk model: SAMSUNG MZVLB512HBJQ-00000
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/nvme2n1: 476.94 GiB, 512110190592 bytes, 1000215216 sectors
Disk model: SAMSUNG MZVLB512HBJQ-00000
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/mapper/vg0-swap: 32 GiB, 34359738368 bytes, 67108864 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/mapper/vg0-root: 2.76 TiB, 3037720477696 bytes, 5933047808 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

本文来自《Miaoblog》,经本网转载发布,本文观点不代表《中国IPv6网》立场,转载请联系原作者。

(0)
中国IPv6网的头像中国IPv6网
上一篇 2022年12月12日 上午1:55
下一篇 2022年12月15日 下午6:43

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注