Linux 补丁生成与使用
我们在升级Linux 内核的时候,难免会接触到补丁的知识。下面对如何生成补丁和如何打补丁作讲解。
生成补丁:
制作 hello.c 和 hello_new.c 两个文件如如下所示。
- ➜ diff ls
- hello.c hello_new.c hello_test.c hi.patch
- ➜ diff cat hello.c
- #include "stdio.h"
- int main(int argc ,char **argv)
- {
- printf("Hello World");
- }
- ➜ diff cat hello_new.c
- #include "stdio.h"
- int main(int argc ,char **argv)
- {
- printf("Hello World\n");
- return ;
- }
使用 diff -uN 命令 进行生成patch
- ➜ diff diff -uN hello_new.c hello.c > hi.patch
- ➜ diff cat hi.patch
- --- hello_new.c -- ::23.679704122 +
- +++ hello.c -- ::59.190677641 +
- @@ -, +, @@
- #include "stdio.h"
- int main(int argc ,char **argv)
- {
- - printf("Hello World\n");
- - return ;
- + printf("Hello World");
- }
至此,patch 已经创建完毕。
之后,我们进行使用 patch 命令 对 hello.c 文件进行打补丁。
- ➜ diff patch -p0 <hi.patch
- patching file hello.c
- Reversed (or previously applied) patch detected! Assume -R? [n] y
- ➜ diff cat hello.c
- #include "stdio.h"
- int main(int argc ,char **argv)
- {
- printf("Hello World\n");
- return ;
- }
- ➜ diff ls
- hello.c hello.c.orig hello_new.c hello_test.c hi.patch
- ➜ diff cat hello.c.orig
- #include "stdio.h"
- int main(int argc ,char **argv)
- {
- printf("Hello World");
- }
- ➜ diff cat hello.c
- #include "stdio.h"
- int main(int argc ,char **argv)
- {
- printf("Hello World\n");
- return ;
- }
- ➜ diff
可见,补丁已经成功应用,并且生成了 .orig 源文件。 --backup-if-mismatch 选项,可以不进行生成orig 文件。
- ➜ diff patch -p0 --no-backup-if-mismatch < hi.patch
- patching file hello.c
- Reversed (or previously applied) patch detected! Assume -R? [n] y
- ➜ diff ls
- hello.c hello_new.c hello_test.c hi.patch
- ➜ diff cat hello.c
- #include "stdio.h"
- int main(int argc ,char **argv)
- {
- printf("Hello World\n");
- return ;
- }
diff 和 patch 命令介绍:
-pnum or --strip=num
Strip the smallest prefix containing num leading slashes from each file name found in the patch file. A sequence of one or more adjacent slashes is counted as a
single slash. This controls how file names found in the patch file are treated, in case you keep your files in a different directory than the person who sent out
the patch. For example, supposing the file name in the patch file was
/u/howard/src/blurfl/blurfl.c
setting -p0 gives the entire file name unmodified, -p1 gives
u/howard/src/blurfl/blurfl.c
without the leading slash, -p4 gives
blurfl/blurfl.c
and not specifying -p at all just gives you blurfl.c. Whatever you end up with is looked for either in the current directory, or the directory specified by the -d
option.
具体的使用说明,可以使用 man diff 和 man patch 命令来进行查看。
保持更新,转载请注明出处。
Linux 补丁生成与使用的更多相关文章
- Linux下生成patch和打patch
转自:http://blog.csdn.net/dl0914791011/article/details/17299103 通过diff工具生成补丁, patch工具打上补丁. 在使用diff之前, ...
- linux下生成core dump文件方法及设置
linux下生成core dump文件方法及设置 from:http://www.cppblog.com/kongque/archive/2011/03/07/141262.html core ...
- random and password 在Linux下生成crypt加密密码的方法,shell 生成指定范围随机数与随机字符串
openssl rand -hex n (n is number of characters) LANG=c < /dev/urandom tr -dc _A-Z-a-z-0-9 | head ...
- linux c生成唯一文件名称
linux c生成唯一文件名称可用mktemp()或mkstemp()函数
- 【linux】在linux上生成SSH-key 简单原理介绍+生成步骤
1.首先什么是SSH Secure Shell (SSH) 是一个允许两台电脑之间通过安全的连接进行数据交换的网络协议.通过加密保证了数据的保密性和完整性.SSH采用公钥加密技术来验证远程主机,以及( ...
- linux 模拟生成 CAN 设备
/************************************************************************************** * linux 模拟生成 ...
- 1.Linux下生成密钥
1.Linux下生成密钥 ssh-keygen的命令手册,通过”man ssh-keygen“命令: 通过命令”ssh-keygen -t rsa“ 生成之后会在用户的根目录生成一个 “.ssh”的文 ...
- Linux中生成Core Dump系统异常信息记录文件的教程
Linux中生成Core Dump系统异常信息记录文件的教程 http://www.jb51.net/LINUXjishu/473351.html
- linux c 生成uuid
/********方法一**********/#include <stdio.h> #include <stdlib.h> #include <string.h> ...
随机推荐
- Leetcode 746. Min Cost Climbing Stairs
思路:动态规划. class Solution { //不能对cost数组进行写操作,因为JAVA中参数是引用 public int minCostClimbingStairs(int[] cost) ...
- [error] 1507#0: *22 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 10.0.0.1, server: www.wordpress.com, request: "GET /info.p
字体比较小,如果你遇到这个问题请仔细的把下面的总结看完. 环境:CentOS6.7.2.6.32-573.el6.x86_64.nginx1.12.2 .php5.5.38 问题:nginx能解析静态 ...
- SQL-结构化查询语言(2)
使用explain查询select查询语句的执行计划 mysql> explain select * from student where Sname='金克斯'\G ************* ...
- set集合容器(常用的使用方法总结)
关于C++STL中set集合容器的学习,看别人的代码一百遍,不如自己动手写一遍. 构造set集合容器的目的是为了去重+排序+快速搜索.由于set集合容器实现了红黑树多的平衡二叉检索树的数据结构,在插 ...
- AWK工具的用法
基本格式 awk '{commands}' filename 或者 stdin | awk '{commands}' 以下,均简写为awk '{commands}'的形式 commands的用法 co ...
- ASP.NET MVC显示UserControl控件(扩展篇)
昨晚Insus.NET有怀旧一下<念念不忘,ASP.NET MVC显示WebForm网页或UserControl控件>http://www.cnblogs.com/insus/p/3641 ...
- 关于ASPxComboBox通过ClientInstanceName,js获取不到控件的问题
今天突然遇到一个很奇葩的问题 ASPxComboBox中设置了ClientInstanceName.但是通过cmbOrganization.GetValue()获取不到值. 报错cmbOrganiza ...
- LINQ查询操作符 LINQ学习第二篇
一.投影操作符 1. Select Select操作符对单个序列或集合中的值进行投影.下面的示例中使用select从序列中返回Employee表的所有列: using (NorthwindDataCo ...
- [日常] C语言中的字符数组和字符串
c语言字符数组和字符串:1.存放字符的数组称为字符数组 char str[]2.'\0'也被称为字符串结束标志3.由" "包围的字符串会自动在末尾添加'\0'4.逐个字符地给数组赋 ...
- Ubuntu安装完成后设置root密码
安装完ubuntu后没有默认的root密码,如果要设置root密码需要进行如下步骤: 1 sudo passwd 2 连续输入两次新密码