Jump to content

Linux: Difference between revisions

1,531 bytes added ,  21 January 2023
Line 822: Line 822:


==Cloning to a new disk==
==Cloning to a new disk==
The easiet way is to use gparted.
The easiest way is to use gparted.


To copy a root partition, make sure you change the following:
{{hidden | Terminal Guide |
To do this in the terminal:
<syntaxhighlight lang="bash">
OLD_DRIVE=/dev/sda
NEW_DRIVE=/dev/sdb
 
# Show old drive partitions in sectors
parted $OLD_DRIVE unit s print free
 
# Apply GPT
parted $NEW_DRIVE mklabel gpt
# Copy new EFI partition with start 1024s and end 1050623s
parted $NEW_DRIVE mkpart primary fat32 2048s 1050623s
# Apply boot and esp flags.
parted $NEW_DRIVE set 1 boot on
parted $NEW_DRIVE set 1 esp on
parted $NEW_DRIVE name 1 'EFI System Partition'
# dd the old to the new
dd if=${OLD_DRIVE}1 of=${NEW_DRIVE}1 bs=4k
 
# Make a new partition. Make sure start and end sectors are aligned to a multiple of
# i.e. start % 8 == 0 and end % 8 == 7
parted $NEW_DRIVE mkpart primary btrfs 1050624s 488396791s
parted $NEW_DRIVE align-check opt 2
 
# Copy the filesystem
mkfs.btrfs ${NEW_DRIVE}2
mkdir /media/${NEW_DRIVE}
mount -t btrfs -o compress=zstd /media/${NEW_DRIVE}2
rsync -axHAWXS --numeric-ids --info=progress2 /media/${NEW_DRIVE}2
</syntaxhighlight>
 
[https://superuser.com/questions/307541/copy-entire-file-system-hierarchy-from-one-drive-to-another rsync reference]
 
;rsync options
* -a    archive mode
* -x    one file system
* -H    preserve hard links
* -A    preserve ACLs
* -W    copy whole files instead of deltas
* -X    preserve extended attributes
* -S    handle sparse files efficiently
* --numeric-ids    use id instead of uid/gid
 
 
To copy a root partition, make sure you change the following on the new drive:
* Update the UUID and mount options in <code>/etc/fstab</code>
* Update the UUID and mount options in <code>/etc/fstab</code>
* Update the UUID in <code>/boot/grub/grub.cfg</code> and run <code>grub-update</code>
* Update the UUID in <code>/boot/grub/grub.cfg</code> and run <code>update-grub</code>
* Update the UUID in <code>/boot/EFI/ubuntu/grub.cfg</code>
* Update the UUID in <code>/boot/EFI/ubuntu/grub.cfg</code>
* Run [https://help.ubuntu.com/community/Boot-Repair boot-repair] from a live disk if you run into any issues.
}}