How to make LINUX patch files and how to play Patch__linux

Source: Internet
Author: User
Tags diff first string local time parent directory

How to make Linux patch files and how to play patch

When you make a change to a version of the Linux kernel, if you want to publish it to someone else, you need to make a patch file for that version.
The patch file, also called a patch, is a text document that contains changes between two different versions of the source code tree.
Patches are created by a diff application.
To get a patch right, you need to know which base version the patch is coming from and that the patch is going to
The current source code tree changes to what the new version is. This information may appear in the original data in the patch file, or it might be inferred from the file name.

1, how to make patch patch file

For example, based on the kernel kernel to modify the LCD code, modify the content before the folder kernel, the modified content placed under the folder Kernel_new, then make patch file command for
zhenwx-desktop:~/sourcecode/$diff-naur kernel/kernel_new/> Zwx-lcd.patch

The current directory is/home/zhenwx/sourcecode/, which has a previously modified kernel kernel directory and a modified directory Kernel_new
Execute command for Diff-naur kernel/kernel_new/> Zwx-lcd.patch
The diff command compares the files in the kernel and kernel_new directories to produce patch files Zwx-lcd.patch
Then you can release zwx-lcd.patch to the Internet.
This patch file is the path information that describes the file and deletes the first few lines, adds content in the first few lines, deletes with a minus sign, adds a plus sign

2, how to Play patch Patch and Uninstall patch patch
You can use the patch program to make a patch. The patch program reads a diff (or patch) file, and then the file
The changed content of the description is applied to the code tree.
Patches in the Linux kernel are generated relative to the parent directory where the kernel source code directory is saved.
This means that the file path in the patch file contains the name of the kernel source file directory on which it is based (or like "a" and "B").
Other names, etc.).
Because this probably doesn't match the name of the kernel source code directory on your local machine. You should switch to your kernel source code directory and remove patch when patching
The first component of the filename path in the file (the-P1 parameter of the patch command can complete this task).
To remove a previously patched patch, use the-r parameter to patch it.
So, if you use the following command to make a patch:
Patch-p1

Then you can uninstall the patch as follows:
Patch-r-P1

For example, when other people download the patch file provided above, just perform it in the standard kernel kernel directory.
zhenwx-desktop:~/sourcecode/kernel/$

Patch-p1< /zwx-lcd.patch


This assumes that the Zwx-lcd.patch and kernel folders are in the same directory and that the above commands are executed in the kernel folder
If you execute a command under the/sourcecode directory
zhenwx-desktop:~/sourcecode/$

Patch-p0< /zwx-lcd.patch


Linux under the patch command to use the detailed

Linux Patch Command

Feature Description: Patch file.

Syntax: Patch [-bceeflnnrsttuvz][-b < Backup header string >][-d < working directory >][-d < symbol &GT;][-F < Supervisor number >][-g < control value >][ -I < patch file >][-o < output file >][-p < Peel level >][-r < reject file >][-v < backup mode >][-y < backup word First string >][-z < Back up tail string >][--backup-if-mismatch][--binary][--help][--nobackup-if-mismatch][--verbose][original file < patch file] or path [-P < peel level] < [patch file]

Supplemental Note: The patch directive lets the user modify, update the original file by using the method of setting up the patching file. If only one file is modified at a time, the instructions can be executed directly in the instruction column. It is also one of the core upgrades to the Linux system if you can patch a large number of files one at a time with patch files.

Parameters
-B or--backup back up each original file.
-b< Backup Header string > or--prefix=< backup header string > When setting a file backup, the first string appended to the file name, which can be the path name.
-C or--context to interpret the patch data as a correlation difference.
-d< working directory > or--directory=< working directory > setting working directory.
-d< sign > or--ifdef=< symbol > mark the change place with the specified symbol.
-E or--ed to interpret the patched data into a descriptive file that can be used by the ED directive.
-E or--remove-empty-files remove the file whose contents are blank when the file is patched.
-F or--force the effect of this parameter is similar to the specified-t parameter, but assumes that the version of the patched data is a new version.
-f< number of > or--fuzz< of the number of Supervisors > set the maximum number of supervisors Bielle.
-g< controls the value > or--get=< control of numeric > Settings to RSC or SCCS control of the repair operation.
-i< patch file > or--input=< patch file > read the specified fix ask home for you.
-L or--ignore-whitespace ignores patch data with the input data of the jump, the space character.
-N or--normal to interpret the patched data into general differences.
-N or--forward ignores patched data older than the version of the original file, or the patch data for that version has been used.
The-o< output file > or--output=< output file > Sets the name of the output file, and the patched file is stored in that name.
-p< Peel level > or--strip=< Peel level > Settings to split several layers of path names.
-f< reject file > or--reject-file=< reject File > Set the name of the file to save the information that was rejected for repair, and the preset file name is. Rej.
-R or--reverse assumes that the patching data is generated by the new and old file interchange location.
-S or--quiet or--silent does not display the instruction execution procedure unless an error occurs.
-T or--batch automatically skips errors without asking for any questions.
-T or--set-time the effect of this parameter is similar to the specified-Z parameter, but local time is the primary.
-U or--unified to interpret the patching data into a consistent difference.
-V or--version display version information.
-v< Backup method > or--version-control=< backup method > Back up the destination file with the-b parameter, the end of the backup file is followed by a backup string, which can be changed not only with the-Z parameter, but also when the-v parameter is used to specify different methods of backup. Also produces a backup string at the end of a different word.
-y< Backup Header string > or--basename-prefix=--< backup header string > Set file Backup, append the first character string at the beginning of the file base name.
-z< backup Word tail string > or--suffix=< back string > The effect of this parameter is similar to the specified-b parameter, except that the path and filename used by the patch job are src/linux/fs/super.c, plus backup/ After the string, the file Super.c is backed up in the/src/linux/fs/backup directory.
-Z or--SET-UTC to make the patched file changes, access time set to UTC.
--backup-if-mismatch backs up files when patching data does not exactly match and does not deliberately specify that you want to back up files.
--binary reads and writes data in binary mode, not through standard output devices.
--help online Help.
--nobackup-if-mismatch do not back up files when patching data does not exactly match and you do not deliberately specify that you want to back up files.
--verbose displays the execution of instructions in detail.

Patch, is a patched command, there are many uses, see Help #man patch
The-p parameter determines whether to use the prefix directory information of the read out source file name and does not provide the-p parameter, ignoring all directory information.
Patch-p0 ("P" refers to a path, followed by a number that represents removing the first part of the path.) 0, means not to remove, for full path)
PATCH-P1 (the number 1 after "p" means to remove the first path, the first "/" previous directory, and so on).
A file name such as/usr/src/linux-2.6.11/makefile will use Linux-2.6.11/makefile as the file to patch when providing-P3 parameters.

For the example of the Linux kernel source LCD upgrade package Just given, assume that the source directory is located in/home/zhenwx/sourcecode/kernel,
The "Patch-p0&lt" is used when the current directory is/home/zhenwx/sourcecode/. /zwx-lcd.patch "can work,
When the current directory is/home/zhenwx/sourcecode/kernel, use the patch-p1< /zwx-lcd.patch "can also work properly.

If the first level directory described in the patch file is not the same as your own first-level directory name, it is useful to remove the first level directory.

For example, if you get a patch description of the directory and you are not the same, patch the first line of directory information described

Diff--git A/arch/arm/mach-msm/acpuclock-8064.c B/arch/arm/mach-msm/acpuclock-8064.c

But your directory is neither a nor B, then you have to remove the first layer of the directory and hit the kernel path below patch

Using-P1 parameters


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.