nerdexam
CompTIA

LX0-103 · Question #31

If the current directory is /root and the kernel source is located in /usr/src/linux, which of the following commands should be used to apply the patch /tmp/foopatch?

The correct answer is D. cd /usr/src/linux; patch -p1 < /tmp/foopatch. Applying a kernel patch requires using patch -p1 with input redirection from the patch file while the working directory is the kernel source tree.

Linux Installation and Package Management

Question

If the current directory is /root and the kernel source is located in /usr/src/linux, which of the following commands should be used to apply the patch /tmp/foopatch?

Options

  • Acd /usr/src/linux; cat /tmp/foopatch | patch
  • Bcd /usr/src/linux; cat /tmp/foopatch | patch -p0
  • Ccd /usr/src/linux; patch -p1 > /tmp/foopatch
  • Dcd /usr/src/linux; patch -p1 < /tmp/foopatch
  • Ecat /tmp/foopatch | patch -p0

How the community answered

(25 responses)
  • A
    4% (1)
  • C
    8% (2)
  • D
    84% (21)
  • E
    4% (1)

Why each option

Applying a kernel patch requires using patch -p1 with input redirection from the patch file while the working directory is the kernel source tree.

Acd /usr/src/linux; cat /tmp/foopatch | patch

Piping through cat without -p1 uses the default -p0, which does not strip any directory prefix, causing patch to fail to locate the target files in the kernel source tree.

Bcd /usr/src/linux; cat /tmp/foopatch | patch -p0

-p0 does not strip the leading directory component from patch paths, so the patched file paths will not match the actual file locations under /usr/src/linux.

Ccd /usr/src/linux; patch -p1 > /tmp/foopatch

Using > instead of < redirects output to /tmp/foopatch, overwriting or truncating the patch file rather than reading it as input.

Dcd /usr/src/linux; patch -p1 < /tmp/foopatchCorrect

The command cd /usr/src/linux; patch -p1 < /tmp/foopatch changes to the kernel source directory and uses patch with -p1 to strip one leading directory component from paths in the patch file, which is the standard convention for kernel patches generated with diff -u. The < operator correctly reads the patch file as input to the patch command.

Ecat /tmp/foopatch | patch -p0

Running from /root with -p0 means the working directory is wrong and no directory stripping is applied, so patch cannot find the kernel source files to modify.

Concept tested: Applying patches to kernel source with patch -p1

Source: https://man7.org/linux/man-pages/man1/patch.1.html

Topics

#patch command#kernel patching#patch -p1#applying patches

Community Discussion

No community discussion yet for this question.

Full LX0-103 Practice