D
D
Denis Nubarsky2022-03-31 15:04:50
linux
Denis Nubarsky, 2022-03-31 15:04:50

How to migrate a running Debian 11 OS to RAID1 with existing LVM partitioning?

Good afternoon!

We rented a server at a remote site with 4 HDDs. Of the possible installation options, only RAID0, RAID1, RAID10 and LVM were offered.
We decided that the following scheme for distributing the HDD volume would be the most suitable:
SWAP - RAID1 - 5Gb
/ - RAID1 - 24Gb
/home - RAID5 - all the remaining space

According to the instructions from the "internets" ( Habr ), it was possible to understand that everything is realizable.

During installation, the LVM installation mode was selected.
We got the following partition scheme:

~# lsblk /dev/sda
NAME           MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda              8:0    0 931.5G  0 disk
├─sda1           8:1    0     1M  0 part
├─sda2           8:2    0   977M  0 part /boot
└─sda3           8:3    0 930.6G  0 part
  ├─vg0-swap_1 254:0    0   4.8G  0 lvm  [SWAP]
  ├─vg0-root   254:1    0  22.9G  0 lvm  /
  └─vg0-home   254:2    0 902.9G  0 lvm  /home
~# fdisk -l /dev/sda
Disk /dev/sda: 931.51 GiB, 1000204886016 bytes, 1953525168 sectors
Disk model: ST1000DM003-1ER1
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: 8B063280-E7F8-4E70-964A-C5C44435B799

Device       Start        End    Sectors   Size Type
/dev/sda1     2048       4095       2048     1M BIOS boot
/dev/sda2     4096    2004991    2000896   977M Linux filesystem
/dev/sda3  2004992 1953523711 1951518720 930.6G Linux LVM


All other drives (/dev/sdb /dev/sdc /dev/sdc) are unpartitioned.

When copying partitions (using the sfdisk -d /dev/sda | sfdisk -f /dev/sdb command), I received the following response:
~# sfdisk -d /dev/sda | sfdisk -f /dev/sdb
Checking that no-one is using this disk right now ... OK

Disk /dev/sdb: 931.51 GiB, 1000204886016 bytes, 1953525168 sectors
Disk model: ST1000DM003-1ER1
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

>>> Script header accepted.
>>> Script header accepted.
>>> Script header accepted.
>>> Script header accepted.
>>> Script header accepted.
>>> Script header accepted.
>>> Script header accepted.
>>> Created a new GPT disklabel (GUID: 8B063280-E7F8-4E70-964A-C5C44435B799).
/dev/sdb1: Created a new partition 1 of type 'BIOS boot' and of size 1 MiB.
/dev/sdb2: Created a new partition 2 of type 'Linux filesystem' and of size 977 MiB.
/dev/sdb3: Created a new partition 3 of type 'Linux LVM' and of size 930.6 GiB.
Partition #3 contains a LVM2_member signature.
/dev/sdb4: Done.

New situation:
Disklabel type: gpt
Disk identifier: 8B063280-E7F8-4E70-964A-C5C44435B799

Device       Start        End    Sectors   Size Type
/dev/sdb1     2048       4095       2048     1M BIOS boot
/dev/sdb2     4096    2004991    2000896   977M Linux filesystem
/dev/sdb3  2004992 1953523711 1951518720 930.6G Linux LVM

The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

The same when copying to /dev/sdc and /dev/sdd. But still the disks are marked:
~# fdisk -l
Disk /dev/sdd: 931.51 GiB, 1000204886016 bytes, 1953525168 sectors
Disk model: ST1000DM003-1ER1
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: 8B063280-E7F8-4E70-964A-C5C44435B799

Device       Start        End    Sectors   Size Type
/dev/sdd1     2048       4095       2048     1M BIOS boot
/dev/sdd2     4096    2004991    2000896   977M Linux filesystem
/dev/sdd3  2004992 1953523711 1951518720 930.6G Linux LVM


Disk /dev/sdc: 931.51 GiB, 1000204886016 bytes, 1953525168 sectors
Disk model: ST1000DM003-1ER1
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: 8B063280-E7F8-4E70-964A-C5C44435B799

Device       Start        End    Sectors   Size Type
/dev/sdc1     2048       4095       2048     1M BIOS boot
/dev/sdc2     4096    2004991    2000896   977M Linux filesystem
/dev/sdc3  2004992 1953523711 1951518720 930.6G Linux LVM


