User:Monospacer/Archiso offline install

From ArchWiki

I needed to create an iso that I could easily use for fast installs with more than just base packages (and even AUR packages), on computers that don't have internet (or it's slow) or on virtual machines, here's what I came up with. I tried first with "pacman -Syw" but it skipped some essential packages for me.

First of all, please make sure that you can build a regular iso by following the wiki: https://wiki.archlinux.org/index.php/archiso

If that works for you, here's how to patch things up to get whatever packages you need on the iso.

As root:

mkdir ~/my_archiso
cp -r /usr/share/archiso/configs/releng/* ~/my_archiso/
cd ~/my_archiso
mkdir out

I'm not building the iso in /root/my_archiso/, since I rebuild and test things a lot, I make file changes here and then copy everything to /root/archiso and build from there, hence the /root/archiso paths mentioned below.

First of all, I'm only building for x86_64, so I edited build.sh, I removed "i686" from all the lines that had the arch loop, so it only builds for x86_64:

...
for arch in i686 x86_64; do
...

to:

...
for arch in x86_64; do
...

It's ugly but it works, there are about 4 lines.

Next, I need to have a valid repository somewhere in the airootfs, so it gets put on the final .iso file. This is the repository that will be used for the offline installs. I guess there are better ways but what I came up with is:
1) make pacman use a directory in airoot as the package cache and, after that,
2) build a custom repository there and load that after booting the iso in pacman.conf:


Here are my changes, for build.sh:

1st of all, make pacman use a cache on the airootfs, namely "root/Packages" (it gets created if it doesn't exist), _cache_dirs is changed

make_pacman_conf() {
      local _cache_dirs
      _cache_dirs="/root/archiso/airootfs/root/Packages"
      sed -r "s|^#?\\s*CacheDir.+|CacheDir = $(echo -n ${_cache_dirs[@]})|g" ${script_path}/pacman.conf > ${work_dir}/pacman.conf
  }

Then, after all the packages are installed but before building the squashfs and iso, call "repo-add" to create a repository called "custom", containing everything in "root/Packages" on the iso.
The second setarch line needs to be added.

 make_packages() {                                                                                     
      setarch ${arch} mkarchiso ${verbose} -w "${work_dir}/${arch}" -C "${work_dir}/pacman.conf" -D "${install_dir}" -p "$(grep -h -v ^# ${script_path}/packages.{both,${arch}})" install
      setarch ${arch} repo-add airootfs/root/Packages/custom.db.tar.gz airootfs/root/Packages/*         
  }

The name "custom" is important, since I will now add a pacman.conf to be used by the cd, that only uses that repository and no others, use any name as long as it's both in build.sh and in the new pacman.conf

Copy the /root/archiso/pacman.conf to airootfs/etc/pacman.conf. then add the custom repo and make sure all the others are commented out, this gets used on the live system.

Edit /root/archiso/pacman.conf:

CacheDir    = /root/archiso/airootfs/root/Packages/

Add the custom repo in airootfs/etc/pacman.conf and make sure all the others are commented out, this gets used on the live system.

...
...
...
[custom]
SigLevel = Optional TrustAll
Server = file:///root/Packages/

#[testing]
#Include = /etc/pacman.d/mirrorlist

#[core]
#Include = /etc/pacman.d/mirrorlist

#[extra]
#Include = /etc/pacman.d/mirrorlist

#[community-testing]
#Include = /etc/pacman.d/mirrorlist

#[community]
#Include = /etc/pacman.d/mirrorlist

Every package mentioned in the packages file will get downloaded to the root/Packages dir on the live system and that dir will be used as the one-true-repo on the live system.

Before starting build.sh, you can add whatever from the local pacman cache, just copy the .pkg.tar.xz from /var/cache/pacman to /root/archiso/airootfs/root/Packages, it's an easy way to make AUR packages available that way.

You can also use pacman -Syw --needed with this cachedir as another option for adding pkg files, besides what was already explicitly installed on the live system.

HTH, edits might come.