<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Alex Tomkins - debian</title>
    <link>https://www.alextomkins.com/tag/debian/</link>
    <atom:link href="https://www.alextomkins.com/tag/debian/feed.xml" rel="self" type="application/rss+xml" />
    <description>Posts tagged with debian</description>
    <language>en</language>
    
    
    <item>
      <title>RUNLEVEL=1 apt-get install package alternative</title>
      <link>https://www.alextomkins.com/2018/03/runlevel-apt-get-install-package-alternative/</link>
      <guid>https://www.alextomkins.com/2018/03/runlevel-apt-get-install-package-alternative/</guid>
      <pubDate>Sat, 31 Mar 2018 17:25:00 +0000</pubDate>
      <description><![CDATA[<p>An old documented way of preventing services from starting immediately after installation in
Debian/Ubuntu is using the <code>RUNLEVEL</code> environment variable to trick the runlevel helper into
returning a response that the system isn't fully running, such as:</p>
<pre><code># RUNLEVEL=1 apt-get install nginx</code></pre>
<p>Sadly this doesn't work in newer versions of Debian/Ubuntu, the official way is to use the policy
helper script <code>/usr/sbin/policy-rc.d</code> and return a 101 exit code. This is a a bit more
inconvenient - having to temporarily create this file only to remove it after installing the
package.</p>
<p>Fortunately there is an alternative - <code>policyrcd-script-zg2</code>. Install the package:</p>
<pre><code>$ sudo apt-get install policyrcd-script-zg2</code></pre>
<p>Create a new script which returns a 101 exit code, I've created it as
<code>/usr/local/sbin/policy-donotstart</code>:</p>
<pre><code>#!/bin/sh
exit 101</code></pre>
<p>Then make it executable:</p>
<pre><code>$ sudo chmod 755 /usr/local/sbin/policy-donotstart</code></pre>
<p>When installing packages where you don't want the service to immediately start, use the <code>POLICYRCD</code>
environment variable:</p>
<pre><code># POLICYRCD=/usr/local/sbin/policy-donotstart apt-get install nginx</code></pre>
<p>The service will install, but you'll a message similar to:</p>
<pre><code>invoke-rc.d: policy-rc.d denied execution of start.</code></pre>
<p>For Ansible, you can add environment variables to any task:</p>
<pre><code>- name: Install nsd
  apt: pkg=nsd install_recommends=no
  environment:
    POLICYRCD: /usr/local/sbin/policy-donotstart</code></pre>
<p>Now you can safely install a package, configure it, and then start it once you've got all the
correct files in place - all with a convenient environment variable.</p>
]]></description>
    </item>
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    <item>
      <title>DigitalOcean Debian kernel</title>
      <link>https://www.alextomkins.com/2013/11/digitalocean-debian-kernel/</link>
      <guid>https://www.alextomkins.com/2013/11/digitalocean-debian-kernel/</guid>
      <pubDate>Sat, 16 Nov 2013 16:38:00 +0000</pubDate>
      <description><![CDATA[<p><a href="https://www.digitalocean.com/?refcode=1ad7cea15b72">DigitalOcean</a> offers some fantastic KVM
powered virtual machines for low prices, however the technical decisions they've made in various
places leaves something to be desired.</p>
<p>One of the problems which you may face at some point is that you're stuck with whatever kernel they
provide, you can't
<a href="https://digitalocean.uservoice.com/forums/136585-digital-ocean/suggestions/2814988-give-option-to-use-the-droplet-s-own-bootloader-">use your own bootloader</a>.
They've attempted to solve this by providing kernels from every Linux distribution they support -
but sadly this isn't the solution which I'd expect a KVM provider to use.</p>
<p>To work around this, we can use kexec to change the kernel on boot. Install kexec:</p>
<pre><code>$ sudo apt-get install kexec-tools</code></pre>
<p>Move <code>/sbin/init</code> to <code>/sbin/init.distrib</code>:</p>
<pre><code>$ dpkg-divert --add --local --rename /sbin/init creates=/sbin/init.distrib</code></pre>
<p>And create a script to replace <code>/sbin/init</code></p>
<pre><code>#!/bin/bash

if grep -qv " kexeced$" /proc/cmdline; then
    /sbin/kexec --load /vmlinuz \
        --reuse-cmdline \
        --initrd=/initrd.img \
        --append="init=/sbin/init.distrib kexeced" \
    &amp;&amp; /bin/mount -o ro,remount / \
    &amp;&amp; /sbin/kexec --exec
fi

exec /sbin/init.distrib "$@"</code></pre>
<p>Make it executable:</p>
<pre><code>$ sudo chmod 755 /sbin/init</code></pre>
<p>And then you can reboot. Next time your server restarts, the script will run before any other init
scripts and will change the running kernel with kexec. You can change the kernel parameters in this
file if you need custom options, or just leave it as is - and you'll be able to stick with your
standard Debian kernel.</p>
<p>Credit to Joe Johnston for the
<a href="https://github.com/simple10/guides/blob/fa8261c17d3bade13da0644a38c3c38b24dc5b96/digitalocean.md#debian-selinux">original script</a>.</p>
<h2>Update</h2>
<p>A couple of years later, DigitalOcean eventually created new images which use the virtual machines
bootloader - which means this hack is no longer needed for newer Linux distributions.</p>
]]></description>
    </item>
    
    
    
    
    
    
    
  </channel>
</rss>
