Click here to close now.

Welcome!

Linux Authors: Esmeralda Swartz, Pat Romanski, Jason Bloomberg, Elizabeth White, Liz McMillan

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
GENBAND has announced that SageNet is leveraging the Nuvia platform to deliver Unified Communications as a Service (UCaaS) to its large base of retail and enterprise customers. Nuvia’s cloud-based solution provides SageNet’s customers with a full suite of business communications and collaboration tools. Two large national SageNet retail customers have recently signed up to deploy the Nuvia platform and the company will continue to sell the service to new and existing customers. Nuvia’s capabilities include HD voice, video, multimedia messaging, mobility, conferencing, Web collaboration, deskt...
The Open Compute Project is a collective effort by Facebook and a number of players in the datacenter industry to bring lessons learned from the social media giant's giant IT deployment to the rest of the world. Datacenters account for 3% of global electricity consumption – about the same as all of Switzerland or the Czech Republic -- according to people I met at the recent Open Compute Summit in San Jose. With increasing mobility at the edge of the cloud and vast new dataflows being predicted with the growth of the Internet of Things (and The Coming Age of Many Zettabytes) in the near...
Wearable technology was dominant at this year’s International Consumer Electronics Show (CES) , and MWC was no exception to this trend. New versions of favorites, such as the Samsung Gear (three new products were released: the Gear 2, the Gear 2 Neo and the Gear Fit), shared the limelight with new wearables like Pebble Time Steel (the new premium version of the company’s previously released smartwatch) and the LG Watch Urbane. The most dramatic difference at MWC was an emphasis on presenting wearables as fashion accessories and moving away from the original clunky technology associated with t...
The WebRTC Summit 2014 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.
SYS-CON Events announced today that Cisco, the worldwide leader in IT that transforms how people connect, communicate and collaborate, has been named “Gold Sponsor” of 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. Cisco makes amazing things happen by connecting the unconnected. Cisco has shaped the future of the Internet by becoming the worldwide leader in transforming how people connect, communicate and collaborate. Cisco and our partners are building the platform for the Internet of Everything by connecting the...
15th Cloud Expo, which took place Nov. 4-6, 2014, at the Santa Clara Convention Center in Santa Clara, CA, expanded the conference content of @ThingsExpo, Big Data Expo, and DevOps Summit to include two developer events. IBM held a Bluemix Developer Playground on November 5 and ElasticBox held a Hackathon on November 6. Both events took place on the expo floor. The Bluemix Developer Playground, for developers of all levels, highlighted the ease of use of Bluemix, its services and functionality and provide short-term introductory projects that developers can complete between sessions.
Temasys has announced senior management additions to its team. Joining are David Holloway as Vice President of Commercial and Nadine Yap as Vice President of Product. Over the past 12 months Temasys has doubled in size as it adds new customers and expands the development of its Skylink platform. Skylink leads the charge to move WebRTC, traditionally seen as a desktop, browser based technology, to become a ubiquitous web communications technology on web and mobile, as well as Internet of Things compatible devices.
SYS-CON Events announced today that robomq.io will exhibit at SYS-CON's @ThingsExpo, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. robomq.io is an interoperable and composable platform that connects any device to any application. It helps systems integrators and the solution providers build new and innovative products and service for industries requiring monitoring or intelligence from devices and sensors.
The list of ‘new paradigm’ technologies that now surrounds us appears to be at an all time high. From cloud computing and Big Data analytics to Bring Your Own Device (BYOD) and the Internet of Things (IoT), today we have to deal with what the industry likes to call ‘paradigm shifts’ at every level of IT. This is disruption; of course, we understand that – change is almost always disruptive.
WebRTC is an up-and-coming standard that enables real-time voice and video to be directly embedded into browsers making the browser a primary user interface for communications and collaboration. WebRTC runs in a number of browsers today and is currently supported in over a billion installed browsers globally, across a range of platform OS and devices. Today, organizations that choose to deploy WebRTC applications and use a host machine that supports audio through USB or Bluetooth can use Plantronics products to connect and transit or receive the audio associated with the WebRTC session.
Docker is an excellent platform for organizations interested in running microservices. It offers portability and consistency between development and production environments, quick provisioning times, and a simple way to isolate services. In his session at DevOps Summit at 16th Cloud Expo, Shannon Williams, co-founder of Rancher Labs, will walk through these and other benefits of using Docker to run microservices, and provide an overview of RancherOS, a minimalist distribution of Linux designed expressly to run Docker. He will also discuss Rancher, an orchestration and service discovery platf...
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
SYS-CON Events announced today that Alert Logic, the leading provider of Security-as-a-Service solutions for the cloud, has been named “Bronze Sponsor” of SYS-CON's 16th International Cloud Expo® and DevOps Summit 2015 New York, which will take place June 9-11, 2015, at the Javits Center in New York City, NY, and the 17th International Cloud Expo® and DevOps Summit 2015 Silicon Valley, which will take place November 3–5, 2015, at the Santa Clara Convention Center in Santa Clara, CA.
Sonus Networks introduced the Sonus WebRTC Services Solution, a virtualized Web Real-Time Communications (WebRTC) offer, purpose-built for the Cloud. The WebRTC Services Solution provides signaling from WebRTC-to-WebRTC applications and interworking from WebRTC-to-Session Initiation Protocol (SIP), delivering advanced real-time communications capabilities on mobile applications and on websites, which are accessible via a browser.
SYS-CON Events announced today that Aria Systems, the leading innovator in recurring revenue, has been named “Bronze Sponsor” of SYS-CON's @ThingsExpo, which will take place on June 9–11, 2015, at the Javits Center in New York, NY. Proven by the world’s most demanding enterprises, including AAA NCNU, Constant Contact, Falck, Hootsuite, Pitney Bowes, Telekom Denmark, and VMware, Aria helps enterprises grow their recurring revenue businesses. With Aria’s end-to-end active monetization platform, global brands can get to market faster with a wider variety of products and services, while maximizin...
SYS-CON Events announced today that Vitria Technology, Inc. will exhibit at SYS-CON’s @ThingsExpo, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. Vitria will showcase the company’s new IoT Analytics Platform through live demonstrations at booth #330. Vitria’s IoT Analytics Platform, fully integrated and powered by an operational intelligence engine, enables customers to rapidly build and operationalize advanced analytics to deliver timely business outcomes for use cases across the industrial, enterprise, and consumer segments.
SYS-CON Events announced today that Solgenia 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. Solgenia is the global market leader in Cloud Collaboration and Cloud Infrastructure software solutions. Designed to “Bridge the Gap” between Personal and Professional Social, Mobile and Cloud user experiences, our solutions help large and medium-sized organizations dr...
SYS-CON Events announced today that Liaison Technologies, a leading provider of data management and integration cloud services and solutions, has been named "Silver Sponsor" of SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York, NY. Liaison Technologies is a recognized market leader in providing cloud-enabled data integration and data management solutions to break down complex information barriers, enabling enterprises to make smarter decisions, faster.
Connected devices and the Internet of Things are getting significant momentum in 2014. In his session at Internet of @ThingsExpo, Jim Hunter, Chief Scientist & Technology Evangelist at Greenwave Systems, examined three key elements that together will drive mass adoption of the IoT before the end of 2015. The first element is the recent advent of robust open source protocols (like AllJoyn and WebRTC) that facilitate M2M communication. The second is broad availability of flexible, cost-effective storage designed to handle the massive surge in back-end data in a world where timely analytics is e...
SYS-CON Events announced today that Akana, formerly SOA Software, has been named “Bronze Sponsor” of SYS-CON's 16th International Cloud Expo® New York, which will take place June 9-11, 2015, at the Javits Center in New York City, NY. Akana’s comprehensive suite of API Management, API Security, Integrated SOA Governance, and Cloud Integration solutions helps businesses accelerate digital transformation by securely extending their reach across multiple channels – mobile, cloud and Internet of Things. Akana enables enterprises to share data as APIs, connect and integrate applications, drive part...