Difference between revisions of "Install from existing Linux"

From ArchWiki
Jump to: navigation, search
m (Method 4: Install pacman natively on non-arch distro (advanced))
(use https link)
 
(212 intermediate revisions by 70 users not shown)
Line 1: Line 1:
 
[[Category:Getting and installing Arch]]
 
[[Category:Getting and installing Arch]]
[[de:Schnellinstallation von einem bestehenden Linuxsystem]]
+
[[es:Install from existing Linux]]
[[es:Install from Existing Linux]]
+
 
[[fr:Install chroot]]
 
[[fr:Install chroot]]
[[it:Install from Existing Linux]]
+
[[it:Install from existing Linux]]
[[ru:Install from Existing Linux]]
+
[[ja:既存の Linux からインストール]]
[[uk:Install from Existing Linux]]
+
[[pt:Install from existing Linux]]
[[zh-CN:Install from Existing Linux]]
+
[[ru:Install from existing Linux]]
[[zh-TW:Install from Existing Linux]]
+
[[uk:Install from existing Linux]]
This guide is intended for anybody who wants to install Arch Linux from any other running Linux -- be it off a LiveCD or a pre-existing install of a different distro.
+
[[zh-cn:Install from existing Linux]]
 +
[[zh-tw:Install from existing Linux]]
 +
{{Related articles start}}
 +
{{Related|Install from SSH}}
 +
{{Related articles end}}
  
This is useful for:
+
This document describes the bootstrapping process required to install Arch Linux from a running Linux host system.
* remotely installing Archlinux (e.g. a (virtual) root server)
+
After bootstrapping, the installation proceeds as described in the [[Installation guide]].
* creating a new linux distribution or LiveCD based on Archlinux
+
 
* creating an Archlinux chroot environments
+
Installing Arch Linux from a running Linux is useful for:
 +
 
 +
* remotely installing Arch Linux, e.g. a (virtual) root server
 +
