Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Creating a custom package for building the kernel
View unanswered posts
View posts from last 24 hours

Goto page 1, 2  Next  
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
medvednic
n00b
n00b


Joined: 11 Apr 2016
Posts: 8

PostPosted: Mon Apr 11, 2016 5:55 pm    Post subject: Creating a custom package for building the kernel Reply with quote

Hello,

I need to create an ebuild for building and installing the kernel (4.1.15-r1) based on a custom configuration file, the following dependencies should be included:
Code:
sys-kernel/gentoo-sources
sys-apps/kmod

This is what I have to start with so far, but I don't know where to proceed from here:

Code:

EAPI=5

DESCRIPTION="Binary kernel for my Linux distro"
HOMEPAGE="https://noexec.org/"

LICENSE="GPL-2"
SLOT="0"
KEYWORDS="~amd64"

DEPEND="
    sys-kernel/gentoo-sources
    sys-apps/kmod"


Where do I get the kernel source from? and what ebuild functions do I need to implement?
I also know that I need to use the following line:
Code:
make -C /usr/src/linux-${PV}-gentoo${PVR#${PV}} O=${T}/... <command>


Thanks,
Back to top
View user's profile Send private message
fpemud
Guru
Guru


Joined: 15 Feb 2012
Posts: 356

PostPosted: Tue Apr 12, 2016 4:06 am    Post subject: Reply with quote

medvednic,

Welcome to Gentoo.


I have been already doing this from 2013:
Project: https://github.com/fpemud/fpemud-kernelmanager
Ebuild: https://github.com/fpemud/fpemud-overlay/tree/master/pkg-fpemud/fpemud-kernelmanager

It manages from linux-3.16 to my current kernel linux-4.4.6.
I suggest you create your own medvednic-kernelmanger by forking this project.
I'd like to offer any help you need.


Compiling linux kernel in ebuild can give perfect experience.
But I failed to make such a ebuild because I found the management procedure for linux kernel is different from applications.
I guess it is the very reason why all the ebuilds install linux source only.

fpemud-kernelmanager does the downloading, configuring, compiling, installing on its own.
And it also does many other related works such as initramfs making, grub installing, resuce kernel managing, history kernel managing.
It is hard to make a generic tool for these job.


If you don't want to bother, you can simply use sys-kernel/genkernel-next which I think you already know about.
But I don't think it can give a perfect experience.
Back to top
View user's profile Send private message
Genone
Retired Dev
Retired Dev


Joined: 14 Mar 2003
Posts: 9643
Location: beyond the rim

PostPosted: Tue Apr 12, 2016 6:30 am    Post subject: Reply with quote

Why would you _need_ such an ebuild?
While it's possible to do kernel compilation/installation in an ebuild it would require a number of hacks to achieve it and is therefore not recommended.
Back to top
View user's profile Send private message
medvednic
n00b
n00b


Joined: 11 Apr 2016
Posts: 8

PostPosted: Tue Apr 12, 2016 9:12 pm    Post subject: Reply with quote

Well I need such an ebuild because I have to do it as part of an assignment at my college, I came to this last bastion of hope to seek some help and guidance, hoping that some one can throw me a bone which I can use.
Back to top
View user's profile Send private message
Genone
Retired Dev
Retired Dev


Joined: 14 Mar 2003
Posts: 9643
Location: beyond the rim

PostPosted: Wed Apr 13, 2016 9:29 am    Post subject: Reply with quote

Thing is: you seem to be quite new to ebuild writing in general, and the kernel is a very special component, so actually answering your question in a way that helps you is a bit much for a forum post if you need an ebuild to build and install a kernel properly.

I could of course just tell you that you'll need the functions src_compile, src_install and pkg_postinst, but I don't think that helps you much. And sorry to be so direct, but that you're asking where to get the kernel source while having a DEPEND on gentoo-sources shows that you don't really understand what you're doing so far. Either you want to rely on gentoo-sources to handle the kernel sources (then your question is obsolete) or you write your own kernel ebuild in which case you'd better use kernel-2.eclass (which is a beast on its own).
And this isn't even talking about stuff like installing modules, setting up bootloaders, rebuilding external modules and some other things I likely forgot.
Back to top
View user's profile Send private message
steveL
Watchman
Watchman


Joined: 13 Sep 2006
Posts: 5153
Location: The Peanut Gallery

PostPosted: Wed Apr 13, 2016 10:09 am    Post subject: Reply with quote

medvednic wrote:
I need such an ebuild because I have to do it as part of an assignment at my college

Oh, I thought it was for a bindist.
One would do a pre-compiled kernel for a binary distro, and the ebuild would not need to do any compilation, just unpack and install.

Building a kernel to admin specification, is a job for the admin to sort out. Many of us (most people I know) do it manually, many use genkernel.

I don't see what point there is in trying to get an ebuild to do all that from a config file, but it's feasible to use genkernel as a DEPEND (= build-time dependency installed to CBUILD), and is what I would do if I were forced to do this. (It means you're just exposing genkernel, and all the configuration is prior-art you don't have to think about.)
Note you have to consider cross-compilation, since the machine building the software, may not be the one running the software (CHOST. Neither CBUILD nor CHOST are CTARGET which only has any meaning for toolchain software.)

I guess that would be a useful point to this: cross-compiling kernels on an automated build-server with FEATURES=buildpkg. Take a look at toolchain-funcs.eclass.
Back to top
View user's profile Send private message
medvednic
n00b
n00b


Joined: 11 Apr 2016
Posts: 8

PostPosted: Wed Apr 13, 2016 6:20 pm    Post subject: Reply with quote

Thanks for the replies, I will try to ask more specific questions after reading some documentation and trying to write something that actually performs.

What I want to achieve:
the ebuild will download the kernel source, configure the kernel according to a custom .config file and install the kernel in a directory that would be specified as an argument to make -C.

What I achieved so far:
after executing emerge on my .ebuild file: emerge gentoo-kernel
which now consists of:
Code:

EAPI=5

DESCRIPTION="Kernel for my Linux distro"
HOMEPAGE=""

LICENSE="GPL-2"
SLOT="0"
KEYWORDS="amd64"

DEPEND="
    sys-kernel/gentoo-sources
    sys-apps/kmod"


1. The kernel source is downloaded to usr/src/linux,
2. I add the .config file to the directory
3. executing make without any arguments compiles the kernel.

In order to continue and achieve my goals I know that the following three functions must to be in the ebuild:
src_install, src_compile , pkg_config
the following commands should also be called:
make -C /usr/src/linux-${PV}-gentoo${PVR#${PV}}
make install_modules

make install_modules actually fails and the log says that modules are disabled in the kernel config.

I would appreciate if someone can shed some more light about what I need to write in the ebuild functions and how can I enable modules in the kernel config file.

Thanks,
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6227
Location: Room 101

PostPosted: Wed Apr 13, 2016 9:40 pm    Post subject: Reply with quote

medvednic ... something you need to understand is that a package (such as yours) doesn't act on some part of the filesystem (ie, /usr/src/linux), what happens is that sources are unpacked in /var/tmp/portage/<category>/<package>/work and all the patching, configuring, building happens there. Once built the resulting binaries, docs, etc, etc, are installed to /var/tmp/portage/<category>/<package>/image, and it is these files that get installed ('merged') into the root of the filesystem. From the above description I can see you don't understand this fact, and this makes your task of writing such an ebuild problematic, because its these concepts, routines, etc, that constitute the ebuild. So, really, you need to understand the basics first, which I would assume is the purpose of this assignment.

An ebuild is in essence a script, what goes into that is script is simply those things required to configure, build, and install the target 'application', or 'package'. So, for that reason, forget about sys-kernel/gentoo-sources, because its not a dependency, or the sources of your package, as its a package in its own right, a package installed already into the root of the filesystem.

As Genone stated above, that is what makes the linux kernel sources different, because these are generally installed into the filesystem, configured, built, and installed, outside the package manager (the package manager is only 'managing' the sources). You could effectively do this via an ebuild but its not a simple matter, particularly if you don't have a basic understanding of what the process involves. That said, I'm trying to understand the nature of the assignment, are you expected to do prior research into ebuild development before attempting such a task, what exactly was the scope of the assignment and its background? It seems that you need to do a lot more research before fielding questions of the type above, because all you really have currently is 'skel.ebuild' with a number of mistaken assumptions about the way ebuilds work. It might be better if you ask questions of a more general nature, or for resources on the subject, because I don't think you'll make much headway without getting such a basic understanding.

best ... khay
Back to top
View user's profile Send private message
Genone
Retired Dev
Retired Dev


Joined: 14 Mar 2003
Posts: 9643
Location: beyond the rim

PostPosted: Thu Apr 14, 2016 9:12 am    Post subject: Reply with quote

And just to clarify a bit more: While building and installing the kernel manually is pretty straightforward, doing the same inside an ebuild (or any other more or less formal automated system) is a whole different story. Especially if you want to do it properly.
Back to top
View user's profile Send private message
C5ace
Guru
Guru


Joined: 23 Dec 2013
Posts: 498
Location: Brisbane, Australia

PostPosted: Thu Apr 14, 2016 9:34 am    Post subject: Reply with quote

I use a "Cut & Paste" script to install gentoo on desktops, VirtualBox and laptops, including building the kernel with genkernel. This script can easily be used as basis to write a "C" command line program to do the same.

This is the script I used last time to install gentoo on VirtualBox:

Code:

# These instructions are for installing Gentoo on Oracle VirtualBox with
# Oracle VirtualBox Extentions installed on the host PC and are based on
# the Gentoo Handbook.
# I allocate 1GB during intallation and change to 512KB after competing the installation.
# I can still work with 255 KB but slow.

# My local setup is a LAN with several Linux and Win$ boxes with fixed IP addresses.
# My local domain name: "itw.lan"
# My Gentoo VM FQDN: "gentoo.home.lan"
# IP address: 192.168.0.6
# Nameserver-1: 192.168.0.2 (I have my own name server for the LAN.)
# Nameserver-2: 192.168.0.1 (my Router has a very basic build in Name Server.)
# Route:   192.168.0.1
# Locale Australia/Brisbane

# Change these at the approbriate places in below text to match yours.

# The text without "#" in front are commands to be entered or copied into
# the terminal followed by hitting the Enter Key.


# Preparation:
# Download Gentoo Install CD from:
# distfiles.gentoo.org/releases/amd64/autobuilds/current-iso/install-amd64-minimal-20150730.iso

# Alternetuvely download and use Rescue CD as installation CD.

# Configure a Gentoo x86_64 virtual maschine to boot with Gentoo CD.iso as CD Drive,
# a virtual 30GB dard drive and Network Adapter as "Bridged Adapter".

# Boot your new virtual maschine from the Gentoo install CD.

## type on Gentoo Installer Screen

ifconfig

# Write down the IP address and name of your ethernet card like "eth0", "enp0s3"
# or whatever is your's.

net-setup eth0  #For manual setup if your Router does not have a DHCP server.

# Create a password for ssh access.
passwd
abc123
abc123

# Start sshd and ping google.com
/etc/init.d/sshd start
ping -c 3 google.com

# This completes configuration of the installation system for ssh access from a second PC.

# --------------------------------------------


# Open a terminal on your second or Host PC and log by ssh into Gentoo
ssh root@gentoo.home.lan
abc123

# Manally, step by step partition your Hard drive with these keybord commands:
# If you make a mistake, exit fdisk by 'q' and start again.

fdisk /dev/sda
o
n
p   
(Enter)
(Enter)
+500M
a

n
e
(Enter)
(Enter)
(Enter)

n
l
(Enter)
+2G
(Enter)
t
(Enter)
82

n
l
(Enter)
+20G

n
l
(Enter)
(Enter)
p
w
# DONE!

# ----------------------------------------------
# Now proceed by copying below texts to your terminal followed by Enter.
# You can copy line by line, section by section or several saections at a time
#-----------------------------------------------


# Create the File System:
mkfs.ext4 /dev/sda1 -L VB_BOOT
mkfs.ext4 /dev/sda6 -L VB_ROOT
mkfs.ext4 /dev/sda7 -L VB_HOME
mkswap /dev/sda5 -L VB_SWAP
swapon -L VB_SWAP

# Mount the Filesystem:
mount -L VB_ROOT /mnt/gentoo
mkdir /mnt/gentoo/boot
mount -L VB_BOOT /mnt/gentoo/boot
mkdir /mnt/gentoo/home
mount -L VB_HOME /mnt/gentoo/home
cd /mnt/gentoo

# Check the date
date

# Get Gentoo files from the internet
# links http://www.gentoo.org/main/en/mirrors/
# Select and download stage3....tar.bz2
# using Links is slow. Download from your local mirror.

wget http://ftp.swin.edu.au/gentoo/releases/amd64/autobuilds/current-stage3-amd64/stage3-amd64-20150730.tar.bz2
ls -l

tar xvjpf stage3-*.tar.bz2


# Change Root
mount -t proc none /mnt/gentoo/proc
mount --rbind /sys /mnt/gentoo/sys
mount --rbind /dev /mnt/gentoo/dev
chroot /mnt/gentoo /bin/bash
source /etc/profile
export PS1="gentoo.itw.lan $PS1"

# Copy DNS information
# Replace "home.lan" with your domain name
echo "domain home.lan" > /etc/resolv.conf
echo "nameserver 192.168.0.2" >> /etc/resolv.conf
echo "nameserver 192.168.0.1" >> /etc/resolv.conf

# Configure compile options in make.conf:
echo "CFLAGS=\"-O2 -march=native -pipe\"" > /etc/portage/make.conf
echo "CXXFLAGS=\"\${CFLAGS}\"" >> /etc/portage/make.conf

#change these flags to match your CPU.
echo "CPU_FLAGS_X86=\"3dnow 3dnowext mmx mmxext sse sse2 sse3\"" >> /etc/portage/make.conf

# Change "-j5" to the number of your processor cores plus 1.
echo "MAKEOPTS=\"-j5\"" >> /etc/portage/make.conf

echo "FEATURES=\"-preserve-libs\"" >> /etc/portage/make.conf
echo "CHOST=\"x86_64-pc-linux-gnu\"" >> /etc/portage/make.conf
echo "ACCEPT_KEYWORDS=\"amd64\"" >> /etc/portage/make.conf
echo "ACCEPT_LICENSE=\"*\"" >> /etc/portage/make.conf
echo "LINGUAS=\"en\"" >> /etc/portage/make.conf
echo "INPUT_DEVISES=\"evdev virtualbox\"" >> /etc/portage/make.conf
echo "VIDEO_CARDS=\"vboxvideo\"" >> /etc/portage/make.conf
echo "USE=\"-bindist -kde -gnome -qt gtk\"" >> /etc/portage/make.conf
echo "PORTDIR=\"/usr/portage\"" >> /etc/portage/make.conf
echo "DISTDIR=\"\${PORTDIR}/distfiles\"" >> /etc/portage/make.conf
echo "PKGDIR=\"\${PORTDIR}/packages\"" >> /etc/portage/make.conf
echo "XFCE_PLUGINS=\"brightness clock trash\"" >> /etc/portage/make.conf


# change "http://ftp.swin.edu.au/gentoo\" to you mirror
echo "GENTOO_MIRRORS=\"http://ftp.swin.edu.au/gentoo\"" >> /etc/portage/make.conf

# Create package.* files
mkdir /etc/portage/package.keywords
mkdir /etc/portage/package.unmask
mkdir /etc/portage/package.mask
mkdir /etc/portage/package.use
mkdir /etc/portage/repos.conf

echo "### package.keywords ###" > /etc/portage/package.keywords/keywords
echo "### package.unmask ###" > /etc/portage/package.unmask/unmask
echo "### package.mask ###" > /etc/portage/package.mask/mask
echo "### package.use ###" > /etc/portage/package.use/use

echo "app-portage/install-mask ~amd64" >> /etc/portage/package.keywords/keywords
echo "=sys-devel/gcc-4.9.3 ~amd64" >> /etc/portage/package.keywords/keywords

echo "dev-util/cmake -qt4" >> /etc/portage/package.use/use
echo "app-text/poppler -qt4" >> /etc/portage/package.use/use
echo "gnome-base/gvfs -http" >> /etc/portage/package.use/use
echo "sys-process/cronie -anacron" >> /etc/portage/package.use/use
echo ""
echo "x11-base/xorg-server udev" >> /etc/portage/package.use/use
echo "net-print/hplip scanner doc hpcups hpijs" >> /etc/portage/package.use/use
echo "xfce-base/thunar gvfs samba xfce_plugins_trash" >> /etc/portage/package.use/use

# Create repos.conf
echo "[DEFAULT]" > /etc/portage/repos.conf/gentoo.conf
echo "" >> /etc/portage/repos.conf/gentoo.conf
echo "main-repo = gentoo" >> /etc/portage/repos.conf/gentoo.conf
echo "" >> /etc/portage/repos.conf/gentoo.conf
echo "[gentoo]" >> /etc/portage/repos.conf/gentoo.conf
echo "location = /usr/portage" >> /etc/portage/repos.conf/gentoo.conf
echo "sync-type = rsync" >> /etc/portage/repos.conf/gentoo.conf
echo "sync-uri = rsync://rsync1.au.gentoo.org/gentoo-portage" >> /etc/portage/repos.conf/gentoo.conf
echo "auto-sync = yes" >> /etc/portage/repos.conf/gentoo.conf


# Sync Portagetree
emerge --sync

# Read IMPORTANT News
eselect news read

# Update and install gcc-4.9.3 required for compiling VirtualBox Guest Additions
emerge -u sys-devel/gcc
gcc-config 2
env-update && source /etc/profile
emerge --oneshot libtool


# Select Timezone
ls /usr/share/zoneinfo
echo "Australia/Brisbane" > /etc/timezone
emerge --config sys-libs/timezone-data

# Specify your locale. (change to yours)
echo "en_AU ISO-8859-1" >> /etc/locale.gen
echo "en_AU.UTF-8 UTF-8" >> /etc/locale.gen
locale-gen
echo "LANG=\"en_AU.UTF-8\"" > /etc/env.d/02locale
echo "LC_COLLATE=\"C\"" >> /etc/env.d/02locale
env-update && source /etc/profile
date

emerge --oneshot portage
source /etc/profile
export PS1="gentoo.home.lan $PS1"

# Select Profile. We list and use Desktop (3)
eselect profile list

# for Xfce Desktop
eselect profile set 3

# Install Kernel Sources
emerge gentoo-sources
ls -l /usr/src/linux

# Use General Kernel and/or modify Kernel Configuration
emerge genkernel
echo "MAKEOPTS=\"-j5\"" >> /etc/genkernel.conf
echo "DISKLABEL=\"yes\"" >> /etc/genkernel.conf
echo "MDADM=\"yes\"" >> /etc/genkernel.conf
#echo "BOOTLOADER=\"grub\"" >> /etc/genkernel.conf
genkernel all

# Verify Kernel installation
ls /boot/kernel* /boot/initramfs*

# Emerge grub and edit its configuration file
emerge grub-static

# Write down the kernel and initramfs full file names and versions
# nano -w /boot/grub/grub.conf
echo "default 0" > /boot/grub/grub.conf
echo "timeout 10" >> /boot/grub/grub.conf
echo "" >> /boot/grub/grub.conf

# Change "4.0.5" to your kernel version
echo "title Gentoo Linux 4.0.5-gentoo" >> /boot/grub/grub.conf
echo "root (hd0,0)" >> /boot/grub/grub.conf

# Change the kernel and initramfs filenames to your full name and versions
echo "kernel /boot/kernel-genkernel-x86_64-4.0.5-gentoo net.ifnames=0 root=/dev/ram0 real_root=LABEL=VB_ROOT" >> /boot/grub/grub.conf
echo "initrd /boot/initramfs-genkernel-x86_64-4.0.5-gentoo" >> /boot/grub/grub.conf
echo "" >> /boot/grub/grub.conf

# Create /etc/fstab
# nano -w /etc/fstab
echo "# <fs>          <mountpoint>    <type>  <opts>          <dump/pass>" > /etc/fstab
echo "LABEL=VB_BOOT   /boot           ext4    noauto,noatime  1 2" >> /etc/fstab
echo "LABEL=VB_ROOT   /               ext4    noatime         0 1" >> /etc/fstab
echo "LABEL=VB_HOME   /home           ext4    noatime         0 2" >> /etc/fstab
echo "LABEL=VB_SWAP   none            swap    sw              0 0" >> /etc/fstab
echo "/dev/cdrom      /mnt/cdrom      auto    noauto,ro       0 0" >> /etc/fstab
echo "# /dev/fd0        /mnt/floppy     auto    noauto          0 0" >> /etc/fstab

cd /etc/conf.d
# Change 192.168.0.6 to your fixed IP address previously written down
echo 'config_eth0="192.168.0.6 netmask 255.255.255.0 brd 192.168.0.255"' > net
echo 'routes_eth0="default via 192.168.0.1"' >> net

# Adding net.eth0 to the default runlevel
cd /etc/init.d
ln -s net.lo net.eth0
rc-update add net.eth0 default

# Filling in the networking information
cd /etc
echo "127.0.0.1     gentoo.home.lan gentoo  localhost" > /etc/hosts

# Change 192.168.0.6 to your fixed IP address previously written down
echo "192.168.0.6  gentoo.home.lan gentoo" >> /etc/hosts

# Configure networking
cd /etc/conf.d
echo 'hostname="gentoo"' > hostname
hostname gentoo
hostname -f

# Install a syslogger, a cron daemon, mc and sshd
emerge app-admin/syslog-ng
rc-update add syslog-ng default
emerge sys-process/cronie
rc-update add cronie default
rc-update add sshd default
env-update && source /etc/profile

emerge sys-apps/mlocate
emerge app-portage/gentoolkit
emerge app-admin/eclean-kernel
emerge app-portage/diffmask
emerge app-portage/flaggie
emerge app-portage/install-mask
emerge app-portage/portpeek
emerge app-portage/smart-live-rebuild
emerge app-misc/mc
eselect fontconfig enable 22

# Adding sshd to the default runlevel
rc-update add sshd default

# Add your username. Change "user" to your username.
useradd -m -G users,wheel,audio,cdrom,portage,usb -s /bin/bash user
passwd user

# Setting the root password
passwd
abc123
abc123

# Install grub leagacy
grub --no-floppy
# grub> root (hd0,0)
# grub> setup (hd0)
# grub> quit

# Poweroff
exit
umount -l /mnt/gentoo/dev{/shm,/pts,}
umount -l /mnt/gentoo{/proc,/boot,/home,/sys,}
poweroff

# ----------------------------------------
# End of basic installation
# ----------------------------------------

# Remove the Gentoo CD


# This completes the installation of the Base System.
# Boot your Gentoo VM, log in with your username "user", ping google.com to verify that it works.
# Then login as root from your workstation terminal.

Change directory to /
cd /

# Install X
emerge xorg-server
emerge app-emulation/virtualbox-guest-additions
rc-update add xdm default
env-update && source /etc/profile
echo XSESSION="Xfce4" > /etc/env.d/90xsession

# Install Xfce
emerge xfce-base/xfce4-meta
emerge x11-terms/xfce4-terminal
emerge app-editor/leafpad
emerge app-portage/porthole
env-update && source /etc/profile
/etc/init.d/dbus start
rc-update add dbus default
rc-update add xdm default

emerge x11-misc/slim

# Editing /etc/conf.d/xdm
# nano -wc /etc/conf.d/xdm
# DISPLAYMANAGER="slim"
echo "CHECKVT=7" > /etc/conf.d/xdm
echo "DISPLAYMANAGER=\"slim\"" >> /etc/conf.d/xdm
rc-update add xdm default

eselect fontconfig enable 1 2 4 5 6 7 8 9 10 11 12 13 14 24 25 26

#-------------------------------------
# End of Xfce installation
# ------------------------------------


reboot

# if all is well, you should now see the Slim login screen
# Login as root
# emerge your favorite Xfce and other applications like:
# porthole
# leafpad
# mc (Midnight Commander)
# midori or firefox
# claws mail or thunderbird
# libreoffice
# webmin
# avoid Gnome and KDE applications. They pull in tons of dependencies
 
# Happy computing!

 
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6227
Location: Room 101

PostPosted: Thu Apr 14, 2016 11:11 am    Post subject: Reply with quote

C5ace wrote:
I use a "Cut & Paste" script to install gentoo on desktops, VirtualBox and laptops, including building the kernel with genkernel. This script can easily be used as basis to write a "C" command line program to do the same.

C5ace ... that isn't going to be any help to the OP, they have been provided an assignment, and that assignment is to create an ebuild to build and install the kernel.

best ... khay
Back to top
View user's profile Send private message
C5ace
Guru
Guru


Joined: 23 Dec 2013
Posts: 498
Location: Brisbane, Australia

PostPosted: Thu Apr 14, 2016 1:08 pm    Post subject: Reply with quote

khayyam wrote:
C5ace wrote:
I use a "Cut & Paste" script to install gentoo on desktops, VirtualBox and laptops, including building the kernel with genkernel. This script can easily be used as basis to write a "C" command line program to do the same.

C5ace ... that isn't going to be any help to the OP, they have been provided an assignment, and that assignment is to create an ebuild to build and install the kernel.

best ... khay


Why not create a ebuild that runs a bash script which runs:
emerge sys-kernel/gentoo-sources
emerge sys-kernel/genkernel
genkernel all
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6227
Location: Room 101

PostPosted: Thu Apr 14, 2016 1:37 pm    Post subject: Reply with quote

C5ace wrote:
khayyam wrote:
C5ace ... that isn't going to be any help to the OP, they have been provided an assignment, and that assignment is to create an ebuild to build and install the kernel.

Why not create a ebuild that runs a bash script which runs:
emerge sys-kernel/gentoo-sources
emerge sys-kernel/genkernel
genkernel all

C5ace ... that should be obvious, such an ebuild would be contrary to the "policies, standards, and procedures [...] of our developement system" (Gentoo developer handbook), for any number of reasons.

best ... khay
Back to top
View user's profile Send private message
szatox
Advocate
Advocate


Joined: 27 Aug 2013
Posts: 3682

PostPosted: Thu Apr 14, 2016 5:13 pm    Post subject: Reply with quote

Quote:

Why not create a ebuild that runs a bash script which runs:
emerge sys-kernel/gentoo-sources
emerge sys-kernel/genkernel
genkernel all
If nothing more, you're running inside sandbox, and sandbox would tell you to die. And it defeats the purpose of ebuilds.

However it is doable with make instead of genkernel, and dependencies instead of calling emerge recursively.
And yes, you do need a few shell commands as well, but not the way you described it.
So, here is the hint on a way that does work:

depend on <SOME>-sources and other things necessary at build time. Like bc, for example. Kernel will not compile without bc.
Copy just-installed sources from /usr/src to emerge's build directory. This is the only location you can think of as a scratch pad. Do not even try writing anything outside of it: you will fail.
Copy your config in.
Run make/emake to build your stuff into the pre-install directory. This is the branch that will be recorded by emerge and installed into your system. For kernel, you will typically want to create boot directory and put your kernel there, as well as lib/modules.

At the end you can even have emerge build a binary package for you. And when you're done, you can emerge -c it and it will be gone, without leaving any files behind (Ops.... you haven't just rendered your box unbootable, have you?)

And no, I don't say it's pretty. But at least it does not make a mess like genkernell all approach would
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6227
Location: Room 101

PostPosted: Thu Apr 14, 2016 6:51 pm    Post subject: Reply with quote

szatox wrote:
depend on <SOME>-sources and other things necessary at build time [...] Copy just-installed sources from /usr/src to emerge's build directory.

szatox ... I don't see any reason to treat this package's source files any differently to any other package ... so rather than a dependency on '*-sources' simply provide it as SRC_URI

Code:
EAPI="5"

K_WANT_GENPATCHES="base extras experimental"
K_GENPATCHES_VER="9"
K_DEBLOB_AVAILABLE="0"

inherit kernel-2 eutils
detect_version
detect_arch

KEYWORDS="~alpha ~amd64 ~arm ~arm64 -hppa ~ia64 ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86"
IUSE="experimental"

DESCRIPTION="blah blah for ${KV_MAJOR}.${KV_MINOR}"
SRC_URI="${KERNEL_URI} ${GENPATCHES_URI} ${ARCH_URI}"

That's pretty much lifted directly from gentoo-sources-*.ebuild, and should be enough to provide the sources in */work.

szatox wrote:
Copy your config in.

Code:
src_prepare() {
   cp "${FILESDIR}"/"${P}".config "${S}"/.config"
   make silentoldconfig # ewww ... your config had better be current as that is interactive.
}

szatox wrote:
Run make/emake to build your stuff into the pre-install directory. This is the branch that will be recorded by emerge and installed into your system. For kernel, you will typically want to create boot directory and put your kernel there, as well as lib/modules.

This is where it gets tricky, I think the kernel still supports INSTALL_PATH and INSTALL_MOD_PATH, so the following should work ...

Code:
src_install() {
   make INSTALL_MOD_PATH="${D}" modules_install || die
   make INSTALL_PATH="${D}"/boot install || die
}

That is probably not enough, as it leaves all of the myrid of options for bootloader, /boot being mounted, or not, ... and the myriad of other things that could go wrong with such a package. Actually, the though of such an ebuild scares me ... take the above as a thought experiment.

best ... khay
Back to top
View user's profile Send private message
szatox
Advocate
Advocate


Joined: 27 Aug 2013
Posts: 3682

PostPosted: Thu Apr 14, 2016 7:41 pm    Post subject: Reply with quote

Quote:
I don't see any reason to treat this package's source files any differently to any other package ... so rather than a dependency on '*-sources' simply provide it as SRC_URI
Why? AFAIR it would simply not work. Sure, I can imagine it could be done the pretty way, but I suppose I just don't know emerge well enough to figure it out. Or maybe didn't know when I tried it, and was too busy with other things to try again after gaining some experience :roll:
So many cool things to do, so little time...
Back to top
View user's profile Send private message
C5ace
Guru
Guru


Joined: 23 Dec 2013
Posts: 498
Location: Brisbane, Australia

PostPosted: Thu Apr 14, 2016 9:29 pm    Post subject: Reply with quote

C5ace wrote:
khayyam wrote:
C5ace wrote:
I use a "Cut & Paste" script to install gentoo on desktops, VirtualBox and laptops, including building the kernel with genkernel. This script can easily be used as basis to write a "C" command line program to do the same.

C5ace ... that isn't going to be any help to the OP, they have been provided an assignment, and that assignment is to create an ebuild to build and install the kernel.

best ... khay


Why not create a ebuild that runs a bash script which runs:
emerge sys-kernel/gentoo-sources
emerge sys-kernel/genkernel
genkernel all


I understood that medvednic's assignment was to create a private ebuild.

regards c5ace
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6227
Location: Room 101

PostPosted: Thu Apr 14, 2016 11:11 pm    Post subject: Reply with quote

C5ace wrote:
I understood that medvednic's assignment was to create a private ebuild.

C5ace ... regardless of who the end user is, or what level of correctness is expected, ebuild's are defined by "policies, standards, and procedures". An ebuild is not a means to run a script that then emerge's x,y,z and then runs an interactive program, it is itself a script that configures, builds, and installs, source code, taking into account that source codes depenedencies, etc, etc, ... to a certain specification (so, correctly).

best ... khay
Back to top
View user's profile Send private message
C5ace
Guru
Guru


Joined: 23 Dec 2013
Posts: 498
Location: Brisbane, Australia

PostPosted: Fri Apr 15, 2016 12:33 am    Post subject: Reply with quote

khayyam wrote:
C5ace wrote:
I understood that medvednic's assignment was to create a private ebuild.

C5ace ... regardless of who the end user is, or what level of correctness is expected, ebuild's are defined by "policies, standards, and procedures". An ebuild is not a means to run a script that then emerge's x,y,z and then runs an interactive program, it is itself a script that configures, builds, and installs, source code, taking into account that source codes depenedencies, etc, etc, ... to a certain specification (so, correctly).

best ... khay


Would it be correct that a ebuild could download and install gentoo-sources and genkernel, but not execute genkernel?

regards C5ace
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6227
Location: Room 101

PostPosted: Fri Apr 15, 2016 1:10 am    Post subject: Reply with quote

C5ace wrote:
khayyam wrote:
... regardless of who the end user is, or what level of correctness is expected, ebuild's are defined by "policies, standards, and procedures". An ebuild is not a means to run a script that then emerge's x,y,z and then runs an interactive program, it is itself a script that configures, builds, and installs, source code, taking into account that source codes depenedencies, etc, etc, ... to a certain specification (so, correctly).

Would it be correct that a ebuild could download and install gentoo-sources and genkernel, but not execute genkernel?

C5ace ... no, because 'gentoo-sources' is not in fact a dependency, the ebuild should get whatever source code is required independently of another package. Take for example sys-power/cpupower or dev-util/perf, the source code is part of the linux kernel tarball, but these packages don't depend on *-sources, they simply use the same tarball. As for genkernel, that isn't strictly a dependency either, though you haven't actually said what the package is, so it could be made optional via a useflag. As for running any potentially interactive app (including, genkernel, or the 'make silentoldconfig' I used above) that is a no-no.

best ... khay
Back to top
View user's profile Send private message
C5ace
Guru
Guru


Joined: 23 Dec 2013
Posts: 498
Location: Brisbane, Australia

PostPosted: Fri Apr 15, 2016 1:32 am    Post subject: Reply with quote

khayyam wrote:
C5ace wrote:
khayyam wrote:
... regardless of who the end user is, or what level of correctness is expected, ebuild's are defined by "policies, standards, and procedures". An ebuild is not a means to run a script that then emerge's x,y,z and then runs an interactive program, it is itself a script that configures, builds, and installs, source code, taking into account that source codes depenedencies, etc, etc, ... to a certain specification (so, correctly).

Would it be correct that a ebuild could download and install gentoo-sources and genkernel, but not execute genkernel?

C5ace ... no, because 'gentoo-sources' is not in fact a dependency, the ebuild should get whatever source code is required independently of another package. Take for example sys-power/cpupower or dev-util/perf, the source code is part of the linux kernel tarball, but these packages don't depend on *-sources, they simply use the same tarball. As for genkernel, that isn't strictly a dependency either, though you haven't actually said what the package is, so it could be made optional via a useflag. As for running any potentially interactive app (including, genkernel, or the 'make silentoldconfig' I used above) that is a no-no.

best ... khay


Example, would this:
A new non-interactive package "install-kernel" depends on package "gentoo-sources" and modified non-interactive "genkernel" with a new useflag: "all" and as the last step the ebuild causes "install-kernel" to execute?
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6227
Location: Room 101

PostPosted: Fri Apr 15, 2016 6:25 am    Post subject: Reply with quote

C5ace wrote:
Example, would this: A new non-interactive package "install-kernel" depends on package "gentoo-sources" and modified non-interactive "genkernel" with a new useflag: "all" and as the last step the ebuild causes "install-kernel" to execute?

C5ace ... that "last step" would trigger a sandbox violation. It sounds as though you don't need an ebuild at all, just a script.

best ... khay
Back to top
View user's profile Send private message
Genone
Retired Dev
Retired Dev


Joined: 14 Mar 2003
Posts: 9643
Location: beyond the rim

PostPosted: Fri Apr 15, 2016 8:10 am    Post subject: Reply with quote

The big issue with depending on *-sources is versioning. If you have a unversioned dependency your ebuild has either no idea which path to use (you can't rely on the /usr/src/linux symlink to exist), or if you use $PV and $PVR you cannot rely on that specific version to be installed. So you have to specify versioned dependencies which means that you have to keep your ebuild up to date with the *-sources package all the time.

Btw, if you go the DEPEND="*-sources" approach you don't actually have to copy the sources as the kernel supports out-of-tree compilation natively.

Short version: Using an ebuild to build+install the kernel is like using a screwdriver to put in a nail - possible, but very inefficient.
Back to top
View user's profile Send private message
medvednic
n00b
n00b


Joined: 11 Apr 2016
Posts: 8

PostPosted: Sat Apr 16, 2016 10:13 pm    Post subject: Reply with quote

If one didn't copy the installed sources from /usr/src to emerge's build directory (as mentioned by szatox), can that be the cause of errors like:
Code:
Makefile:610: arch/amd64/Makefile: No such file or directory make[1]: *** No rule to make target 'arch/amd64/Makefile'. Stop.

this error shows up while performing make -C action (with destination directory and O directory arguments) in src_compile().
I managed to solve the error by creating a symlink from x86 to amd64 but now I experience error of missing headers:
Code:
fatal error: asm/unistd_64.h: No such file or directory # include
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6227
Location: Room 101

PostPosted: Sat Apr 16, 2016 11:16 pm    Post subject: Reply with quote

medvednic ...

please show us the ebuild and the build.log ...

Code:
# command -v wgetpaste || emerge wgetpaste
# wgetpaste /var/tmp/portage/<category>/<package>-<version>/build-info/<package>-<version>.ebuild
# wgetpaste /var/tmp/portage/<category>/<package>-<version>/temp/build.log

... then post the urls.

best ... khay
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum