Difference between revisions of "Install from existing Linux"

From ArchWiki
Jump to: navigation, search
(Installation and configuration: Rename section and intro, bring up one header level)
m (From a host running another Linux distribution: Various grammatical corrections, and removed unnecessary editorializing.)
Line 54: Line 54:
 
== From a host running another Linux distribution ==
 
== From a host running another Linux distribution ==
  
There are multiple tools automating a larger part of the steps described in the following subsections, see their homepage for detailed instructions.
+
There are multiple tools which automate a large part of the steps described in the following subsections. See their respective homepages for detailed instructions.
  
 
* [https://github.com/tokland/arch-bootstrap arch-bootstrap] (Bash)
 
* [https://github.com/tokland/arch-bootstrap arch-bootstrap] (Bash)
Line 60: Line 60:
 
* [https://github.com/drizzt/vps2arch vps2arch] (Bash)
 
* [https://github.com/drizzt/vps2arch vps2arch] (Bash)
  
The manual way is presented in the following subsections. The idea is to run an Arch system inside the host system, the actual installation is then executed from the Arch system. The nested system is contained inside a chroot.
+
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 ===
 
=== 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 and then continue at [[#Using the chroot environment]].
+
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) ====
 
==== Method A: Using the bootstrap image (recommended) ====
Line 96: Line 96:
 
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.
 
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}}.}}
+
{{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 then mount it.
+
* 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
 
*To unsquash the root image, run
Line 118: Line 118:
 
}}
 
}}
  
* Now everything is prepared to chroot into the newly installed Arch environment
+
* Now, everything is prepared to chroot into the newly installed Arch environment
 
{{bc|# chroot /arch bash}}
 
{{bc|# chroot /arch bash}}
  
 
=== Using the chroot environment ===
 
=== Using the chroot environment ===
  
The bootstrap environment is really barebone (no {{ic|nano}}, no {{ic|ping}}, no {{ic|cryptsetup}}, no {{ic|lvm}}...), therefore we need to set up [[pacman]] right now in order to download the rest of the {{ic|base}} and maybe {{ic|base-devel}} groups.
+
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 ====
 
==== 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:
+
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|
 
# pacman-key --init
 
# pacman-key --init
Line 137: Line 137:
 
See [[Beginners'_guide#Select_a_mirror|select a mirror]] for information on generating a suitable mirrorlist.
 
See [[Beginners'_guide#Select_a_mirror|select a mirror]] for information on generating a suitable mirrorlist.
  
Then [[Mirrors#Force_pacman_to_refresh_the_package_lists|update the package lists]] and [[install]] what you need:
+
Then, [[Mirrors#Force_pacman_to_refresh_the_package_lists|update the package lists]] and [[install]] what you need:
  
 
   # pacman -Syyu base base-devel parted ...
 
   # pacman -Syyu base base-devel parted ...
Line 145: Line 145:
 
You can now proceed to [[Beginners%27_guide#Prepare_the_storage_devices|preparing the storage devices]] and follow the rest of the [[Installation guide#Installation|installation procedure]].
 
You can now proceed to [[Beginners%27_guide#Prepare_the_storage_devices|preparing the storage devices]] and follow the rest of the [[Installation guide#Installation|installation procedure]].
  
Some host systems or configurations may require certain extra steps, see the sections below for tips.
+
Some host systems or configurations may require certain extra steps. See the sections below for tips.
  
 
===== Debian-based host =====
 
===== Debian-based host =====
Line 171: Line 171:
 
}}
 
}}
  
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], which relies on newer features of {{Pkg|util-linux}} incompatible with Debian 7 userland (see {{Bug|45737}}).
+
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"}}):
+
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=
 
{{bc|1=
Line 189: Line 189:
 
}}
 
}}
  
And instead of using {{ic|arch-chroot}} for [[Beginners%27_guide#Chroot_and_configure_the_base_system|configuring the base system]], simply use {{ic|chroot "$newroot"}}.
+
Instead of using {{ic|arch-chroot}} for [[Beginners%27_guide#Chroot_and_configure_the_base_system|configuring the base system]], simply use {{ic|chroot "$newroot"}}.
  
 
====== lvmetad ======
 
====== lvmetad ======
Line 203: Line 203:
 
(Physical volume and volume group creation worked despite {{ic|/run/lvm/lvmetad.socket: connect failed: No such file or directory}} being displayed.)
 
(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 were then readily available once chrooted again.
+
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).}}
 
{{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).}}
Line 224: Line 224:
 
}}
 
}}
  
This is because debian does not use lvmetad by default (security purpose they say). You need to edit {{ic|/etc/lvm/lvm.conf}} and set {{ic|use_lvmetad}} to {{ic|0}}:
+
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}}:
  
 
  use_lvmetad = 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:
+
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.
 
* After installing all the system, when you have to do all the initramfs (mkinitcpio) and grub thing.

Revision as of 23:10, 26 July 2015

zh-CN:Install from existing Linux zh-TW:Install from Existing Linux

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.

From a host running Arch Linux

Install arch-install-scripts from the official repositories.

Installation and configuration

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.

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 (rcsync -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:

$ curl -O https://mirrors.kernel.org/archlinux/iso/2015.06.01/archlinux-bootstrap-2015.06.01-x86_64.tar.gz

Extract the tarball:

# cd /tmp
# tar xzf <path-to-bootstrap-image>/archlinux-bootstrap-2015.06.01-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:
# 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 -d /squashfs-root root-image.fs.sfs
  • Now loop mount the root image
# mkdir /arch
# mount -o loop /squashfs-root/root-image.fs /arch
  • Before chrooting to it, we need to set up some mount points and copy the resolv.conf for networking.
# mount -t proc none /arch/proc
# mount -t sysfs none /arch/sys
# mount -o bind /dev /arch/dev
# mount -o bind /dev/pts /arch/dev/pts # important for pacman (for signature check)
# cp -L /etc/resolv.conf /arch/etc #this is needed to use networking within the chroot
  • Now, everything is prepared to chroot into the newly installed Arch environment
# chroot /arch 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

Selecting a mirror and downloading basic tools

See select a mirror for information on generating a suitable mirrorlist.

Then, update the package lists and install what you need:

 # pacman -Syyu base base-devel parted ...

Installation tips

You can now proceed to preparing the storage devices and follow the rest of the installation procedure.

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 -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 configuring the base system, 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.

Replacing the existing system without a LiveCD

Find ~700MB of free space somewhere on the disk, e.g. by partitioning a swap partition. 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.