Forked from "Pacman on LFS Version 12.0-systemd" By Matthew Sexton wich in turn is
Forked from "Pacman on LFS 8.1" By Ben Van Daele.
Added changes and PKGBUILD files from "LFS-11.2-systemd-with-EFI-and-pacman"
Based on the guide writen by James Kimball in 2013.
Building on Linux From Scratch
"Archlinux from Scratch" but without the Arch repo's unless you add them.
I hope you know what Linux from Scratch is, or (GNU, lol) Linux at all. if so, this tries to add arch linux their package manager to Linux from Scratch. by building everything ourselves, and then installing it. But not using Arch or its friends repositories of precompiled software. Because that would defeat the purpose of LFS and slowly replacing LFS with basicly what Arch makes Arch.
So we basicly build LFS, but make every package, a installable arch package. You could then in theory, make your own package repo and host these (beyound the scope of this repo). To start, get familiar with the LFS book, prefferably youve completed the book atleast once and got it working
Licensed under the Creative Commons Attribution-ShareAlike 3.0 License.
This guide is divided in five stages, the first one of which starts just before installing tools to your final system.
- Stage 1 - Installing pacman to your temporary toolchain
- Stage 2 - Installing pacman with pacman
- Stage 3 - Installing packages of chapter eight of the LFS book
- Stage 4 - Installing pacman to your final system
- Stage 5 - Finishing the book
This stage begins right before 7.13. Cleaning up and Saving the Temporary System, after completing 7.12. Util-linux-2.39.3. So yes, youve completed the previous chapters of the LFS book. If not, start reading :D
When you finished 7.12, its best to grab these extra wget download list and md5 checksum check. adapt to what feels right. Also, make sure $LFS points to your LFS target mount point when doing these steps. And you could make a backup either or both before and or after adding pacman, now be the time to decide.
Probably good to do outside chroot, grab the pacman install scripts:
git clone https://github.com/CodeAsm/lfs-pacman $LFS/sources/pacmanthe work in progress branch:
git clone --branch LFS-12.2 --single-branch https://github.com/CodeAsm/lfs-pacman $LFS/sources/pacmanPacman and to use makepkg later, they depend on the following packages:
- Python 3.12.5
- zlib 1.3.1
- meson 1.5.1
- ninja 1.12.1
- util-linux for getopt 2.40.2
- libxcrypt-4.4.36
- shadow for su 4.16.0
- fakeroot 1.36
- libcap 2.70
- libarchive 3.7.4
- OpenSSL 3.3.1 (libcryto)
- pkgconf 2.3.0 (and not pkg-config, as dev has stalled)
- pacman 7.0.0
We will also need (or nano):
- Vim 9.1.0660
Some of these are not part of the LFS book, so download their sources manually:
From the BLFS book:
- libarchive: https://github.com/libarchive/libarchive/releases/download/v3.7.4/libarchive-3.7.4.tar.xz
Outside of the LFS ecosystem:
- fakeroot: https://deb.debian.org/debian/pool/main/f/fakeroot/fakeroot_1.36.orig.tar.gz
- pacman: https://gitlab.archlinux.org/pacman/pacman/-/releases/v7.0.0/downloads/pacman-7.0.0.tar.xz
To download all of the packages (including libarchive from BLFS) by using wget-list-pacman as an input to the wget command, use:
wget --input-file=$LFS/sources/pacman/install-files/wget-list-pacman --continue --directory-prefix=$LFS/sourcesAdditionally, there is a separate file, md5sums, which can be used to verify that all the correct packages are available before proceeding. Place that file in $LFS/sources and run:
pushd $LFS/sources
md5sum -c $LFS/sources/pacman/install-files/md5sums-pacman
popdThis check can be used after retrieving the needed files with any of the methods listed above.
Build these packages using the following commands. Just like the LFS book, these commands assume you've extracted the relevant sources and cd'd into the resulting directory.
You need to be inside the chroot environment, if you quit (to backup/restore) and have the virtual kernel file system mounted. (see Section 7.4, “Entering the Chroot Environment”) before continuing.
./configure --prefix=/usr
make
make install
rm -fv /usr/lib/libz.a
./config --prefix=/usr \
--openssldir=/etc/ssl \
--libdir=lib \
shared \
zlib-dynamic
make
sed -i '/INSTALL_LIBS/s/libcrypto.a libssl.a//' Makefile
make MANSUFFIX=ssl install
check if the following is needed?
mv -v /usr/share/doc/openssl /usr/share/doc/openssl-3.3.1./configure --prefix=/usr \
--enable-shared \
--without-ensurepip
make
make installNote: This is temporary python builded with same commands as LFS book chapter 7.10. Python-3.12.5. All messages about missing libararies and headers could be safely ignored because you only need zlib module. Even openssl has already build, it's not require for this version of python, if desired you could build openssl after python.
python3 configure.py --bootstrap
install -vm755 ninja /usr/bin/
install -vDm644 misc/bash-completion /usr/share/bash-completion/completions/ninja
install -vDm644 misc/zsh-completion /usr/share/zsh/site-functions/_ninjaNote: Since python was build without setuptools module you need put meson in single executable ziped file what will be stored in /source directory. This file will be used by python later to build pacman
./packaging/create_zipapp.py --outfile meson.pyz --interpreter '/usr/bin/python3' .
cp meson.pyz ..mkdir -pv /var/lib/hwclock
./configure ADJTIME_PATH=/var/lib/hwclock/adjtime \
--libdir=/usr/lib \
--docdir=/usr/share/doc/util-linux-2.40.2 \
--disable-chfn-chsh \
--disable-login \
--disable-nologin \
--disable-su \
--disable-setpriv \
--disable-runuser \
--disable-pylibmount \
--disable-static \
--disable-liblastlog2 \
--without-python \
runstatedir=/run
make
make installPrevent static libraries from being installed:
sed -i '/install -m.*STA/d' libcap/Makefile
Compile and install the package:
make prefix=/usr lib=lib
make test
make prefix=/usr lib=lib install
To be able to build su, we apparently DO need a function called crypt and its these days located in libxcrypt.
./configure --prefix=/usr \
--enable-hashes=strong,glibc \
--enable-obsolete-api=no \
--disable-static \
--disable-failure-tokens
make
make installsed -i 's/groups$(EXEEXT) //' src/Makefile.in
find man -name Makefile.in -exec sed -i 's/groups\.1 / /' {} \;
find man -name Makefile.in -exec sed -i 's/getspnam\.3 / /' {} \;
find man -name Makefile.in -exec sed -i 's/passwd\.5 / /' {} \;
./configure --sysconfdir=/etc \
--disable-static \
--without-libbsd \
--with-group-name-max-length=32
make
cp ./src/su /usr/bin/sed '/linux\/fs\.h/d' -i libarchive/archive_read_disk_posix.c
./configure --prefix=/usr --disable-static
make
make install./configure --prefix=/usr \
--disable-static \
--docdir=/usr/share/doc/pkgconf-2.3.0
make
make installTo maintain compatibility with the original Pkg-config create two symlinks
ln -sv pkgconf /usr/bin/pkg-config
ln -sv pkgconf.1 /usr/share/man/man1/pkg-config.1As part of its installation, fakeroot calls ldconfig, which is located in /tools/sbin. /tools/sbin is not part of our PATH, so we must add it now.
# Don't install docs
sed -i 's/SUBDIRS=doc \(.*\)/SUBDIRS=\1/' Makefile.am
./configure --prefix=/usr \
--libdir=/usr/lib/libfakeroot \
--disable-static \
--with-ipc=sysv
make
make install
the following nomore needed?
install -dm0755 "/etc/ld.so.conf.d/"
echo '/usr/lib/libfakeroot' > "/etc/ld.so.conf.d/fakeroot.conf"In the following command, the meson file needs a target directory, thats build in our case.
this bit me already once.
cp ../meson.pyz .
python3 meson.pyz setup --prefix=/usr \
--buildtype=plain \
-Ddoc=disabled \
-Ddoxygen=enabled \
-Dscriptlet-shell=/usr/bin/bash \
-Dldconfig=/usr/bin/ldconfig \
build
python3 meson.pyz compile -C build
python3 meson.pyz install -C build
rm ../meson.pyz
This will have installed, amongst others, the makepkg.conf and pacman.conf config files in /etc; you may want to edit them. For makepkg.conf, be sure that CARCH and CHOST are appropriate. You may want to build vim from the next step.
CARCH="x86_64"
CHOST="x86_64-lfs-linux-gnu"
You can set your name and email address as the PACKAGER if you want.
For default makepkg using options such striping debug symbols keeping static libraries empty directories and compress man files. Also it removes some info files like .pod. Some of those change not compatible with lfs and should be changed. Edit lines in makepkg.conf file to achive it:
OPTIONS=(strip !libtool !staticlibs !zipman purge)
PURGE_TARGETS=(usr/{,share}/info/dir .packlist)If you desire you can change them for you own use. Refer to makepkg.conf (manual)[https://man.archlinux.org/man/makepkg.conf.5.en].
We wont bother testing VIM as this is just to our temporary tools and it'll be recompiled later.
echo '#define SYS_VIMRC_FILE "/etc/vimrc"' >> src/feature.h
./configure --prefix=/usr
make
make install
Create a new user by adding the following to /etc/passwd:
lfs:x:1000:999:LFS:/home/lfs:/bin/bash
Where 999 is the ID of the users group. Check /etc/group for the correct ID, or if users is not present in that file, add the following to it.
users:x:999:
Create a home directory:
mkdir -v /home/lfs
chown -Rv lfs:users /home/lfs
(after the next step, before chroot into lfs, ive decided to make another backup. dont forget to mount the things again!)
Exit your current chroot, then chroot into your new user (make sure 1000, 999 and lfs are set to the proper values for your system):
chroot --userspec=1000:999 "$LFS" /bin/env -i \
HOME=/home/lfs \
TERM="$TERM" \
PS1='(lfs chroot) \u:\w\$ ' \
PATH=/bin:/usr/bin:/sbin:/usr/sbin \
/bin/bash --login +h
You may want to create a builds directory in your home dir. In there, you would then create a directory for each package you're building.
From the chroot environment, create a builds directory:
cd /home/lfs
mkdir -v builds
Copy the pacman sources to its build directory, ~/builds/pacman-7.0.0.
(Testing) Extract the pacman sources into the builds directory:
tar -xvf /sources/pacman-7.0.0.tar.xz
cp /sources/meson.pyz pacman-7.0.0/Download the necessary build files (PKGBUILD, makepkg.conf and pacman.conf) from the Install-Files to the build directory.
cp -rf /sources/pacman/install-files/pacman-7.0.0/* .The included PKGBUILD has had the following edits made:
- Removed 'groups' and 'depends' sections (We're not using groups, and as far as pacman knows none of the dependencies are installed.)
- Edited the 'source' section to point to local tarball and files
- Removed 'check' section as most of the tests will fail with our current environment
- Added the PKG_CONFIG=pkgconf flag to find the newer pkg config tool
The default pacman.conf is overwritten by our altered version. Signature checking is done on files, not on databases. Additionally, color output is enabled, and like in later versions of pacman, simultaneous downloads are set to 5.
Now run the following command as your non-root user from the build directory:
makepkg
If all goes well, this should have created a file that you can now install as follows, as root this time (thus, logout, use the chroot command like you would in Section 7.4, “Entering the Chroot Environment”):
newer pacman doesnt just overwrite files, so we must for now force it. ive also overwritten the "old" configs with our package new ones, unless you
pacman -U --overwrite '*' pacman-7.0.0-1-x86_64.pkg.tar.gz
mv /etc/makepkg.conf.pacnew /etc/makepkg.conf
mv /etc/pacman.conf.pacnew /etc/pacman.conf
Before starting with stage 3, you left the LFS book right before 7.13. Cleaning up and Saving the Temporary System as either chroot lfs or chroot root user continue from there, clean up and I suggest
- backup your tools
- save and backup your notes and customized configurations
Come back after you have read 8.2. Package Management
Now we will continue with the rest of the book, but instead of building and installing the packages manually, we will create packages and then use pacman to install them.
All of the necessary PKGBUILD files can be found in the packages directory, but if you want to learn how to create these, I suggest you only refer to them when you get stuck.
The general process goes like this:
As the dedicated lfs user:
- Create a new directory in the builds directory.
- Copy all needed files to it (source archive, possibly other files like patches or config files).
- Write a
PKGBUILDfile. - Run
makepkg. (we have OpenSSL right? no --skipchecksums) - Check the contents of the
pkgdirectory; this is what pacman will install, so you may want to verify that it looks good. - Install the package (as root chroot(!), from a seperate terminal maybe) with
pacman -U $filename
Writing a PKGBUILD file can take some trial and error. Essentially you'll need to copy what the LFS book wants you to do and paste it in the PKGBUILD at the right place, but usually you will not be able to copy things verbatim from the book.
If you're stuck, check the official Arch Linux packages or thePKGBUILD files in the packages directory of this repo.
as a reminder:
chroot --userspec=1000:999 "$LFS" /bin/env -i \
HOME=/home/lfs \
TERM="$TERM" \
PS1='(lfs chroot) \u:\w\$ ' \
PATH=/bin:/usr/bin:/sbin:/usr/sbin \
/bin/bash --login +h
and root:
chroot "$LFS" /usr/bin/env -i \
HOME=/root \
TERM="$TERM" \
PS1='(lfs chroot) \u:\w\$ ' \
PATH=/usr/bin:/usr/sbin \
MAKEFLAGS="-j$(nproc)" \
TESTSUITEFLAGS="-j$(nproc)" \
/bin/bash --loginWhen calling any of the PKGBUILD functions, makepkg will automatically cd you into the source dir, which is where it will have extracted or symlinked all your source files.
makepkg will automatically extract all archives you specify in the sources array. Typically, your source tarball will have been extracted into a separate directory (although that depends on the tarball itself; the tzdata tarball for instance, extracts directly, without a subdirectory).
This is why the first step of each function will usually be to cd into the directory created during the extraction of the source tarball.
When installing files, you cannot install them to the system root, but instead you have to install them in ${pkgdir}. For certain packages this is done by using make DESTDIR=${pkgdir} install instead of make install. Not all packages use DESTDIR, however. If you're not sure how those packages should be built, you can always check the Arch Linux packages or the PKGBUILD files from this repo.
In some cases, the book will tell you to mv a directory. This will work while creating the package, but will cause problems when installing it. You should first create the directory with install -vdm755 $dir_name.
Things that the LFS book wants you to do after having called make install will likely need to be placed in an .install file. Check the Arch Linux wiki for more info.
Pacman will execute the functions in the .install file at the end of the installation process.
Some packages require additional steps besides simply converting the LFS instructions into a PKGBUILD. These steps are documented here.
The book wants you to create some symlinks; I did that manually, as I felt it would be out of place in the package.
The tzdata part of glibc requires zic to be installed to the system, which means after glibc was installed with pacman -U. While I suppose you could directly call the zic binary residing in the src or pkg directories, I thought it would be cleaner to split the tzdata installation to a separate package, much like Arch Linux does.
Because files exist, add the overwrite argument:
--overwrite '*'I wont suggest you use this regularly tho, it may and will break your system
Because files exist, add the overwrite argument:
--overwrite '*'I wont suggest you use this regularly tho, it may and will break your system
for the following (and 1 previous) packages, this might be needed aswell:
- glibc
- zlib
- bzip2
- xz
- file
- m4
- pkgconf
- binutils
- libcap
- libxcrypt
- shadow
- gcc
- sed
- gettext
- bison
- grep
- bash
- openssl
- python
- ninja
- coreutils
- diffutils
- gawk
- findutils
- patch
- tar
- texinfo
- vim
- util-linux
- libarchive
- fakeroot
- pacman
run passwd root now.
Ive tried adding a chroot or non interactive envirement check, might work. if not, run this command manually.
the stack size these days in host distro's is set pretty large, unlimited. if thats not the case on yours, it wont hurt to run:
ulimit -s -H unlimited
But ive already done so in the package build. you might need that overwrite command again upon installing if using the tools.
I re-chrooted, using /bin/bash instead of /tools/bin/bash.
this package seems to require LANG to be set, issue:
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
LC_ALL is for kdb, but its fine for now.
You still have to run the grub install commands if you wish to use grub. Ive enabled the efi parts aswell. efibootmgr might intrest you.
Ive decided to not set the name in os-release, we arent testing systemd here anyway. Lets move this together with the hosts file (that also nolonger is set by perl) to a new package that will generally prep the system. same for timezone settings that appear not to be required anymore to be set.
Stage four starts immediately after the last package in chapter six, currently vim. Before continuing with the rest of the chapter, build and install pacman and its dependencies.
As part of chapter six you should already have installed most of these packages, except for:
- libarchive
- fakeroot
- pacman
Use your temporary pacman installation to install them. Remember, we're installing to the final system, not to /tools.
Weirdly, maybe during earlier compilations and installing, fakeroot got the wrong permisions. issue the following from the root user:
chmod 755 /bin/faked
chmod 755 /bin/fakerootPossibly not an issue, my fakeroot package should install correctly.
And previously other people said:
When restarting my machine, the LFS system wouldn't boot properly. It turned out that many binaries and other files were owned by `ben`, the user with which I built the packages. I have no idea why that happened, but chowning them to `root:root` allowed my system to boot.Ive figured, fakeroot would automaticly fix this but not if we copy files differently or whatever. I may have fixed it with:
# change ownership
chown -R root:root "$pkgdir"in the following packages:
- check
- coreutils
- dbus
- diffutils
- e2fsprogs
- findutils
- gawk
- groff
- grub
- gzip
- iproute2
- kbd
- libarchive
- libpipeline
- make
- man-db
- patch
- procps-ng
- tar
- texinfo
- vim
I "fixed" it. hopefully this is the way. else, we need to fix the PKGBUILDs
Finish up the rest of the book manually.
you probably need to go to:
8.82. About Debugging Symbols
but stripping would best be done from the PKGBUILDs already.