Patch Command Usage detailed

Source: Internet
Author: User
Tags bz2 diff ftp site

Patch, is a patched command, there are many uses, see Help #man patch

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 the "P" indicates the first path to be removed)

Fetch HTTP://PEOPLE.FREEBSD.ORG/~DELPHIJ/MISC/PATCH-BGE-RELENG62

Fetch Http://people.freebsd.org/~delphij/misc/patch-bce-watchdog-rewrite

Cd/sys/dev/bge

Fetch ...

Patch-p0 < ...

Fetch Http://people.freebsd.org/~delphij/misc/patch-tcp_auto_buf-20061212-RELENG_6.diff

Patch-p < Patch-tcp_auto_buf-20061212-releng_6.diff

You can also change the directory in the file to the system already in the directory such as/usr/src/sys ...

Attention:

1, confirm the catalogue

Then confirm the directory, such as not in the default directory, write down the current absolute directory to be patched. such as/usr/src/sys/dev/bge/if_bce.c

The use of 2,p

You can use parameters with no numbers.

Software Installation after patch

telnetd server problems and patches

In all versions of the current FreeBSD, that is, FreeBSD 5.0, FreeBSD 4.3, FreeBSD 4.2, FreeBSD 4.1.1, FreeBSD 4.1, FreeBSD 4.0, FreeBSD 3.x, FreeBSD 2. x, a fatal buffer overflow vulnerability exists in its telnetd daemon because telnetd does not perform a valid bounds check in functions that handle the Telnet protocol option, and a buffer overflow may occur when certain options (' AYT ') are used. This can lead to a security threat at the remote root level.

Therefore, if you have to use the Telnet service, you must have the latest patch for the server, which can be obtained from the following links: Patch

