Click here to close now.

Welcome!

Linux Authors: Carmen Gonzalez, Roger Strukhoff, Hovhannes Avoyan, Jason Bloomberg, Pat Romanski

Related Topics: Linux

Linux: Article

Kernel source merging 101

How to play Linus Torvalds and update the Linux kernel yourself

(LinuxWorld) -- If you're not familiar with the kernel patch and development process, here it is in a nutshell. People modify source files to fix bugs, add or remove features, or adapt to changes in the way the kernel handles certain tasks. They produce patch files by using a utility called diff. diff compares the old source file to the new one and produces a text file from the differences. You can then distribute this text file to others, who can use it to patch their source code with the utility called (what else?) patch.

Incidentally, the tradition for using patch to produce kernel patch files is to add the command line switches -urN, which tells diff to use the unified output format (which is what everyone on the kernel development team uses), recurse through directories, and keep track of new files that appear in one branch but not another. The full command would be diff -Nru.

Until recently, kernel developers submitted their patch files by including them within the body of an email message. Then they sent the message to one or more kernel maintainers and/or the kernel development mailing list. I'm not quite sure how the patch submission process will change now that Linus Torvalds and others are using the Bitkeeper Web-based source management system, but it looks like they'll still rely largely on the diff

Linus or one of the other kernel maintainers merge the various patches into the kernel source tree, make other changes, and then release a collection of patches in one large text file, which is compressed for faster downloads. If you want to apply the patches, you download the file and apply it to the correct version of the kernel source code.

I don't know how others do this, but I keep kernel versions in directories like /usr/src/linux-2.4.18-pre8 to identify the kernel version for that source tree. Then I download the latest patches to the /usr/src directory. For example, I downloaded the Michael Cohen patch file patch-2.4.18-pre8-mjc.bz2 and put it in /usr/src. If I wanted to apply the Michael Cohen patch as is, I would then change to the /usr/src/linux-2.4.18-pre8 directory and run the command:

# bzcat ../patch-2.4.18-pre8-mjc.bz2 | patch -p1 -E --dry-run

Don't type the pound sign (#) - it's the part of the prompt that usually tells you you're logged in as the root user.

The -p1 switch tells patch to ignore the first level of directories in the patch file. This can be important, because the maintainers all seem to use their own conventions for the root directory for the kernel source tree, and that directory name gets included in the patch file. For example, if someone keeps the old kernel source in /usr/src/oldkernel and the modified source in /usr/src/newkernel, then the patch file will contain the two directory names oldkernel and newkernel. If you use the switch -p0, patch will expect to find the newkernel directory name on your system as part of the full path name (for example, newkernel/drivers/ide/ide-dma.c). If, like me, you named the top directory of the kernel tree something like linux-2.4.18-pre8, patch will fail. The -p1 switch tells it to ignore that top level and go straight to drivers/ide/ide-dma.c.

The -E switch tells patch to go ahead and delete any files that shouldn't exist after the patch. These are generally files that the maintainer moved to another location or deleted because they were no longer needed.

The --dry-run portion of the command tells patch to pretend to apply the patches without actually changing anything. I do this out of habit because it prevents me from making stupid mistakes like changing to the wrong kernel tree before applying the patch. If the patch process produces many error messages, I know I've probably done something wrong. If it looks like everything patched ok, then I run the command again, only for real. That "for real" command is just the same command without the --dry-run:

# bzcat ../patch-2.4.18-pre8-mjc.bz2 | patch -p1 -E

The challenge

The 2.5 branch is still in too transitory a state to tackle with any confidence, so I started with linux-2.4.18-pre8. I figured I'd better take it slow. I've led a rather sedentary lifestyle when it comes to examining the kernel source, so I didn't want to break into a sprint on the first go and risk a heart attack. In other words, I wanted to merge only a handful of changes, not 50 at a shot the way Linus and others do.

