Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
07-19-2017, 04:31 PM
|
#1
|
LQ Newbie
Registered: Sep 2012
Posts: 22
Rep:
|
CentOS rpmbuild overwrites my modded fault.c
Using CentOS 7.0 on x86/64 arch under VMWare vSphere. I have added code to fault.c for a new syscall. (It needs access to data in fault.c, so the function may as well be there). I have added the syscall number to syscall_64.tbl.
I added my buildid to kernel.specs.
I did a "cd" to /rpmbuild/SPECS.
I did rpmbuild -bb kernel-* (with my kernel #s for *).
When it was done, all my mods were gone. Looking in the build-err.log, I see that there are a couple of rm -rf commands, followed by copying the source back over my code.
As an experiment, a friend did this on MY system:
inside SOURCES: mkdir mydir and cd to it
cp linux-3.10.0-514.10.2.el7.tar.xz
tar xvf linux-3.10.0-514.10.2.el7.tar.xz
// make changes to kernel:
// add a file 'kernel/foo.c' which has a dummy syscall'; also add this to 'kernel/Makefile'
// add the syscall in 'arch/x86/syscalls/syscall_64.tbl'
tar cvf cp linux-3.10.0-514.10.2.el7.tar.xz cp linux-3.10.0-514.10.2.el7/
cp linux-3.10.0-514.10.2.el7.tar.xz ..
// I have backed up the original source tree as cp linux-3.10.0-514.10.2.el7.tar.xz.backup
and then run rpmbuild
*** THIS WORKED *** but why?
I can't figure out why my code in rpmbuild/BUILD/kernel-*/Linux-*/x86_64/arch/x86/mm/fault.c is being overwritten before the rpm is built, but not when it is inside a a separate directory inside SOURCES. Any suggestions would be very welcome.
Last edited by noguru; 07-19-2017 at 04:32 PM.
Reason: clarification
|
|
|
07-19-2017, 07:29 PM
|
#2
|
LQ Guru
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524
|
Rpm probably cleans the source tree before it compiles. But if you put your changes outside of the clean routine, and list it in Makefile, the compiler can still find it.
|
|
|
07-20-2017, 06:07 AM
|
#3
|
LQ Newbie
Registered: Sep 2012
Posts: 22
Original Poster
Rep:
|
According to all the CentOS documents I have used as references for building a new kernel, unless I am misunderstanding the flow, rpmbuild is supposed to work, without having to update the makefile.
As I understand it, I run rpmbuild -bb for the 1st time to create my base pkg. Then I should make my kernel changes, run rpmbuild -bb (again), then do an rpm -ivh.
Or should I not re-run the rpmbuild after the 1st time (by "1st time", I mean "before I make my changes")?
|
|
|
07-20-2017, 09:23 AM
|
#4
|
Senior Member
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,792
|
Reading the rpmbuild manpage would be helpful. Building the binary package ("-bb") always does a complete rebuild from the supplied SOURCES files and the SPEC file. "-bb Build binary package (after doing the %prep, %build, and %install stages)." If you want your patch included, you have to create a patch file in the SOURCES directory and adjust the SPEC file to include your patch. It's done that way to ensure that any binary or source package built is consistent with the supplied SOURCES.
Your first step would usually be " rpmbuild -bp ..." to unpack the source tree and apply the existing patches without going through the (perhaps lengthy) %build and %install stages. Of course it doesn't hurt to do the whole "-bb" procedure, but the resulting package will be discarded when you build your patched version.
Last edited by rknichols; 07-20-2017 at 09:30 AM.
Reason: Add recommendation for "rpmbuild -bp".
|
|
|
07-20-2017, 10:18 AM
|
#5
|
LQ Newbie
Registered: Sep 2012
Posts: 22
Original Poster
Rep:
|
Thanks for the clarification. So you're basically saying, it's either bad form or not possible to modify the ORIGINAL kernel code, but I have to create a "patch" file for things I want to mod, like fault.c and syscall_64.tbl, if I plan to continue to use rpm's. (FYI: my syscall is INSIDE fault.c because it needs access to data in that file and to run as part of the fault handling mechanism, when fault.c runs .)
And if I understand correctly, to CREATE a patch file, I need to - copy the original file (fault.c) to someplace safe,
- modify the copy
- create a (patch) file with only the differences using diff, etc.
- put the resulting file where rpmbuild "knows" where to find it (Sources ?? or a subdirectory ??)
Modify kernel.spec by adding the following line after last SourceN: line
===> PatchN: nameOfPatch (where name would be fault.c.patch)
Then goto the %prep section, add the following line after setup/unpack sources
===> patchN -p1
|
|
|
07-20-2017, 10:58 AM
|
#6
|
Senior Member
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,792
|
Quote:
Originally Posted by noguru
And if I understand correctly, to CREATE a patch file, I need to - copy the original file (fault.c) to someplace safe,
- modify the copy
- create a (patch) file with only the differences using diff, etc.
- put the resulting file where rpmbuild "knows" where to find it (Sources ?? or a subdirectory ??)
Modify kernel.spec by adding the following line after last SourceN: line
===> PatchN: nameOfPatch (where name would be fault.c.patch)
Then goto the %prep section, add the following line after setup/unpack sources
===> patchN -p1
|
That should do it. The patches typically go directly in the SOURCES directory, but I suppose they could be put in a subdirectory as long as you referenced them that way in the "PatchN: ..." line in the SPEC file.
If you just want to build a kernel for testing without actually building the new binary RPM, you can do it by manually running " rpmbuild -bc --short-circuit ..." and then " rpmbuild -bi --short-circuit ...". The "--short-circuit" bypasses the earlier build stages. You'll get files including your changes in the BUILD directory that you can copy to /boot and test. But when building the new binary RPM, rpmbuild insists on going through all the steps, thus ensuring that the result agrees with the SOURCES. ("--short-circuit" works only with "-bc" and "-bi".)
|
|
|
07-20-2017, 04:16 PM
|
#7
|
LQ Newbie
Registered: Sep 2012
Posts: 22
Original Poster
Rep:
|
And hopefully, 3 more questions before I try it all. To set it all up:
1. as user, create the tree folders (rpmbuild/{RPMS, SPECS, SOURCES, SRPMS, BUILD, BUILDROOT)
2. as root, use yum install for all the pre-req pkgs for build, such as rpm-build, python-devel, etc (I think steps 1 & 2 can be switched)
3. as user, "install" (i.e.; download) the source pkg via "rpm -i http://vault.....")
4. as user, modify SPECS/kernel.spec to add buildid
5. as root, unpack and prepare the source pkg via cd ~/rpmbuild and rpmbuild -bp ... (pointing to eh downloaded rpm
BUT: in step 1, the rpmbuild folder was created in USER's $HOME/ but in step 5, we are running rpmbuild from root. The syntax of the command instep 5 appears as if the rpmbuild folder is in root's home directory. I guess I'm not clear on how root is getting at USER's home directory without something special.
in step 3, how does "rpm -i" know where to put the downloaded rpm? There is nothing in the command to specify the location or even the file name.
And shouldn't my step 4 come AFTER step 5?
|
|
|
07-20-2017, 06:24 PM
|
#8
|
LQ Guru
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524
|
You should not work with the source tree as root. Always place it in your home directory. The rpm file specifies where it is to be installed. There are scripts inside of it. Here's a good link: https://fedoraproject.org/wiki/Building_a_custom_kernel
|
|
|
07-20-2017, 07:30 PM
|
#10
|
Senior Member
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,792
|
Quote:
Originally Posted by noguru
|
Install, yes. Root privileges are required. Build, no. That's running a lot of scripts and tools for which root privileges are not needed.
|
|
|
07-21-2017, 02:13 AM
|
#11
|
LQ Guru
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524
|
Quote:
Originally Posted by noguru
it says to install the rpm as root.
|
They're talking about the rpm after all the changes are made (installing the kernel rpm). The source rpm is just the source code for the kernel. You can install the source code rpm as a regular user.
See: https://wiki.centos.org/HowTos/I_need_the_Kernel_Source
will make the build structure for the installation of the source rpm.
Last edited by AwesomeMachine; 07-21-2017 at 02:24 AM.
|
|
|
07-21-2017, 06:11 AM
|
#12
|
LQ Newbie
Registered: Sep 2012
Posts: 22
Original Poster
Rep:
|
Sorry for all the questions. Hopefully, I have it right now.
So my step 5 above (unpack & prep the rpm) should be done as USER and only step 2 (yum install pre-reqs) is done as root. Then I can do the rpm -ivh as root to "install" {is the term again "install"?} the actual bootable rpm? I guess "install pre-reqs" means download and make them runable, whereas "install source rpm" means "put it in a folder", and "install the kernel rpm" means put the "bootable" code in /boot.
My plan is to:
A. for practice, create a non-modified version of the system as my buildid v0, (rpmbuild -bb followed by rpm -ivh)
B. create my patches with buildid v1 and rpmbuild -bb followed by rpm -ivh for this new version.
Do I have that all correct?
|
|
|
07-21-2017, 06:34 PM
|
#13
|
LQ Guru
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524
|
You must configure the kernel before you build it, with at least: make oldconfig. The main reason for building your own kernel is to make your own kernel config.
|
|
|
07-21-2017, 07:13 PM
|
#14
|
LQ Newbie
Registered: Sep 2012
Posts: 22
Original Poster
Rep:
|
Since I only plan to add a syscall function to the INSIDE of fault.c (to count page faults), I don't see any reason to reconfigure the kernel. No new modules. No new interfaces. And this version of the system will NOT be used by "general users". (It will be used to demo the differences in how user code can affect system performance.) What am I not seeing?
|
|
|
All times are GMT -5. The time now is 06:04 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|