Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install from Existing Linux
#!/bin/sh
#
ARCH=x86_64
ARCH_TMP=/tmp/archlinux
ARCH_ROOT=/mnt/archlinux
mkdir $ARCH_TMP
cd $ARCH_TMP
# download and extract the packages we need
wget http://www.archlinux.org/packages/core/$ARCH/libfetch/download/
wget http://www.archlinux.org/packages/core/$ARCH/libarchive/download/
wget http://www.archlinux.org/packages/core/$ARCH/openssl/download/
wget http://www.archlinux.org/packages/core/$ARCH/xz/download/
tar xzvf *.tar.gz
# prepare the environment for pacman
export PATH=$ARCH_TMP/usr/bin:$PATH
export LD_LIBRARY_PATH=$ARCH_TMP/usr/lib:$LD_LIBRARY_PATH
alias pacman="pacman --config $ARCH_TMP/etc/pacman.conf"
# configuration
cat > $ARCH_TMP/etc/pacman.conf <<DELIM
DBPath = $ARCH_ROOT/var/lib/pacman/
CacheDir = $ARCH_ROOT/var/cache/pacman/pkg/
LogFile = $ARCH_ROOT/var/log/pacman.log
DELIM
# mirror
mkdir /etc/pacman.d/
echo "Server = http://mirrors.sohu.com/archlinux/\$repo/os/$ARCH" > /etc/pacman.d/mirrorlist
# the new root partition
mkdir $ARCH_ROOT
mount /dev/sdx $ARCH_ROOT
mkdir -p $ARCH_ROOT/var/lib/pacman
mkdir -p $ARCH_ROOT/var/cache/pacman/pkg
# install the "base" group of packages
pacman -Sy -r $ARCH_ROOT
pacman -S base -r $ARCH_ROOT
# prepare the correct /dev nodes for udev
cd $ARCH_ROOT/dev
rm console ; mknod -m 600 console c 5 1
rm null ; mknod -m 666 null c 1 3
rm zero ; mknod -m 666 zero c 1 5
# chroot
cp /etc/resolv.conf $ARCH_ROOT/etc
cp $ARCH_TMP/etc/pacman.d/mirrorlist $ARCH_ROOT/etc/pacman.d/
mount -t proc proc $ARCH_ROOT/proc
mount -t sysfs sys $ARCH_ROOT/sys
mount -o bind /dev $ARCH_ROOT/dev
chroot $ARCH_ROOT /bin/bash
# install and configure the new arch linux
pacman -S kernel26
pacman -R vi
pacman -S vim
ln -s /usr/bin/vim /usr/bin/vi
vi /etc/fstab
vi /etc/rc.conf
vi /etc/hosts
vi /etc/mkinitcpio.conf
mkinitcpio -p kernel26
vim /etc/locale.gen
locale-gen
grep -v rootfs /proc/mounts > /etc/mtab
grub-install /dev/sdx
exit
# clean
umount $ARCH_ROOT/{proc,sys,dev}
umount $ARCH_ROOT
rm /etc/pacman.d -rf
rm $ARCH_TMP -rf
rm $ARCH_ROOT -rf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment