Debian Wheezy Post Install Customization

I have been using Debian Testing (Wheezy) installer disks for a while now, and every time I do a fresh install I have to manually customize it. This list is the things which I customize. During installation, I don’t even install Standard utilities, preferring to install only what I need (a real minimal install).

Install Necessary Packages

su -
aptitude install vim sudo less ssh

Configure default editor

Once you have installed vim, you may want to enable it as the default editor

su -
update-alternatives --config editor

You will be presented a list of installed editors and you can choose “vim basic” from it.

Add user for sudo

visudo

Add the following line to the file, under User privilege specification

codeghar ALL=(ALL:ALL) ALL

INIT: Id “co” respawning too fast: disabled for 5 minutes

If you see this message popping up all the time, do the following:

sudo sed -e 's/^co:2345/#co:2345/g' -i /etc/inittab

This comments out the line with ‘co’ in it. Now tell init to re-examine the inittab file

sudo init q

Configure SSH

Backup the config file first

sudo cp /etc/ssh/sshd_config /etc/ssh/bkp.sshd_config

Disable root login

sudo sed -e 's/^PermitRootLogin yes$/#PermitRootLogin yes\nPermitRootLogin no/g' -i /etc/ssh/sshd_config

Don’t use DNS

sudo sh -c "echo 'UseDNS no' >> /etc/ssh/sshd_config"

Only allow certain users to login via SSH

sudo sh -c "echo 'AllowUsers codeghar' >> /etc/ssh/sshd_config"

Setup Aliases

I always setup a standard set of aliases to make things easier for me.

vim ~/.bash_aliases

And I put the following lines in the file:


alias update="sudo aptitude update"
alias upgrade="sudo aptitude dist-upgrade"
alias install="sudo aptitude install"
alias search="aptitude search"
alias show="aptitude show"

An alternative is to run the following series of commands:

echo 'alias update="sudo aptitude update"' >> ~/.bash_aliases
echo 'alias upgrade="sudo aptitude dist-upgrade"' >> ~/.bash_aliases
echo 'alias install="sudo aptitude install"' >> ~/.bash_aliases
echo 'alias search="aptitude search"' >> ~/.bash_aliases
echo 'alias show="aptitude show"' >> ~/.bash_aliases

Change from ‘wheezy’ to ‘testing’ (optional)

Change the apt source.list file, replacing ‘wheezy’ with ‘testing’. This way I can continue to use the ‘testing’ branch, even after ‘wheezy’ is made ‘stable’.

sudo sed -e 's/ wheezy/ testing/g' -i /etc/apt/sources.list

After changing, run the following commands. The first command updates apt database/cache/etc. based on ‘testing’ and the second command upgrades your system (if necessary).

sudo aptitude update

sudo aptitude dist-upgrade

Setup static IP (optional)

If you want to setup static IP address, you need to modify /etc/network/interfaces file. You can run the following commands to do so.

sudo sed -e 's/^allow-hotplug eth0/#allow-hotplug eth0/g' -e 's/^iface eth0 inet dhcp/#iface eth0 inet dhcp/g' -i /etc/network/interfaces

sudo sh -c "echo 'auto eth0' >> /etc/network/interfaces"

sudo sh -c "echo 'iface eth0 inet static' >> /etc/network/interfaces"

sudo sh -c "echo 'address 192.168.0.101' >> /etc/network/interfaces"

sudo sh -c "echo 'netmask 255.255.255.0' >> /etc/network/interfaces"

sudo sh -c "echo 'gateway 192.168.0.1' >> /etc/network/interfaces"

Advertisements

Debian: Running /etc/init.d/networking restart is deprecated because it may not enable again some interfaces

