boltblog

Save and restore partition tables with sfdisk

Posted on January 10, 2011

In my raid setup, I set up the partitions a certain way for running several mdadm raids on the same drive.

My server currently boots off of two drives, sda and sdb, where sda1 and sdb1 are the root file system in raid 1 (mirror) and sda2 and sdb2 are (encrypted) swap in raid 0 (striped). This is useful to have the redundancy of raid for booting, but none of that redundancy for the volatile swap partition. Instead I get higher write speed, which is always a bonus.

Note: Most Linux distros would actually stripe the swap anyway, given two swap partitions with equal priority, but I chose to do it this way.

Anyway, when one of the drives went for a one-way trip to electronic oblivion, the need arose to configure my new drive exactly as the old ones. Mind you, mdadm can actually handle non-equal partition sizes in a raid, but I'm kind of anal about this.

sfdisk to the rescue!

First, of course, I replaced the faulty drive (sdb) with one of the same brand and equal size. You don't necessarily need the same brand, but that's what I had.

Then, to export and save the partition table from sda (which was still working)
sfdisk -d /dev/sda > sda_partitions
..and save it to the replaced sdb
sfdisk /dev/sdb < sda_partitions
You can also do it all in one go
sfdisk -d /dev/sda | sfdisk /dev/sdb
As usual, RTM for more options :)

Filed under: Linux, Reference No Comments

sudo without a password

Posted on November 14, 2010

Note, this is not something I recommend doing. In fact, the only reason why I'm documenting it is that I am removing this solution from the last box I used to have it on.

Anyway, edit the /etc/sudoers file (with visudo, as root), then add lines under the default one for root, like this:

# User privilege specification
root	ALL=(ALL) ALL
bolt    ALL=(ALL) ALL
bolt    ALL=NOPASSWD: ALL

(replace "bolt" with your own username)

If you would rather want to not type a password only for specific commands, specify them like this:

bolt	ALL=NOPASSWD: /sbin/shutdown, /bin/mount, /bin/umount

(replacing the username and commands with the ones you want)

Filed under: Linux, Reference No Comments

Using Flags and Arguments in Bash

Posted on November 8, 2010

Here's a simple example script, showing how to deal with different inputs depending on the flag preceding them:

#!/bin/bash
USAGE="Usage: Enter a noun after either -p (polite) or -i (insulting)."

while getopts ":p:i:" OPTIONS; do
  case $OPTIONS in
    p ) polite=$OPTARG;;
    i ) insulting=$OPTARG;;
    h ) echo $USAGE;;
    \? ) echo $USAGE
         exit 1;;
    * ) echo $usage
        exit 1;;
  esac

if [ $polite ];then echo "Your $polite smells good."; fi
if [ $insulting ];then echo "Your $insulting smells bad."; fi
done

Stolen from http://www.okboot.org/2010/04/using-flags-and-arguments-in-bash.html

Filed under: Linux, Reference No Comments

exim4 smarthost smtp password

Posted on October 25, 2010

Note to self:

To use a smarthost you have to authenticate to with exim4, edit /etc/exim4/passwd.client

# password file used when the local exim is authenticating to a remote
# host as a client.
#
# see exim4_passwd_client(5) for more documentation
#
# Example:
### target.mail.server.example:login:password
*:myusername:myawfullylongpassword

Here I added a username and password for all target mail servers (*) because this host sends everything through the smarthost.

If yours does not, you have to be more specific (like the example).

Surprisingly, there is no need to reload or restart exim4 after modifying the passwd.client file.

Filed under: Linux, Reference No Comments

Use OpenDNS with Smoothwall Express 3.x

Posted on October 23, 2010

If you're using DHCP to get your public IP, Smoothwall doesn't allow you to override the DNS addresses given by your ISP through the DHCP protocol. Time to override Smoothwall :)

Edit /etc/rc.d/rc.updatered, and add "DNSMASQ_DNS1=208.67.222.222" and "DNSMASQ_DNS2=208.67.220.220" at the bottom of the DHCP section, making the file look like this:

#!/bin/sh

. /var/smoothwall/ethernet/settings

if [ "$RED_TYPE" = "DHCP" ]; then
 DNSMASQ_DNS1=`/usr/bin/smoothwall/getdnsfromdhcpc.pl 1`
 DNSMASQ_DNS2=`/usr/bin/smoothwall/getdnsfromdhcpc.pl 2`
 . /var/lib/dhcpc/dhcpcd-${RED_DEV}.info
 echo "$IPADDR" >/var/smoothwall/red/local-ipaddress
 echo "$GATEWAY" >/var/smoothwall/red/remote-ipaddress
 DNSMASQ_DNS1=208.67.222.222
 DNSMASQ_DNS2=208.67.220.220