I noticed that Michael Cohen had released a large patch against 2.4.18-pre8 that included many interesting features. It merges the code to handle hardware health sensors (so you can view things like the fan speed on your motherboard). It also adds code to make the kernel preemptive. It has other performance enhancing modifications to the kernel and includes several fixes that weren't in the 2.4 branch at the time Cohen posted his patch, such as fixes to the Reiserfs file system.

Thibaut Laurent posted on the kernel development mailing list that there was a minor problem with the file timer.c in Cohen's patch. Thomas Hood pointed out that Cohen's updates to the plug-and-play BIOS code were out of date. Paul P Komkoff Jr posted a set of patches that adds new capabilities for IP net filtering. Finally, I like to add a line to drivers/acpi/hardware/hwsleep.c to force the kernel to shut off the machine. This is not a patch for general use. I only include it because the funky ACPI BIOS tables in ASUS motherboards keep me from being able to shut off my system with the halt command.

I figured it would be a good lesson in patch management if I could apply all of the above fixes and additions to Michael Cohen's patch and produce my own patch from the result.

I downloaded the latest PnP BIOS code for 2.4.18-pre8 by Thomas Hood and began the grunt work of replacing the PnP portions of Cohen's patch with the latest code. The job was tedious, but it was easy because both Cohen's patch and Hood's patch are applied against the same kernel version (2.4.18-pre8). So all I really had to do was find all the sections of Cohen's patch that corresponded to Hood's and make the swap. It was even easier to apply the net filter additions, timer.c fix, and my shutdown kludge.

The result is patch-2.4.18-pre8-np.gz, which you can find at the download section of www.varlinux.org. I'm using that kernel right now, but things are moving so quickly it will probably be well out of date by the time you read this. There's already a linux-2.4.18-pre9 available as I write this and pre9 includes some of the same fixes you'll find in my patch. (It lacks all the added features, however, such as the net filter code, preemptive kernel, etc.)

What's the big deal about merging patches? It was only easy for me because I chose to work with a stable branch of the kernel and patches that were supposed to be applied against the same kernel version.

I tackled the 2.5.4-pre3 kernel source just to see what the differences would be like if I used an unstable branch. I didn't even have to look for patches to apply. It wouldn't compile on my system as is. It broke on ide-dma.c, ide-scsi.c, sg.c, and in other places. I couldn't find any fixes for these problems so I started scanning the code to see if I could fix it myself.

That's when I realized what this kernel development process really needs -- an editor with an integrated cross-reference and source code analysis system.

Perhaps people like Linus Torvalds doesn't need such a program because he knows where every instance of a variable appears in the source tree (I doubt it, since so many of his patches lately leave many files with legacy variables and structures unpatched to work with updates to other parts of the kernel source tree). Alternatively, perhaps he and others have some neat command-line utilities that do the job. I'm not an emacs user, so for all I know emacs has these capabilities (I have no idea if Linus uses emacs anyway).

However, I would want something more powerful than a multi-file editor for a job like this. So I searched Freshmeat and found a few snazzy products that analyze source code, cross reference the source, and let you perform recursive updates in ways that help prevent disaster. Some run on Linux, so I plan to play with one or two.

I'll get back to you on them when I've had time to learn how well they work. In the meantime, unless you're a kernel guru, stay away from the 2.5 branch. Stick to the easy stuff, like I do. Your heart will thank you for it.

More Stories By Nicholas Petreley

Nicholas Petreley is a computer consultant and author in Asheville, NC.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