Have you run /etc/init.d/networking restart on a recent Debian? Or maybe you ran invoke-rc.d networking restart? Then you have seen this warning: Running /etc/init.d/networking restart is deprecated because it may not enable again some interfaces. It was reported to folks at Debian (#565187 netbase: Command deprecated and not explained) and a response was “That is not the place for documentation. There is not a good solution either.” Even though there is no good solution, there must at least be one solution, right? So the solution is to manually stop and start each interface (say, using ifdown eth0 and then ifup eth0). But some things to consider are:

(1) If you are SSH’ed into interface eth0, if you do an ifdown eth0, you lose connectivity. One thing I tested in a VirtualBox Debian virtual machine (VM) is the following command and my connection didn’t break. But before you do anything on a production system, test this out properly.

su -
ifdown eth0 && ifup eth0

Or if you have sudo privileges, then only

sudo ifdown eth0 && sudo ifup eth0

An even better method may be below, adapted from the suggestion of Eduardo Ivanec. I tried it out over an SSH session and it worked well. Since there’s no visible output, whatever output the command generates is appended to nohup.out file in the same directory as where you ran this command. This is the only log you have of what actually happened and if it shows the right messages, it means networking was restarted successfully.

su -
nohup sh -c "ifdown eth0 && ifup eth0"

If you have sudo privileges, you can do the following. But the nohup.out log file created is owned by root.

sudo nohup sh -c "ifdown eth0 && ifup eth0"

(2) If you have multiple interfaces, you need to ifdown/ifup all of them one by one. I don’t have an easier way to manage this, while keeping true to the philosophy that Debian has adopted: “Now devices come online when they are plugged in and go offline when they are disconnected. Everything has been rewritten to be event driven.” (source: Re: Restarting Networking in Debian; this is not official wording, just interpretation by one person). But you could try something like the following (again, I have only tested it in a VM):

su -
invoke-rc.d networking stop && invoke-rc.d networking start

Or if you have sudo privileges, then only

sudo invoke-rc.d networking stop && sudo invoke-rc.d networking start

Continuing our adaptation of Eduardo Ivanec’s suggestion, you can do the following instead:

su -
nohup sh -c "invoke-rc.d networking stop; sleep 2; invoke-rc.d networking start"

If you have sudo privileges, you can do the following. But the nohup.out log file created is owned by root.

sudo nohup sh -c "invoke-rc.d networking stop; sleep 2; invoke-rc.d networking start"

Since it’s tough to remember and type such a long command every time, you may want to add the following to your .bash_aliases file. It acts as a good log with dates and times.

alias netrestart="sudo nohup sh -c 'invoke-rc.d networking stop; date; echo sleeping; sleep 2; echo waking; date; invoke-rc.d networking start'"

Further Reading

Restarting Networking in Debian; What is the preferred method to restart networking in Ubuntu and Debian

Install KDE4 Desktop Environment in Debian Wheezy

Before you read this post, I strongly encourage you to read Install KDE 4 packages because it contains more information. I started with a netinstall CD and only installed standard stuff and no GUI. Once the installation was complete, I ran the following command to install KDE 4.

sudo aptitude install kdm kde-plasma-desktop

I installed KDM for my display manager and also the KDE4 plasma desktop package. Once everything was installed, I rebooted the machine.

One thing I noticed was that in KDM, both a GNOME and KDE session was available. I made sure that I selected KDE session at login. I also noticed that the network management widget was missing from the system tray. I like how I can use this widget to manage my network connections. Therefore, I needed to install it by running the following command:

sudo aptitude install plasma-widget-networkmanagement

After installing it, you need to use “Add Widgets” to add the “Network Management” widget to the system tray. Open the Network Management widget and click enable networking. I had to reboot the machine before I was able to manage network connections through it. It might be that “Network Manager“, the application actually managing the network connections, needed to take over from the traditional management in Debian CLI. I really don’t know but I do know that after a reboot it allowed me to manage my network connections.

So this was how I got my Debian Wheezy up and running with KDE 4.

I Keep Returning to Debian

I have been trying out many different distributions recently (6-12 months). The purposes have been from curious exploration to putting things in enterprise-level production. I have tried, amongst others, RHEL, CentOS, Debian, Ubuntu, Fedora, Mint, and ScientificLinux. And I keep returning to Debian; here’s why.

RHEL, although used at my work for production VoIP telephony systems, costs license and support fees to keep updated. The kinds of systems we run, we need a lot of servers and at some point RHEL becomes cost-prohibitive for a small shop. But we do need RHEL because our application provider only supports RHEL. So we are stuck with no place to go.

Unless, of course, there’s a project like CentOS out there. So we solve the problem of large license costs by using a freely available alternative. Our application provider is happy and our management is happy. But when the need arises to build a home-grown application, say a Django-based web portal, CentOS falls short on the latest and greatest. Of course, we don’t expect RHEL or CentOS to be a fit for all projects. So now the search continues.

In a bid to remain consistent, we tried using Fedora. It does give us the latest and greatest so we can build our shiny new applications and deploy on it. This works great for now but we want some semblance of stability once the application is deployed. We cannot afford to keep updating Fedora to the latest and greatest. The dilemma, then, is that during development we need the latest versions of everything but once we put this in production, we don’t want to have to keep pace with the changes.

How about Ubuntu LTS? Of course, we are now diverging from the RHEL platform into new territories. We get the latest and greatest during development and stability during deployment. And once again there’s a roadblock. If you start with the latest LTS release, it is already a year old. So any project you start now is not exactly using the latest stuff. By the time you are ready to deploy, it might be six or eight months from now, closer to the next LTS release. Of course, things are not always perfect and this might be good enough for applications that need to maintained as-is for the mid-term, say 2-3 years.

I, on the other hand, wanted to explore Debian. One thing I learned is that no matter what time you start a project, you will always have two options: either to start with the last stable release for any applications not requiring the latest and greatest, or start with the current testing releases. I opt for the testing releases because by the time I am done, I will be closer to the next stable release and further from the last stable release. When I deploy, there is a period of uncertainty where there are changes still being made.

To counter this, create a dev/test platform to keep pace with the latest updates (called dev1), a dev/test platform matching the current versions running on production system (called dev2), and a production system. Test your application on dev1 after updating your OS, etc., and fix all broken things. Then deploy your application on dev2 and test. Update OS, etc., as required and test again. If everything is fine, upgrade production and deploy your application.

By not using RHEL, CentOS, Fedora, and Ubuntu, I get, for my projects, a little bit of future-proofing while also getting great stability during deployment. Another thing I love about Debian is the number and variety of pre-packaged libraries and applications available. I don’t need to add third-party repositories for stuff I expect my distribution to provide.

Of course, this post deals with the enterprise server computing aspect of Linux. If you need to deploy desktops, there are other considerations. For me, though, if it’s something I am creating, I prefer Debian. If it’s something someone else created and only supports RHEL, then I always go to CentOS. (psst… I have also recently started exploring ScientificLinux).

Install MoinMoin in Debian

I have read some good things about MoinMoin and decided to give it a shot. Some of its features I like are: built using Python, stores data in files (not in database), and Debian has a package available.

Install Software

To install the software, run the following command:

sudo aptitude install python python-moinmoin apache2

After installation, some paths related to MoinMoin are as below:

Source code for MoinMoin is located at: /usr/lib/pymodules/python2.5/MoinMoin/
Templates for MoinMoin are located at: /usr/share/moin/
Config for your wikis is located at: /etc/moin/

Create Your First Wiki

I want to thank these pages for helping me write this section. You should read them in this order as well: Basic Installation; WikiInstanceCreation.

I installed my wiki in the /opt/wiki/ path. So I needed to create the directory.

sudo mkdir /opt/wiki/

Once the directory has been created, you need to copy over files from the MoinMoin templates.

cd /opt/wiki/
sudo cp -R /usr/share/moin/data/ /opt/wiki/
sudo cp -R /usr/share/moin/underlay/ /opt/wiki/
sudo cp /usr/share/moin/config/wikiconfig.py /opt/wiki/
mkdir /opt/wiki/cgi-bin
cd /opt/wiki/cgi-bin/
cp /usr/share/moin/server/moin.cgi /opt/wiki/cgi-bin/

Since we installed in a location which is accessible to root by default only, we need to change its permissions. We change the owners: owned by user codeghar and owned by group www-data. www-data is the user and group under which Apache runs in Debian. This way I, as a user, and Apache, as a program, can edit files easily.

cd /opt/
sudo chown -R codeghar:www-data wiki
sudo chmod -R ug+rwx wiki
sudo chmod -R o-rwx wiki

The config for MoinMoin is stored in /etc/moin/. To install our first wiki, we need to make some changes.

cd /etc/moin/
sudo vim mywiki.py

Change the following settings in the file /etc/moin/mywiki.py

sitename = u'CodeGharWiki'
interwikiname = u'CodeGharWiki'
data_dir = '/opt/wiki/data/'
data_underlay_dir = '/opt/wiki/underlay/'
url_prefix_static = '/moin_static192' # here the value 192 depends on which version of MoinMoin you have installed. On my Debian Squeeze installation it was 1.9.2; hence, 192.

Configure Apache

Now you need to configure Apache to run your wiki. I want to thank Apache on Linux in helping with this section.

cd /etc/apache2/sites-available/
sudo vim wiki

Make sure the following exists in this file.

<VirtualHost *:80>
#comment the line below if you intend to use only http://localhost/mywiki
ServerName wiki.codeghar.com
DocumentRoot /opt/wiki/
Alias /moin_static192/ "/usr/share/moin/htdocs/"
ScriptAlias /wiki "/opt/wiki/cgi-bin/moin.cgi"
<Directory /opt/wiki/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
Options +ExecCGI
</Directory>
</VirtualHost>

Once you have created the file, you need to install the site in Apache by running the following commands.

sudo a2ensite /etc/apache2/sites-available/wiki
sudo /etc/init.d/apache2 reload

Browse Your Wiki

Everything should be installed and ready to go. Just point your browser to http://wiki.codeghar.com/wiki/ (or whatever your website is) and enjoy.

Hat tips: MoinMoin; Help on Installing.

Install FreeSWITCH on Debian

Installing FreeSWITCH is fairly easy if you follow the FreeSWITCH Download & Installation Guide. But the instructions are not step-by-step. Following is an attempt to rectify this.

Install Essential and Required Packages

You need to first install all packages required by using aptitude. The following command installs packages without using specific version numbers. Following is a single command but may be displayed on multiple lines due to page formatting.

sudo aptitude install build-essential debhelper automake autoconf libtool unixodbc-dev libssl-dev libogg-dev libvorbis-dev libperl-dev libgdbm-dev libdb-dev libgnutls-dev subversion subversion-tools wget

For the following packages I could not find packages which did not have specific version numbers in the name. In other words, I couldn’t find virtual packages. Please make sure that when you follow this guide then you do a search for package versions required by FreeSWITCH before you blindly follow me and install the versions I did. Following is a single command but may be displayed on multiple lines due to page formatting.

sudo aptitude install libncurses5-dev libcurl4-openssl-dev libasound2-dev libtiff4-dev

Download Source Code

It is recommended that you always download the latest source from trunk before installing for the first time.

cd /usr/src/

sudo svn checkout http://svn.freeswitch.org/svn/freeswitch/trunk freeswitch

You now have the latest source code in the freeswitch directory. In case you want to update from trunk again, just run the following command in the /usr/src/freeswitch/ directory

sudo svn update

Compile and Install

You are now able to compile and install directly. If you would like to build deb packages and install from there, skip this section and read “Build Debian Packages” section. If you want to install directly from source, start by running the following commands.

cd /usr/src/freeswitch/

sudo ./bootstrap.sh

sudo make

sudo make install

sudo make cd-sounds-install

sudo make cd-moh-install

This installs FreeSWITCH in /opt/freeswitch/.

Build Debian Packages

I love how FreeSWITCH has made it so easy to create deb packages from the source you just downloaded. It makes it easier to compile once and then install on multiple machines. Just follow the steps below

cd /usr/src/freeswitch/

sudo dpkg-buildpackage

dpkg-buildpackage gave an error that uuid-dev was not installed. So I had to install it by running the following command.

sudo aptitude install uuid-dev

I ran dpkg-buildpackage again and did not find any other errors. If you do encounter any errors, please install the required packages and run dpkg-buildpackage again. Continue doing this until there are no more errors.

It will take some time for the compiling and packaging to be done. Once finished, you will see a bunch of .deb, .dsc, .changes, and .tar.gz files. You may install all of them using dpkg -i.

Start and Stop FreeSWITCH

Be aware that this will install FreeSWITCH in the /opt/freeswitch/ directory instead of the /usr/local/freeswitch/ directory which FreeSWTICH considers its default installation directory. No worries there; you just have to modify the instructions in documentation, etc., to use /opt/ instead of /usr/local/.
To start FreeSWITCH in the background, run the following command:

/opt/freeswitch/bin/freeswitch -nc

To stop, run the following command

/opt/freeswitch/bin/freeswitch -stop

To control FreeSWITCH via a Telnet interface, run the following command

/opt/freeswitch/bin/fs_cli

Cannot Set to Default Locale

On my Debian machine I kept getting the following error messages when using sudo aptitude safe-upgrade

perl: warning: Falling back to the standard locale (“C”).
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory

There are many solutions but the one that worked for me came from a Debian bug report: apt-get update fails to get index package list and therefore does nothing. If you have the locales package installed, you should run the following:

sudo dpkg-reconfigure locales

I generated all locales, even if I did not need them right then. I also chose en_US.UTF-8 as my default locale. If running dpkg-reconfigure gives you errors, it may mean that you do not have the locales package installed. To install it, run the following

sudo aptitude install locales

It will also ask you which locales you want to generate and which one you want to use as default.

I want to thank all the pages which helped me understand the problem before I could fix it: locale: Cannot Set LC_ALL to default locale: No such file or directory; I keep getting this weird error; locale: Cannot set LC_ALL to default locale: No such file or directory; Ubuntu perl locale errors.