WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: linux-kernel-sources-env.sh fails with wget and tar errors  (Read 2843 times)

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1496
I'm trying to compile a kernel module for TCL10 (32-bit).

If I run  linux-kernel-sources-env.sh  as regular user (as per the .info file), it doesn't work due to insufficient permissions (multiple "Permission denied"):

Code: [Select]
$ tce-load -wi linux-kernel-sources-env
$ linux-kernel-sources-env.sh
Script will prepare kernel sources and deps
for a 10.x x86 compile environment.

////////////////////////////////////////////////////////////////////////////////

compiletc.tcz loaded
glibc_apps.tcz loaded
automake.tcz loaded
findutils.tcz loaded
bash.tcz loaded
ncursesw-dev.tcz loaded
autoconf.tcz loaded
perl5.tcz loaded
xz.tcz loaded
bc.tcz loaded
checking repo for linux-4.19.10-patched.tar.xz
Connecting to www.tinycorelinux.net (89.22.99.37:80)
wget: server returned error: HTTP/1.1 404 Not Found
checking repo for linux-4.19.10-patched.txz
Connecting to www.tinycorelinux.net (89.22.99.37:80)

 Cleaning up previous builds
/usr/src cleaned

Searching for src files...

Verifying src files...
linux-4.19.10-patched.txz ready
config-4.19.10-tinycore ready
Module.symvers-4.19.10-tinycore.gz ready

preparing kernel src...
extracting kernel src... tar: can't make dir linux-4.19.10: Permission denied
tar: can't create directory 'linux-4.19.10': Permission denied
tar: can't make dir linux-4.19.10/virt: No such file or directory
tar: can't create directory 'linux-4.19.10/': Permission denied
tar: can't make dir linux-4.19.10/: Permission denied
tar: can't create directory 'linux-4.19.10/': Permission denied
tar: can't open 'linux-4.19.10/': Is a directory
/usr/local/bin/linux-kernel-sources-env.sh: cd: line 224: can't cd to /usr/src/linux-4.19.10: No such file or directory

Step 1 "make mrproper"... make: *** No rule to make target 'mrproper'.  Stop.
cp: can't create '/usr/src/linux-4.19.10/.config': Path does not exist
/usr/local/bin/linux-kernel-sources-env.sh: cd: line 231: can't cd to /usr/src/linux-4.19.10: No such file or directory

Step 2 "make oldconfig" make: *** No rule to make target 'oldconfig'.  Stop.

Step 3 "make prepare" make: *** No rule to make target 'prepare'.  Stop.

Step 4 "make modules_prepare" make: *** No rule to make target 'modules_prepare'.  Stop.
cp: can't create '/usr/src/linux-4.19.10/Module.symvers': Path does not exist
/usr/local/bin/linux-kernel-sources-env.sh: cd: line 246: can't cd to /usr/src/linux-4.19.10: No such file or directory
make: *** No targets specified and no makefile found.  Stop.
Set ownership...
make symlinks to source...
ln: failed to create symbolic link '/lib/modules/build': File exists
ln: failed to create symbolic link '/lib/modules/4.19.10-tinycore/build': File exists
kernel src files ready


////////////////////////////////////////////////////////////////////////////////


Finished

If I try running the script with  sudo  then I can get a bit farther, but the  wget  error persists and I also notice that the "extracting kernel src" step and all subsequent steps fail:
Code: [Select]
$ sudo linux-kernel-sources-env.sh
Script will prepare kernel sources and deps
for a 10.x x86 compile environment.

////////////////////////////////////////////////////////////////////////////////

compiletc.tcz loaded
glibc_apps.tcz loaded
automake.tcz loaded
findutils.tcz loaded
bash.tcz loaded
ncursesw-dev.tcz loaded
autoconf.tcz loaded
perl5.tcz loaded
xz.tcz loaded
bc.tcz loaded
checking repo for linux-4.19.10-patched.tar.xz
Connecting to www.tinycorelinux.net (89.22.99.37:80)
wget: server returned error: HTTP/1.1 404 Not Found
checking repo for linux-4.19.10-patched.txz
Connecting to www.tinycorelinux.net (89.22.99.37:80)

 Cleaning up previous builds
