Difference between revisions of "Archbootstrap"

From ArchWiki
Jump to: navigation, search
(Change the outdated script)
(13 intermediate revisions by 5 users not shown)
Line 1: Line 1:
[[Category:Boot process (English)]]
+
[[Category:Boot process]]
 +
[http://github.com/tokland/arch-bootstrap/raw/master/arch-bootstrap.sh arch-bootstrap.sh] is a Bash script that creates a minimum Arch Linux system where you can chroot to. Report bugs [https://github.com/tokland/arch-bootstrap/issues here]. Some examples:
 +
=== Installing Arch ===
  
This Bash script creates a base Arch Linux system where you can chroot to (it should work in any UNIX environment). Download the last version [http://tokland.googlecode.com/svn/trunk/archlinux/arch-bootstrap.sh here] (and report bugs [http://code.google.com/p/tokland/issues/list here]).
+
* Using default architecture (i686) and repository:
  
<pre>
+
{{bc|
#!/bin/bash
+
# bash arch-bootstrap.sh myarch
#
+
}}
# arch-bootstrap: Bootstrap a base Arch Linux system.
 
#
 
# Example:
 
#
 
# $ bash arch-bootstrap.sh myarch x86_64
 
#
 
# Depends: wget, tar, gzip, chroot
 
# Author: Arnau Sanchez <tokland@gmail.com>
 
#
 
# Packages needed by pacman can be obtained that way:
 
#
 
# $ for PACKAGE in $(ldd /usr/bin/pacman | grep "=> /" | awk '{print $3}'); do
 
#    pacman -Qo $PACKAGE
 
#  done | awk '{print $5}' | sort -u | xargs
 
#
 
set -e
 
  
### Generic functions
+
* Bootstrap a ''x86_64'' system using a specific repository:
  
# Output to standard error
+
{{bc|
stderr() { echo "$@" >&2; }
+
# bash arch-bootstrap.sh -a x86_64 -r "ftp://ftp.archlinux.org" myarch
 +
}}
 +
 +
== Related ==
  
# Output debug message to standard error
+
* Port for sh4 CPU: http://code.google.com/p/sh4twbox.
debug() { stderr "--- $@"; }
 
 
 
# Extract href attribute from HTML link
 
extract_href() { sed -n "s/^.*<a [^>]*href=\"\([^\"]*\)\".*$/\1/p"; }
 
 
 
# Simple wrapper around wget
 
fetch() { wget -c --passive-ftp --quiet "$@"; }
 
 
 
### Main
 
 
 
BASIC_PACKAGES=(acl attr bzip2 glibc libarchive libfetch openssl pacman
 
                pacman-mirrorlist xz-utils zlib)
 
EXTRA_PACKAGES=(coreutils bash)
 
 
 
test $# -ge 2 || {
 
  stderr "Usage: $(basename "$0") DESTDIR i686|x86_64 [REPO_URL] [CORE_OS_HTMLFILE]"
 
  exit 2
 
}
 
 
 
DEST=$1
 
ARCH=$2
 
REPO_URL=${3:-"http://mirrors.kernel.org/archlinux"}
 
LIST_HTML=$4
 
 
 
REPO="${REPO_URL%/}/core/os/$ARCH"
 
debug "using core repository: $REPO"
 
 
 
if test "$LIST_HTML"; then
 
  debug "using packages HTML index: $LIST_HTML"
 
  LIST=$(extract_href < "$LIST_HTML")
 
else
 
  debug "fetching packages list: $REPO"
 
  # Force trailing '/' needed for FTPs server. Also, get only package relative paths
 
  LIST=$(fetch -O - "$REPO/" | extract_href | awk -F"/" '{print $NF}') ||
 
    { debug "cannot fetch packages list: $REPO"; exit 1; }
 
fi
 
 
 
debug "creating destination directory: $DEST"
 
mkdir -p "$DEST"
 
 
 
debug "fetching pacman and dependencies: ${BASIC_PACKAGES[*]}"
 
for PACKAGE in ${BASIC_PACKAGES[*]}; do
 
  FILE=$(echo "$LIST" | grep "^$PACKAGE-[[:digit:]]" | sort -n | tail -n1)
 
  test "$FILE" || { debug "cannot find package: $PACKAGE"; exit 1; }
 
  test -f "$FILE" && gunzip -t "$FILE" || {
 
    debug "downloading: $REPO/$FILE"
 
    fetch "$REPO/$FILE"
 
  }
 
  debug "uncompressing package: $FILE"
 
  tar xzf "$FILE" -C "$DEST"
 
done
 
 
 
debug "doing minimal system configuration (DNS, passwd, hostname, mirrorlist)"
 
cp "/etc/resolv.conf" "$DEST/etc/resolv.conf"
 
echo "root:x:0:0:root:/root:/bin/bash" > "$DEST/etc/passwd"
 
echo "bootstrap" > "$DEST/etc/hostname"
 
echo "Server = $REPO_URL/\$repo/os/$ARCH" >> "$DEST/etc/pacman.d/mirrorlist"
 
 
 
debug "installing extra packages: ${EXTRA_PACKAGES[*]}"
 
chroot "$DEST" /usr/bin/pacman --noconfirm -Syf ${EXTRA_PACKAGES[*]}
 
 
 
debug "done - you should now be able to use the system (i.e. chroot \"$DEST\")"
 
</pre>
 

Revision as of 14:13, 1 July 2013

arch-bootstrap.sh is a Bash script that creates a minimum Arch Linux system where you can chroot to. Report bugs here. Some examples:

Installing Arch

  • Using default architecture (i686) and repository:
# bash arch-bootstrap.sh myarch
  • Bootstrap a x86_64 system using a specific repository:
# bash arch-bootstrap.sh -a x86_64 -r "ftp://ftp.archlinux.org" myarch

Related