How to apply a patch to aid in development

In some instances there may be the requirement to test a patch; this is most likely to be associated with small changes that need testing on hardware that is not in the hands of a core developer. It is advised that if you undertake this task that you are prepared to break your current install. It is also advisable to be running the latest testing channel updates; however this may not be required in some circumstances and the author of the patch should be able to advise accordingly.

The following example indicates applying a simple patch to a single file.

How to Apply a patch

This involves several steps that must be performed by the root user.

Backup the file or files first

Then if there are issues you can simply copy the backed up versions over the top of the patched version and mostly return to where you were. This step may require the advise of the patch author but in the case of for example a single file patch to /opt/rockstor/src/rockstor/system/ you can simply copy that file to /root to safeguard it’s pre-patch state ie cp /opt/rockstor/src/rockstor/system/ /root/

TODO add whole tree cp backup here, or even a snapshot arrangement given we are on ‘/’ mount point ie stop rockstor servies and db then snapshot, then apply patch then start all services again.

Get the patch program.

yum install patch

Change to a know directory.


Download the specific patch

Take care to use the correct address and a meaningful destination file name without spaces.

curl url-supplied-by-developer > test_patch_name.patch

We should now have a patch file in the /root directory with the name specified in the last command.

Applying the patch.

patch -d /opt/rockstor/ -p1 < test_patch_name.patch

In the above command the -d options specifies the base directory to apply the patch to which in this case is the default Rockstor install directory. The -p1 options strips the first internal directory name used within the patch.

Take a copy of the text returned by the patch command in case the patch author need it. If all is well the result should simple be a list of the files patched eg “patching file src/rockstor/system/”

How to Make a patch url

From the developers point of view the simplest example of creating a patch is in the case of a single commit that you wish to supply as a patch. In this case if one is viewing the single commit in Github that you wish to generate a patch url for, simply add the following:


to the end of the url bar’s contents. Note this does not work for commits viewed within pull requests. The view must be from within your own fork / branch view. So the url will be of the form:<long-commit-hash>.patch

In the above we are a accessing a specific commit by user MFlyer on GitHub from within their fork of the rockstor-core repo. Urls of this form should then work in the above “How to Apply a patch” section.