sandip's blog

How to create and use a patch in Linux

Creating a Patch File:

diff -Naur olddir newdir > new-patch
- or -
diff -Naur oldfile newfile >new-patch

A Note concerning Patch and the number of Directory Levels used:

Try to make sure when creating a patch file that you have the same number of directories levels for both the olddir path and newdir path. For Ex:

--- old/modules/pcitable	Mon Sep 27 11:03:56 1999
+++ new/modules/pcitable	Tue Dec 19 20:05:41 2000

The above diff would work ok as a patch.

--- old/try1/other/modules/pcitable	Mon Sep 27 11:03:56 1999
+++ new/modules/pcitable	Tue Dec 19 20:05:41 2000

You may have problems with the above diff working as a patch. Note that the first one has 4 directory levels mentioned and the 2nd one has only two. I would suggest modifying the --- and +++ lines to make the directory structure in both to be the same number of levels deep.

Using the Patch Command:

patch -p0 < new-patch
patch -p1 < new-patch

Which one of the above patch commands you use depends on your current working directory.

Other Methods for calling the patch command - using standard input of patch:

cat new-patch | patch -p0

Other methods for calling the patch command - using a "here document":

patch -p0 << EOF
--- old/modules/pcitable	Mon Sep 27 11:03:56 1999
+++ new/modules/pcitable	Tue Dec 19 20:05:41 2000
@@ -1,4 +1,6 @@
 0x0e11	0xae10	"cpqarray"	"Compaq|Smart-2/P RAID Controller"
+0x1000	0x0010	"cpqarray"	"Compaq|Integrated Array Controller"
+0x1011	0x0046	"cpqarray"	"Compaq|Smart-2/P RAID Controller"
 0x0e11	0xae32	"tlan"	"Compaq|Netelligent 10/100"
 0x0e11	0xae34	"tlan"	"Compaq|Netelligent 10"
 0x0e11	0xae35	"tlan"	"Compaq|Integrated NetFlex-3/P"
@@ -21,6 +23,7 @@
 0x1000	0x000f	"ncr53c8xx"	"Symbios|53c875"
 0x1000	0x0012	"ncr53c8xx"	"Symbios|53c895a"
 0x1000	0x008f	"ncr53c8xx"	"Symbios|53c875J"
+0x1000	0x000a	"sym53c8xx"	"Symbios|53c1510"
 0x1000	0x0701	"yellowfin"	"Symbios|83C885 gigabit ethernet"
 0x1000	0x0702	"yellowfin"	"Symbios|Yellowfin G-NIC gigabit ethernet"
 0x1011	0x0001	"tulip"	"DEC|DECchip 21050"
--- old/usr/share/kudzu/pcitable	Sun Sep 26 17:11:23 1999
+++ new/usr/share/kudzu/pcitable	Tue Dec 19 20:05:41 2000
@@ -15,6 +15,8 @@
 0x0e11	0x3034	"unknown"	"Compaq|QVision 1280/p"
 0x0e11	0x4000	"unknown"	"Compaq|4000 [Triflex]"
 0x0e11	0xa0f3	"ignore"	"Compaq|Triflex PCI to ISA Bridge"
+0x1000	0x0010	"cpqarray"	"Compaq|Integrated Array Controller"
+0x1011	0x0046	"cpqarray"	"Compaq|Smart-2/P RAID Controller"
 0x0e11	0xae10	"cpqarray"	"Compaq|Smart-2/P RAID Controller"
 0x0e11	0xae29	"unknown"	"Compaq|MIS-L"
 0x0e11	0xae2a	"unknown"	"Compaq|MPC"
@@ -46,6 +48,7 @@
 0x1000	0x000f	"ncr53c8xx"	"Symbios|53c875"
 0x1000	0x0012	"ncr53c8xx"	"Symbios|53c895a"
 0x1000	0x008f	"ncr53c8xx"	"Symbios|53c875J"
+0x1000	0x000a	"sym53c8xx"	"Symbios|53c1510"
 0x1000	0x0701	"yellowfin"	"Symbios|83C885 gigabit ethernet"
 0x1000	0x0702	"yellowfin"	"Symbios|Yellowfin G-NIC gigabit ethernet"
 0x1000	0x0901	"unknown"	"Symbios|61C102"
EOF

For the "here document", patch will read all the following lines, up until it reaches the delimeter that we specified after the << symbol. The delimeter we choose must appear at the beginning of a line, and must appear alone. In our case we are using the delimeter EOF. EOF has no special meaning, other than the fact that it is not likely that we would have a reason to type EOF at the beginning of any given line.

Levels in the Patch Command (-p0 or -p1?):

The -p option will optionally strip off directory levels from the patchfile. For Ex: if you have a patchfile with a header as such:

--- old/modules/pcitable	Mon Sep 27 11:03:56 1999
+++ new/modules/pcitable	Tue Dec 19 20:05:41 2000

Using a -p0 will expect, from your current working directory, to find a subdirectory called "new", then "modules" below that, then the "pcitable" file below that.

Hosting Backup

Hosting Backup is a set if PHP command line scripts that provides an easy way to backup hosted Web sites to your local computer. It works with sites hosted on Linux servers with MySQL databases using FTP.

Java Search Applet - HouseSpider !!

HouseSpider is an Java applet that adds indexing and search capability to your web site. It can search by two methods, by spidering through your site or by searching a cached index file. Spider-searching is slow, but very easy to set up and requires no maintenance. Cache-searching requires only a little more attention to set-up and is very fast, sometimes even faster than server-hosted cgi programs. HouseSpider also supports compression (in zip-format) of the index file. HouseSpider has 100% support for i18n (internationalization). It is already translated to several languages. And best of all - it is free!

Installing Dual Boot Windows 2000 or XP and Linux - Page 2

