Thanks, but that's a long guide, at first I'll try the clone with CloneZilla/resize with GParted approach. If something doesnt work out, no big deal, I'll still have my original drive with all contents intact. I plan to format it, but only after I've verified that Debian boots from the new disk and all is seemingly working as it should.I do it at least weekly and just cloned my install to spare machine yesterday with new nvme in it. The easiest way is to have usb nvme dongle to put one of the drives in if you do not have second slot. There are three files you need to worry about for the new machine to just boot after the procedure I am going to describe. The /boot/efi/EFI/debian/grub.cfg on original drive is copied along with everything else in the EFI directory to the new drives partition for the new /boot/efi partition. This contains the UUID of your root partition and is the first file used in the chain of booting the machine.So, I currently have Debian Bookworm installed on a Samsung 980 1TB M.2 NVMe SSD. I want to transfer it to a Samsung 990 Pro 4TB SSD, also NVME.
My current partition layout is:
EFI system partition, 256MB
Boot partition, 512MB
Root partition, 100GB
Home partition, 733GB
Swap partition, 4GB
Unallocated space at end of disk, 93GB, which is 10% of the disk's total size. This is for overprovisioning.
It's a pretty simple layout. Nothing fancy like encryption/LUKS/dm-crypt, LVM, btrfs, etc. Just a Debian installed with UEFI boot mode.
I think the best way is to use Clonezilla. But the bigger concern is, will it boot? And how to repair it if it doesnt? My current plan is to make the swap partition bigger, the home partition will take up the lion's share of the disk. I'll probably just make a copy of anything important in the home partition, then use GParted post-clone to make those 2 partitions bigger. Any caveats I need to be aware of?
The section of my script where I copy this when running it or doing it manually in a Terminal if booted from a live usb, the live option is the easiest as you do not need to exclude things it is just a simple rsync for the / and /home then. The EFI copy stays the same no matter which method used except for deleting files on new partition as there will be none so only the copy is needed to its partition mounted at /tmp/efi.Code:
# remove files on /tmp/efi gets only the files present on the install.rm -r /tmp/efi/*echo "efi directory now empty"# Snyc/Copy the efi directory.scp -r /boot/efi/* /tmp/efi/echo "Completed Sync/Copy to /tmp/efi directory used for efi files backup"
I mount the partition for the efi on the /tmp/efi for the copying. What the directory looks like to copy over copying.For the second file needed editing on the transferred files is the /tmp/root/etc/fstab the /tmp/root is the place where I mount the to be copied to root in my script. The three commands used for making the directories needed.Code:
root@kingston:~# ls -l /boot/efi/EFI/BOOT/ debian/ root@kingston:~# ls -l /boot/efi/EFI/total 8drwx------ 2 root root 4096 Jul 18 20:10 BOOTdrwx------ 2 root root 4096 Jul 19 04:46 debianroot@kingston:~# ls -l /boot/efi/EFI/BOOT/total 1852-rwx------ 1 root root 948768 Jul 19 00:06 BOOTX64.EFI-rwx------ 1 root root 85672 Jul 18 20:10 fbx64.efi-rwx------ 1 root root 856232 Jul 18 20:10 mmx64.efiroot@kingston:~# ll /boot/efi/EFI/debian/total 4468-rwx------ 1 root root 108 Jul 21 00:31 BOOTX64.CSV-rwx------ 1 root root 87376 Jul 21 00:31 fbx64.efi-rwx------ 1 root root 126 Jul 21 00:31 grub.cfg-rwx------ 1 root root 2672064 Jul 21 00:31 grubx64.efi-rwx------ 1 root root 850176 Jul 21 00:31 mmx64.efi-rwx------ 1 root root 948768 Jul 21 00:31 shimx64.efi
The mounting for them if internal nvme drive is to be used.Code:
root@kingston:~# mkdir /tmp/efiroot@kingston:~# mkdir /tmp/rootroot@kingston:~# mkdir /tmp/home
The first command gets the partition /dev names using the fdisk command, the last of them shows the mounting of them partitions needed. I always go with efi partition 1, / partitiion 2 and /home partition 3 it makes the script entirely predictable as to what needs to be done on any drive it gets cloned to. If the new drive is in usb nvme case the it will show as /dev/sd?. As shown here on my drive I used to clone the install a nvme in external case.Code:
root@kingston:~# fdisk -lDisk /dev/nvme0n1: 1.82 TiB, 2000398934016 bytes, 3907029168 sectorsDisk model: KINGSTON SNVS2000GB Units: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: gptDisk identifier: DE09AABB-0B30-41E7-8A28-3D0AC0EBF65ADevice Start End Sectors Size Type/dev/nvme0n1p1 2048 411647 409600 200M EFI System/dev/nvme0n1p2 411648 84297727 83886080 40G Linux filesystem/dev/nvme0n1p3 84297728 252069887 167772160 80G Linux filesystem/dev/nvme0n1p4 252069888 1594247167 1342177280 640G Linux filesystem/dev/nvme0n1p5 1594247168 3907029134 2312781967 1.1T Linux filesystemroot@kingston:~# mount /dev/nvme0n1p1 /tmp/efiroot@kingston:~# mount /dev/nvme0n1p2 /tmp/rootroot@kingston:~# mount /dev/nvme0n1p3 /tmp/home
The fstab on the mounted drive that was copied/cloned.Code:
root@kingston:~# fdisk -l /dev/sdbDisk /dev/sdb: 119.24 GiB, 128035676160 bytes, 250069680 sectorsDisk model: MZVLW128HEGR Units: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 4096 bytesI/O size (minimum/optimal): 4096 bytes / 4096 bytesDisklabel type: gptDisk identifier: 718558F0-991A-4896-981E-242454D04770Device Start End Sectors Size Type/dev/sdb1 2048 1026047 1024000 500M EFI System/dev/sdb2 1026048 82946047 81920000 39.1G Linux filesystem/dev/sdb3 82946048 250069646 167123599 79.7G Linux filesystem
This shows the UUIDs that have been changed to the drive they are now on. The command to get them on nvme drive.Code:
root@kingston:~# cat /tmp/root/etc/fstab# /etc/fstab: static file system information.## Use 'blkid' to print the universally unique identifier for a# device; this may be used with UUID= as a more robust way to name devices# that works even if disks are added and removed. See fstab(5).## <file system> <mount point> <type> <options> <dump> <pass># / is on /dev/nvme0n1p2 8400 machineUUID=f5b84b31-ce88-48ed-bbe4-edeec7a29fb2 / ext4 errors=remount-ro 0 1# /home is on /dev/nvme0n1p3 8400 machineUUID=124c4634-0b5b-411d-9a2d-d66d7d0964a4 /home ext4 defaults02# /boot/efi is on /dev/nvme0n1p1 8400 machineUUID=CA4B-9184 /boot/efi vfat umask=0077 0 1/swapfile none swap sw 0 0
When the root partition has been cloned to the new partition the already mentioned /tmp/root/etc/fstab file needs to be edited with the new drive UUIDs put into the file so when booting the machine will find the correct locations to load the files from. The /tmp/efi/EFI/debian/grub.cfg needs to have the UUID in it changed to new drive too.Code:
root@kingston:~# blkid | grep /dev/nvme0/dev/nvme0n1p3: LABEL="NVMEHome" UUID="124c4634-0b5b-411d-9a2d-d66d7d0964a4" BLOCK_SIZE="4096" TYPE="ext4" PARTLABEL="Linux filesystem" PARTUUID="d7f7aa74-45c1-48c5-8f3c-f523467c5345"/dev/nvme0n1p1: SEC_TYPE="msdos" LABEL_FATBOOT="NVMEEFI" LABEL="NVMEEFI" UUID="CA4B-9184" BLOCK_SIZE="512" TYPE="vfat" PARTLABEL="EFI system partition" PARTUUID="4c8d4bec-263a-4b06-9959-3472b5e9fb92"/dev/nvme0n1p2: LABEL="NVMERoot" UUID="f5b84b31-ce88-48ed-bbe4-edeec7a29fb2" BLOCK_SIZE="4096" TYPE="ext4" PARTLABEL="Linux filesystem" PARTUUID="bd07b5ad-4124-47a0-ae11-94bd61589203"
Code:
root@kingston:~# cat /tmp/efi/EFI/debian/grub.cfgsearch.fs_uuid f5b84b31-ce88-48ed-bbe4-edeec7a29fb2 root set prefix=($root)'/boot/grub'configfile $prefix/grub.cfg
To sync a running system this command is used.This excludes the numerous system directories that are created on every boot and will mess up a cloning attempt if copied over. The commands to do it from live usb two nvme in machine.Code:
root@kingston:~# rsync -ahPHAXx --delete --exclude={/boot/efi/*,/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/swapfile,/lost+found} / /tmp/root/
You of course use the appropriate /dev/nvme1n1p2 & /dev/nvme0n1p2 according to the drive locations for the old and new drives. Which leads to the third file needing to be changed on new drive for successful booting the /tmp/root/boot/grub/grub.cfg.Code:
root@kingston:~# mkdir /tmp/root_oldroot@kingston:~# mount /dev/nvme1n1p2 /tmp/root_oldroot@kingston:~# rsync -avP /tmp/root_old/* /tmp/root/
This replaces the old_drive_root_UUID_here in the dozen or so places in the file with the new_drive_root_UUID_here in the file to allow it to boot from the new drive.Code:
root@kingston:~# sed -i "s/old_drive_root_UUID_here/new_drive_root_UUID_here/g" /tmp/root/boot/grub/grub.cfg
Now onto the /home the script section I use for running machine.I am very specific as I know what I want to be on the new partition. The /rsync-homedir-excludes.txt file can be found here below that line gets all the . files in the home directory and excludes the files that mess up applications from starting properly on a live cloned system by excluding the caches and things like that of live running programs. The USER=zeus is the name of my user directory to be rsync'd.Code:
# Snyc/Copy the /home directory.USER=zeusrsync -avP --delete --exclude-from=/usr/local/bin/rsync-homedir-excludes.txt /home/$USER/.[^.]* /tmp/home/$USER/ rsync -avP --delete /home/$USER/bin /tmp/home/$USER/rsync -avP --delete /home/$USER/Desktop /tmp/home/$USER/rsync -avP --delete /home/$USER/Documents /tmp/home/$USER/rsync -avP --delete /home/$USER/Downloads /tmp/home/$USER/rsync -avP --delete /home/$USER/Pictures /tmp/home/$USER/rsync -avP --delete /home/$USER/Public /tmp/home/$USER/rsync -avP --delete /home/$USER/src /tmp/home/$USER/rsync -avP --delete /home/$USER/Templates /tmp/home/$USER/rsync -avP --delete /home/$USER/Videos /tmp/home/$USER/# For my wallpapers to be copiedmkdir -p /tmp/home/$USER/.cache/gnome-control-center/backgroundschown $USER:$USER /tmp/home/$USER/.cache/gnome-control-center/backgroundscp -vp /home/$USER/Pictures/background/* /tmp/home/$USER/.cache/gnome-control-center/backgrounds/# For the Music directory that is not synced, if this is fresh formatted disk# so the mount point will exist and it not fail on boot due lack of it.if [ ! -d "/tmp/home/$USER/Music" ]; thenmkdir "/tmp/home/$USER/Music"chown $USER:$USER "/tmp/home/$USER/Music"fi
https://github.com/rubo77/rsync-homedir-excludes
For a clean partition if doing it for the first time then the commands to be run before any rsync commands would be.This would create the user directory needed and change the permission to it so it can be used, of course the zeus is changed to your actual directory name.Code:
root@kingston:~# USER=zeusroot@kingston:~# mkdir /tmp/home/$USERroot@kingston:~# chown $USER:$USER /tmp/home/$USER
The command if run from live usb new drive partition.No exclusions are required as nothing is running to to mess up a fresh cloning you get byte for byte copy of what is on the old partition using the live usb method, for the / too.Code:
root@kingston:~# mkdir /tmp/home_oldroot@kingston:~# mount /dev/nvme1n1p3 /tmp/home_oldroot@kingston:~# rsync -avP /tmp/home_old/* /tmp/home/
No idea if you need help on partitioning the drive but for completeness here is how to partition new drive EFI and make it a system drive. I recently did this with new external drive and cloned the system to it to make it bootable too It is backup drive of all my media files.You can see I first deleted the existing single NTFS partition that came on it the proceeded to create the partitions for the efi as number 1, the root of 40G as number 2, the home as number 3 size of 80G and finally let it use the rest for the media partition. Then formatted using the ext4 file system with no reserved space (-m 0 option) with labels for each partition (-L option). The efi was formatted vfat type ef00 when creating it as shown the EFI System Type partition that needs to be created as such or an EFI booting machine will never use it if not made so during creation or subsequent editing of partition to change to that type.Code:
root@8400t:~# gdisk /dev/sdbGPT fdisk (gdisk) version 1.0.10Partition table scan: MBR: protective BSD: not present APM: not present GPT: presentFound valid GPT with protective MBR; using GPT.Command (? for help): dUsing 1Command (? for help): nPartition number (1-128, default 1):First sector (34-31251693534, default = 2048) or {+-}size{KMGTP}:Last sector (2048-31251693534, default = 31251691519) or {+-}size{KMGTP}: +200MCurrent type is 8300 (Linux filesystem)Hex code or GUID (L to show codes, Enter = 8300): ef00Changed type of partition to 'EFI system partition'Command (? for help): nPartition number (2-128, default 2):First sector (34-31251693534, default = 411648) or {+-}size{KMGTP}:Last sector (411648-31251693534, default = 31251691519) or {+-}size{KMGTP}: +40GCurrent type is 8300 (Linux filesystem)Hex code or GUID (L to show codes, Enter = 8300):Changed type of partition to 'Linux filesystem'Command (? for help): nPartition number (3-128, default 3):First sector (34-31251693534, default = 84297728) or {+-}size{KMGTP}:Last sector (84297728-31251693534, default = 31251691519) or {+-}size{KMGTP}: +80GCurrent type is 8300 (Linux filesystem)Hex code or GUID (L to show codes, Enter = 8300):Changed type of partition to 'Linux filesystem'Command (? for help): nPartition number (4-128, default 4):First sector (34-31251693534, default = 252069888) or {+-}size{KMGTP}:Last sector (252069888-31251693534, default = 31251691519) or {+-}size{KMGTP}:Current type is 8300 (Linux filesystem)Hex code or GUID (L to show codes, Enter = 8300):Changed type of partition to 'Linux filesystem'Command (? for help): wFinal checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTINGPARTITIONS!!Do you want to proceed? (Y/N): yOK; writing new GUID partition table (GPT) to /dev/sdb.The operation has completed successfully.root@8400t:~# fdisk -lDisk /dev/sdb: 14.55 TiB, 16000867106816 bytes, 31251693568 sectorsDisk model: Elements 25A3Units: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 4096 bytesI/O size (minimum/optimal): 4096 bytes / 4096 bytesDisklabel type: gptDisk identifier: 1D0CF95A-68BF-4EA2-9C92-FBA2A42FA244Device Start End Sectors Size Type/dev/sdb1 2048 411647 409600 200M EFI System/dev/sdb2 411648 84297727 83886080 40G Linux filesystem/dev/sdb3 84297728 252069887 167772160 80G Linux filesystem/dev/sdb4 252069888 31251691519 30999621632 14.4T Linux filesystemroot@8400t:~# mkfs.vfat /dev/sdb1mkfs.fat 4.2 (2021-01-31)root@8400t:~# fatlabel /dev/sdb1 ELEMENTSEFIroot@8400t:~# mkfs.ext4 -m 0 -L ElementsRoot /dev/sdb2mke2fs 1.47.0 (5-Feb-2023)Creating filesystem with 10485760 4k blocks and 2621440 inodesFilesystem UUID: 57cd2293-ca19-4333-8cda-49d111cac269Superblock backups stored on blocks:32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,4096000, 7962624Allocating group tables: doneWriting inode tables: doneCreating journal (65536 blocks): doneWriting superblocks and filesystem accounting information: doneroot@8400t:~# mkfs.ext4 -m 0 -L ElementsHome /dev/sdb3mke2fs 1.47.0 (5-Feb-2023)Creating filesystem with 20971520 4k blocks and 5242880 inodesFilesystem UUID: 6097b38a-25f2-4d6c-9043-8fdbf1c62f8eSuperblock backups stored on blocks:32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,4096000, 7962624, 11239424, 20480000Allocating group tables: doneWriting inode tables: doneCreating journal (131072 blocks): doneWriting superblocks and filesystem accounting information: doneroot@8400t:~# mkfs.ext4 -m 0 -L ElementsMedia /dev/sdb4mke2fs 1.47.0 (5-Feb-2023)Creating filesystem with 3874952704 4k blocks and 484372480 inodesFilesystem UUID: 6e2245ce-f9b6-4ee5-8e21-d73d77eec311Superblock backups stored on blocks:32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,102400000, 214990848, 512000000, 550731776, 644972544, 1934917632,2560000000, 3855122432Allocating group tables: doneWriting inode tables: doneCreating journal (262144 blocks): doneWriting superblocks and filesystem accounting information: doneroot@8400t:~# mkdir /tmp/efiroot@8400t:~# mkdir /tmp/rootroot@8400t:~# mkdir /tmp/homeroot@8400t:~# mkdir /tmp/elements
Almost forgot if you go with swap file as I always do then the script I use to create it.This creates 2G swapfile then corrects the permissions, formats and mounts it on running system.Code:
root@9600k:~# cat bin/fix_swap.sh #!/bin/bash# A script to fix the swapfile missed when using new partition without one already there for a backup/clone/restore.# make the /swapfile filefallocate -l 2G /swapfile# correct the permissionschmod 600 /swapfile# format as swap spacemkswap /swapfile# load the /swapfileswapon /swapfile
Good luck with it, this method never fails for me unless I forget to edit one of the UUIDs required in the few years of using it.
Edit: If not going with swap file then make certain to change the UUID of its partition in the /tmp/root/etc/fstab file as well.
Edit2: And now I think of it when partition the disk at the creation of its partition use ? mark I think at the "Hex code or GUID" step to get a listing of the type to choose from and pick linux swap from the rather extensive listing of type you are going to see. Then when formatting.To make the formatting swap on the first nmve drive in the system , nvme0, fourth partition, n1p4.Code:
root@kingston:~# mkswap /dev/nvme0n1p4
Statistics: Posted by Enigma83 — 2024-07-22 16:30