* replacing an existing Linux without a LiveCD (see [[#Replacing the existing system without a LiveCD]])
 +
* creating a new Linux distribution or LiveCD based on Arch Linux
 +
* creating an Arch Linux chroot environment, e.g. for a Docker base container
 
* [[Diskless_network_boot_NFS_root|rootfs-over-NFS for diskless machines]]
 
* [[Diskless_network_boot_NFS_root|rootfs-over-NFS for diskless machines]]
  
This guide requires that the existing host system be able to execute the new target Arch Linux architecture programs.  In the case of an x86_64 host, it is possible to use i686-pacman to build a 32-bit chroot environment.  See [[Arch64 Install bundled 32bit system]].  However it is not so easy to build a 64-bit environment when the host only supports running 32-bit programs.
+
The goal of the bootstrapping procedure is to setup an environment from which the scripts from {{Pkg|arch-install-scripts}} (such as {{ic|pacstrap}} and {{ic|arch-chroot}}) can be run.
  
{{Note|If you are already using Arch, instead of following this guide, just install {{Pkg|arch-install-scripts}} from the [[Official Repositories|official repositories]] and follow the [[Installation Guide]]}}
+
If the host system runs Arch Linux, this can be achieved by simply installing {{Pkg|arch-install-scripts}}. If the host system runs another Linux distribution, you will first need to set up an Arch Linux-based chroot.
  
'''This guide provides additional steps to the [[Installation Guide]]. The steps of that guide must still be followed as needed.'''
+
{{Note|This guide requires that the existing host system be able to execute the new target Arch Linux architecture programs. In the case of an x86_64 host, it is possible to use i686-pacman to build a 32-bit chroot environment. See [[Arch64 Install bundled 32bit system]]. However it is not so easy to build a 64-bit environment when the host only supports running 32-bit programs.}}
  
==Prepare the system==
+
{{Warning|Please make sure you understand each step before proceeding. It is easy to destroy your system or to lose critical data, and your service provider will likely charge a lot to help you recover. }}
  
Follow the [[Installation Guide]] steps, until you have your partitions, keyboard and internet connection ready.
+
==Backup and Preparation==
 +
Backup all your data including mails, webservers, etc. Have all information at your fingertips. Preserve all your server configurations, hostnames, etc.
  
==Setup the environment for pacman==
+
Here is a list of data you will likely need:
 +
* IP address
 +
* hostname(s), (note: rootserver are mostly also part of the providers domain, check or save your {{ic|/etc/hosts}} before you delete)
 +
* DNS server (check {{ic|/etc/resolv.conf}})
 +
* SSH keys (if other people work on your server, they will have to accept new keys otherwise. This includes keys from your Apache, your mail servers, your SSH server and others.)
 +
* Hardware info (network card, etc. Refer to your pre-installed {{ic|/etc/modules.conf}} )
 +
* Grub configuration files.
  
You need to create an environment where ''pacman'' and the ''arch install scripts'' can run on your current linux distro. (If you choose the Method 1, only pacman is necessary)
+
In general, it is a good idea to have a local copy of your original {{ic|/etc}} directory on your local hard drive.
  
There are in principle two different methods to prepare that environment: either by '''installing pacman natively (Method 4 below)''' on your linux distro or by setting up a '''chroot environment'''.
+
== From a host running Arch Linux ==
The latter way will generally be easier and is discussed next:
+
  
There are two possible ways of using the ''chroot'' method:
+
Install the {{Pkg|arch-install-scripts}} package.
* '''Using chroot as an installation environment''': The prepared Archlinux chroot environment will be used temporarily to set up the actual Archlinux installation using the ''arch-install-scripts''. This is a bit more work and takes longer but once you set up the installation system you can quickly install several Archlinux systems. '''However''', if you want to set up only a single Archlinux this might be overkill. You are actually setting up the system twice, have a lot more network traffic and especially need a lot more RAM, mostly due to the quite big iso image.
+
  
* '''Installing Archlinux directly/Direct Bootstrapping''': Thanks to tokland's ''arch-bootstrap'' script this method is effectively a one-liner and very fast. After that one line of code your Archlinux base system is installed to disk. '''However''', if setting up multiple copies of Archlinux, this method requires the re-downloading of the base packages every time, so is slower.
+
Follow [[Installation guide#Mount the partitions]]. If you already use the {{ic|/mnt}} directory for something else, just create another directory such as {{ic|/mnt/install}}, and use that instead.
  
The best advice is probably to use '''Direct bootstrapping''' to set up only a small number of systems. If you set up many Archlinux systems the '''chroot install environment''' or even the '''native pacman''' installation might suit you better.
+
Then follow [[Installation guide#Installation]]. You can skip [[Installation guide#Select the mirrors]], since the host should already have a correct mirrorlist.
  
===Method 1: Chroot into LiveCD-image===
+
{{Tip|In order to avoid redownloading all the packages, consider following [[Pacman/Tips and tricks#Network shared pacman cache]] or using ''pacstrap'''s {{ic|-c}} option.}}
  
This is the prefered method.
+
{{Merge|Moving_an_existing_install_into_(or_out_of)_a_virtual_machine#Moving_into_a_VM|Same approach.}}
  
It is possible to mount the root image of the latest Archlinux installation media and then chroot into it. This method has the advantage of providing you with a working Arch Linux installation right within your host system without the need to prepare it by installing specific packages.
+
{{Note|If you only want to create an exact copy of an existing Arch installation, it is also possible to just copy the filesystem to the new partition. With this method, you will still need to
  
{{Note|Before proceeding, make sure the latest version of {{Pkg|squashfs-tools}} is installed on the host system. Otherwise you will get errors like: {{ic|FATAL ERROR aborting: uncompress_inode_table: failed to read block}}.}}
+
* Create [[Installation guide#Fstab|{{ic|/etc/fstab}}]] and edit {{ic|/etc/hostname}}
 +
* Delete {{ic|/etc/machine-id}} so that a new, unique, one will be regenerated on boot
 +
* Make any other changes appropriate to the installation medium
 +
* Install the bootloader
  
* Download the lastest installation CD image from https://www.archlinux.org/download/
+
When copying the filesystem root, use something like {{ic|cp -ax}} or {{ic|rsync -axX}}. This avoids copying contents of mountpoints ({{ic|-x}}), and preserves the [[capabilities]] attributes of some system binaries ({{ic|rsync -X}}).
 +
}}
  
* Mount the Live CD image:
+
== From a host running another Linux distribution ==
{{bc|# mount -o loop archlinux-{date}-dual.iso /mnt}}
+
  
* The root image exists in [[Wikipedia:Squashfs|squashfs format]] on the Live CD. The squashfs format is not editable as such. Hence, we unsquash the root image and then mount it.
+
There are multiple tools which automate a large part of the steps described in the following subsections. See their respective homepages for detailed instructions.
  
To unsquash the x86_64 (or i686 respectively) root image, run
+
* [https://github.com/tokland/arch-bootstrap arch-bootstrap] (Bash)
{{bc|# unsquashfs -d /squashfs-root /mnt/arch/x86_64/root-image.fs.sfs}}
+
* [https://github.com/hartwork/image-bootstrap image-bootstrap] (Python)
 +
* [https://github.com/drizzt/vps2arch vps2arch] (Bash)
 +
* [https://github.com/m4rienf/ArchCX archcx] (Bash, from Hetzner CX Rescue System)
  
* Now you can unmount and remove the iso image
+
The manual way is presented in the following subsections. The idea is to run an Arch system inside the host system, with the actual installation being executed from the Arch system. The nested system is contained inside a chroot.
 +
 
 +
=== Creating the chroot ===
 +
 
 +
Two methods to setup and enter the chroot are presented below, from the easiest to the most complicated. Select only one of the two methods. Then, continue at [[#Using the chroot environment]].
 +
 
 +
==== Method A: Using the bootstrap image (recommended) ====
 +
 
 +
Download the bootstrap image from a [https://www.archlinux.org/download mirror]:
 +
# cd /tmp
 +
# curl -O https://mirrors.kernel.org/archlinux/iso/2016.09.03/archlinux-bootstrap-2016.09.03-x86_64.tar.gz
 +
 
 +
You can also download the signature (same URL with {{ic|.sig}} added) and [[GnuPG#Verify_a_signature|verify it with GnuPG]].
 +
 
 +
Extract the tarball:
 +
# tar xzf <path-to-bootstrap-image>/archlinux-bootstrap-2016.09.03-x86_64.tar.gz
 +
 
 +
Select a repository server by editing {{ic|/tmp/root.x86_64/etc/pacman.d/mirrorlist}}.
 +
 
 +
{{Note|If bootstrapping an i686 image from an x86_64 host system, also edit {{Ic|/tmp/root.i686/etc/pacman.conf}} and explicitly define {{Ic|1=Architecture = i686}} in order for pacman to pull the proper i686 packages.}}
 +
 
 +
Enter the chroot
 +
 
 +
* If bash 4 or later is installed, and unshare supports the --fork and --pid options:
 +
# /tmp/root.x86_64/bin/arch-chroot /tmp/root.x86_64/
 +
* Otherwise, run the following commands:
 +
# mount --bind /tmp/root.x86_64 /tmp/root.x86_64
 +
# cd /tmp/root.x86_64
 +
# cp /etc/resolv.conf etc
 +
# mount -t proc /proc proc
 +
# mount --rbind /sys sys
 +
# mount --rbind /dev dev
 +
# mount --rbind /run run    # (assuming /run exists on the system)
 +
# chroot /tmp/root.x86_64 /bin/bash
 +
 
 +
==== Method B: Using the LiveCD image ====
 +
 
 +
It is possible to mount the root image of the latest Arch Linux installation media and then chroot into it.  This method has the advantage of providing a working Arch Linux installation right within the host system without the need to prepare it by installing specific packages.
 +
 
 +
{{Note|Before proceeding, make sure the latest version of [http://squashfs.sourceforge.net/ squashfs] is installed on the host system. Otherwise, errors like the following are to be expected: {{ic|FATAL ERROR aborting: uncompress_inode_table: failed to read block}}.}}
 +
 
 +
* The root image can be found on one of the [https://www.archlinux.org/download mirrors] under either arch/x86_64/ or arch/i686/, depending on the desired architecture. The squashfs format is not editable, so we unsquash the root image and mount it.
 +
 
 +
*To unsquash the root image, run
 +
{{bc|# unsquashfs airootfs.sfs}}
 +
 
 +
* Before [[Change root|chrooting]] to it, we need to set up some mount points and copy the resolv.conf for networking.
 
{{bc|
 
{{bc|
# umount /mnt
+
# mount --bind squashfs-root squashfs-root
# rm archlinux-{date}-dual.iso
+
# mount -t proc none squashfs-root/proc
 +
# mount -t sysfs none squashfs-root/sys
 +
# mount -o bind /dev squashfs-root/dev
 +
# mount -o bind /dev/pts squashfs-root/dev/pts  ## important for pacman (for signature check)
 +
# cp -L /etc/resolv.conf squashfs-root/etc  ## this is needed to use networking within the chroot
 
}}
 
}}
  
* Now you can loop mount the root image
+
* Now, everything is prepared to chroot into the newly installed Arch environment
{{bc|# mount -o loop /squashfs-root/root-image.fs /arch}}
+
{{bc|# chroot squashfs-root bash}}
  
* Before [[Change Root|chrooting]] to it, we need to set up some mount points.
+
=== Using the chroot environment ===
 +
 
 +
The bootstrap environment is really barebones (no {{ic|nano}}, no {{ic|ping}}, no {{ic|cryptsetup}}, no {{ic|lvm}}). Therefore, we need to set up [[pacman]] in order to download the rest of the {{ic|base}} and, if needed, {{ic|base-devel}}.
 +
 
 +
==== Initializing pacman keyring ====
 +
 
 +
Before starting the installation, pacman keys need to be setup. Before running the following two commands, read [[pacman-key#Initializing the keyring]] to understand the entropy requirements:
 
{{bc|
 
{{bc|
# mount -t proc none /arch/proc
+
# pacman-key --init
# mount -t sysfs none /arch/sys
+
# pacman-key --populate archlinux
# mount -o bind /dev /arch/dev
+
# mount -o bind /dev/pts /arch/dev/pts # important for pacman (for signature check)
+
 
}}
 
}}
  
* Now everything is prepared to chroot into your newly installed Arch environment
+
{{Tip|Installing and running {{Pkg|haveged}} must be done on the host system, since it is not possible to install packages before initializing pacman keyring and because ''systemd'' will detect it is running in a chroot and [https://superuser.com/questions/688733/start-a-systemd-service-inside-chroot ignore activation request].
{{bc|# chroot /arch bash}}
+
  
This chroot is able to execute the arch install scripts. The destination partitions should be mounted under the {{ic|/mnt}} directory from this chroot.
+
If you go with doing {{ic|ls -Ra /}} in another console (TTY, terminal, SSH session...), do not be afraid of running it in a loop a few times: five or six runs from the host proved sufficient to generate enough entropy on a remote headless server.}}
  
===Method 2: Bootstrapping the arch installation scripts===
+
==== Selecting a mirror and downloading basic tools ====
  
Contrary to the other methods, '''this method is one-step only'''; you only have to execute the script below and thats it.
+
After [[Mirrors#Enabling_a_specific_mirror|selecting a mirror]], [[Mirrors#Force_pacman_to_refresh_the_package_lists|refresh the package lists]] and [[install]] what you need: {{Grp|base}}, {{Grp|base-devel}}, {{Pkg|parted}} etc.
  
This method can be considered an hybrid between Method 1 and Method 2. It provides a chroot enviroment from where to execute the arch install scripts (similar to Method 2), by using a bootstrapping script (similar to Method 1).
+
=== Installation tips ===
  
The script below is going to create a directory called {{ic|archinstall-pkg}} and download the required packages there. Then, is going to extract them into the {{ic|archinstall-chroot}} directory. Finally, is going to prepare mount points, configure pacman and enter into a chroot.
+
You can now proceed to [[Installation_guide#Partition_the_disks]] and follow the rest of the [[Installation guide]].
{{Note|This is '''only''' an enviroment to execute the arch install scripts: '''this is not your final installation'''. }}
+
  
This chroot is able to execute the arch install scripts. '''The destination partitions should be mounted under the {{ic|/mnt}} directory from this chroot'''. After that, continue with the next step, which is [[#Fix the Pacman Signature Keyring]].
+
Some host systems or configurations may require certain extra steps. See the sections below for tips.
  
{{hc|archinstall-bootstrap.sh|<nowiki>
+
===== Debian-based host =====
#!/bin/bash
+
# This script is inspired on the archbootstrap script.
+
  
PACKAGES=(acl attr bzip2 curl expat glibc gpgme libarchive libassuan libgpg-error libssh2 openssl pacman xz zlib pacman-mirrorlist coreutils bash grep gawk file tar ncurses readline libcap util-linux pcre arch-install-scripts)
+
====== /dev/shm ======
# Change the mirror as necessary
+
MIRROR='http://mirrors.kernel.org/archlinux'
+
# You can set the ARCH variable to i686 or x86_64
+
ARCH=`uname -m`
+
LIST=`mktemp`
+
CHROOT_DIR=archinstall-chroot
+
DIR=archinstall-pkg
+
mkdir -p "$DIR"
+
mkdir -p "$CHROOT_DIR"
+
# Create a list with urls for the arch packages
+
for REPO in core community extra; do 
+
        wget -q -O- "$MIRROR/$REPO/os/$ARCH/" |sed  -n "s|.*href=\"\\([^\"]*\\).*|$MIRROR\\/$REPO\\/os\\/$ARCH\\/\\1|p"|grep -v 'sig$'|uniq >> $LIST 
+
done
+
# Download and extract each package.
+
for PACKAGE in ${PACKAGES[*]}; do
+
        URL=`grep "$PACKAGE-[0-9]" $LIST|head -n1`
+
        FILE=`echo $URL|sed 's/.*\/\([^\/][^\/]*\)$/\1/'`
+
        wget "$URL" -c -O "$DIR/$FILE"
+
        xz -dc "$DIR/$FILE" | tar x -k -C "$CHROOT_DIR"
+
done
+
# Create mount points
+
mkdir -p "$CHROOT_DIR/dev" "$CHROOT_DIR/proc" "$CHROOT_DIR/sys" "$CHROOT_DIR/mnt"
+
mount -t proc proc "$CHROOT_DIR/proc/"
+
mount -t sysfs sys "$CHROOT_DIR/sys/"
+
mount -o bind /dev "$CHROOT_DIR/dev/"
+
mkdir -p "$CHROOT_DIR/dev/pts"
+
mount -t devpts pts "$CHROOT_DIR/dev/pts/"
+
  
# Hash for empty password  Created by doing: openssl passwd -1 -salt ihlrowCo and entering an empty password (just press enter)
+
On some Debian-based host systems, {{ic|pacstrap}} may produce the following error:
echo 'root:$1$ihlrowCo$sF0HjA9E8up9DYs258uDQ0:10063:0:99999:7:::' > "$CHROOT_DIR/etc/shadow"
+
echo "root:x:0:0:root:/root:/bin/bash" > "$CHROOT_DIR/etc/passwd"
+
touch "$CHROOT_DIR/etc/group"
+
echo "myhost" > "$CHROOT_DIR/etc/hostname"
+
test -e "$CHROOT_DIR/etc/mtab" || echo "rootfs / rootfs rw 0 0" > "$CHROOT_DIR/etc/mtab"
+
[ -f "/etc/resolv.conf" ] && cp "/etc/resolv.conf" "$CHROOT_DIR/etc/"
+
sed -ni '/^[ \t]*CheckSpace/ !p' "$CHROOT_DIR/etc/pacman.conf"
+
sed -i "s/^[ \t]*SigLevel[ \t].*/SigLevel = Never/" "$CHROOT_DIR/etc/pacman.conf"
+
echo "Server = $MIRROR/\$repo/os/$ARCH" >> "$CHROOT_DIR/etc/pacman.d/mirrorlist"
+
  
chroot $CHROOT_DIR /usr/bin/pacman -Sy
+
{{hc|# pacstrap /mnt base|
chroot $CHROOT_DIR /bin/bash
+
==> Creating install root at /mnt
</nowiki>}}
+
mount: mount point /mnt/dev/shm is a symbolic link to nowhere
 +
==> ERROR: failed to setup API filesystems in new root
 +
}}
  
===Method 3: Install pacman natively on non-arch distro (advanced)===
+
This is because in some versions of Debian, {{ic|/dev/shm}} points to {{ic|/run/shm}} while in the Arch-based chroot, {{ic|/run/shm}} does not exist and the link is broken. To correct this error, create a directory {{ic|/run/shm}}:
{{Warning|This method is potentially difficult, your mileage may vary from distro to distro. If you just want to do an arch installation from another distro and you are not interested in have pacman as a regular program under such distro, is better to use a different method.}}
+
# mkdir /run/shm
  
This method is about installing pacman and the arch install scripts directly under another distro, so they become regular programs on that distro.
+
====== /dev/pts ======
 +
 
 +
While installing {{ic|archlinux-2015.07.01-x86_64}} from a Debian 7 host, the following error prevented both [https://projects.archlinux.org/arch-install-scripts.git/tree/pacstrap.in pacstrap] and [[Change_root#Using_arch-chroot|arch-chroot]] from working:
 +
 
 +
{{hc|# pacstrap -i /mnt|
 +
mount: mount point /mnt/dev/pts does not exist
 +
==> ERROR: failed to setup chroot /mnt
 +
}}
 +
 
 +
Apparently, this is because these two scripts use a common function. {{ic|chroot_setup()}}[https://projects.archlinux.org/arch-install-scripts.git/tree/common#n76] relies on newer features of {{Pkg|util-linux}}, which are incompatible with Debian 7 userland (see {{Bug|45737}}).
 +
 
 +
The solution for ''pacstrap'' is to manually execute its [https://projects.archlinux.org/arch-install-scripts.git/tree/pacstrap.in#n77 various tasks], but use the [[Change_root#Using_chroot|regular procedure]] to mount the kernel filesystems on the target directory ({{ic|"$newroot"}}):
 +
 
 +
{{bc|1=
 +
# newroot=/mnt
 +
# mkdir -m 0755 -p "$newroot"/var/{cache/pacman/pkg,lib/pacman,log} "$newroot"/{dev,run,etc}
 +
# mkdir -m 1777 -p "$newroot"/tmp
 +
# mkdir -m 0555 -p "$newroot"/{sys,proc}
 +
# mount --bind "$newroot" "$newroot"
 +
# mount -t proc /proc "$newroot/proc"
 +
# mount --rbind /sys "$newroot/sys"
 +
# mount --rbind /run "$newroot/run"
 +
# mount --rbind /dev "$newroot/dev"
 +
# pacman -r "$newroot" --cachedir="$newroot/var/cache/pacman/pkg" -Sy base base-devel ... ## add the packages you want
 +
# cp -a /etc/pacman.d/gnupg "$newroot/etc/pacman.d/"      ## copy keyring
 +
# cp -a /etc/pacman.d/mirrorlist "$newroot/etc/pacman.d/"  ## copy mirrorlist
 +
}}
 +
 
 +
Instead of using {{ic|arch-chroot}} for [[Installation guide#Chroot]], simply use {{ic|chroot "$newroot"}}.
 +
 
 +
====== lvmetad ======
 +
 
 +
Trying to create [[LVM]] [[LVM#Logical_volumes|logical volumes]] from an {{ic|archlinux-bootstrap-2015.07.01-x86_64}} environment on a Debian 7 host resulted in the following error:
 +
 
 +
{{hc|# lvcreate -L 20G lvm -n root|
 +
  /run/lvm/lvmetad.socket: connect failed: No such file or directory
 +
  WARNING: Failed to connect to lvmetad. Falling back to internal scanning.
 +
  /dev/lvm/root: not found: device not cleared
 +
  Aborting. Failed to wipe start of new LV.}}
 +
 
 +
(Physical volume and volume group creation worked despite {{ic|/run/lvm/lvmetad.socket: connect failed: No such file or directory}} being displayed.)
 +
 
 +
This could be easily worked around by creating the logical volumes outside the chroot (from the Debian host). They are then available once chrooted again.
 +
 
 +
{{Accuracy|This problem did not arise when installing from a Debian 7 host without lvmetad enabled. The recommended messaround with {{ic|/etc/lvm/lvm.conf}} looks rather error prone (2015-07-26).}}
 +
{{Style|Language and formatting are lacking, links to relevant articles in the wiki as well.}}
 +
 
 +
Also, if the system you are using has lvm, you might have the following output:
 +
 
 +
{{hc|1=# grub-install --target=i386-pc --recheck /dev/mapper/main-archroot|2=
 +
Installing for i386-pc platform.
 +
  /run/lvm/lvmetad.socket: connect failed: No such file or directory
 +
  WARNING: Failed to connect to lvmetad. Falling back to internal scanning.
 +
  /run/lvm/lvmetad.socket: connect failed: No such file or directory
 +
  WARNING: Failed to connect to lvmetad. Falling back to internal scanning.
 +
  /run/lvm/lvmetad.socket: connect failed: No such file or directory
 +
  WARNING: Failed to connect to lvmetad. Falling back to internal scanning.
 +
  /run/lvm/lvmetad.socket: connect failed: No such file or directory
 +
  WARNING: Failed to connect to lvmetad. Falling back to internal scanning.
 +
  /run/lvm/lvmetad.socket: connect failed: No such file or directory
 +
  WARNING: Failed to connect to lvmetad. Falling back to internal scanning.
 +
}}
  
This is really useful if you are planning to use another distro regularly to install arch linux, or do fancy things like updating packages of an arch installation using another distro. This is the only method that not imply creating a chroot to be able to execute pacman and the arch install scripts. (but since part of the installation includes entering inside a chroot, you'll end using a chroot anyway)
+
This is because debian does not use lvmetad by default. You need to edit {{ic|/etc/lvm/lvm.conf}} and set {{ic|use_lvmetad}} to {{ic|0}}:
  
==== Download pacman source code and pacman packages ====
+
use_lvmetad = 0
Visit the pacman homepage: https://www.archlinux.org/pacman/#_releases and download the latest release.
+
  
Now, download the following packages:
+
This will trigger later an error on boot in the initrd stage. Therefore, you have to change it back after the grub generation. In a software RAID + LVM, steps would be the following:
  
* pacman-mirrorlist: https://www.archlinux.org/packages/core/any/pacman-mirrorlist/download/
+
* After installing all the system, when you have to do all the initramfs (mkinitcpio) and grub thing.
* arch-install-scripts: https://www.archlinux.org/packages/extra/any/arch-install-scripts/download/
+
* Change /etc/mdadm.conf to reflect your RAID config (if any)
* pacman (necessary for the config files): https://www.archlinux.org/packages/core/x86_64/pacman/download/ (change x86_64 as necessary)
+
* Change HOOKS and MODULES according to lvm and raid requirements: {{ic|1=MODULES="dm_mod" HOOKS="base udev '''mdadm_udev''' ... block '''lvm2''' filesystems ..."}}
 +
* Generate initrd images with mkinitcpio
 +
* Change /etc/lvm/lvm.conf to put use_lvmetad = 0
 +
* Generate grub config (grub-mkconfig)
 +
* Change /etc/lvm/lvm.conf to put use_lvmetad = 1
  
==== Install dependencies ====
+
===== Fedora-based host =====
Using your distribution mechanisms, install the required packages for pacman and the arch install scripts. libcurl, libarchive, fakeroot, xz, asciidoc, wget, and sed are among them. Of course, gcc, make and maybe some other "devel" packages are necessary too.
+
  
==== Compile pacman ====
+
On Fedora based hosts and live USBs you may encounter problems when using {{ic|genfstab}} to generate your [[fstab]]. Remove duplicate entries and the "seclabel" option where it appears, as this is Fedora-specific and will keep your system from booting normally.
  
* Decompress the pacman source code and cd inside.
+
== Things to check before you reboot==
* Execute configure, adapting the paths as necessary: {{bc|<nowiki> ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --enable-doc</nowiki>}}
+
If you get errors here, chances are you are missing dependencies, or your current libcurl, libarchive or others, are too old. Install the dependencies missing using your distro options, or if they are too old, compile them from source.
+
* Compile {{bc|make}}
+
* If there were no errors, install the files {{bc|make install}}
+
* You may need to manually call {{ic|ldconfig}} to make your distro detect libalpm.
+
==== Prepare configuration files ====
+
Now is time to extract the configuration files. Change the x86_64 as necessary.
+
* Extract the pacman.conf and makepkg.conf files from the pacman package, and disable signature checking: {{bc|<nowiki>tar xJvf pacman-*-x86_64.pkg.tar.xz etc -C / ; sed -i 's/SigLevel.*/SigLevel = Never/g' /etc/pacman.conf</nowiki>}}
+
* Extract the mirror list: {{bc|tar xJvf pacman-mirrorlist-*-any.pkg.tar.xz -C /}}
+
* Enable some mirrors on {{ic|/etc/pacman.d/mirrorlist}}
+
* Extract the arch-install-scripts {{bc|tar xJvf arch-install-scripts-*-any.pkg.tar.xz -C /}}
+
  
Another option is using the {{ic|alien}} tool to convert the {{ic|pacman-mirrorlist}} and {{ic|arch-install-scripts}} (but no {{ic|pacman}}) to native packages of your distro.
+
Before rebooting, chroot into the newly-installed system.
  
==Fix the Pacman Signature Keyring==
+
Set a root password so that you can log in with ssh later:
 +
# passwd
  
It is necessary to initialize ''pacman's'' keyring for signature checking.
+
Install [[ssh]] and [[enable]] it to start automatically at boot.
  
This is done using
+
Configure the [[network]] connection to start automatically at boot.
# pacman-key --init # read the note below!
+
# pacman-key --populate archlinux
+
  
'''However''', when connected via SSH you might run out of [http://en.wikipedia.org/wiki/Entropy_(computing) entropy]. In this case you can try something like
+
Set up a [[boot loader]] and configure it to use the swap partition you appropriated earlier as the root partition. You might want to configure your bootloader to be able to boot into your old system; it is helpful to re-use the server's existing /boot partition in the new system for this purpose.
  
# cat /usr/bin/* > /dev/null &
+
== Replacing the existing system without a LiveCD ==
# find / > /dev/null &
+
  
before executing {{ic|pacman-key --init}}.
+
Find ~700MB of free space somewhere on the disk, e.g. by partitioning a swap partition. You can disable the swap partition and set up your system there.  
  
It might take some time. If nevertheless all this does help install {{Pkg|haveged}} and run prior to {{ic|pacman-key --init}}
+
===Set old swap partition as new root partition===
# /usr/sbin/haveged -w 1024 -v 1
+
  
 +
Check {{ic|cfdisk}}, {{ic|/proc/swaps}} or {{ic|/etc/fstab}} to find your swap partition. Assuming your hard drive is located on sdaX (X will be a number).
  
==Setup the target system==
+
Do the following:
  
At this point, follow the normal steps of [[Installation Guide]]. Remember to mount the destination partition under the {{ic|/mnt}} of the chroot.
+
Disable the swap space:
 +
# swapoff /dev/sdaX
  
  # pacstrap /mnt base base-devel
+
Create a filesystem on it
  # # ...
+
  # fdisk /dev/sda
 +
(set /dev/sdaX ID field to "Linux" - Hex 83)
 +
  # mke2fs -j /dev/sdaX
  
===Edit the fstab file===
+
Create a directory to mount it in
 +
# mkdir /mnt/newsys
  
Probably the {{ic|genfstab}} script won't work. In that case, you'll need to edit the {{ic|/mnt/etc/fstab}} file by hand.
+
Finally, mount the new directory for installing the intermediate system.
You can use the content of {{ic|/etc/mtab}} as reference.
+
# mount -t ext4 /dev/sdaX /mnt/newsys
  
===Finish the Installation===
+
=== Installation ===
Now just do the rest of the steps normally.
+
If less than 700MB are available, examine the packages in the group base, and select only those required to get a system with internet connection up and running in the temporary partition. This will mean explicitly specifying individual packages to pacstrap, as well as passing it the -c option, to get packages downloaded to the host system to avoid filling up valuable space.
  
==Tips and tricks==
+
Once the new Arch Linux system is installed, reboot into the newly created system, and [[Full system backup with rsync#With_a_single_command|rsync the entire system]] to the primary partition.
* In case you want to replace an existing system, but can for some reason not use a LiveCD, since, e.g., you have no physical access to the computer, the following tip might help: If you manage to get ~500MB of free space somewhere on the disk (e.g. by partitioning a swap partition) you can install the new Archlinux system there, reboot into the newly created system and [[Full_System_Backup_with_rsync#With_a_single_command|rsync the entire system]] to the primary partition. Finally don't forget to fix the bootloader configuration before rebooting.
+
Fix the bootloader configuration before rebooting.

Latest revision as of 17:14, 4 September 2016

Related articles

This document describes the bootstrapping process required to install Arch Linux from a running Linux host system. After bootstrapping, the installation proceeds as described in the Installation guide.

Installing Arch Linux from a running Linux is useful for:

The goal of the bootstrapping procedure is to setup an environment from which the scripts from arch-install-scripts (such as pacstrap and arch-chroot) can be run.

If the host system runs Arch Linux, this can be achieved by simply installing arch-install-scripts. If the host system runs another Linux distribution, you will first need to set up an Arch Linux-based chroot.

Note: This guide requires that the existing host system be able to execute the new target Arch Linux architecture programs. In the case of an x86_64 host, it is possible to use i686-pacman to build a 32-bit chroot environment. See Arch64 Install bundled 32bit system. However it is not so easy to build a 64-bit environment when the host only supports running 32-bit programs.
Warning: Please make sure you understand each step before proceeding. It is easy to destroy your system or to lose critical data, and your service provider will likely charge a lot to help you recover.

Backup and Preparation

Backup all your data including mails, webservers, etc. Have all information at your fingertips. Preserve all your server configurations, hostnames, etc.

Here is a list of data you will likely need:

  • IP address
  • hostname(s), (note: rootserver are mostly also part of the providers domain, check or save your /etc/hosts before you delete)
  • DNS server (check /etc/resolv.conf)
  • SSH keys (if other people work on your server, they will have to accept new keys otherwise. This includes keys from your Apache, your mail servers, your SSH server and others.)
  • Hardware info (network card, etc. Refer to your pre-installed /etc/modules.conf )
  • Grub configuration files.

In general, it is a good idea to have a local copy of your original /etc directory on your local hard drive.

From a host running Arch Linux

Install the arch-install-scripts package.

Follow Installation guide#Mount the partitions. If you already use the /mnt directory for something else, just create another directory such as /mnt/install, and use that instead.

Then follow Installation guide#Installation. You can skip Installation guide#Select the mirrors, since the host should already have a correct mirrorlist.

Tip: In order to avoid redownloading all the packages, consider following Pacman/Tips and tricks#Network shared pacman cache or using pacstrap's -c option.

Merge-arrows-2.pngThis article or section is a candidate for merging with Moving_an_existing_install_into_(or_out_of)_a_virtual_machine#Moving_into_a_VM.Merge-arrows-2.png

Notes: Same approach. (Discuss in Talk:Install from existing Linux#)
Note: If you only want to create an exact copy of an existing Arch installation, it is also possible to just copy the filesystem to the new partition. With this method, you will still need to
  • Create /etc/fstab and edit /etc/hostname
  • Delete /etc/machine-id so that a new, unique, one will be regenerated on boot
  • Make any other changes appropriate to the installation medium
  • Install the bootloader

When copying the filesystem root, use something like cp -ax or rsync -axX. This avoids copying contents of mountpoints (-x), and preserves the capabilities attributes of some system binaries (rsync -X).

From a host running another Linux distribution

There are multiple tools which automate a large part of the steps described in the following subsections. See their respective homepages for detailed instructions.

The manual way is presented in the following subsections. The idea is to run an Arch system inside the host system, with the actual installation being executed from the Arch system. The nested system is contained inside a chroot.

Creating the chroot

Two methods to setup and enter the chroot are presented below, from the easiest to the most complicated. Select only one of the two methods. Then, continue at #Using the chroot environment.

Method A: Using the bootstrap image (recommended)

Download the bootstrap image from a mirror:

# cd /tmp
# curl -O https://mirrors.kernel.org/archlinux/iso/2016.09.03/archlinux-bootstrap-2016.09.03-x86_64.tar.gz

You can also download the signature (same URL with .sig added) and verify it with GnuPG.

Extract the tarball:

# tar xzf <path-to-bootstrap-image>/archlinux-bootstrap-2016.09.03-x86_64.tar.gz

Select a repository server by editing /tmp/root.x86_64/etc/pacman.d/mirrorlist.

Note: If bootstrapping an i686 image from an x86_64 host system, also edit /tmp/root.i686/etc/pacman.conf and explicitly define Architecture = i686 in order for pacman to pull the proper i686 packages.

Enter the chroot

  • If bash 4 or later is installed, and unshare supports the --fork and --pid options:
# /tmp/root.x86_64/bin/arch-chroot /tmp/root.x86_64/
  • Otherwise, run the following commands:
# mount --bind /tmp/root.x86_64 /tmp/root.x86_64
# cd /tmp/root.x86_64
# cp /etc/resolv.conf etc
# mount -t proc /proc proc
# mount --rbind /sys sys
# mount --rbind /dev dev
# mount --rbind /run run    # (assuming /run exists on the system)
# chroot /tmp/root.x86_64 /bin/bash

Method B: Using the LiveCD image

It is possible to mount the root image of the latest Arch Linux installation media and then chroot into it. This method has the advantage of providing a working Arch Linux installation right within the host system without the need to prepare it by installing specific packages.

Note: Before proceeding, make sure the latest version of squashfs is installed on the host system. Otherwise, errors like the following are to be expected: FATAL ERROR aborting: uncompress_inode_table: failed to read block.
  • The root image can be found on one of the mirrors under either arch/x86_64/ or arch/i686/, depending on the desired architecture. The squashfs format is not editable, so we unsquash the root image and mount it.
  • To unsquash the root image, run
# unsquashfs airootfs.sfs
  • Before chrooting to it, we need to set up some mount points and copy the resolv.conf for networking.
# mount --bind squashfs-root squashfs-root
# mount -t proc none squashfs-root/proc
# mount -t sysfs none squashfs-root/sys
# mount -o bind /dev squashfs-root/dev
# mount -o bind /dev/pts squashfs-root/dev/pts  ## important for pacman (for signature check)
# cp -L /etc/resolv.conf squashfs-root/etc  ## this is needed to use networking within the chroot
  • Now, everything is prepared to chroot into the newly installed Arch environment
# chroot squashfs-root bash

Using the chroot environment

The bootstrap environment is really barebones (no nano, no ping, no cryptsetup, no lvm). Therefore, we need to set up pacman in order to download the rest of the base and, if needed, base-devel.

Initializing pacman keyring

Before starting the installation, pacman keys need to be setup. Before running the following two commands, read pacman-key#Initializing the keyring to understand the entropy requirements:

# pacman-key --init
# pacman-key --populate archlinux
Tip: Installing and running haveged must be done on the host system, since it is not possible to install packages before initializing pacman keyring and because systemd will detect it is running in a chroot and ignore activation request. If you go with doing ls -Ra / in another console (TTY, terminal, SSH session...), do not be afraid of running it in a loop a few times: five or six runs from the host proved sufficient to generate enough entropy on a remote headless server.

Selecting a mirror and downloading basic tools

After selecting a mirror, refresh the package lists and install what you need: base, base-devel, parted etc.

Installation tips

You can now proceed to Installation_guide#Partition_the_disks and follow the rest of the Installation guide.

Some host systems or configurations may require certain extra steps. See the sections below for tips.

Debian-based host
/dev/shm

On some Debian-based host systems, pacstrap may produce the following error:

# pacstrap /mnt base
==> Creating install root at /mnt
mount: mount point /mnt/dev/shm is a symbolic link to nowhere
==> ERROR: failed to setup API filesystems in new root

This is because in some versions of Debian, /dev/shm points to /run/shm while in the Arch-based chroot, /run/shm does not exist and the link is broken. To correct this error, create a directory /run/shm:

# mkdir /run/shm
/dev/pts

While installing archlinux-2015.07.01-x86_64 from a Debian 7 host, the following error prevented both pacstrap and arch-chroot from working:

# pacstrap -i /mnt
mount: mount point /mnt/dev/pts does not exist
==> ERROR: failed to setup chroot /mnt

Apparently, this is because these two scripts use a common function. chroot_setup()[1] relies on newer features of util-linux, which are incompatible with Debian 7 userland (see FS#45737).

The solution for pacstrap is to manually execute its various tasks, but use the regular procedure to mount the kernel filesystems on the target directory ("$newroot"):

# newroot=/mnt
# mkdir -m 0755 -p "$newroot"/var/{cache/pacman/pkg,lib/pacman,log} "$newroot"/{dev,run,etc}
# mkdir -m 1777 -p "$newroot"/tmp
# mkdir -m 0555 -p "$newroot"/{sys,proc}
# mount --bind "$newroot" "$newroot"
# mount -t proc /proc "$newroot/proc"
# mount --rbind /sys "$newroot/sys"
# mount --rbind /run "$newroot/run"
# mount --rbind /dev "$newroot/dev"
# pacman -r "$newroot" --cachedir="$newroot/var/cache/pacman/pkg" -Sy base base-devel ... ## add the packages you want
# cp -a /etc/pacman.d/gnupg "$newroot/etc/pacman.d/"       ## copy keyring
# cp -a /etc/pacman.d/mirrorlist "$newroot/etc/pacman.d/"  ## copy mirrorlist

Instead of using arch-chroot for Installation guide#Chroot, simply use chroot "$newroot".

lvmetad

Trying to create LVM logical volumes from an archlinux-bootstrap-2015.07.01-x86_64 environment on a Debian 7 host resulted in the following error:

# lvcreate -L 20G lvm -n root
  /run/lvm/lvmetad.socket: connect failed: No such file or directory
  WARNING: Failed to connect to lvmetad. Falling back to internal scanning.
  /dev/lvm/root: not found: device not cleared
  Aborting. Failed to wipe start of new LV.

(Physical volume and volume group creation worked despite /run/lvm/lvmetad.socket: connect failed: No such file or directory being displayed.)

This could be easily worked around by creating the logical volumes outside the chroot (from the Debian host). They are then available once chrooted again.

Tango-inaccurate.pngThe factual accuracy of this article or section is disputed.Tango-inaccurate.png

Reason: This problem did not arise when installing from a Debian 7 host without lvmetad enabled. The recommended messaround with /etc/lvm/lvm.conf looks rather error prone (2015-07-26). (Discuss in Talk:Install from existing Linux#)

Tango-edit-clear.pngThis article or section needs language, wiki syntax or style improvements.Tango-edit-clear.png

Reason: Language and formatting are lacking, links to relevant articles in the wiki as well. (Discuss in Talk:Install from existing Linux#)

Also, if the system you are using has lvm, you might have the following output:

# grub-install --target=i386-pc --recheck /dev/mapper/main-archroot
Installing for i386-pc platform.
  /run/lvm/lvmetad.socket: connect failed: No such file or directory
  WARNING: Failed to connect to lvmetad. Falling back to internal scanning.
  /run/lvm/lvmetad.socket: connect failed: No such file or directory
  WARNING: Failed to connect to lvmetad. Falling back to internal scanning.
  /run/lvm/lvmetad.socket: connect failed: No such file or directory
  WARNING: Failed to connect to lvmetad. Falling back to internal scanning.
  /run/lvm/lvmetad.socket: connect failed: No such file or directory
  WARNING: Failed to connect to lvmetad. Falling back to internal scanning.
  /run/lvm/lvmetad.socket: connect failed: No such file or directory
  WARNING: Failed to connect to lvmetad. Falling back to internal scanning.

This is because debian does not use lvmetad by default. You need to edit /etc/lvm/lvm.conf and set use_lvmetad to 0:

use_lvmetad = 0

This will trigger later an error on boot in the initrd stage. Therefore, you have to change it back after the grub generation. In a software RAID + LVM, steps would be the following:

  • After installing all the system, when you have to do all the initramfs (mkinitcpio) and grub thing.
  • Change /etc/mdadm.conf to reflect your RAID config (if any)
  • Change HOOKS and MODULES according to lvm and raid requirements: MODULES="dm_mod" HOOKS="base udev mdadm_udev ... block lvm2 filesystems ..."
  • Generate initrd images with mkinitcpio
  • Change /etc/lvm/lvm.conf to put use_lvmetad = 0
  • Generate grub config (grub-mkconfig)
  • Change /etc/lvm/lvm.conf to put use_lvmetad = 1
Fedora-based host

On Fedora based hosts and live USBs you may encounter problems when using genfstab to generate your fstab. Remove duplicate entries and the "seclabel" option where it appears, as this is Fedora-specific and will keep your system from booting normally.

Things to check before you reboot

Before rebooting, chroot into the newly-installed system.

Set a root password so that you can log in with ssh later:

# passwd

Install ssh and enable it to start automatically at boot.

Configure the network connection to start automatically at boot.

Set up a boot loader and configure it to use the swap partition you appropriated earlier as the root partition. You might want to configure your bootloader to be able to boot into your old system; it is helpful to re-use the server's existing /boot partition in the new system for this purpose.

Replacing the existing system without a LiveCD

Find ~700MB of free space somewhere on the disk, e.g. by partitioning a swap partition. You can disable the swap partition and set up your system there.

Set old swap partition as new root partition

Check cfdisk, /proc/swaps or /etc/fstab to find your swap partition. Assuming your hard drive is located on sdaX (X will be a number).

Do the following:

Disable the swap space:

# swapoff /dev/sdaX

Create a filesystem on it

# fdisk /dev/sda
(set /dev/sdaX ID field to "Linux" - Hex 83)
# mke2fs -j /dev/sdaX

Create a directory to mount it in

# mkdir /mnt/newsys

Finally, mount the new directory for installing the intermediate system.

# mount -t ext4 /dev/sdaX /mnt/newsys

Installation

If less than 700MB are available, examine the packages in the group base, and select only those required to get a system with internet connection up and running in the temporary partition. This will mean explicitly specifying individual packages to pacstrap, as well as passing it the -c option, to get packages downloaded to the host system to avoid filling up valuable space.

Once the new Arch Linux system is installed, reboot into the newly created system, and rsync the entire system to the primary partition. Fix the bootloader configuration before rebooting.