Disk /dev/sda: 931.51 GiB, 1000204886016 bytes, 1953525168 sectors
Disk model: ST1000DM003-1ER1
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: 8B063280-E7F8-4E70-964A-C5C44435B799

Device       Start        End    Sectors   Size Type
/dev/sda1     2048       4095       2048     1M BIOS boot
/dev/sda2     4096    2004991    2000896   977M Linux filesystem
/dev/sda3  2004992 1953523711 1951518720 930.6G Linux LVM


Disk /dev/sdb: 931.51 GiB, 1000204886016 bytes, 1953525168 sectors
Disk model: ST1000DM003-1ER1
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: 8B063280-E7F8-4E70-964A-C5C44435B799

Device       Start        End    Sectors   Size Type
/dev/sdb1     2048       4095       2048     1M BIOS boot
/dev/sdb2     4096    2004991    2000896   977M Linux filesystem
/dev/sdb3  2004992 1953523711 1951518720 930.6G Linux LVM


Disk /dev/mapper/vg0-swap_1: 4.77 GiB, 5117050880 bytes, 9994240 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


Disk /dev/mapper/vg0-root: 22.89 GiB, 24574427136 bytes, 47996928 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


Disk /dev/mapper/vg0-home: 902.9 GiB, 969484009472 bytes, 1893523456 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
~# lsblk
NAME           MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda              8:0    0 931.5G  0 disk
├─sda1           8:1    0     1M  0 part
├─sda2           8:2    0   977M  0 part /boot
└─sda3           8:3    0 930.6G  0 part
  ├─vg0-swap_1 254:0    0   4.8G  0 lvm  [SWAP]
  ├─vg0-root   254:1    0  22.9G  0 lvm  /
  └─vg0-home   254:2    0 902.9G  0 lvm  /home
sdb              8:16   0 931.5G  0 disk
├─sdb1           8:17   0     1M  0 part
├─sdb2           8:18   0   977M  0 part
└─sdb3           8:19   0 930.6G  0 part
sdc              8:32   0 931.5G  0 disk
├─sdc1           8:33   0     1M  0 part
├─sdc2           8:34   0   977M  0 part
└─sdc3           8:35   0 930.6G  0 part
sdd              8:48   0 931.5G  0 disk
├─sdd1           8:49   0     1M  0 part
├─sdd2           8:50   0   977M  0 part
└─sdd3           8:51   0 930.6G  0 part


There were questions:
- How to copy the LVM partition /dev/sda3 to /dev/sdb3, /dev/sdc3 and /dev/sdd3? And is it necessary to do so?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Melkij, 2022-03-31
@Deni_Noob

We decided that the following HDD volume distribution scheme would be the most suitable:
SWAP - RAID1 - 5Gb
/ - RAID1 - 24Gb
/home - RAID5 - all remaining space

do not touch sda at all at this stage!
You forgot to mention /boot, I will assume that we consider it as a gigabyte partition without significant changes.
Ignore sda ​​markup completely, make partition tables on sd[bcd] like
1MiB bios_grub
1GiB boot
29GiB sys
everything else data
mdadm -C /dev/md0 -l 1 -n 4 missing /dev/sdb2 /dev/sdc2 /dev/sdd2
mdadm -C /dev/md1 -l 1 -n 4 missing /dev/sdb3 /dev/sdc3 /dev/sdd3
mdadm -C /dev/md2 -l 5 -n 4 missing /dev/sdb4 /dev/sdc4 /dev/ sdd4 # other options to your liking
wait for resync, update mdadm.conf, send the hardware to reboot to check that the arrays are correctly assembled themselves.
pvinit, vgextend new md1 and md2 to existing LVM
pvmove root and swap on md1, hamster on md2
umount /boot , dd if=/dev/sda2 of=/dev/md0, grub-install /dev/sdb , grub-install /dev/sdc , grub-install /dev/ sdd, update fstab instead of sda2 write md0
control
reboot vgreduce sda3 from lvm, delete the sda ​​partition table and create a new one identical to other disks,
mdadm /dev/md0 -a /dev/sda2
mdadm /dev/md1 -a /dev/sda3
mdadm / dev/md2 -a /dev/sda4
after resync you're done. Through lvresize, expand the sizes of volumes and resize2fs as usual.

O
Oleg Volkov, 2022-04-01
@voleg4u

I do Redundant LVM THIS is how .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question