将现有安装转换为 RAID 1

将现有安装转换为 RAID 1

我有一个 Ubuntu 19-04 LVM 安装,我想使用此处的教程将其转换为 RAID 1:

https://www.prado.lt/how-to-set-up-software-raid1-on-a-running-lvm-system-incl-grub2-configuration-ubuntu-18-04

在实际系统上尝试之前,我想看看它在虚拟机上的运行情况。因此,我在 VirtualBox 上创建了一个带有 250GB 虚拟磁盘的 Ubuntu 19-04 LVM 虚拟机。然后我创建了第二个 250GB 虚拟磁盘。

运行后:

sfdisk -d /dev/sda | sfdisk --force /dev/sdb

这是 fdisk -l 的输出:

Disk /dev/sda: 250 GiB, 268435456000 bytes, 524288000 sectors
Disk model: VBOX HARDDISK   
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: 0x3f9af72a

Device     Boot Start       End   Sectors  Size Id Type
/dev/sda1  *     2048 524285951 524283904  250G 8e Linux LVM


Disk /dev/sdb: 250 GiB, 268435456000 bytes, 524288000 sectors
Disk model: VBOX HARDDISK   
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: 0x3f9af72a

两个驱动器的字节数和扇区数完全相同。

当我读到这一点时:

mdadm --create /dev/md0 --level=1 --raid-disks=2 missing /dev/sdb1

终端输出为:

mdadm: Note: this array has metadata at the start and
may not be suitable as a boot device.  If you plan to
store '/boot' on this device please ensure that
your boot-loader understands md/v1.x metadata, or use
--metadata=0.90
Continue creating array? 

我注意到教程中没有提到这一点。有人能解释一下我为什么收到此消息以及它意味着什么吗?

[编辑:根据这篇文章,这没什么可担心的:https://www.howtoforge.com/how-to-set-up-software-raid1-on-a-running-lvm-system-incl-grub2-configuration-debian-squeeze-p2]

无论如何,我答应了,并继续下去。

当我读到这一点时:

pvmove -i 2 /dev/sda1 /dev/md0

终端输出为:

root@Ubuntu19:/home/mike# pvmove -i 2 /dev/sda1 /dev/md0
Insufficient free space: 63991 extents needed, but only 63967 available
Unable to allocate mirror extents for ubuntu-vg/pvmove0.
Failed to convert pvmove LV to mirrored.

这两个驱动器的大小完全相同,所以我不明白为什么没有足够的空间。

这个问题的解决方案是什么?我应该减小逻辑卷的大小吗?减小物理卷的大小?还是其他什么?

编辑:

我想尝试减小 LVM 的大小,因此我启动了 Live CD。输出如下:

root@ubuntu:/home/ubuntu# lvdisplay
WARNING: Device for PV FvC0uz-efgT-zqqB-NK3f-2yTZ-QWlO-vXuneh not found 
rejected by a filter.
--- Logical volume ---
LV Path                /dev/ubuntu-vg/root
LV Name                root
VG Name                ubuntu-vg
LV UUID                RJi0Hn-fuk3-kEEe-xVeG-FqeJ-OUXR-iTpW8Y
LV Write Access        read/write
LV Creation host, time ubuntu, 2019-04-15 08:25:48 +0000
LV Status              NOT available
LV Size                249.01 GiB
Current LE             63747
Segments               1
Allocation             inherit
Read ahead sectors     auto

--- Logical volume ---
LV Path                /dev/ubuntu-vg/swap_1
LV Name                swap_1
VG Name                ubuntu-vg
LV UUID                JX3Scc-fGIM-e8Z1-zwY3-1ACM-U70M-m8OshG
LV Write Access        read/write
LV Creation host, time ubuntu, 2019-04-15 08:25:48 +0000
LV Status              NOT available
LV Size                976.00 MiB
Current LE             244
Segments               1
Allocation             inherit
Read ahead sectors     auto

当我尝试

root@ubuntu:/home/ubuntu# resize2fs /dev/ubuntu-vg/root 248GB

我有:

resize2fs 1.44.6 (5-Mar-2019)
open: No such file or directory while opening /dev/ubuntu-vg/root

答案1

好的,我明白了。

我跑完之后:

sfdisk -d /dev/sda | sfdisk --force /dev/sdb  

在使用 fdisk 更改分区类型之前,我启动了实时 CD 并执行了以下操作:

ubuntu@ubuntu:~$ sudo su
root@ubuntu:/home/ubuntu# lvdisplay
--- Logical volume ---
LV Path                /dev/ubuntu-vg/root
LV Name                root
VG Name                ubuntu-vg
LV UUID                RJi0Hn-fuk3-kEEe-xVeG-FqeJ-OUXR-iTpW8Y
LV Write Access        read/write
LV Creation host, time ubuntu, 2019-04-15 08:25:48 +0000
LV Status              available
# open                 0
LV Size                249.01 GiB
Current LE             63747
Segments               1
Allocation             inherit
Read ahead sectors     auto
- currently set to     256
Block device           253:0

--- Logical volume ---
LV Path                /dev/ubuntu-vg/swap_1
LV Name                swap_1
VG Name                ubuntu-vg
LV UUID                JX3Scc-fGIM-e8Z1-zwY3-1ACM-U70M-m8OshG
LV Write Access        read/write
LV Creation host, time ubuntu, 2019-04-15 08:25:48 +0000
LV Status              available
# open                 0
LV Size                976.00 MiB
Current LE             244
Segments               1
Allocation             inherit
Read ahead sectors     auto
- currently set to     256
Block device           253:1

root@ubuntu:/home/ubuntu# e2fsck -f /dev/ubuntu-vg/root
e2fsck 1.44.6 (5-Mar-2019)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/ubuntu-vg/root: 201304/16326656 files (0.1% non-contiguous), 
2764077/65276928 blocks

root@ubuntu:/home/ubuntu# resize2fs /dev/ubuntu-vg/root 247G
resize2fs 1.44.6 (5-Mar-2019)
Resizing the filesystem on /dev/ubuntu-vg/root to 65011712 (4k) 
blocks.
The filesystem on /dev/ubuntu-vg/root is now 65011712 (4k) blocks 
long.

root@ubuntu:/home/ubuntu# lvreduce -L 248G /dev/ubuntu-vg/root
WARNING: Reducing active logical volume to <248.82 GiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce ubuntu-vg/root? [y/n]: y
Size of logical volume ubuntu-vg/root changed from 249.01 GiB (63747
extents) to <248.82 GiB (63697 extents).
Logical volume ubuntu-vg/root successfully resized.
root@ubuntu:/home/ubuntu# 

重新启动我的虚拟机,之后一切就顺利了。

相关内容