You are not logged in.

#1 2021-09-25 17:41:53

Mr Green
Forum Fellow
From: U.K.
Registered: 2003-12-21
Posts: 5,853

Minimal Linux building under Archlinux

I have run into a problem while trying to build Minimal Linux under Archlinux. Can build syslinux and kernel just fine but busybox breaks as it is not statically linked... complains about glibc-static which I cannot seem to find in arch.

Can I do this under Arch? or should I just add some code to create links?

Mr Green


Mr Green

Offline

#2 2021-09-25 18:34:33

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 25,723
Website

Re: Minimal Linux building under Archlinux

Mr Green wrote:

... but busybox breaks as it is not statically linked... complains about ...

Uh...

I've been building a customized / configured static busybox for years with no issue whatsoever.  So it certainly can be done quite easily.  For specifics, though we'd need to know what the actual problem / error is.  I generally build against musl, but I've certainly had glibc builds too (the glibc package from the repos includes libc.a along with several other static libs).

Last edited by Trilby (2021-09-25 18:37:24)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2021-09-26 07:00:28

Mr Green
Forum Fellow
From: U.K.
Registered: 2003-12-21
Posts: 5,853

Re: Minimal Linux building under Archlinux

Sorry ;-(

 LINK    busybox_unstripped
Static linking against glibc, can't use --gc-sections
Trying libraries: crypt m resolv rt
Failed: -Wl,--start-group  -lcrypt -lm -lresolv -lrt  -Wl,--end-group
Output of:
gcc -malign-data=abi -Wall -Wshadow -Wwrite-strings -Wundef -Wstrict-prototypes -Wunused -Wunused-parameter -Wunused-function -Wunused-value -Wmissing-prototypes -Wmissing-declarations -Wno-format-security -Wdeclaration-after-statement -W>
==========
/usr/bin/ld: cannot find -lcrypt
collect2: error: ld returned 1 exit status
Note: if build needs additional libraries, put them in CONFIG_EXTRA_LDLIBS.
Example: CONFIG_EXTRA_LDLIBS="pthread dl tirpc audit pam"
make: *** [Makefile:718: busybox_unstripped] Error 1

I tried Minimal Linux full build scripts and it works. so it is just this script that fails [as above]

https://github.com/ivandavidov/minimal-linux-script

Would be nice to use Arch kernel and not have to rebuild with every minor change, but that is for another day...


Mr Green

Offline

#4 2021-09-26 09:44:26

progandy
Member
Registered: 2012-05-17
Posts: 4,549

Re: Minimal Linux building under Archlinux

Modify your script to use musl (arch provides static libs) or build a static copy of glibc first to make the busybox build work. The full build script probably does one or the other.


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#5 2021-09-26 11:42:00

Mr Green
Forum Fellow
From: U.K.
Registered: 2003-12-21
Posts: 5,853

Re: Minimal Linux building under Archlinux

The full build script grabs and builds glibc, 'minimal' script uses local glibc and that is why it failed.

Guessing musl will make iso even smaller ;-)

For now just playing with scripts...

Thanks for your help


Mr Green

Offline

#6 2021-09-26 12:49:15

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 25,723
Website

Re: Minimal Linux building under Archlinux

Trimmed output isn't very useful, especially when the lines included have even been truncated (e.g., the compiler command line is cut off).  But it seems the error is not even what you initially implied, but is due to lcrypt.

That script really doesn't seem to do much of anything useful.  It would be easier to just build busybox yourself so you could actually walk through the steps to see where problems actually are.

EDIT: but FYI, the PKGBUILD I've been using for busybox for years is now failing on an up-to-date arch whether I try to use glibc or musl, though for different missing libs than what you are getting.  And the community/busybox PKGBUILD is failing with the same series of missing libs that I'm getting with my build.

Last edited by Trilby (2021-09-26 13:14:35)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#7 2021-10-02 08:10:55

Mr Green
Forum Fellow
From: U.K.
Registered: 2003-12-21
Posts: 5,853

Re: Minimal Linux building under Archlinux

Am tryng out minimal script but using musl, now kernel is failing... under 5.14.8

