linux:system:disk:clone-system
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| linux:system:disk:clone-system [2023/09/08 11:32] – oscar | linux:system:disk:clone-system [2023/09/08 12:33] (current) – [Write Target System] oscar | ||
|---|---|---|---|
| Line 2: | Line 2: | ||
| ---- | ---- | ||
| - | ===== Grub Configuration | + | ===== Overview |
| - | GRUB settings are stored | + | This page assumes that system is installed |
| - | * **/etc/ | + | |
| - | * **/ | + | |
| - | * **/ | + | |
| - | When you run the update-grub command, GRUB automatically combines | + | ===== Get Source Images ===== |
| - | # / | + | Create a live USB and boot system from USB. Once booted into the live-cd, mount the source filesystem. First check the correct device with lsblk |
| - | # update-grub | + | < |
| - | # grub-install /dev/sdX | + | # lsblk |
| - | # grub-install --recheck /dev/sdX | + | NAME |
| + | sda 8:0 0 931, | ||
| + | ├─sda1 | ||
| + | ├─sda2 | ||
| + | └─sdb3 | ||
| + | sdb 8:0 0 931, | ||
| + | ├─sdb1 | ||
| + | ├─sdb2 | ||
| + | ├─sdb3 | ||
| + | └─sdb4 | ||
| + | </code> | ||
| + | We need to copy the **"/boot/efi"** and **"/" | ||
| + | ==== Get EFI Partition ==== | ||
| + | We will use dd to get an exact image copy and the size of source and target partitions are usually similar. | ||
| + | Create Backup Image: | ||
| - | ===== Probe installed OS ===== | + | # dd bs=4M if=/dev/sdb1 | gzip > efi-image.gz |
| - | Open a terminal and run the os-prober command | + | # sync |
| + | ==== Get Root Partition | ||
| + | For the root partition we only want to copy the files. This is faster since the root partitions is usually partially filled. | ||
| + | < | ||
| + | # mkdir / | ||
| + | # mount -t ext4 /dev/sdXY / | ||
| + | # tar -zcvf image-sdXY.tgz / | ||
| + | </ | ||
| + | ===== Create Target Disk ===== | ||
| + | Again, first check with lsblk the disk structure, before proceeding: | ||
| + | < | ||
| + | # lsblk | ||
| + | NAME | ||
| + | sda 8:0 0 931, | ||
| + | ├─sda1 | ||
| + | ├─sda2 | ||
| + | └─sdb3 | ||
| + | sdb 8:0 0 931, | ||
| + | ├─sdb1 | ||
| + | ├─sdb2 | ||
| + | ├─sdb3 | ||
| + | └─sdb4 | ||
| + | </ | ||
| + | ==== Write EFI Partition ==== | ||
| + | < | ||
| + | # gzip -dc efi-image.gz | dd bs=4M of=/ | ||
| + | # sync | ||
| + | </ | ||
| + | ==== Write Root Partition ==== | ||
| + | Empty and create a fresh filesystem on the root partition of the target disk: | ||
| + | # mkfs.ext4 -l root /dev/sdbX | ||
| + | Mount the root partition. Use the same / | ||
| + | # mount -t ext4 /dev/sdX / | ||
| + | Now restore the files to the partitions. | ||
| + | # cd / | ||
| + | # tar -zxvf image-sdX1.tgz | ||
| - | $ sudo os-prober | + | ===== install a bootloader ===== |
| + | At this point we have all the files we need on the new system, but we need to make the new system bootable. We will chroot into the newly extracted filesystem to install a bootloader. | ||
| - | It should find your Linux distro, the Windows | + | First, change directories to where the new installation |
| - | $ sudo update-grub | + | |
| - | The output should show that Windows 10 has been found and added to the GRUB boot menu. | + | # cd / |
| + | Then we’ll use mount ---bind to give the chroot access to the linux special directories. The bind option of the mount command allows you to remount part of a file hierarchy at a different location while it is still available at the original location. The format of this command is as follows. | ||
| + | < | ||
| + | # for i in /dev /dev/pts /proc /sys /run; do mount --bind $i .$i; done | ||
| + | Which is similar to: | ||
| + | # mount --bind /dev / | ||
| + | # mount --bind /dev/pts / | ||
| + | # mount --bind /proc / | ||
| + | # mount --bind /sys / | ||
| + | </ | ||
| - | ===== Repair, Restore, or Reinstall Grub 2 with Live USB ===== | + | Because we installing in EFI mode we also need to give our chroot access to the EFI partition we mounted earlier. mount --bind comes to the rescue again here, we simply bind mount the livecd mount point into the /boot/efi directory inside the chroot |
| - | Grub 2 typically gets overridden when you install Windows or another Operating System. To make Linux control | + | First mount the new EFI partition: |
| + | # mkdir / | ||
| + | # mount /dev/sdX1 / | ||
| + | Now bind it in the new croot partition: | ||
| + | # cd / | ||
| + | # mkdir -p boot/efi | ||
| + | # mount --bind / | ||
| - | Create a live USB and boot system from USB | + | Now that we have access to the Linux special folders (and the EFI partition), we can use the chroot command to actually use our source installation: |
| + | |||
| + | # chroot / | ||
| + | |||
| + | At this point you should have a shell inside the same Linux environment you originally copied. | ||
| + | We can run grub-install from inside the chroot to update the boot partition. | ||
| + | |||
| + | ===== Install bootloader ===== | ||
| + | Run grub-install against the drive you installed to. In my case that’s /dev/sdb, but this may be different on your machine. Next we install grub to our drive, thereby making it bootable. Be careful to install grub to a drive and not to a partition. | ||
| + | |||
| + | # grub-install /dev/sdX | ||
| + | # grub-install --recheck /dev/sdX | ||
| + | |||
| + | # update-grub | ||
| + | |||
| + | If all went well you will see messages saying that grub was successfully installed. When you see this feel free to reboot and check out your freshly cloned installation. | ||
| + | |||
| + | ===== Troubleshooting ===== | ||
| + | If you get a a warning saying that “EFI variables cannot be set on this system,” you may need to mount the EFI vars into the chroot (h/t Jesse Dhillon): | ||
| + | |||
| + | # mount -t efivarfs none / | ||
| + | |||
| + | If you get error messages when installing in EFI mode it’s possible grub’s autodetect got confused and tried to use MBR mode when it should’ve used EFI. You may be able to succesfully perform an EFI install by forcing EFI mode like so: | ||
| + | |||
| + | @ grub-install --target=x86_64-efi | ||
| + | |||
| + | |||
| + | ===== Write Target System ===== | ||
| + | Create a live USB and boot system from USB. Once booted into the live-cd, mount your destination filesystem. | ||
| Mount the partition your broken Linux installation is on. If you are not sure which it is, launch GParted (included in the Live CD) and find out. It is usually a EXT4 Partition. Replace the XY with the drive letter, and partition number, for example: sudo mount /dev/sda1 /mnt. | Mount the partition your broken Linux installation is on. If you are not sure which it is, launch GParted (included in the Live CD) and find out. It is usually a EXT4 Partition. Replace the XY with the drive letter, and partition number, for example: sudo mount /dev/sda1 /mnt. | ||
| Line 61: | Line 150: | ||
| </ | </ | ||
| - | Alternatively, | ||
| - | < | ||
| - | apt-get remove --purge grub-pc grub-common | ||
| - | apt-get install grub-pc | ||
| - | grub-mkconfig | ||
| - | update-grub | ||
| - | grub-install /dev/sda | ||
| - | </ | ||
| - | |||
| - | Now grub is back, all that is left is to exit the chrooted system and unmount everything: | ||
| - | < | ||
| - | # exit | ||
| - | # umount /mnt/sys | ||
| - | # umount /mnt/proc | ||
| - | # umount /mnt/dev/pt | ||
| - | # umount /mnt/dev | ||
| - | # umount /mnt | ||
| - | </ | ||
| Shut down and turn your computer back on, and you will be met with the default Grub2 screen. | Shut down and turn your computer back on, and you will be met with the default Grub2 screen. | ||
| - | ===== Customize boot layout ===== | ||
| - | For customizing the layout of the Grub startup screen at boot, the files are located in:/ | ||
| - | The sample below illustrates adding a background image and changing the font size. | ||
| - | Copy the background images to the folder: /boot/grub. Remember that other partitions might not yet be mounted and available at boot time. | ||
| - | |||
| - | === Find screen resolution === | ||
| - | To find the possible screen resolutions for Grub, do to the command line when Grub starts, by pressing ' | ||
| - | videoinfo | ||
| - | Then a list of possible option will be shown. | ||
| - | |||
| - | === Configure screen resolution and background image === | ||
| - | Grub prefers png images instead of jpg images. Update / | ||
| - | |||
| - | #nano / | ||
| - | | ||
| - | Modify Lines: | ||
| - | | ||
| - | GRUB_BACKGROUND=/ | ||
| - | GRUB_GFXMODE=1920x1080 | ||
| - | | ||
| - | If you change this file, run ' | ||
| - | update-grub | ||
| - | |||
| - | Currently a grub2 wallpaper image cannot be larger than 1024×768px, | ||
| - | |||
linux/system/disk/clone-system.1694172748.txt.gz · Last modified: by oscar
