Moving to a new harddrive - with lvm - luks encryption

In this post, I will describe how to move to a new harddrive, either server or desktop (linux).
This topic is outside the "hosting" topic, but may be useful for you.

I have one old drive, (/dev/sda), Luks encrypted.
one new drive, bigger (/dev/sdb)

New drive has no partitions (or may have also...)

This command copies all of old drive onto new one, with a kind of progress indicator..
pv -n /dev/sda | dd of=/dev/sdb bs=128M conv=notrunc,noerror

this takes long time, depending on your old drive size.

Then, I shut down the system, connect new drive, boot it normally,
everything works normal, except we cannot use all capacity of new drive.

To fix this situation, we need following:

Situation before resize

# pvdisplay
--- Physical volume ---
PV Name /dev/mapper/sda5_crypt
VG Name myvg
PV Size 111,31 GiB / not usable 2,00 MiB
Allocatable yes
PE Size 4,00 MiB
Total PE 28495
Free PE 5
Allocated PE 28490
PV UUID d9a10a71-ada0-49ba-a5ad-2b6f297d6b5e

# pvresize /dev/mapper/sda5_crypt
Physical volume "/dev/mapper/sda5_crypt" changed
1 physical volume(s) resized / 0 physical volume(s) not resized

Situation after resize:

# pvdisplay
--- Physical volume ---
PV Name /dev/mapper/sda5_crypt
VG Name myvg
PV Size 476,46 GiB / not usable 2,00 MiB
Allocatable yes
PE Size 4,00 MiB
Total PE 121973
Free PE 93483
Allocated PE 28490
PV UUID d9a10a71-ada0-49ba-a5ad-2b6f297d6b5e

Logical volumes not extended yet;
Logical volumes now:

# lvdisplay
--- Logical volume ---
LV Path /dev/myvg/root
LV Name root
VG Name myvg
LV UUID 5d3091f4-3f4d-46d5-89d6-e47acafa8bf2
LV Write Access read/write
LV Creation host, time linux, 2017-06-04 14:03:30 +0200
LV Status available
# open 1
LV Size 103,49 GiB
Current LE 26493
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1

--- Logical volume ---
LV Path /dev/myvg/swap_1
LV Name swap_1
VG Name myvg
LV UUID 6db7e391-ef77-4a18-915b-4583e3fe93c0
LV Write Access read/write
LV Creation host, time linux, 2017-06-04 14:03:30 +0200
LV Status available
# open 2
LV Size 7,80 GiB
Current LE 1997
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2

Then, run system-config-lvm gui program,

click logical volumes, click your root (or any partition), click edit, resize as you wish,
I think we can do this via lvresize also, but I did with system-config-lvm gui

Situation after resize:

# lvdisplay
--- Logical volume ---
LV Path /dev/myvg/root
LV Name root
VG Name myvg
LV UUID 5d3091f4-3f4d-46d5-89d6-e47acafa8bf2
LV Write Access read/write
LV Creation host, time linux, 2017-06-04 14:03:30 +0200
LV Status available
# open 1
LV Size 468,66 GiB
Current LE 119976
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1

--- Logical volume ---
LV Path /dev/myvg/swap_1
LV Name swap_1
VG Name myvg
LV UUID 6db7e391-ef77-4a18-915b-4583e3fe93c0
LV Write Access read/write
LV Creation host, time linux, 2017-06-04 14:03:30 +0200
LV Status available
# open 2
LV Size 7,80 GiB
Current LE 1997
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2

Now, my root partition is bigger.