EDIT it is busybox as you have said that is the issue....

 CC      console-tools/fgconsole.o
  CC      console-tools/kbd_mode.o
console-tools/kbd_mode.c:32:10: fatal error: linux/kd.h: No such file or directory
   32 | #include <linux/kd.h>
      |          ^~~~~~~~~~~~
compilation terminated.
make[1]: *** [scripts/Makefile.build:198: console-tools/kbd_mode.o] Error 1
make: *** [Makefile:743: console-tools] Error 2

Feel like I have something... sorry to be so vague really new to this build/glib stuff

Last edited by Mr Green (2021-10-02 08:16:19)


Mr Green

Offline

#8 2021-10-02 08:43:33

progandy
Member
Registered: 2012-05-17
Posts: 4,549

Re: Minimal Linux building under Archlinux

You probably need the linux-api-headers package installed or add the linux headers from your linux build in the busybox include path.
Edit: kernel-headers-musl might be the correct package.

Last edited by progandy (2021-10-02 11:11:10)


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#9 2021-10-02 11:01:34

latalante1
Member
Registered: 2018-08-30
Posts: 87

Re: Minimal Linux building under Archlinux

Currently librcypt.a is removed from the glibc package. It has been replaced by libxcrypt and it is built without a static library.
Solution. Rebuild libxcrypt with the option to build a static library "--enable-static".
Then you will build a correctly statically linked busybox with glibc. I built busybox-1.34.1 without any problems.

With busybox configuration atypical, static libtirpc library may be required.

Offline

#10 2021-10-02 11:52:40

Mr Green
Forum Fellow
From: U.K.
Registered: 2003-12-21
Posts: 5,853

Re: Minimal Linux building under Archlinux

Am a little further forward [am trying to build with musl]

*** Default configuration is based on 'x86_64_defconfig'
#
# configuration written to .config
#
  SYSHDR  arch/x86/include/generated/uapi/asm/unistd_32.h
  SYSHDR  arch/x86/include/generated/uapi/asm/unistd_64.h
  SYSHDR  arch/x86/include/generated/uapi/asm/unistd_x32.h
  SYSTBL  arch/x86/include/generated/asm/syscalls_32.h
  SYSHDR  arch/x86/include/generated/asm/unistd_32_ia32.h
  SYSHDR  arch/x86/include/generated/asm/unistd_64_x32.h
  SYSTBL  arch/x86/include/generated/asm/syscalls_64.h
  HOSTCC  arch/x86/tools/relocs_32.o
  HOSTCC  arch/x86/tools/relocs_64.o
  HOSTCC  arch/x86/tools/relocs_common.o
  HOSTLD  arch/x86/tools/relocs
  HOSTCC  scripts/selinux/genheaders/genheaders
  HOSTCC  scripts/selinux/mdp/mdp
  HOSTCC  scripts/kallsyms
  HOSTCC  scripts/sorttable
  HOSTCC  scripts/asn1_compiler
  HOSTCC  scripts/extract-cert
scripts/extract-cert.c:21:10: fatal error: openssl/bio.h: No such file or directory
   21 | #include <openssl/bio.h>
      |          ^~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [scripts/Makefile.host:95: scripts/extract-cert] Error 1
make[1]: *** [Makefile:1203: scripts] Error 2
make: *** [Makefile:351: __build_one_by_one] Error 2

Think Busybox is building now but kernel 5.14.9 breaks as above


Mr Green

Offline

#11 2021-10-02 12:54:16

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 25,723
Website

Re: Minimal Linux building under Archlinux

And?  You know how to ask pacman which package provides that missing file.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#12 2021-10-02 13:19:11

Mr Green
Forum Fellow
From: U.K.
Registered: 2003-12-21
Posts: 5,853

Re: Minimal Linux building under Archlinux

I think I can remember ;-) ....


Mr Green

Offline

#13 2021-10-02 19:19:06

Mr Green
Forum Fellow
From: U.K.
Registered: 2003-12-21
Posts: 5,853

Re: Minimal Linux building under Archlinux

After a long day building and breaking...