Partitioning Drive

In order to prepare the drive for a dual boot system install Windows first and then Redhat Fedora. Below is what my drive looks like when partitioned:

Output of the "fdisk -l" command showing the partitions.

#fdisk -l

Disk /dev/hda: 40.0 GB, 40007761920 bytes
255 heads, 63 sectors/track, 4864 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot    Start       End    Blocks   Id  System
/dev/hda1   *         1      1567  12586896    7  HPFS/NTFS

/dev/hda2          1568      1580    104422+  83  Linux
/dev/hda3          1581      2885  10482412+  83  Linux
/dev/hda4          2886      4864  15896317+   f  Win95 Ext'd (LBA)
/dev/hda5          2886      3407   4192933+   c  Win95 FAT32 (LBA)
/dev/hda6          3408      3538   1052226   82  Linux swap
/dev/hda7          3539      4864  10651063+  83  Linux

Output of the "df" command showing the mount points.

Installing Dual Boot Windows 2000 or XP and Linux - Page 3

Installing Fedora

The NVIDIA GeForce FX5200 video card was not compatible with the generic "nv" driver that the installer detected and had to do the install in text mode. The installation is a breeze once you have setup your partitioning and decided what goes where. If this is your first time, you may want to refer to the Redhat docs for installation as Fedora currently lacks one.

See the video troubleshooting...

Installing Dual Boot Windows 2000 or XP and Linux
Partitioning Drive
Installing Fedora
Dual Booting
Troubleshooting XFree86 GUI display!

Installing Dual Boot Windows 2000 or XP and Linux - Page 4

Dual Booting

Once the Fedora installation is complete, start fedora in rescue mode and make a copy of the Linux boot sector onto the FAT32 partition and name the copy "fedora.bin".

  1. To start fedora in rescue mode:
    • Boot from your install disk 1
    • At the Linux prompt, enter "linux rescue"
    • Specify your keyboard and language stuff. Your Linux partitions will get mounted under "/mnt/sysimage".
    • Run the following command:
      #chroot /mnt/sysimage
      

      This command makes "/mnt/sysimage" your root directory. So the filesystem looks the way it would if you booted up normally.

  2. To make a copy onto a FAT32 (vfat) partition:
    • Mount the FAT32 partition if it's not mounted yet. If it isn't listed in the df output, it hasn't been mounted yet.
      #mount -t msdos /dev/hda5 /win
      
    • Run the following command, which copies the first sector of the /boot partition, 512 byte size to the /win partition as the binary file, fedora.bin:
      #dd if=/dev/hda2 of=/win/fedora.bin bs=512 count=1
      
    • Substitute the path for the if= parameter (the input file) with the appropriate partition from the previous step, set if= to /dev/hda2. Substitute the path for the of= parameter (the output file) with whatever is appropriate for your system. The example here (of=/win/fedora.bin) is for copying onto a FAT32 partition called win.
  3. Reboot into Windows
  4. Copy the fedora.bin file to C:\
  5. Run notepad and edit "C:\boot.ini". Note that C:\boot.ini is a hidden system file, so it probably won't show up in Windows Explorer. To edit the file, try: "Start->Run" and enter: "notepad C:\boot.ini". Add the following line at the end: "c:\fedora.bin="Fedora Linux".
    If your C: filesystem is NTFS (not FAT32), you must edit C:\boot.ini as a user with administrator-level privileges.

    Below is what my "boot.ini" file looks like:

    [boot loader]
    timeout=5
    default=multi(0)disk(0)rdisk(0)partition(1)\WINNT
    [operating systems]
    multi(0)disk(0)rdisk(0)partition(1)\WINNT="Microsoft Windows 2000 Professional" /fastdetect
    c:\fedora.bin="Linux Fedora"
    
  6. Reboot again. You should be able to pick either Windows or Linux. Selecting Linux will start GRUB

Installing Dual Boot Windows 2000 or XP and Linux
Partitioning Drive
Installing Fedora
Dual Booting
Troubleshooting XFree86 GUI display!

Installing Dual Boot Windows 2000 or XP and Linux - Page 5

Troubleshooting XFree86 GUI display!

You may not be able to "startx" as the NVIDIA GeForce FX5200 video card is not compatible with the generic "nv" driver that the anaconda installer detects. Luckily NVIDIA has a driver and can be downloaded from here. See the README file for the installation and configuration of the driver. Check to see that your nvidia kernel module is loaded via "lsmod | grep nvidia". I had to "insmod nvidia" to load the nvidia module into the kernel after driver installation. Also check that you have the line, "alias char-major-195 nvidia" in your "/etc/modules.conf" file.

Installing Dual Boot Windows 2000 or XP and Linux - Page 1

Inside Security Rescue Toolkit

INSERT is a complete, bootable linux system. It comes with a graphical user interface running the fluxbox window manager while still being sufficiently small to fit on a credit card-sized CD-ROM.

INSERT contains a multitude of useful tools to be at your hand in a variety of situations:

  • full read-write support for NTFS-partitions using captive
  • support for various file system types: EXT2,EXT3,MINIX,REISERFS,JFS,XFS,NTFS,FAT,MSDOS,NFS,SMBFS,NCPFS,UDF,UFS,HFS,HFS+
  • support for linux software RAID and LVM
  • network analysis (e.g. nmap, tcpdump)
  • disaster recovery (e.g. gpart, partimage, testdisk)
  • virus scanning (Clam Antivirus)
  • computer forensics (e.g. chkrootkit)
  • surf the internet (e.g. links-hacked, AxY FTP)

AntiExploit

AntiExploit is a small Perl script that scans for well known exploit files. It currently recognizes over 1700 suspicious files, and the database is updated weekly.

Syndicate content
Comment