@ThingsExpo Stories
Containers and microservices have become topics of intense interest throughout the cloud developer and enterprise IT communities. Accordingly, attendees at the upcoming 16th Cloud Expo at the Javits Center in New York June 9-11 will find fresh new content in a new track called PaaS | Containers & Microservices Containers are not being considered for the first time by the cloud community, but a current era of re-consideration has pushed them to the top of the cloud agenda. With the launch of Docker's initial release in March of 2013, interest was revved up several notches. Then late last...
SYS-CON Events announced today that B2Cloud, a provider of enterprise resource planning software, will exhibit at SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. B2cloud develops the software you need. They have the ideal tools to help you work with your clients. B2Cloud’s main solutions include AGIS – ERP, CLOHC, AGIS – Invoice, and IZUM
There is no doubt that Big Data is here and getting bigger every day. Building a Big Data infrastructure today is no easy task. There are an enormous number of choices for database engines and technologies. To make things even more challenging, requirements are getting more sophisticated, and the standard paradigm of supporting historical analytics queries is often just one facet of what is needed. As Big Data growth continues, organizations are demanding real-time access to data, allowing immediate and actionable interpretation of events as they happen. Another aspect concerns how to deliver ...
SYS-CON Events announced today that MangoApps will exhibit at SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY., and the 17th International Cloud Expo®, which will take place on November 3–5, 2015, at the Santa Clara Convention Center in Santa Clara, CA. MangoApps provides private all-in-one social intranets allowing workers to securely collaborate from anywhere in the world and from any device. Social, mobile, and easy to use. MangoApps has been named a "Market Leader" by Ovum Research and a "Cool Vendor" by Gartner...
The world's leading Cloud event, Cloud Expo has launched Microservices Journal on the SYS-CON.com portal, featuring over 19,000 original articles, news stories, features, and blog entries. DevOps Journal is focused on this critical enterprise IT topic in the world of cloud computing. Microservices Journal offers top articles, news stories, and blog posts from the world's well-known experts and guarantees better exposure for its authors than any other publication. Follow new article posts on Twitter at @MicroservicesE
WebRTC defines no default signaling protocol, causing fragmentation between WebRTC silos. SIP and XMPP provide possibilities, but come with considerable complexity and are not designed for use in a web environment. In his session at @ThingsExpo, Matthew Hodgson, technical co-founder of the Matrix.org, discussed how Matrix is a new non-profit Open Source Project that defines both a new HTTP-based standard for VoIP & IM signaling and provides reference implementations.
The security devil is always in the details of the attack: the ones you've endured, the ones you prepare yourself to fend off, and the ones that, you fear, will catch you completely unaware and defenseless. The Internet of Things (IoT) is nothing if not an endless proliferation of details. It's the vision of a world in which continuous Internet connectivity and addressability is embedded into a growing range of human artifacts, into the natural world, and even into our smartphones, appliances, and physical persons. In the IoT vision, every new "thing" - sensor, actuator, data source, data con...
The Internet of Things is not new. Historically, smart businesses have used its basic concept of leveraging data to drive better decision making and have capitalized on those insights to realize additional revenue opportunities. So, what has changed to make the Internet of Things one of the hottest topics in tech? In his session at @ThingsExpo, Chris Gray, Director, Embedded and Internet of Things, discussed the underlying factors that are driving the economics of intelligent systems. Discover how hardware commoditization, the ubiquitous nature of connectivity, and the emergence of Big Data a...
SYS-CON Events announced today the IoT Bootcamp – Jumpstart Your IoT Strategy, being held June 9–10, 2015, in conjunction with 16th Cloud Expo and Internet of @ThingsExpo at the Javits Center in New York City. This is your chance to jumpstart your IoT strategy. Combined with real-world scenarios and use cases, the IoT Bootcamp is not just based on presentations but includes hands-on demos and walkthroughs. We will introduce you to a variety of Do-It-Yourself IoT platforms including Arduino, Raspberry Pi, BeagleBone, Spark and Intel Edison. You will also get an overview of cloud technologies s...
SYS-CON Media announced today that @WebRTCSummit Blog, the largest WebRTC resource in the world, has been launched. @WebRTCSummit Blog offers top articles, news stories, and blog posts from the world's well-known experts and guarantees better exposure for its authors than any other publication. @WebRTCSummit Blog can be bookmarked ▸ Here @WebRTCSummit conference site can be bookmarked ▸ Here
Scott Jenson leads a project called The Physical Web within the Chrome team at Google. Project members are working to take the scalability and openness of the web and use it to talk to the exponentially exploding range of smart devices. Nearly every company today working on the IoT comes up with the same basic solution: use my server and you'll be fine. But if we really believe there will be trillions of these devices, that just can't scale. We need a system that is open a scalable and by using the URL as a basic building block, we open this up and get the same resilience that the web enjoys.
As we approach the next @ThingsExpo, to be held June 9-11 at the Javits Center in New York, my thoughts naturally turn to the Internet of Things. The IoT is a leviathan—in the best possible sense of the term—that will sweep up most everything in the ocean of data and technology being created today and tomorrow. But rather than try to grasp all of its possible uses, for today I'm looking at “just” the Industrial Internet part. I just read a long paper co-authored by Tim Berners-Lee about the possibility of describing a “web science,” that is, discipline that combines the study involved ...
Chuck Piluso will present a study of cloud adoption trends and the power and flexibility of IBM Power and Pureflex cloud solutions. Speaker Bio: Prior to Data Storage Corporation (DSC), Mr. Piluso founded North American Telecommunication Corporation, a facilities-based Competitive Local Exchange Carrier licensed by the Public Service Commission in 10 states, serving as the company's chairman and president from 1997 to 2000. Between 1990 and 1997, Mr. Piluso served as chairman & founder of International Telecommunications Corporation, a facilities-based international carrier licensed by t...
There are lots of challenges in IoT around secure, scalable and business friendly infrastructure for enterprises. For large corporations, IoT implementations are one of the top priorities of the decade. All industries are seeing a competitive need to sustain by investing in IoT initiatives. The value addition comes from improved customer service, innovative product and additional revenue streams. The data from these IP-connected devices can be leveraged for a variety of business applications as well as responsive action controls. The various architectural building blocks of an IoT ...
The WebRTC Summit 2015 New York, to be held June 9-11, 2015, at the Javits Center in New York, NY, announces that its Call for Papers is open. Topics include all aspects of improving IT delivery by eliminating waste through automated business models leveraging cloud technologies. WebRTC Summit is co-located with 16th International Cloud Expo, @ThingsExpo, Big Data Expo, and DevOps Summit.
Recent technology advances in miniaturization has positioned the wearables as the pinnacle of technology convergence with the human body. We inquire if wearables are mere standard miniaturized devices extended with the connectivity and present our views on considerations like design, applications, performance, efficiency, interoperability, usage scenarios, human device interaction and consequent trade-offs enabling wearables to impart optimal value.
In this session we look at creating interactive communications via the web by adding messaging, file transfer, and group communication (group chat and audio/video conferencing) into the web experience. We will also discuss potential applications of this technology in areas including B2B, B2C, P2P, and gaming. Peter is Technical Director at Acision. He graduated from The University of Edinburgh in 2000 with a BSc (Hons) in Computer Science. After graduation Peter worked on a PSTN switch developing signalling stacks for SS7, ISDN and similar protocols and creating advanced routing and serv...
The Internet of Things Maturity Model (IoTMM) is a qualitative method to gauge the growth and increasing impact of IoT capabilities in an IT environment from both a business and technology perspective. In his session at @ThingsExpo, Tony Shan will first scan the IoT landscape and investigate the major challenges and barriers. The key areas of consideration are identified to get started with IoT journey. He will then pinpoint the need of a tool for effective IoT adoption and implementation, which leads to IoTMM in which five maturity levels are defined: Advanced, Dynamic, Optimized, Primitive,...
SYS-CON Events announced today that AIC, a leading provider of OEM/ODM server and storage solutions, will exhibit at SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. AIC is a leading provider of both standard OTS, off-the-shelf, and OEM/ODM server and storage solutions. With expert in-house design capabilities, validation, manufacturing and production, AIC's broad selection of products are highly flexible and are configurable to any form factor or custom configuration. AIC leads the industry with nearly 20 years of ...
SYS-CON Events announced today that Vicom Computer Services, Inc., a provider of technology and service solutions, will exhibit at SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. They are located at booth #427. Vicom Computer Services, Inc. is a progressive leader in the technology industry for over 30 years. Headquartered in the NY Metropolitan area. Vicom provides products and services based on today’s requirements around Unified Networks, Cloud Computing strategies, Virtualization around Software defined Data Ce...