LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 07-19-2017, 04:31 PM   #1
noguru
LQ Newbie
 
Registered: Sep 2012
Posts: 22

Rep: Reputation: Disabled
Unhappy 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
 
Old 07-19-2017, 07:29 PM   #2
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524

Rep: Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015
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.
 
Old 07-20-2017, 06:07 AM   #3
noguru
LQ Newbie
 
Registered: Sep 2012
Posts: 22

Original Poster
Rep: Reputation: Disabled
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")?
 
Old 07-20-2017, 09:23 AM   #4
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,792

Rep: Reputation: 2220Reputation: 2220Reputation: 2220Reputation: 2220Reputation: 2220Reputation: 2220Reputation: 2220Reputation: 2220Reputation: 2220Reputation: 2220Reputation: 2220
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".
 
Old 07-20-2017, 10:18 AM   #5
noguru
LQ Newbie
 
Registered: Sep 2012
Posts: 22

Original Poster
Rep: Reputation: Disabled
Question

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
  1. copy the original file (fault.c) to someplace safe,
  2. modify the copy
  3. create a (patch) file with only the differences using diff, etc.
  4. 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
 
Old 07-20-2017, 10:58 AM   #6
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,792

Rep: Reputation: 2220Reputation: 2220Reputation: 2220Reputation: 2220Reputation: 2220Reputation: 2220Reputation: 2220Reputation: 2220Reputation: 2220Reputation: 2220Reputation: 2220
Quote:
Originally Posted by noguru View Post
And if I understand correctly, to CREATE a patch file, I need to
  1. copy the original file (fault.c) to someplace safe,
  2. modify the copy
  3. create a (patch) file with only the differences using diff, etc.
  4. 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".)
 
Old 07-20-2017, 04:16 PM   #7
noguru
LQ Newbie
 
Registered: Sep 2012
Posts: 22

Original Poster
Rep: Reputation: Disabled
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?
 
Old 07-20-2017, 06:24 PM   #8
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524

Rep: Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015
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
 
Old 07-20-2017, 06:52 PM   #9
noguru
LQ Newbie
 
Registered: Sep 2012
Posts: 22

Original Poster
Rep: Reputation: Disabled
Unhappy

Quote:
Originally Posted by AwesomeMachine View Post
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
In https://wiki.centos.org/HowTos/Custo...81ad79077ba79b Step 6, it says to install the rpm as root.

I guess that's why I'm confused.
 
Old 07-20-2017, 07:30 PM   #10
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,792

Rep: Reputation: 2220Reputation: 2220Reputation: 2220Reputation: 2220Reputation: 2220Reputation: 2220Reputation: 2220Reputation: 2220Reputation: 2220Reputation: 2220Reputation: 2220
Quote:
Originally Posted by noguru View Post
In https://wiki.centos.org/HowTos/Custo...81ad79077ba79b Step 6, it says to install the rpm as root.

I guess that's why I'm confused.
Install, yes. Root privileges are required. Build, no. That's running a lot of scripts and tools for which root privileges are not needed.
 
Old 07-21-2017, 02:13 AM   #11
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524

Rep: Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015
Quote:
Originally Posted by noguru View Post
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

Code:
$ rpmdev-setuptree
will make the build structure for the installation of the source rpm.

Last edited by AwesomeMachine; 07-21-2017 at 02:24 AM.
 
Old 07-21-2017, 06:11 AM   #12
noguru
LQ Newbie
 
Registered: Sep 2012
Posts: 22

Original Poster
Rep: Reputation: Disabled
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?
 
Old 07-21-2017, 06:34 PM   #13
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524

Rep: Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015
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.
 
Old 07-21-2017, 07:13 PM   #14
noguru
LQ Newbie
 
Registered: Sep 2012
Posts: 22

Original Poster
Rep: Reputation: Disabled
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?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Rpmbuild vs .rpm for Centos newbie14 Linux - Server 8 09-25-2013 05:33 AM
LXer: Modded Android: A Space Odyssey LXer Syndicated Linux News 0 02-29-2012 11:40 PM
Rpmbuild spec file for virtual rpm - removing obsolete packages - CentOS/RHEL 5.3 DrLove73 Linux - Software 3 10-10-2009 10:22 AM
segmentation fault after using apt-get, rpmbuild ehawk Linux - Software 0 02-21-2004 09:16 AM
Anyone modded firstboot? TheRealDeal Linux - General 6 07-13-2003 07:37 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:04 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration