Difference between revisions of "Migrate installation to new hardware"

From ArchWiki
Jump to navigation Jump to search
(append dhcpcd section, because I forgot in my hardware migration and it took me a while to figure out how to fix it)
 
(39 intermediate revisions by 9 users not shown)
Line 1: Line 1:
[[Category:System administration]]
 
 
[[Category:System recovery]]
 
[[Category:System recovery]]
{{out of date|Mentions rc.conf and uses links to wiki articles that don't exist anymore.}}
+
{{Related articles start}}
This article discusses the steps required for moving an Arch Linux system to new hardware. The goal is to achieve the same ArchLinux installation, as far as installed software and configuration is concerned.
+
{{Related|Migrating between architectures}}
 +
{{Related|Moving an existing install into (or out of) a virtual machine}}
 +
{{Related articles end}}
 +
This article discusses the steps required for moving an Arch Linux system to new hardware. The goal is to achieve the same ArchLinux installation, in terms of the installed software and configuration that is independent of the hardware.
 +
 
 +
{{Warning|Some of the following instructions can be dangerous: you are advised to backup all of your important data on the old system before continuing.}}
  
 
There are two different approaches to migrating an installation:
 
There are two different approaches to migrating an installation:
# ''Bottom to Top'': Install a fresh Arch Linux system on the new hardware, afterwards restore the installed packages and configuration files.
+
# ''Bottom to Top'': Install a fresh Arch Linux system on the new hardware, afterwards restore the installed packages and configuration files, e.g. as describedn in [[dotfiles]].
 
# ''Top to Bottom'': Clone the old harddrive to the new harddrive, or place the old harddrive into the new system; modify configuration files where necessary.
 
# ''Top to Bottom'': Clone the old harddrive to the new harddrive, or place the old harddrive into the new system; modify configuration files where necessary.
Which way you choose depends heavily on how the new system differs from your old and how exact you want to reproduce the system.
+
The Top to bottom approach gives a more exact reproduction of the original system than the Bottom to Top approach.
{{Warning|Some of the following instructions can be dangerous: you are advised to backup all of your important data on the old system before continuing.}}
+
 
 +
== Adapt to new hardware ==
 +
{{Warning|For both approaches we have to account for differences between the old and hardware and change the installed drivers and configuration accordingly.}} Before you begin, research aspects of the new hardware and make a list of differences. Common differences are
 +
=== Hard drive vs. SSD ===
 +
See the article [[SSD]].
 +
=== CPU vendor ===
 +
If you switch the CPU, to a CPU from another vendor (e.g. Intel to AMD), change the [[Microcode]] configuration.
 +
=== GPU vendor ===
 +
If you changed the GPU to a GPU from another vendor (e.g. from [[Amd]] to [[NVIDIA]]) change the graphics driver.
 +
=== UEFI vs. MBR boot code booting ===
 +
If you switch to a more recent mainboard with UEFI, it might be preferable or required to switch from "MBR boot code" booting to [[UEFI]] booting. In this case an new [[EFI system partition]] is needed.
  
 
== Bottom to Top ==
 
== Bottom to Top ==
 
=== On the old system ===
 
=== On the old system ===
==== What software? ====
+
We define here a minimal configuration that carries over from the old to the new system which differentiates this approach from the Installation guide. Think about the configuration files from {{ic|/etc}} and dotfiles in {{ic|/home}} that you want to copy to the new system, as well as user data files. If you will not have access to the old system from the new system then backup up all the files that you want to copy over.
  $ pacman -Qqe | grep -vx "$(pacman -Qqm)" > Packages
+
 
  $ pacman -Qqm > Packages.aur
+
==== List of installed packages ====
gives you a nice list of explicitly installed packages. Don't forget the software ''not'' installed through pacman (also see [[Arch_User_Repository#Why_has_foo_disappeared_from_the_AUR.3F|AUR FAQ]]). You may also use the following script to give you a better overview of the binaries and libraries installed unbeknownst to pacman (e. g. installed via Steam, Desura or using their own install methods):
+
  $ pacman -Qqen > pkglist.txt
 +
  $ pacman -Qqem > pkglist_aur.txt
 +
gives you a nice list of explicitly installed packages from the repositories and from the [[AUR]]. Include it in your backup if you make one.
 +
 
 +
You may also use the following script to give you a better overview of the binaries and libraries installed unbeknownst to pacman (e. g. installed via Steam, Desura or using their own install methods):
  
 
  find / -regextype posix-extended -regex "/(sys|srv|proc)|.*/\.ccache/.*" -prune -o -type f \
 
  find / -regextype posix-extended -regex "/(sys|srv|proc)|.*/\.ccache/.*" -prune -o -type f \
Line 24: Line 42:
 
  done
 
  done
  
==== Copy to some backup space. ====
+
==== pacman cache ====
* You can consider backing up /var/cache/pacman/pkg if you do not change architectures (examplefrom x86 to x86_64)
+
Consider backing up {{ic|/var/cache/pacman/pkg}} if you do not change architectures (for example from x86 to x86_64).
* /etc should be backed up, in order to peek if necessary.
 
  
 
=== On the new system ===
 
=== On the new system ===
==== Wiki articles ====  
+
==== Installation guide first half ====
* Read some Wiki articles concerning new hardware, for examples your new [[SSD]].
+
For basics about installing a new system, refer to the [[Installation guide]]. Follow the first half of the installation guide up to but excluding the pacstrap command.
* Stick to the well-written installation guidelines here in this wiki. Since you are experienced, the [[Installation guide]] could be enough.  
 
* Try to configure as much as possible sticking to ''current'' wiki articles and forum posts.  
 
  
==== Copy from backup space ====
+
==== Copy pacman cache ====
* Copy the pacman cache to var/cache/pacman/pkg
+
Copy the pacman cache found at {{ic|/var/cache/pacman/pkg}} from the old to the new system, or from the backup to the new system.
* Don't forget to edit /etc/pacman.d/mirrorlist
 
  
==== Install software ====
+
==== Installation guide second half ====
As root, grab a cup of coffee and execute:
+
Continue with the installation guide from, and including the pacstrap command, up to the end, but do not reboot. Do not skip the pacstrap command as it does additional work besides the installation of packages.
  # xargs -a Packages pacman -S --noconfirm --needed
+
 
 +
==== Install previously installed software ====
 +
Edit pkglist.txt (and pkglist_aur.txt) and remove drivers that are not needed on the new system. Then install any other previously installed software with
 +
 
 +
  # pacman -S --needed - < pkglist.txt
  
 
== Top to Bottom ==
 
== Top to Bottom ==
{{Merge|Migrating Between Architectures Without Reinstalling}}
+
There are two options for the Top to Bottom approach, you can either keep the drive where the system is already installed, and modify its contents, or you can copy the system to a new drive. If you keep the drive, and modify it, then place it back into the old system, the modifications will likely prevent the old system from booting.
*See these forum threads:
 
**https://bbs.archlinux.org/viewtopic.php?id=71038
 
**https://bbs.archlinux.org/viewtopic.php?pid=543214
 
  
=== Move the system to the new HDDs ===
+
=== Clean up the old system ===
 +
It is also worth to clean up your system before cloning it, as described in [[System maintenance#Clean the filesystem]]. Make sure that the old system is still working as expected after the cleanup before moving on.
 +
 
 +
=== Copy the system to a new drive ===
 
{{Note|If you are planning to keep the hard drive where the system is already installed, you can skip this section.}}
 
{{Note|If you are planning to keep the hard drive where the system is already installed, you can skip this section.}}
There are two fundamental methods for copying data between two disks, cloning an entire disk, and copying single files. For details see [[Disk cloning]]. If you want to clone the entire disk, it is required to use a live cd to do so.
 
  
At the same time there are many different methods for how to transport the data between the two drives:
+
There are two fundamental methods for copying the system to a new drive, [[disk cloning]] and file copying.
 +
 
 +
==== Disk cloning ====
 +
It is required to use a live linux system rather than the old ArchLinux system; for example you could use the ArchLinux [[USB flash installation media]]. The partition layout and filesystems of the old system will be reproduced.
 +
 
 +
==== File copying ====
 +
* Create new [[partitions]] and [[filesystems]] on the new drive. You can use the opportunity to chose a different partition layout and/or filesystems than before.
 +
* For each filesystem, copy the files from the old to the new drive, using [[Rsync]] or other tools that preserve permissions, attributes, etc., see [[Rsync#Full system backup]], [[Rsync#File system cloning]] for further details.
 +
 
 +
==== Transport options ====
 +
There are many different methods for how to transport the data between the two drives:
 
*Connect origin and destination HDDs to the same computer, either the old or the new one. Data link: old HDD -> computer -> new HDD.
 
*Connect origin and destination HDDs to the same computer, either the old or the new one. Data link: old HDD -> computer -> new HDD.
*Make use of temporary storage devices like external HDDs, or cloud backups. Data link: old HDD -> old computer -> storage -> new computer -> new HDD.
+
*Make use of temporary storage devices like external HDDs, or cloud backups. Data link: old HDD -> old computer -> storage -> new computer -> new HDD. For an overview see the article [[System backup]].
 
*Transfer data over network, for example with [[rsync]]. Data link: old HDD -> old computer -> network -> new computer -> new HDD.
 
*Transfer data over network, for example with [[rsync]]. Data link: old HDD -> old computer -> network -> new computer -> new HDD.
 
For the first two options, consider that you might need adapters to connect the HDDs (PATA->SATA, USB-HDD-Cases, etc.), and choose a connection that is sufficiently fast.
 
For the first two options, consider that you might need adapters to connect the HDDs (PATA->SATA, USB-HDD-Cases, etc.), and choose a connection that is sufficiently fast.
The last two options require you to use a live system on the new computer, as it is not possible to boot from the new harddrive at this point. It is also worth to clean up your system before cloning it. See [[List of applications#Disk usage display]] for useful tools.
+
The last two options require you to use a live linux system on the new computer, as it is not possible to boot from the new hard drive at this point.
 +
 +
=== Update fstab ===
 +
{{Warning|Before doing this step please make sure that you do not wish to use this drive in the old system, as changing the [[fstab]] file will likely prevent the system from booting in the old configuration.}}
 +
If you are using an Arch Linux Installation Image, mount the new root partition to {{ic|/mnt}}, and any other partitions required like you would in a normal install (see [[Installation guide#Mount the file systems]]).
  
=== Update fstab ===
+
Insert an arbitrary comment such as {{ic|#end of old fstab}} at the end of your {{ic|/mnt/etc/fstab}}. Generate a new fstab file as indicated on [[Installation guide#Fstab]], appending it to the current fstab file. In general, always review the fstab file created by genfstab. In this case, check the older fstab entries before the comment, if they are outdated or duplicates then delete them, and if the old entries remain useful then keep them. For example, mount entries for network drives can be kept. In general it is recommended to use [[Persistent block device naming]].
*using /dev paths: this should change depending on how the new drives are connected to the mainboard, on the BIOS and on the new partitions scheme
 
*using fs labels: should be safe
 
*using UUIDs
 
  
 
=== Reconfigure the bootloader ===
 
=== Reconfigure the bootloader ===
*because of:
+
You might need to reinstall and/or reconfigure the [[Bootloader]] for the following reasons:
**new HDD and partitions configuration
+
* Different disks, partition layout, or filesystem
**new BIOS configuration
+
* Adding [[UEFI]] boot entries into the new mainboard NVRAM
*GRUB allows to edit entries with 'e'
+
* Migration from "MBR boot code" booting to UEFI booting
*use a live system?
+
* Migration from USB to SATA/NVMe
*update framebuffer mode (if new gpu)
+
* Updating the kernel commandline
 +
** In case of a different GPU, update the framebuffer mode
 +
** Update the [[Microcode]] initramfs image
 +
 
 +
If you are using a Arch Linux live environment, then before configuring the bootloader, [[change root]] into the new system:
 +
 
 +
# arch-chroot /mnt
 +
 
 +
Refer to [[Bootloader]] for how to reconfigure your bootloader.
  
 
=== Regenerate kernel image ===
 
=== Regenerate kernel image ===
*initially the Fallback image could work
+
It is recommended to regenerate the initramfs image with [[mkinitcpio]], although initially the fallback initramfs image may work.
*regenerate image
 
**mkinitcpio -p linux
 
 
 
=== Update the graphic drivers ===
 
*if changed driver (e.g. from ATI to NVIDIA) can uninstall the old drivers
 
  
 
=== Reconfigure audio ===
 
=== Reconfigure audio ===
Line 85: Line 116:
  
 
=== Reconfigure network ===
 
=== Reconfigure network ===
*if need to change hostname:
+
If the old installation and the migrated installation shall coexist in the same network, set a new hostname with [[Network configuration#Set the hostname|hostnamectl]].
**[[Network configuration#Set the hostname|hostnamectl]]
+
 
**/etc/hosts
+
Also consider configuration changes that are required after a change in hostname:
**other apps using hostname: synergy, nut (network ups tools)
+
*/etc/hosts
***{{Ic|# grep -Ri 'hostname' /etc}} should give some hints on the files to be updated
+
*other apps using hostname: synergy, nut (network ups tools)
*if using [[dhcpcd]] with named network interfaces:
+
*{{Ic|# grep -Ri 'hostname' /etc}} should give some hints on the files to be updated
** {{Ic|$ dmesg <nowiki>|</nowiki> grep 'renamed from eth'}} might help to find the new interface name
+
 
** remove old {{Ic|# systemctl remove dhcpcd@enp''X''s0.service}}
+
The network interface names may change when using [[dhcpcd]] with named network interfaces.
** activate new {{Ic|# systemctl start dhcpcd@enp''X''s0.service}}
+
* {{Ic|$ dmesg <nowiki>|</nowiki> grep 'renamed from eth'}} might help to find the new interface name
 +
* remove old {{Ic|# systemctl disable dhcpcd@enp''X''s0.service}}
 +
* activate new {{Ic|# systemctl start dhcpcd@enp''X''s0.service}}
  
 
== See also ==
 
== See also ==
*[[Disk cloning]]
 
*[[Migrating Between Architectures Without Reinstalling]]
 
*[[Moving an existing install into (or out of) a virtual machine]]
 
 
*[http://positon.org/clone-a-linux-system-install-to-another-computer Howto clone a linux system]
 
*[http://positon.org/clone-a-linux-system-install-to-another-computer Howto clone a linux system]
 +
*[https://bbs.archlinux.org/viewtopic.php?id=71038]
 +
*[https://bbs.archlinux.org/viewtopic.php?pid=543214]

Latest revision as of 23:08, 17 January 2020

This article discusses the steps required for moving an Arch Linux system to new hardware. The goal is to achieve the same ArchLinux installation, in terms of the installed software and configuration that is independent of the hardware.

Warning: Some of the following instructions can be dangerous: you are advised to backup all of your important data on the old system before continuing.

There are two different approaches to migrating an installation:

  1. Bottom to Top: Install a fresh Arch Linux system on the new hardware, afterwards restore the installed packages and configuration files, e.g. as describedn in dotfiles.
  2. Top to Bottom: Clone the old harddrive to the new harddrive, or place the old harddrive into the new system; modify configuration files where necessary.

The Top to bottom approach gives a more exact reproduction of the original system than the Bottom to Top approach.

Adapt to new hardware

Warning: For both approaches we have to account for differences between the old and hardware and change the installed drivers and configuration accordingly.

Before you begin, research aspects of the new hardware and make a list of differences. Common differences are

Hard drive vs. SSD

See the article SSD.

CPU vendor

If you switch the CPU, to a CPU from another vendor (e.g. Intel to AMD), change the Microcode configuration.

GPU vendor

If you changed the GPU to a GPU from another vendor (e.g. from Amd to NVIDIA) change the graphics driver.

UEFI vs. MBR boot code booting

If you switch to a more recent mainboard with UEFI, it might be preferable or required to switch from "MBR boot code" booting to UEFI booting. In this case an new EFI system partition is needed.

Bottom to Top

On the old system

We define here a minimal configuration that carries over from the old to the new system which differentiates this approach from the Installation guide. Think about the configuration files from /etc and dotfiles in /home that you want to copy to the new system, as well as user data files. If you will not have access to the old system from the new system then backup up all the files that you want to copy over.

List of installed packages

$ pacman -Qqen > pkglist.txt
$ pacman -Qqem > pkglist_aur.txt

gives you a nice list of explicitly installed packages from the repositories and from the AUR. Include it in your backup if you make one.

You may also use the following script to give you a better overview of the binaries and libraries installed unbeknownst to pacman (e. g. installed via Steam, Desura or using their own install methods):

find / -regextype posix-extended -regex "/(sys|srv|proc)|.*/\.ccache/.*" -prune -o -type f \
-exec bash -c 'file "{}" | grep -E "(32|64)-bit"' \; | \
awk -F: '{print $1}' | \
while read -r bin; \
do pacman -Qo "$bin" &>/dev/null || echo "$bin"; \
done

pacman cache

Consider backing up /var/cache/pacman/pkg if you do not change architectures (for example from x86 to x86_64).

On the new system

Installation guide first half

For basics about installing a new system, refer to the Installation guide. Follow the first half of the installation guide up to but excluding the pacstrap command.

Copy pacman cache

Copy the pacman cache found at /var/cache/pacman/pkg from the old to the new system, or from the backup to the new system.

Installation guide second half

Continue with the installation guide from, and including the pacstrap command, up to the end, but do not reboot. Do not skip the pacstrap command as it does additional work besides the installation of packages.

Install previously installed software

Edit pkglist.txt (and pkglist_aur.txt) and remove drivers that are not needed on the new system. Then install any other previously installed software with

# pacman -S --needed - < pkglist.txt

Top to Bottom

There are two options for the Top to Bottom approach, you can either keep the drive where the system is already installed, and modify its contents, or you can copy the system to a new drive. If you keep the drive, and modify it, then place it back into the old system, the modifications will likely prevent the old system from booting.

Clean up the old system

It is also worth to clean up your system before cloning it, as described in System maintenance#Clean the filesystem. Make sure that the old system is still working as expected after the cleanup before moving on.

Copy the system to a new drive

Note: If you are planning to keep the hard drive where the system is already installed, you can skip this section.

There are two fundamental methods for copying the system to a new drive, disk cloning and file copying.

Disk cloning

It is required to use a live linux system rather than the old ArchLinux system; for example you could use the ArchLinux USB flash installation media. The partition layout and filesystems of the old system will be reproduced.

File copying

Transport options

There are many different methods for how to transport the data between the two drives:

  • Connect origin and destination HDDs to the same computer, either the old or the new one. Data link: old HDD -> computer -> new HDD.
  • Make use of temporary storage devices like external HDDs, or cloud backups. Data link: old HDD -> old computer -> storage -> new computer -> new HDD. For an overview see the article System backup.
  • Transfer data over network, for example with rsync. Data link: old HDD -> old computer -> network -> new computer -> new HDD.

For the first two options, consider that you might need adapters to connect the HDDs (PATA->SATA, USB-HDD-Cases, etc.), and choose a connection that is sufficiently fast. The last two options require you to use a live linux system on the new computer, as it is not possible to boot from the new hard drive at this point.

Update fstab

Warning: Before doing this step please make sure that you do not wish to use this drive in the old system, as changing the fstab file will likely prevent the system from booting in the old configuration.

If you are using an Arch Linux Installation Image, mount the new root partition to /mnt, and any other partitions required like you would in a normal install (see Installation guide#Mount the file systems).

Insert an arbitrary comment such as #end of old fstab at the end of your /mnt/etc/fstab. Generate a new fstab file as indicated on Installation guide#Fstab, appending it to the current fstab file. In general, always review the fstab file created by genfstab. In this case, check the older fstab entries before the comment, if they are outdated or duplicates then delete them, and if the old entries remain useful then keep them. For example, mount entries for network drives can be kept. In general it is recommended to use Persistent block device naming.

Reconfigure the bootloader

You might need to reinstall and/or reconfigure the Bootloader for the following reasons:

  • Different disks, partition layout, or filesystem
  • Adding UEFI boot entries into the new mainboard NVRAM
  • Migration from "MBR boot code" booting to UEFI booting
  • Migration from USB to SATA/NVMe
  • Updating the kernel commandline
    • In case of a different GPU, update the framebuffer mode
    • Update the Microcode initramfs image

If you are using a Arch Linux live environment, then before configuring the bootloader, change root into the new system:

# arch-chroot /mnt

Refer to Bootloader for how to reconfigure your bootloader.

Regenerate kernel image

It is recommended to regenerate the initramfs image with mkinitcpio, although initially the fallback initramfs image may work.

Reconfigure audio

  • alsamixer volume
    • save settings

Reconfigure network

If the old installation and the migrated installation shall coexist in the same network, set a new hostname with hostnamectl.

Also consider configuration changes that are required after a change in hostname:

  • /etc/hosts
  • other apps using hostname: synergy, nut (network ups tools)
  • # grep -Ri 'hostname' /etc should give some hints on the files to be updated

The network interface names may change when using dhcpcd with named network interfaces.

  • $ dmesg | grep 'renamed from eth' might help to find the new interface name
  • remove old # systemctl disable dhcpcd@enpXs0.service
  • activate new # systemctl start dhcpcd@enpXs0.service

See also