elif [ "$RED_TYPE" = "STATIC" ]; then
 DNSMASQ_DNS1=$DNS1
 DNSMASQ_DNS2=$DNS2
 echo "$RED_ADDRESS" >/var/smoothwall/red/local-ipaddress
 echo "$DEFAULT_GATEWAY" >/var/smoothwall/red/remote-ipaddress
fi

echo -n "$RED_DEV" >/var/smoothwall/red/iface
touch /var/smoothwall/red/active
echo "$DNSMASQ_DNS1" >/var/smoothwall/red/dns1
echo "$DNSMASQ_DNS2" >/var/smoothwall/red/dns2

/usr/bin/smoothcom dnsproxyrestart $DNSMASQ_DNS1 $DNSMASQ_DNS2

/usr/bin/smoothcom setxtaccess
/usr/bin/smoothcom setincoming
/usr/bin/smoothcom snortrestart
/usr/bin/smoothcom upnpdrestart
/usr/bin/smoothcom trafficrestart

/usr/bin/smoothwall/setddns.pl
/usr/bin/smoothwall/updatelists.pl

/etc/rc.d/rc.vpn.up
/etc/rc.d/rc.machineregister

The next time you Smoothwall connects, the setting you just put will override the ones from your ISP. Reboot or reconnect to apply.

Filed under: Linux, Reference No Comments

What’s touching that config file?!

Posted on October 21, 2010

Recently I started wondering what the heck was putting "root: bolt" at the end of /etc/aliases "every time" I did an upgrade of something.

I asked #debian on irc.freenode.net, who told me to run this:

grep /etc/aliases /var/lib/dpkg/info/*postinst

What it does is basically to look though all files which names end in "postinst" in the /var/lib/dpkg/info/ directory, showing all lines which contain "/etc/aliases", and where they're at.

The result was this:

$ grep /etc/aliases /var/lib/dpkg/info/*postinst
/var/lib/dpkg/info/exim4-config.postinst:    echo "root: ${poma}" >> /etc/aliases
/var/lib/dpkg/info/exim4-config.postinst:#initialize /etc/aliases
/var/lib/dpkg/info/exim4-config.postinst:echo '# /etc/aliases' > /etc/aliases.tmp
/var/lib/dpkg/info/exim4-config.postinst:echo 'mailer-daemon: postmaster' >> /etc/aliases.tmp
/var/lib/dpkg/info/exim4-config.postinst:done >> /etc/aliases.tmp
/var/lib/dpkg/info/exim4-config.postinst:mv /etc/aliases.tmp /etc/aliases
/var/lib/dpkg/info/exim4-config.postinst:    if [ ! -e /etc/aliases ] ; then
/var/lib/dpkg/info/exim4-config.postinst:    if ! grep -q '^root:[[:space:]]*[[:alnum:]]' /etc/aliases && \

This tells you a lot of things. Firstly, exim4 is likely the culprit here. Upgrading it will likely cause "root: bolt" (or whoever is set as your postmaster in exim4) to be added to the end of the file again. Also, if you notice the last line there, it's actually grepping for a line starting with "root:", followed by a space and something alpha-numeric.

This means that if I, instead of removing or commenting the "root: bolt" line, replace it with "root: root", directing all of root's mail... to root, there will be a line matching the aforementioned description, and exim4's postinst script will leave /etc/aliases alone.

Hooray!

Switching alsa sound cards around

Posted on September 19, 2010

Short reference on switching around alsa sound cards, making another one the default.
Needed to do this since my computer has 3 sound cards (M-Audio, SoundBlaster and the G35 headset)

List alsa modules:

cat /proc/asound/modules
0 snd_ice1724
1 snd_ctxfi
2 snd_usb_audio

Edit /etc/modprobe.d/alsa-base.conf, adding the following lines (note the underscores from above are now dashes):

options snd-ctxfi index=-2
options snd-usb-audio index=-2
options snd-ice1724 index=-1

Done.
If you're reading this, and you're not me, customize the above to match your settings, and the priorities you want for your modules.

Filed under: Linux, Reference No Comments

Hide join/part messages in XChat

Posted on November 8, 2009

To do this, type /set irc_conf_mode 1

To re-enable join/part messages do /set irc_conf_mode 0

The setting is automagically remembered by XChat

Filed under: Linux, Reference No Comments

Windows 7 autologin

Posted on November 8, 2009

Short and simple: to allow automatically logging in on Windows 7, you need to press Win+R to open the run menu, then type "control userpasswords2" without the quotes and run it.

Filed under: Reference, Windows No Comments

XFCE: Unable to perform shutdown

Posted on May 31, 2009

To fix this issue, add the following lines between <config .....> and </config> in /etc/PolicyKit/PolicyKit.conf

<match action="org.freedesktop.hal.storage.mount-removable">
<return result="yes"/>
</match>
<match action="org.freedesktop.hal.power-management.shutdown">
<return result="yes"/>
</match>
<match action="org.freedesktop.hal.power-management.reboot">
<return result="yes"/>
</match>
Filed under: Linux, Reference No Comments