Skip to content

Latest commit

 

History

History
52 lines (40 loc) · 1.08 KB

vhd_transfer.md

File metadata and controls

52 lines (40 loc) · 1.08 KB

Encrypted transfer of disk using socat and dd

I've used this method to migrate vps but there are many other usecases.

1. Server (source):

openssl req -newkey rsa:2048 -nodes -keyout encrypted.key -x509 -days 10 -subj '/CN=example.com/O=acme/C=US' -out encrypted.crt
cat encrypted.key encrypted.crt > encrypted.pem
# change sdb to your device!
sudo dd if=/dev/sdb bs=2M | socat STDIO OPENSSL-LISTEN:9876,cert=encrypted.pem,verify=0,reuseaddr

2. Client (destination):

# change ip to your server
socat -u OPENSSL:IP.IP.IP.IP:9876,verify=0 OPEN:sda.img,creat

3. Restore

sudo dd if=/tmp/sdb.img of=/dev/sda bs=2M status=progress

4. Fix grub - credits: OVH Support

mount /dev/sdb1 /mnt
mount -o bind /proc /mnt/proc
mount -o bind /sys /mnt/sys
mount -o bind /dev /mnt/dev
chroot /mnt /bin/bash
# grub
grub-install /dev/sdb
update-grub
# grub2  
grub2-install /dev/sdb
grub2-mkconfig -o /boot/grub2/grub.cfg