/usr/src cleaned

Searching for src files...

Verifying src files...
linux-4.19.10-patched.txz ready
config-4.19.10-tinycore ready
Module.symvers-4.19.10-tinycore.gz ready

preparing kernel src...
extracting kernel src... tar: corrupted data
tar: short read

Step 1 "make mrproper"... make: *** No rule to make target 'mrproper'.  Stop.

Step 2 "make oldconfig" make: *** No rule to make target 'oldconfig'.  Stop.

Step 3 "make prepare" make: *** No rule to make target 'prepare'.  Stop.

Step 4 "make modules_prepare" make: *** No rule to make target 'modules_prepare'.  Stop.

Module.symvers-4.19.10-tinycore copied
make: *** No targets specified and no makefile found.  Stop.
Set ownership...
make symlinks to source...
kernel src files ready


////////////////////////////////////////////////////////////////////////////////


Finished

It seems to me these are the possible explanations:
- a necessary file is missing from the server
- the downloaded tarball is corrupt
- the script has a bug
- I'm doing something wrong

Please help.
« Last Edit: May 14, 2020, 10:01:28 AM by GNUser »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11573
Re: linux-kernel-sources-env.sh fails with wget and tar errors
« Reply #1 on: May 14, 2020, 10:01:21 AM »
Hi GNUser
You want the source and config file used to build the kernel you are running. Here's a step by step I used when I needed
some kernel modules:

Hi pditty
I'm guessing maybe some permissions got messed up in  rootfs.gz.  Maybe I missed it, but I didn't see why  rootfs.gz  needed
to be changed.

Try this procedure:
... A couple of months ago I had to recompile a kernel to get some hardware on an ASUS T100 Transformer recognized and ran into
the same problem ("is already owned by kernel" error).

The error ("is already owned by kernel") is basically saying a symbol that a module is defining is already defined by the kernel. When
configuring a kernel, selecting certain options will force some drivers to be built into the kernel instead of as a module. So, assuming
you already have existing kernel modules, DRIVER_A is a module depending on DRIVER_B. You select a kernel option that requires
DRIVER_B to be built into the kernel. If you try loading DRIVER_A with the new kernel, it will attempt to load DRIVER_B (a dependency)
and you get that symbol "is already owned by kernel" error. This means DRIVER_A also needs to be recompiled so it no longer tries
to load DRIVER_B.

What I wound up doing is recompiling all modules when I changed the kernel. Here's a step by step for the whole procedure:
Code: [Select]
Compile a kernel:
tce-load -i compiletc perl5 bash ncursesw-dev bc glibc_apps elfutils-dev
wget http://tinycorelinux.net/10.x/x86_64/release/src/kernel/config-4.19.10-tinycore64
wget http://tinycorelinux.net/10.x/x86_64/release/src/kernel/linux-4.19.10-patched.txz
tar xf linux-4.19.10-patched.txz
cd  linux-4.19.10
make mrproper
# Start with the most recent config file.
cp ../config-4.19.10-tinycore64 .config
make oldconfig
make menuconfig [make your changes]
# I like to save a copy of the config file to use as a starting point for the next time.
cp .config ../config-4.19.10-tinycore64-asusT100CHIrev1
# Compile kernel
make -j 2 bzImage
# Copy the kernel where the bootloader can find it.
cp arch/x86/boot/bzImage /mnt/sdg1/Linux/vmlinuzASUS64rev1
# Compile modules
make -j 2 modules
# Place the modules somewhere for packaging.
mkdir -p /home/tc/tmp/ASUS/modules/usr/local
make INSTALL_MOD_PATH=/home/tc/tmp/ASUS/modules/usr/local modules_install
cd /home/tc/tmp/ASUS/
# I like to keep the mod.alias, mod.builtin, mod.dep, mod.order, and mod.symbols files.
mv modules/usr/local/lib/modules/4.19.10-tinycore64/modules.* .
# Remove the 2 links in modules/usr/local/lib/modules/4.19.10-tinycore64/
rm modules/usr/local/lib/modules/4.19.10-tinycore64/build
rm modules/usr/local/lib/modules/4.19.10-tinycore64/source

