I have a Xubuntu running with a standard Hard Disk, my objective is to move the system to a new SSD without reinstall the system and use my current hard disk as a big free space inside a sub-directory in my home dir.
The problem is: my system uses EFI boot and my disk is LVM with LUKS enabled to make a full disk encryption.
The system is a Xubuntu v??? with Kernel 4.15.0-72 installed with the following partition structure:
Disk /dev/sda: 931,5 GiB, 1000204886016 bytes, 1953525168 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
Disklabel type: gpt
Disk identifier: 982A9167-F6FF-4041-B714-38B121868118
Device Start End Sectors Size Type
/dev/sda1 2048 452607 450560 220M EFI System
/dev/sda2 452608 1550335 1097728 536M Linux filesystem
/dev/sda3 1550336 1953523711 1951973376 930,8G Linux LVM
Worth note that /dev/sdb3 is further “partitioned” as:
--- Logical volume ---
LV Path /dev/vg0/root
LV Name root
VG Name vg0
LV UUID Wn8E00-FVSm-0pdE-Jn2x-6T5Z-8cxm-uYntvq
LV Write Access read/write
LV Creation host, time xubuntu, 2017-11-14 10:34:40 -0200
LV Status available
# open 1
LV Size 100,00 GiB
Current LE 25600
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
--- Logical volume ---
LV Path /dev/vg0/swap
LV Name swap
VG Name vg0
LV UUID sFUUlG-IGDB-0Ld0-UVMG-VfsA-1s3L-DNq1Sw
LV Write Access read/write
LV Creation host, time xubuntu, 2017-11-14 10:35:13 -0200
LV Status available
# open 2
LV Size 8,00 GiB
Current LE 2048
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2
--- Logical volume ---
LV Path /dev/vg0/home
LV Name home
VG Name vg0
LV UUID uGTzqc-h42Y-0OFE-UZJz-iWfp-Vdzq-fFAUa7
LV Write Access read/write
LV Creation host, time xubuntu, 2017-11-14 10:35:26 -0200
LV Status available
# open 1
LV Size 250,00 GiB
Current LE 64000
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:3
The /etc/fstab is:
/dev/mapper/vg0-root / ext4 errors=remount-ro 0 1
UUID=a1f16cd1-de94-475b-836b-aed69305f90d /boot ext2 defaults 0 2
UUID=9C99-6D37 /boot/efi vfat umask=0077 0 1
/dev/mapper/vg0-home /home ext4 defaults 0 2
/dev/mapper/vg0-swap none swap sw 0 0
So… let’s begin
First, I physically installed the SSD: a simple SanDisk 240GB. It’s detected as /dev/sdb
With fdisk I reassembled a similar partition structure into SSD as follow
Disk /dev/sdb: 223,6 GiB, 240065183744 bytes, 468877312 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
Disklabel type: gpt
Disk identifier: BF486DA2-993B-3F46-8113-5C46B8027C3D
Device Start End Sectors Size Type
/dev/sdb1 2048 264191 262144 128M EFI System
/dev/sdb2 264192 980991 716800 350M Linux filesystem
/dev/sdb3 980992 468877278 467896287 223,1G Linux LVM
Made the filesystems:
$ sudo mkfs.vfat /dev/sdb1
$ sudo mkfs.ext2 -m 0 /dev/sdb2
$ sudo cryptsetup luksFormat --hash=sha512 --key-size=512 --cipher=aes-xts-plain64 --verify-passphrase /dev/sdb3
Now, my blkid returns:
/dev/mapper/sda3_crypt: UUID="AaEdPM-FXSl-XIju-mWPO-Ztj7-gOah-AueeYz" TYPE="LVM2_member"
/dev/mapper/vg0-root: UUID="3cd67e3b-1db9-4e32-a874-727757638aef" TYPE="ext4"
/dev/sda1: UUID="9C99-6D37" TYPE="vfat" PARTUUID="a6a37d31-9611-4a3d-b127-e02aabc0c423"
/dev/sda2: UUID="a1f16cd1-de94-475b-836b-aed69305f90d" TYPE="ext2" PARTUUID="a7a50d99-3d82-4956-96b5-9b934fa11a5c"
/dev/sda3: UUID="3efcfe49-c769-41de-9586-5f7496821826" TYPE="crypto_LUKS" PARTUUID="8a5adb8c-48d5-48ff-95d1-d6be73c1df7b"
/dev/sdb1: SEC_TYPE="msdos" UUID="D825-708D" TYPE="vfat" PARTUUID="a7696905-5b87-444c-a37f-f4adedfdca3f"
/dev/sdb2: UUID="9db8a6f1-1977-4196-b924-5734d39ab0fd" TYPE="ext2" PARTUUID="7e4fe304-378c-764e-b1ea-5cc4ae12bfa7"
/dev/mapper/vg0-swap: UUID="2dca77a1-4b59-4fb5-bb16-af86c4930ee5" TYPE="swap"
/dev/mapper/vg0-home: UUID="12379215-ac7a-4f54-a6a3-af31d8d46b81" TYPE="ext4"
/dev/sdb3: UUID="6c3bc5c6-1248-4813-a0cd-cbef0a7b1bf9" TYPE="crypto_LUKS" PARTUUID="663ba6ee-b928-3a42-b870-7b470cf33b14"
Now, prepare LUKS automount
$ sudo cryptsetup luksDump /dev/sdb3 | grep "UUID"
UUID: 6c3bc5c6-1248-4813-a0cd-cbef0a7b1bf9
>>> inside /etc/crypttab, add <<<
ssd_crypt UUID=6c3bc5c6-1248-4813-a0cd-cbef0a7b1bf9 none luks,discard
Test automount: $ sudo /sbin/cryptdisks_start ssd_crypt
Prepare volumes inside LUKS disk
$ sudo pvcreate /dev/mapper/ssd_crypt
$ sudo vgcreate vg1 /dev/mapper/ssd_crypt
$ sudo lvcreate -n ssdroot -L 100GB vg1
$ sudo mkfs.ext4 /dev/mapper/vg1-ssdroot
$sudo blkid /dev/mapper/vg1-ssdroot
/dev/mapper/vg1-ssdroot: UUID="7737287f-8f47-438e-94b5-f3de181d3396" TYPE="ext4"
Let’s copy our root partition into ssdroot, and make it automount
$ sudo init 1
# mount /dev/mapper/vg1-ssdroot /mnt
# cd /mnt
# dump -a0f - /dev/mapper/vg0-root | restore -rf -
>>> inside /etc/fstab, comment <<<
/dev/mapper/vg0-root / ext4 errors=remount-ro 0 1
>>> and add <<<
/dev/mapper/vg1-ssdroot / ext4 errors=remount-ro 0 1
>>> or... <<<
UUID=7737287f-8f47-438e-94b5-f3de181d3396 / ext4 errors=remount-ro 0 1
$sudo init 1
# mount /dev/mapper/vg1-ssdroot /mnt
# cd /mnt
# dump -a0f - /dev/mapper/vg0-root | restore -rf -
# umount /mnt
# mount /dev/sdb2 /mnt
# cd /mnt
# dump -a0f - /boot | restore -rf -
# umount /mnt
# reboot
Chroot environment
mkdir newpart
sudo mount /dev/mapper/vg1-ssdroot newpart
sudo mount /dev/sdb2 newpart/boot
sudo mount /dev/sdb1 newpart/boot/efi
sudo mount -t proc /proc newpart/proc
sudo mount --rbind /dev newpart/dev
sudo mount --rbind /dev/pts newpart/dev/pts
sudo mount --rbind /sys newpart/sys
sudo mount --rbind /run newpart/run
sudo chroot newpart
Inside chroot…
** adjust /etc/fstab
UUID=7737287f-8f47-438e-94b5-f3de181d3396 / ext4 errors=remount-ro 0 1
UUID=9db8a6f1-1977-4196-b924-5734d39ab0fd /boot ext2 defaults 0 2
UUID=D825-708D /boot/efi vfat umask=0077 0 1
/dev/mapper/vg0-home /home ext4 defaults 0 2
/dev/mapper/vg0-swap none swap sw 0 0
**
# update-grub
# grub-install --recheck /dev/sdb
# update-initramfs -u
# vgscan (Is it really necessary???)
(exit from chroot jail)
sudo umount --recursive newpart
sudo mount --make-rslave newpart/sys
sudo mount --make-rslave newpart/proc
sudo mount --make-rslave newpart/dev
sudo umount -R newpart/sys
sudo umount -R newpart/proc
sudo umount -R newpart/dev
sudo umount newpart
lvcreate -L 50G -n ssdapps vg1
mkfs.ext4 /dev/mapper/vg1-ssdapps
cd ~
mkdir mnt
sudo mount /dev/mapper/vg1-ssdapps mnt
sudo chown jjn.jjn mnt
cp -a -R apps/* mnt/
$ sudo mkswap /dev/sdb3
$ sudo swaplabel -L SWAP_SSD /dev/sdb3
UUID=a1f16cd1-de94-475b-836b-aed69305f90d /boot ext2 defaults 0 2
UUID=9C99-6D37 /boot/efi vfat umask=0077 0 1
sdb1 128M EFI
UUID=D825-708D /boot/efi vfat umask=0077 0 1
sdb2 350M EXT2
UUID=9db8a6f1-1977-4196-b924-5734d39ab0fd
grub-mkconfig
ref: https://unix.stackexchange.com/questions/385696/can-i-move-boot-linux-partition-to-another-drive-partition-and-just-boot-from-th
sudo mount /dev/mapper/vg1-ssdroot /newpart
sudo mount /dev/sdb2 /newpart/boot
sudo mount /dev/sdb1 /newpart/boot/efi
sudo mount --rbind /dev /newpart/dev
sudo mount --rbind /proc /newpart/proc
sudo mount --rbind /sys /newpart/sys
sudo chroot /newpart
sudo umount -R /newpart/sys
sudo umount -R /newpart/proc
sudo umount -R /newpart/dev
sudo umount /newpart