Click here to close now.

Welcome!

Linux Authors: Elizabeth White, Pat Romanski, Carmen Gonzalez, Harry Trott, Adrian Bridgwater

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
There's no doubt that the Internet of Things is driving the next wave of innovation. Google has spent billions over the past few months vacuuming up companies that specialize in smart appliances and machine learning. Already, Philips light bulbs, Audi automobiles, and Samsung washers and dryers can communicate with and be controlled from mobile devices. To take advantage of the opportunities the Internet of Things brings to your business, you'll want to start preparing now.
17th Cloud Expo, taking place Nov 3-5, 2015, at the Santa Clara Convention Center in Santa Clara, CA, will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud strategy. Meanwhile, 94% of enterprises are using some form of XaaS – software, platform, and infrastructure as a service.
P2P RTC will impact the landscape of communications, shifting from traditional telephony style communications models to OTT (Over-The-Top) cloud assisted & PaaS (Platform as a Service) communication services. The P2P shift will impact many areas of our lives, from mobile communication, human interactive web services, RTC and telephony infrastructure, user federation, security and privacy implications, business costs, and scalability. In his session at @ThingsExpo, Robin Raymond, Chief Architect at Hookflash, will walk through the shifting landscape of traditional telephone and voice services ...
Explosive growth in connected devices. Enormous amounts of data for collection and analysis. Critical use of data for split-second decision making and actionable information. All three are factors in making the Internet of Things a reality. Yet, any one factor would have an IT organization pondering its infrastructure strategy. How should your organization enhance its IT framework to enable an Internet of Things implementation? In his session at Internet of @ThingsExpo, James Kirkland, Chief Architect for the Internet of Things and Intelligent Systems at Red Hat, described how to revolutioniz...
For IoT to grow as quickly as analyst firms’ project, a lot is going to fall on developers to quickly bring applications to market. But the lack of a standard development platform threatens to slow growth and make application development more time consuming and costly, much like we’ve seen in the mobile space. In his session at @ThingsExpo, Mike Weiner is Product Manager of the Omega DevCloud with KORE Telematics Inc., will discuss the evolving requirements for developers as IoT matures and conduct a live demonstration of how quickly application development can happen when the need to comply...
Container frameworks, such as Docker, provide a variety of benefits, including density of deployment across infrastructure, convenience for application developers to push updates with low operational hand-holding, and a fairly well-defined deployment workflow that can be orchestrated. Container frameworks also enable a DevOps approach to application development by cleanly separating concerns between operations and development teams. But running multi-container, multi-server apps with containers is very hard. You have to learn five new and different technologies and best practices (libswarm, sy...
SYS-CON Events announced today that DragonGlass, an enterprise search platform, 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. After eleven years of designing and building custom applications, OpenCrowd has launched DragonGlass, a cloud-based platform that enables the development of search-based applications. These are a new breed of applications that utilize a search index as their backbone for data retrieval. They can easily adapt to new data sets and provide access to both structured and unstruc...
Converging digital disruptions is creating a major sea change - Cisco calls this the Internet of Everything (IoE). IoE is the network connection of People, Process, Data and Things, fueled by Cloud, Mobile, Social, Analytics and Security, and it represents a $19Trillion value-at-stake over the next 10 years. In her keynote at @ThingsExpo, Manjula Talreja, VP of Cisco Consulting Services, will discuss IoE and the enormous opportunities it provides to public and private firms alike. She will share what businesses must do to thrive in the IoE economy, citing examples from several industry sector...
With major technology companies and startups seriously embracing IoT strategies, now is the perfect time to attend @ThingsExpo in Silicon Valley. Learn what is going on, contribute to the discussions, and ensure that your enterprise is as "IoT-Ready" as it can be! Internet of @ThingsExpo, taking place Nov 3-5, 2015, at the Santa Clara Convention Center in Santa Clara, CA, is co-located with 17th Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The Internet of Things (IoT) is the most profound change in personal an...
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...
IoT is still a vague buzzword for many people. In his session at @ThingsExpo, Mike Kavis, Vice President & Principal Cloud Architect at Cloud Technology Partners, discussed the business value of IoT that goes far beyond the general public's perception that IoT is all about wearables and home consumer services. He also discussed how IoT is perceived by investors and how venture capitalist access this space. Other topics discussed were barriers to success, what is new, what is old, and what the future may hold. Mike Kavis is Vice President & Principal Cloud Architect at Cloud Technology Pa...
Disruptive macro trends in technology are impacting and dramatically changing the "art of the possible" relative to supply chain management practices through the innovative use of IoT, cloud, machine learning and Big Data to enable connected ecosystems of engagement. Enterprise informatics can now move beyond point solutions that merely monitor the past and implement integrated enterprise fabrics that enable end-to-end supply chain visibility to improve customer service delivery and optimize supplier management. Learn about enterprise architecture strategies for designing connected systems tha...
There's Big Data, then there's really Big Data from the Internet of Things. IoT is evolving to include many data possibilities like new types of event, log and network data. The volumes are enormous, generating tens of billions of logs per day, which raise data challenges. Early IoT deployments are relying heavily on both the cloud and managed service providers to navigate these challenges. In her session at Big Data Expo®, Hannah Smalltree, Director at Treasure Data, discussed how IoT, Big Data and deployments are processing massive data volumes from wearables, utilities and other machines...
SYS-CON Events announced today that the "First Containers & Microservices Conference" will take place June 9-11, 2015, at the Javits Center in New York City. The “Second Containers & Microservices Conference” will take place November 3-5, 2015, at Santa Clara Convention Center, Santa Clara, CA. Containers and microservices have become topics of intense interest throughout the cloud developer and enterprise IT communities.
Buzzword alert: Microservices and IoT at a DevOps conference? What could possibly go wrong? In this Power Panel at DevOps Summit, moderated by Jason Bloomberg, the leading expert on architecting agility for the enterprise and president of Intellyx, panelists will peel away the buzz and discuss the important architectural principles behind implementing IoT solutions for the enterprise. As remote IoT devices and sensors become increasingly intelligent, they become part of our distributed cloud environment, and we must architect and code accordingly. At the very least, you'll have no problem fil...
SYS-CON Events announced today that MetraTech, now part of Ericsson, 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. Ericsson is the driving force behind the Networked Society- a world leader in communications infrastructure, software and services. Some 40% of the world’s mobile traffic runs through networks Ericsson has supplied, serving more than 2.5 billion subscribers.
The 4th International Internet of @ThingsExpo, co-located with the 17th International Cloud Expo - to be held November 3-5, 2015, at the Santa Clara Convention Center in Santa Clara, CA - announces that its Call for Papers is open. The Internet of Things (IoT) is the biggest idea since the creation of the Worldwide Web more than 20 years ago.
The 17th International Cloud Expo has announced that its Call for Papers is open. 17th International Cloud Expo, to be held November 3-5, 2015, at the Santa Clara Convention Center in Santa Clara, CA, brings together Cloud Computing, APM, APIs, Microservices, Security, Big Data, Internet of Things, DevOps and WebRTC to one location. With cloud computing driving a higher percentage of enterprise IT budgets every year, it becomes increasingly important to plant your flag in this fast-expanding business opportunity. Submit your speaking proposal today!
Since 2008 and for the first time in history, more than half of humans live in urban areas, urging cities to become “smart.” Today, cities can leverage the wide availability of smartphones combined with new technologies such as Beacons or NFC to connect their urban furniture and environment to create citizen-first services that improve transportation, way-finding and information delivery. In her session at @ThingsExpo, Laetitia Gazel-Anthoine, CEO of Connecthings, will focus on successful use cases.
The explosion of connected devices / sensors is creating an ever-expanding set of new and valuable data. In parallel the emerging capability of Big Data technologies to store, access, analyze, and react to this data is producing changes in business models under the umbrella of the Internet of Things (IoT). In particular within the Insurance industry, IoT appears positioned to enable deep changes by altering relationships between insurers, distributors, and the insured. In his session at @ThingsExpo, Michael Sick, a Senior Manager and Big Data Architect within Ernst and Young's Financial Servi...