(Note: There are usually two versions of the telnetd server, with crypto and crypto versions, so you need to determine which version of telnetd the host is using, which can often be judged by the SRC file, such as # ls/usr/src/crypto/ TELNET/TELNETD, if it does not exist, then the use of the version is not crypto, after the identification and then download the relevant patch file separately)

Crypto version Patch:

Ftp://ftp.freebsd.org/pub/FreeBSD/CERT/patches/SA-01:49/telnetd-crypto.patch

Ftp://ftp.freebsd.org/pub/FreeBSD/CERT/patches/SA-01:49/telnetd-crypto.patch.asc

Patch Method:

# cd/usr/src/

# Patch-p </path/to/patch

# cd/usr/src/secure/libexec/telnetd

# make depend && make all install

No crypto version Patch:

Ftp://ftp.freebsd.org/pub/FreeBSD/CERT/patches/SA-01:49/telnetd.patch

Ftp://ftp.freebsd.org/pub/FreeBSD/CERT/patches/SA-01:49/telnetd.patch.asc

Patch Method:

# cd/usr/src/

# Patch-p </path/to/patch

# cd/usr/src/libexec/telnetd

# make depend && make all install

Example Sources http://toby.bokee.com/

File: Isp1161-2.6.12.patch (under/root)

Because the first line of the patch file already indicates the path, use the patch command with different parameters depending on the current directory:

1: If the current directory is and linux-2.6.12 's sibling directory:

[ROOT@KCN-110MW] #patch-p0 </root/isp1161-2.6.12.patch

2: If the current directory is linux-2.6.12/:

[ROOT@KCN-110MW] #patch-p1 </root/isp1161-2.6.12.patch

3: If the current directory is linux-2.6.12/drivers/:

[ROOT@KCN-110MW] #patch-p2 </root/isp1161-2.6.12.pathc

0,1,2 refers to the first few levels of the patch file that is omitted.

Use of ln command

This is a very important command in Linux. Its function is to create a different link for a file in another location, the most common parameter of this command is-s, which is the Ln-s source file destination file.

When we need to use the same file in a different directory, we don't need to put a file that must be the same in every directory we need, so we just put the file in a fixed directory and then use the LN command link in the other directory to do it without duplicating the disk space.

For example: Ln-s/bin/less/usr/local/bin/less

-S is the meaning of the Code name (symbolic).

Here are two points to note:

First, the LN command keeps the synchronization of each linked file in place. In other words, no matter which place you change, the other files will change the same.

Patch comes with a nice help with a list of options, but 99% of the time is just two options to meet our needs:

PATCH-P1 < [Patchfile]

Patch-r < [Patchfile] (used to undo a patch)

The-P1 option represents the number of layers in the directory to the left of the file name in Patchfile, and the top-level directory differs on different machines. To use this option, place your patch in the directory where you want to be patched, and then run PATH-P1 < [patchfile] in this directory. A short reference from the Linux kernel patch can be implemented as follows:

Diff-u--recursive--new-file v2.1.118/linux/mm/swapfile.c linux/mm/swapfile. c---v2.1.118/linux/mm/swapfile.c Wed Aug 11:37:45 1998 +++ linux/mm/swapfile.c Wed Aug 26 16:01:57 1998 @@ -489,7 +489 , 7 @@

int swap_header_version;

int lock_map_size = page_size;

int nr_good_pages = 0; -Char tmp_lock_map = 0; + unsigned long tmp_lock_map = 0;

Applications from this section using the-P1 switch copy of the patch can effectively reduce the patch location of the path; patch looks for a subdirectory named/mm in the current directory, then you should find the swapfile.c file here and wait for the patch. In this process, the line starting with the dash ("-") is replaced by a row starting with a plus sign ("+" number, translator). A typical patch will contain updates to multiple files, each of which consists of the output of the Diff-u command running against two versions of the file.

Patch displays its output on the screen while it is operating, but the output is often scrolled too fast to watch. The file name originally prepared for Patch is *.orig, and the new patch file overwrites this initial filename.

The problem of patching

Using different versions of the patch problem source may be different, and all versions are available on the network. Larry Wall has not done much to update patch in recent years, possibly because one of his last releases is working properly in most cases. In recent years, it has been the patch of a new version of the GNU Project by the FSF programmer. They first revised the problematic patch, but I have recently been using the 2.5 version without problems (this is the release number of the Debian2.0). In the past, my version 2.1 has been running very well. The current version of the GNU patch can be obtained from the GNU FTP site, but most people only use the version provided in their Linux distributions.

Let's assume that you've done a patch patch on the source program file in a directory, but patch doesn't work clearly. This may happen by accident, and an error message appears with the line number in the patch, indicating which file is having a problem. Sometimes errors are obvious, such as the absence of semicolons, which can be corrected without much effort. Another possibility is to remove the part that caused the problem from the patch section, but it might work correctly depending on the file involved, or it might not work properly.

Another common dislocation is: Suppose you have a kernel source program file that is not packaged with tar, and you'll find a variety of machine architecture subdirectories, such as Alpah, SPARC, and so on, when browsing the subdirectories under/linux/arch/. If you're using an Intel processor (or an Intel family) like most Linux users, you can decide to delete these directories that don't need to compile your particular kernel, but take up disk space. After a period of time, a new kernel patch was released, and an attempt was made to patch, and it would pause when it found that it could not find the Alpha or PPC files it needed to patch. Fortunately patch allows users to participate in these places, and it asks "Skip this patch?" Answer "y" and patch can continue to follow the correct path. You may need to answer this question many times, so it's a good way to allow your unwanted directory to remain on disk.

Tips for patching the kernel

Many Linux users use patch mainly to patch the kernel source program, so there are some tricks to use. Perhaps the easiest way to do this is to use a shell script to patch the kernel, which can be found in the/scripts subdirectory of the kernel source tree. This handy, well-written script was written by Nick Holloway in 1995 years, and two years later Adam Sulmicki added support for a variety of compression formats, including *.BZ, *.bz2, compress, Gzip and unformatted text (that is, uncompressed patch). This script assumes that when you use the new version of patch, your kernel source program is in the/usr/src/linux directory. These defaults can be overridden by command-line switches in this format: Patch-kernel [SourceDir [Patchdir]]. If any part of the patch fails, the process of patching the kernel will fail, but if patch works clearly, it calls find, which deletes all *.orig files left by patch.

If you are ready to view the output of the command, or perhaps you wish to keep the *.orig file until you are sure that the source program that has been patched has been compiled, it is reliable to run the patch directly (as described earlier, patch is the highest directory in the kernel source program). To avoid decompressing the patch, you can use one of these techniques before using:

GZIP-CD patchxx.gz | Patch-p1

Or

BZIP2-DC patchxx.bz2 | Patch-p1

After you use patch, you can use the Find program to detect rejected files:

Find. -name *.rej

The first time you use this command, the syntax may be somewhat unclear. Point number ("." ) explains that find should look for the current directory and recursively find all subdirectories below the current directory. Remember, there should be a space before and after the dots. The backslash in front of the wildcard character "*" escapes the asterisk to avoid the shell being confused and the asterisk has other meanings. If find finds any *.rej file, it prints the file name to the screen. If there is no output find to exit, then it is almost certain that the patch is functioning correctly.

Another job of find is to delete the *.orig file:

Find. -name *.orig-print0 | XARGS-0R rm-f

This command is rather cumbersome to knock, and a new shell alias can be used instead of this command. A line like this in your ~/.BASHRC file:

Alias Findorig ' Find. -name *.orig-print0 | xargs-0r rm-f '

It allows you to simply type in the Findorig to invoke the preceding command. If the definition of an alias command contains spaces, you must use single quotes. You can use a new alias in order to knock it out of the command line as ~/.BASHRC, without first exiting and then landing again. Third, soft links can span partitions, but hard links can only be within the same partition.

If you use LS to see a directory, found that some files or folders color and other different, blue, that is a file in the ln command generated, with the ls-l command to view, you can find the path of the link displayed. Second, the links in Ln are both soft links and hard links. A soft link is the ln-s * * *, which will only generate a mirror image of a file in your chosen location. Does not consume disk space, hard link LN * * *, no parameter-s, it will generate a file of the same size as the source file in your chosen position, whether it is a soft link or a hard link, the files are kept synchronized.

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.