Difference between revisions of "Install from existing Linux"
WonderWoofy (talk | contribs) (→Prepare the system - note about genbootstrap) |
(→Alternative: Install arch-install-scripts natively on non Arch distro: Mark for deletion.) |
||
(42 intermediate revisions by 4 users not shown) | |||
Line 4: | Line 4: | ||
[[fr:Install chroot]] | [[fr:Install chroot]] | ||
[[it:Install from Existing Linux]] | [[it:Install from Existing Linux]] | ||
+ | [[pt:Install from Existing Linux]] | ||
[[ru:Install from Existing Linux]] | [[ru:Install from Existing Linux]] | ||
[[uk:Install from Existing Linux]] | [[uk:Install from Existing Linux]] | ||
[[zh-CN:Install from Existing Linux]] | [[zh-CN:Install from Existing Linux]] | ||
[[zh-TW:Install from Existing Linux]] | [[zh-TW:Install from Existing Linux]] | ||
− | |||
− | This is useful for: | + | This document describes the bootstrapping process required to install Arch Linux from a running Linux host system. |
− | * remotely installing | + | After bootstrapping, the installation proceeds as described in the [[Installation Guide]]. |
− | * creating a new | + | |
− | * creating an | + | 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]] | ||
− | + | The goal of the bootstrapping procedure is to setup an environment from which {{Pkg|arch-install-scripts}} (such as {{ic|pacstrap}} and {{ic|arch-root}}) run. | |
− | + | This goal is achieved by installing {{Pkg|arch-install-scripts}} natively on the host system, or setting up an Arch Linux-based chroot. | |
− | |||
− | |||
− | |||
− | + | If the host system runs Arch Linux, installing {{Pkg|arch-install-scripts}} is straightforward. | |
− | + | On other distributions, the process is more complicated (described in [[#Alternative: Install arch-install-scripts natively on non Arch distro]]). | |
− | + | For these distributions, it is recommended to set up a chroot instead. | |
− | + | {{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.}} | |
− | + | ==Arch Linux-based chroot== | |
− | + | The idea is to run an Arch system inside the host system. | |
+ | The actual installation is then executed from this Arch system. | ||
+ | This nested system is contained inside a chroot. | ||
+ | Three methods to setup and enter this chroot are presented below, from the easiest to the most complicated. | ||
− | + | {{Note|Your host system must run Linux 2.6.32 or later.}} | |
− | |||
− | + | ===Method 1: Using the Bootstrap Image=== | |
− | + | Download the bootstrap image from a [https://www.archlinux.org/download mirror]: | |
+ | curl -O http://www.gtlib.gatech.edu/pub/archlinux/iso/2013.10.01/archlinux-bootstrap-2013.10.01-x86_64.tar.gz | ||
+ | Extract the tarball: | ||
+ | # cd /tmp | ||
+ | # tar xzf <path-to-bootstrap-image>/archlinux-bootstrap-2013.10.01-x86_64.tar.gz | ||
+ | Select a repository server: | ||
+ | # nano /tmp/root.x86_64/etc/pacman.d/mirrorlist | ||
+ | Enter the chroot | ||
+ | * If you have bash 4 or later installed: | ||
+ | # /tmp/root.x86_64/bin/arch-chroot /tmp/root.x86_64/ | ||
+ | * Else run the following commands: | ||
+ | # cp /etc/resolv.conf /tmp/root.x86_64/etc | ||
+ | # mount --rbind /proc /tmp/root.x86_64/proc | ||
+ | # mount --rbind /sys /tmp/root.x86_64/sys | ||
+ | # mount --rbind /dev /tmp/root.x86_64/dev | ||
+ | # mount --rbind /run /tmp/root.x86_64/run | ||
+ | (assuming /run exists on your system) | ||
+ | # chroot /tmp/root.x86_64/ | ||
− | ===Method | + | ===Method 2: Using the LiveCD Image=== |
− | It is possible to mount the root image of the latest | + | 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 you with a working Arch Linux installation right within your 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 you will get errors like: {{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 you will get errors like: {{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 then mount it. | ||
− | *To unsquash the | + | *To unsquash the root image, run |
{{bc|# unsquashfs -d /squashfs-root root-image.fs.sfs}} | {{bc|# unsquashfs -d /squashfs-root root-image.fs.sfs}} | ||
Line 70: | Line 88: | ||
{{bc|# chroot /arch bash}} | {{bc|# chroot /arch bash}} | ||
− | + | ===Method 3: Assembling the chroot Manually (with a script)=== | |
− | + | The script creates a directory called {{ic|archinstall-pkg}} and downloads the required packages in it. It then extracts them in the {{ic|archinstall-chroot}} directory. Finally, it prepares mount points, configures pacman and enters a chroot. | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | The script | ||
− | |||
− | |||
− | |||
− | |||
− | |||
{{hc|archinstall-bootstrap.sh|<nowiki> | {{hc|archinstall-bootstrap.sh|<nowiki> | ||
Line 135: | Line 140: | ||
</nowiki>}} | </nowiki>}} | ||
− | === | + | ===Using the chroot Environment=== |
− | |||
− | + | ====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| | ||
+ | # pacman-key --init | ||
+ | # pacman-key --populate archlinux | ||
+ | }} | ||
+ | |||
+ | ====Installation==== | ||
+ | Follow the [[Installation Guide#Mount the partitions|Mount the partitions]] and [[Installation Guide#Install the base system|Install the base system]] sections of the [[Installation Guide]]. | ||
+ | |||
+ | =====Debian-based host===== | ||
+ | On Debian-based host systems, {{ic|pacstrap}} produces 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 | ||
− | + | In Debian, /dev/shm points to /run/shm. However, 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 | ||
+ | |||
+ | ====Configure the system==== | ||
+ | |||
+ | From that point, simply follow the [[Installation Guide#Mount the partitions|Mount the partitions]] section of the [[Installation Guide]] and following sections. | ||
+ | |||
+ | ==Alternative: Install arch-install-scripts natively on non Arch distro== | ||
+ | {{Deletion|This method is overkill after Arch provide Bootstrap image.}} | ||
+ | {{Warning|This method is potentially difficult, your mileage may vary from distro to distro.}} | ||
==== Download pacman source code and pacman packages ==== | ==== Download pacman source code and pacman packages ==== | ||
Line 171: | Line 199: | ||
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. | 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. | ||
− | == | + | ==Replacing the Existing System without a LiveCD== |
− | + | Find ~500MB of free space somewhere on the disk, e.g. by partitioning a swap partition. | |
− | + | Install the new Arch Linux 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. | |
− | + | Fix the bootloader configuration before rebooting. | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− |
Revision as of 01:13, 26 October 2013
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:
- 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
- rootfs-over-NFS for diskless machines
The goal of the bootstrapping procedure is to setup an environment from which arch-install-scripts (such as pacstrap
and arch-root
) run.
This goal is achieved by installing arch-install-scripts natively on the host system, or setting up an Arch Linux-based chroot.
If the host system runs Arch Linux, installing arch-install-scripts is straightforward.
On other distributions, the process is more complicated (described in #Alternative: Install arch-install-scripts natively on non Arch distro). For these distributions, it is recommended to set up a chroot instead.
Contents
Arch Linux-based chroot
The idea is to run an Arch system inside the host system. The actual installation is then executed from this Arch system. This nested system is contained inside a chroot. Three methods to setup and enter this chroot are presented below, from the easiest to the most complicated.
Method 1: Using the Bootstrap Image
Download the bootstrap image from a mirror:
curl -O http://www.gtlib.gatech.edu/pub/archlinux/iso/2013.10.01/archlinux-bootstrap-2013.10.01-x86_64.tar.gz
Extract the tarball:
# cd /tmp # tar xzf <path-to-bootstrap-image>/archlinux-bootstrap-2013.10.01-x86_64.tar.gz
Select a repository server:
# nano /tmp/root.x86_64/etc/pacman.d/mirrorlist
Enter the chroot
- If you have bash 4 or later installed:
# /tmp/root.x86_64/bin/arch-chroot /tmp/root.x86_64/
- Else run the following commands:
# cp /etc/resolv.conf /tmp/root.x86_64/etc # mount --rbind /proc /tmp/root.x86_64/proc # mount --rbind /sys /tmp/root.x86_64/sys # mount --rbind /dev /tmp/root.x86_64/dev # mount --rbind /run /tmp/root.x86_64/run (assuming /run exists on your system) # chroot /tmp/root.x86_64/
Method 2: 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 you with a working Arch Linux installation right within your host system without the need to prepare it by installing specific packages.
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 then mount it.
- To unsquash the root image, run
# unsquashfs -d /squashfs-root root-image.fs.sfs
- Now you can 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 your newly installed Arch environment
# chroot /arch bash
Method 3: Assembling the chroot Manually (with a script)
The script creates a directory called archinstall-pkg
and downloads the required packages in it. It then extracts them in the archinstall-chroot
directory. Finally, it prepares mount points, configures pacman and enters a chroot.
archinstall-bootstrap.sh
#!/bin/bash # This script is inspired on the archbootstrap script. PACKAGES=(acl attr bzip2 curl expat glibc gpgme gnupg libarchive libassuan libgcrypt libgpg-error libssh2 lzo2 openssl pacman xz zlib pacman-mirrorlist coreutils bash grep gawk file filesystem tar ncurses readline libcap util-linux pcre arch-install-scripts) # 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) 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 chroot $CHROOT_DIR /bin/bash
Using the chroot Environment
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
Installation
Follow the Mount the partitions and Install the base system sections of the Installation Guide.
Debian-based host
On Debian-based host systems, pacstrap
produces 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
In Debian, /dev/shm points to /run/shm. However, 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
Configure the system
From that point, simply follow the Mount the partitions section of the Installation Guide and following sections.
Alternative: Install arch-install-scripts natively on non Arch distro
Download pacman source code and pacman packages
Visit the pacman homepage: https://www.archlinux.org/pacman/#_releases and download the latest release.
Now, download the following packages:
- pacman-mirrorlist: https://www.archlinux.org/packages/core/any/pacman-mirrorlist/download/
- arch-install-scripts: https://www.archlinux.org/packages/extra/any/arch-install-scripts/download/
- pacman (necessary for the config files): https://www.archlinux.org/packages/core/x86_64/pacman/download/ (change x86_64 as necessary)
Install dependencies
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
- Decompress the pacman source code and cd inside.
- Execute configure, adapting the paths as necessary:
./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --enable-doc
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
make
- If there were no errors, install the files
make install
- You may need to manually call
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:
tar xJvf pacman-*-x86_64.pkg.tar.xz etc -C / ; sed -i 's/SigLevel.*/SigLevel = Never/g' /etc/pacman.conf
- Extract the mirror list:
tar xJvf pacman-mirrorlist-*-any.pkg.tar.xz -C /
- Enable some mirrors on
/etc/pacman.d/mirrorlist
- Extract the arch-install-scripts
tar xJvf arch-install-scripts-*-any.pkg.tar.xz -C /
Another option is using the alien
tool to convert the pacman-mirrorlist
and arch-install-scripts
(but no pacman
) to native packages of your distro.
Replacing the Existing System without a LiveCD
Find ~500MB of free space somewhere on the disk, e.g. by partitioning a swap partition. Install the new Arch Linux system there, reboot into the newly created system, and rsync the entire system to the primary partition. Fix the bootloader configuration before rebooting.