How to clone an Arch Linux installation
This also works to install Arch on a disk that is to become the system disk of
another computer. This is briefly described
here
, but
there are some additional caveats as well as shortcuts if you already have a
comparable system. To make best use of this, you need an internal or external
enclosure in which you can attach a bare hard disk to your computer (otherwise,
you would have to temporarily build the new system disk into your existing
computer). This is how I have repeatedly created new Arch Linux installations
both at work and at home.
To avoid confusion farther on, let me give names to the three systems involved:
- The target system is the installation we are creating
- The host system is the one to which the new system disk is attached
- The template system is the existing system that is to be cloned
The three systems need not all be different -- for example, the template system
could be the same as the host system. The template system may not exist at
all, if you want to create a new installation rather than clone one. The host
system has to be able to run software on the target system, but otherwise need
not be the same CPU architecture -- for example, it may be an x86_64 system
when you want to create an i686 system.
I will assume you have already partitioned the target disk and created a file
system on the system partition. Then you proceed as follows.
- If you have a template system, copy the packages
/var/cache/pacman/pkg/* and the databases /var/lib/pacman/sync/* from
it to the target disk (after creating the directories).
- Extract (with tar) the following packages to the root of the target
system in the given order, to get a minimal system to work with:
filesystem
bash gawk grep file glibc ncurses readline sed
acl archlinux-keyring attr bzip2 coreutils curl e2fsprogs expat gcc-libs gnupg gpgme keyutils krb5 libarchive libassuan libgpg-error libgcrypt libidn libssh2 lz4 lzo openssl pacman xz zlib
pacman-mirrorlist tar libcap arch-install-scripts util-linux systemd
This list of packages is copied from the shell script
arch-bootstrap.sh
linked from the
Wiki
page
, look there for an up-to-date list.
- If you do not have a template system, you can run the script
arch-bootstrap.sh which downloads the packages above. You have to
customise it before running it: Choose your Arch mirror, target root
directory and system architecture. The script also tries to perform some of
the following steps, but in my experience this never works 100% and has to be
postprocessed manually.
- Select a mirror in /etc/pacman.d/mirrorlist on the target installation
and set the architecture explicitly in /etc/pacman.conf if it is not the
same as the host. Pacman refuses to even install packages from the cache
when no mirror is selected.
- Install the
arch-install-scripts
package on the host. This contains the arch-chroot script which creates
bind mounts for /proc and /dev and others before chroot'ing, which
saves a lot of hassle. If you host runs a different Linux, you could try
downloading the scripts from
here
, but you may
have to make modifications to arch-chroot if it is not completely
compatible.
This
section
describes how to do the necessary bind mounts manually. (One should
mention that --rbind mounts are next to impossible to unmount again
— try something like grep <mountpoint> /proc/mounts | awk '{ print
$2; }' | sort -ru | while read m ; umount -n $m ; done or be prepared to
reboot.)
- arch-chroot into the target system (as root). Alternatively run the
commands below without chroot but with the --sysroot option of pacman
and the --gpgdir option of pacman-key.
- Initialise pacman's keyring:
pacman-key --init
pacman-key --populate archlinux
- Run pacman -S --overwrite \* ... to reinstall the packages we unpacked
manually above, except for pacman and arch-install-scripts.
- Again select your mirror in /etc/pacman.d/mirrorlist as this was
overwritten by reinstalling pacman-mirrorlist.
- Reinstall the remaining two packages pacman -S --overwrite \* pacman
arch-install-scripts.
- Set the architecture in /etc/pacman.conf again if not the same as the
host.
- Make a list of the packages installed on the template system:
pacman -Qneq | sort > /root/tmp/explicit-packages
pacman -Qndq | sort > /root/tmp/depend-packages
The list of dependency packages may not be strictly necessary. It helps
recreate exactly the same system in case you came to rely on a dependency
package that is not needed by an explicitly installed package any more and
would therefore not be installed automatically. The sorting is also not
necessary, but allows to compare lists with diff between different
systems or times.
- Install these packages on the target system after transferring the lists to
somewhere on the target system:
cat /root/tmp/explicit-packages | pacman -S --needed -
cat /root/tmp/depend-packages | pacman -S --needed --asdeps -
The --needed prevents reinstallation of packages we installed already.
As noted above, installing the dependency packages may be redundant. (The
pacman commands above are from the commendable Wiki page
"pacman tips"
.)
- Copy configuration files from the template system and/or configure
/etc/fstab, /etc/hostname, /etc/localtime, /etc/locale.gen,
/etc/locale.conf, /etc/vconsole.conf manually as described
here
.
- Install the bootloader, for example by running syslinux-install_update -i
-a -m for syslinux (still from the chroot) as described
on its Wiki page
.
- Run mkinitcpio -p linux from the chroot.
- ... (More configuration and installation that may be more comfortable from
the host system.)
- Attach the target system disk to the target hardware.
- When booting the new box for the first time, boot into "Arch Linux
Fallback". mkinitcpio minimises the normal "Arch Linux" boot to contain
only drivers needed for the system on which it is run, i.e. the host system
in our case.
- Rerun mkinitcpio -p linux on the target system to get a working and
fast-booting normal boot option.
- ... (More configuration and installation on the target system)
TOS / Impressum