{"id":113,"date":"2016-09-17T02:31:38","date_gmt":"2016-09-17T06:31:38","guid":{"rendered":"http:\/\/unliterate.net\/?p=113"},"modified":"2016-09-17T02:31:38","modified_gmt":"2016-09-17T06:31:38","slug":"how-to-build-an-rpm-from-scratch-with-centos-6-8","status":"publish","type":"post","link":"https:\/\/www.unliterate.net\/index.php\/2016\/09\/17\/how-to-build-an-rpm-from-scratch-with-centos-6-8\/","title":{"rendered":"How to build an RPM from scratch with Centos 6.8"},"content":{"rendered":"<p style=\"text-align: left;\">I&#8217;ve been completely curious on how to actually build an RPM for Redhat\/Centos from since&#8230;well, I knew they existed. There are many articles out there on the interwebs, but I felt it necessary to dig on out and get it going from conception to death.<\/p>\n<p style=\"text-align: left;\"><strong>Virtual Hardware and Software:<\/strong><\/p>\n<p style=\"text-align: left;\">To start, i&#8217;m gonna use <a href=\"https:\/\/www.virtualbox.org\/wiki\/Downloads\">Oracle VM Virtualbox<\/a>\u00a0(currently at 5.0.26 r108824) and a <a href=\"http:\/\/isoredirect.centos.org\/centos\/6\/isos\/x86_64\/\">Centos 6.8\u00a0Minimal install<\/a>. What better way to start this than from nothing.<\/p>\n<p style=\"text-align: left;\">I created the VM with 1GB of RAM and the standard 8GB Virtual Hard Drive. Made some minor modifications to the VM such as:<\/p>\n<ul>\n<li style=\"text-align: left;\">Disabled the Audio<\/li>\n<li style=\"text-align: left;\">Enabled NIC1 and bridged it to my Ethernet Adapter<\/li>\n<li style=\"text-align: left;\">Disabled the USB Controller<\/li>\n<\/ul>\n<p>I mounted the ISO and booted it up for the install.<\/p>\n<p><strong>Operating System Installation:<\/strong><\/p>\n<p>Clicking <span style=\"color: #008000;\">Start &gt;<\/span>, I\u00a0skipped media testing and sailed into Anaconda. I accepted all default options except for allowing my Network Interface to be configured On and DHCP enabled. This saves me\u00a0configuration options later on for \/etc\/sysconfig\/networking-scripts and \/etc\/resolv.conf. Made roots password, well, password, since i&#8217;ll be sudo&#8217;ing a user for good measure. 205 packages later I have my system ready to be SSH&#8217;d into.<\/p>\n<p><strong>First Boot:<\/strong><\/p>\n<p>Once everything was installed and configured from Anaconda there was a bit of cleanup I like to do. It&#8217;s not required on every installation, but it helps me do things in my development environments without issues later on.<\/p>\n<p><span style=\"text-decoration: underline;\">More updates:<\/span><\/p>\n<p>At the time of this writing, with a fresh ISO you still need to belt out a\u00a0<em>yum upgrade<\/em>. There exists 1 package to install, 27 to upgrade, and 76M of data to download. Best to get this out of the way before changing system configurations and having them reset back to basics.\u00a0<em>shutdown -r now<\/em>, and we&#8217;re back in business.<\/p>\n<p><span style=\"text-decoration: underline;\">Disabling selinux:<\/span><\/p>\n<p>Fairly easy to do, and there is a plethora of documents on the interwebs to do it. All done as\u00a0<em>root<\/em>:<\/p>\n<pre>vi \/etc\/selinux\/config\r\nSELINUX=permissive<\/pre>\n<p><span style=\"text-decoration: underline;\">Firing the firewall:<\/span><\/p>\n<p>Cleanly shutting off iptables just helps in debugging local and remote connection issues. Good thing we won&#8217;t come into this with making our RPMs, but I might want to use this development machine later on and I don&#8217;t want to have to assume I did it when debugging issues. All done as\u00a0<em>root<\/em>:<\/p>\n<pre>service iptables save\r\nservice iptables stop\r\nchkconfig iptables off<\/pre>\n<p><span style=\"text-decoration: underline;\">Making myself useful<\/span><span style=\"text-decoration: underline;\">:<\/span><\/p>\n<p>Still have to do the basic administration, and create my user and give it some god-like sudo permissions:<\/p>\n<pre>adduser mheick\r\npasswd mheick\r\nvisudo\r\nmheick ALL=(ALL) ALL<\/pre>\n<p>Finally, we do some minor shell-related things like setting our <em>TERM=xterm-256color<\/em> and finding out our ip address so we can SSH into it to get this party started.<\/p>\n<p><strong>Finding and following instructions:<\/strong><\/p>\n<p>So, we need a couple things that do not come with the minimum install to prepare for this journey:<\/p>\n<p>1 &#8211; We need a user that we will \/use\/ to build things with. We&#8217;re gonna create one called\u00a0<em>builder:<\/em><\/p>\n<pre>sudo adduser robertbuilder\r\nsudo passwd\u00a0robertbuilder<\/pre>\n<p>2 &#8211; We are going to need\u00a0rpm-build, devtools and their\u00a0dependencies:<\/p>\n<pre>sudo yum install rpm-build rpmdevrools<\/pre>\n<p><strong>Our data:<\/strong><\/p>\n<p>We&#8217;re gonna be a good sport and create some test data, and go ahead and tar it up:<\/p>\n<pre>mkdir data\r\nchdir data\r\ntouch main\r\ntouch final\r\ntouch one\r\ntar -czf myfirstrpm.tar.gz<\/pre>\n<p>This creates\u00a0<em>myfirstrpm.tar.gz<\/em>, which we will use to extract these junky files\u00a0somewhere.<\/p>\n<p><strong>Before making a .spec file, we must be prepared:<\/strong><\/p>\n<p>The heart and soul of an RPM is this specific file. It contains all the instructions on \/what\/ to do with the contents of the RPM, where to install things, what to say, etc. We&#8217;re going to start off getting our RPM over in <em>robertbuilder<\/em>&#8216;s home folder, passing along ownership, and then\u00a0becoming\u00a0<em>robertbuilder<\/em>\u00a0to continue on.<\/p>\n<pre>sudo cp myfirstrpm.tar.gz \/home\/robertbuilder\/\r\nsudo chown robertbuilder:robertbuilder \/home\/robertbuilder\/myfirstrpm.tar.gz\r\nsudo su robertbuilder<\/pre>\n<p>Our builder user needs a folder structure in order to store our files, test out our RPMs, store our other files, and do testing and funsies. We use what we&#8217;re given.<\/p>\n<pre>rpmdev-setuptree<\/pre>\n<p>This creates the ~\/rpmbuild\/(BUILD|RPMS|SOURCES|SPECS|SRPMS) folders so that we can actually make this build happen.<\/p>\n<p><strong>Getting the .spec into it<\/strong><\/p>\n<p>We need to hope into the ~\/rpmbuild\/SPECS folder and execute our spec-template creator<\/p>\n<pre>rpmdev-newspec myfirstrpm<\/pre>\n<p>This creates a basic .spec:<\/p>\n<pre>Name: myfirstrpm\r\nVersion:\r\nRelease: 1%{?dist}\r\nSummary:\r\n\r\nGroup:\r\nLicense:\r\nURL:\r\nSource0:\r\n\r\nBuildRequires:\r\nRequires:\r\n\r\n%description\r\n\r\n\r\n%prep\r\n%setup -q\r\n\r\n\r\n%build\r\n%configure\r\nmake %{?_smp_mflags}\r\n\r\n\r\n%install\r\nrm -rf $RPM_BUILD_ROOT\r\nmake install DESTDIR=$RPM_BUILD_ROOT\r\n\r\n\r\n%clean\r\nrm -rf $RPM_BUILD_ROOT\r\n\r\n\r\n%files\r\n%defattr(-,root,root,-)\r\n%doc\r\n\r\n%changelog<\/pre>\n<p>We&#8217;re going to modify lines in that so that we can properly install our <em>myfirstrpm.tar.gz<\/em><\/p>\n<p><strong>Now, we need HAAAALP!:<\/strong><\/p>\n<p>No worries. We have <a href=\"https:\/\/fedoraproject.org\/wiki\/How_to_create_an_RPM_package\">centos.org documentation!<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been completely curious on how to actually build an RPM for Redhat\/Centos from since&#8230;well, I knew they existed. There are many articles out there on the interwebs, but I felt it necessary to dig on out and get it going from conception to death. Virtual Hardware and Software: To start, i&#8217;m gonna use Oracle [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19,20,17,18],"tags":[],"class_list":["post-113","post","type-post","status-publish","format-standard","hentry","category-centos","category-geek-instructions","category-linux","category-rpm"],"_links":{"self":[{"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/posts\/113","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/comments?post=113"}],"version-history":[{"count":6,"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/posts\/113\/revisions"}],"predecessor-version":[{"id":119,"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/posts\/113\/revisions\/119"}],"wp:attachment":[{"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/media?parent=113"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/categories?post=113"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.unliterate.net\/index.php\/wp-json\/wp\/v2\/tags?post=113"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}