# Set up sorter.sh to package all the modules.
cd ..
mkdir sorter
cd sorter
tce-load -i squashfs-tools zsync
wget https://github.com/tinycorelinux/sorter/archive/master.zip
unzip master.zip
cd sorter-master/
# This creates all of the Tinycore module packages and leaves them in the current directory.
./sorter.sh 4.19.10-tinycore64 /home/tc/tmp/ASUS/modules
# Back to the tmp directory.
cd ../../
# Fetch a 32 bit root file system.
wget http://tinycorelinux.net/10.x/x86/release/distribution_files/rootfs.gz
# Copy the module archive that's part of the base system
cp sorter/sorter-master/modules64.gz modulesASUS64rev1.gz
# Make a new initrd, 64 bit modules with 32 bit root file system (32 bit apps) in this example.
cat rootfs.gz modulesASUS64rev1.gz > coreASUS64rev1.gz
# Copy the initrd where the bootloader can find it.
cp coreASUS64rev1.gz /mnt/sdg1/Linux/

The downloads only need to be done once. If you need to compile again, use the config file you saved previously as a starting point.

Created directories to archive the results of each build. This allows you to revert to a previous build and keeps matching config,
kernels, modules, and initrd files together. Append  rev1  to the config, kernel, and initrd filenames and place them in a  rev1
directory along with their matching modules.

Compile times on a Dell Dimension E310 were 52 minutes for the kernel and 3 hours 45 minutes for the modules.
Apply your patch, probably after  make mrproper.  There's a sorter script that separates and packages all of the modules. I mixed
a 64 bit kernel with a 32 bit  rootfs.gz  for my needs. Download the  rootfs.gz  that matches your requirements. The procedure is
fairly well commented as to what's going on. Ask questions if something I did seems unclear.

If you really feel the need to unpack/pack  rootfs.gz:
To unpack:
Code: [Select]
mkdir tempdir
cd tempdir
zcat /path/to/existing/rootfs.gz | sudo cpio -i

To repack:
Code: [Select]
sudo find . | sudo cpio -o -H newc | gzip > /path/to/new/initrd.gz
Found here:
http://forum.tinycorelinux.net/index.php/topic,22398.msg140327.html#msg140327

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1496
Re: linux-kernel-sources-env.sh fails with wget and tar errors
« Reply #2 on: May 14, 2020, 10:12:49 AM »
Thank you, Rich, but I'm not sure how that's going to help with my specific goal.
I'm trying to perform steps 2 and 3 here: https://www.wireguard.com/compilation/

Code: [Select]
$ tce-load -wi compiletc git linux-4.19_api_headers linux-kernel-sources-env
$ sudo linux-kernel-sources-env.sh # output as above (with wget, tar, and make errors)
$ git clone https://git.zx2c4.com/wireguard-linux-compat
$ make -C wireguard-linux-compat/src -j2
make -C wireguard-linux-compat/src -j2
make: Entering directory '/home/bruno/wireguard-linux-compat/src'
make[1]: *** No rule to make target 'modules'.  Stop.
make: *** [Makefile:25: module] Error 2
make: Leaving directory '/home/bruno/wireguard-linux-compat/src'

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11573
Re: linux-kernel-sources-env.sh fails with wget and tar errors
« Reply #3 on: May 14, 2020, 10:19:16 AM »
Hi GNUser
Sorry, when you said kernel module I presumed you were referring to an in tree module. I didn't catch the part about  wireguard.

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14790
Re: linux-kernel-sources-env.sh fails with wget and tar errors
« Reply #4 on: May 14, 2020, 10:40:26 AM »
If you look at the build notes for the wl module in the 10.x x86_64 src directory, it outlines a quick method to prepare the kernel source.

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1496
Re: linux-kernel-sources-env.sh fails with wget and tar errors
« Reply #5 on: May 14, 2020, 10:48:40 AM »
Thank you, juanito. That's exactly what I needed :)

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14790
Re: linux-kernel-sources-env.sh fails with wget and tar errors
« Reply #6 on: May 14, 2020, 10:52:06 AM »
No problem - unfortunately it doesn’t work for the linux-5.x kernels..