Kernel: arch/x86/boot/bzImage is ready  (#1)
+ cp arch/x86/boot/bzImage ../isoimage/kernel.gz
+ cd ../isoimage
+ cp ../syslinux-6.03/bios/core/isolinux.bin .
+ cp ../syslinux-6.03/bios/com32/elflink/ldlinux/ldlinux.c32 .
+ echo 'default kernel.gz initrd=rootfs.gz'
+ xorriso -as mkisofs -o ../minimal_linux_live.iso -b isolinux.bin -c boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table ./
xorriso 1.5.4 : RockRidge filesystem manipulator, libburnia project.

Drive current: -outdev 'stdio:../minimal_linux_live.iso'
Media current: stdio file, overwriteable
Media status : is blank
Media summary: 0 sessions, 0 data blocks, 0 data, 9355m free
Added to ISO image: directory '/'='/root/minimal/isoimage'
xorriso : UPDATE :       5 files added in 1 seconds
xorriso : UPDATE :       5 files added in 1 seconds
ISO image produced: 5218 sectors
Written to medium : 5218 sectors at LBA 0
Writing to 'stdio:../minimal_linux_live.iso' completed successfully.
-rw-r--r--    1 root     root       10.2M Oct  2 20:01 minimal_linux_live.iso

Once I know iso boots will have a go at minimal scripts...

Now I know why I stopped making custom kernels ;-)


Mr Green

Offline

#14 2021-10-04 19:22:18

Mr Green
Forum Fellow
From: U.K.
Registered: 2003-12-21
Posts: 5,853

Re: Minimal Linux building under Archlinux

Decided to have a go at creating busybox-static myself... After some searching found that arch uses musl to build package [community] So with that information and adding a couple of package was able to get busybox 1.34.1 to build...

Packages required are musl, kernel-headers-musl, cpio ....

#!/bin/bash

# Project Vole mini iso
# Based on minimal linux [link]
# testing with local kernel
# TODO
# change busybox version, syslinux
# init as a here doc!

set -ex

# Versions ....
BUSYBOX_VERSION=1.34.1
SYSLINUX_VERSION=6.03

# Grab source and extract...
wget -O busybox.tar.bz2 http://busybox.net/downloads/busybox-${BUSYBOX_VERSION}.tar.bz2
wget -O syslinux.tar.xz http://kernel.org/pub/linux/utils/boot/syslinux/syslinux-${SYSLINUX_VERSION}.tar.xz
tar -xvf busybox.tar.bz2
tar -xvf syslinux.tar.xz

# create build directory
mkdir isoimage

# Build busybox
cd busybox-${BUSYBOX_VERSION}
make distclean defconfig
sed -i "s|.*CONFIG_STATIC.*|CONFIG_STATIC=y|" .config
make CC=musl-gcc busybox install
cd _install
rm -f linuxrc
mkdir dev proc sys
echo '#!/bin/sh' > init
echo 'dmesg -n 1' >> init
echo 'mount -t devtmpfs none /dev' >> init
echo 'mount -t proc none /proc' >> init
echo 'mount -t sysfs none /sys' >> init
echo 'setsid cttyhack /bin/sh' >> init
chmod +x init
find . | cpio -R root:root -H newc -o | gzip > ../../isoimage/rootfs.gz


# Kernel ... use local version from /boot YMMV
cp /boot/vmlinuz-linux ../isoimage/kernel.gz

# Create bios booting
cd ../isoimage
cp ../syslinux-${SYSLINUX_VERSION}/bios/core/isolinux.bin .
cp ../syslinux-${SYSLINUX_VERSION}/bios/com32/elflink/ldlinux/ldlinux.c32 .
echo 'default kernel.gz initrd=rootfs.gz' > ./isolinux.cfg

# Build iso
xorriso \
  -as mkisofs \
  -o ../minimal_linux_live.iso \
  -b isolinux.bin \
  -c boot.cat \
  -no-emul-boot \
  -boot-load-size 4 \
  -boot-info-table \
  ./
cd ..
set +ex

Not fully tested yet... YMMV


Mr Green

Offline

Board footer

Powered by FluxBB