Changing the default displaymanager in Fedora 18

With the release of Fedora 18, there have been some changes to the /etc/sysconfig directory. For example, switching the default display manager is no longer done by altering parameters in /etc/sysconfig/desktop but via

# systemctl enable --force displaymanager.service 

Therefore, to switch from the default gdm to kdm you’d run:

# systemctl enable --force kdm.service 

How to send a client’s hostname to the DHCP server

In contrast to Ubuntu (or even Microsoft Windows) default installations of Fedora do not send the client’s hostname to the DHCP server.

To change this behaviour, add a DHCP_HOSTNAME variable to your /etc/sysconfig/network-scripts/ifcfg-eth0 file (eth0 being your NIC’s interface name):

UUID="616426f3-ac0b-4a4a-9221-62a0055bfb07"
NM_CONTROLLED="yes"
NETBOOT="yes"
BOOTPROTO="dhcp"
DHCP_HOSTNAME="MyFedoraBox"
DEVICE="eth0"
TYPE="Ethernet"
ONBOOT=yes
NAME="DHCP"
HWADDR=00:25:22:4A:3F:F2
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
USERS=user

Of course, this only works if you actually get your IP address via DHCP (since the DHCP server hands off the hostname to the DNS server). If you use a static IP configuration, nsupdate can be used to dynamically update the DNS server records. Examples and instructions on how to use nsupdate can be found at http://linux.yyz.us/nsupdate/ or http://dijks.wordpress.com/2012/07/17/register-a-hostnames-static-ip-with-your-corporate-dns-server/.

Run JUnit test from the command line

      No Comments on Run JUnit test from the command line

JUnit tests can be run easily from within your IDE. Every remotely up to date IDE has some built-in view that gives nice visual feedback, usually red or green indicators.

But of course it is also possible to invoke your tests from the command line. A simple example:

import org.junit.runner.JUnitCore;

public class MyClass {
    public static void main(String[] args) {
        JUnitCore.main(MyJUnitTest.class.getName());
    }
}

A very nice article on JUnit testing by Lars Vogel can be found at http://www.vogella.com/articles/JUnit/article.html. He suggests iterating through the failures of a Result class to run the tests via code, which works fine, too:

import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;

public class MyClass {
    public static void main(String[] args) {
        Result result = JUnitCore.runClasses(MyJUnitTest.class);
        for (Failure failure : result.getFailures()) {
            System.out.println(failure.toString());
        }
    }
}

Set file’s time stamp to exif header date

      No Comments on Set file’s time stamp to exif header date

Jhead is a great tool for manipulating jpeg exif headers. To change a file’s time stamp to what’s stored in the header, invoke:

$ jhead -ft filename.jpg

To change the time stamp of all files that were changed within the last day:

find . -mtime -1 -exec -type f jhead -ft {} \;

See also http://www.sentex.net/~mwandel/jhead/usage.html

KDE multi-monitor display settings are lost on logout

There are quite a few bug reports on the kde bug tracking system about kde losing display settings on logout (e.g. Bug 183143). But since this problem has been present for a couple of years and is still existing in the latest version of KDE (i.e. 4.8.5 at this writing), here’s a workaround:

Add a parameter called StartupCommands to the krandr configuration file (usually located at ~/.kde/share/config/krandrrc that adjusts your display layout using xrandr on login:

[Display]
ApplyOnStartup=true
StartupCommands=xrandr --output "HDMI-0" --primary --output "VGA-0" --right-of "HDMI-0"

You also need to make sure that the command is invoked on login by setting the ApplyOnStartup parameter to true.

The actual xrandr command may of course look different, depending on the actual number and layout of screens. So YMMV!

Expendable Fedora 17 default services

      No Comments on Expendable Fedora 17 default services

Based on Harald Hoyer’s great tutorial on boot time optimization for Fedora 17, here’s a list of services I usually disable on my Fedora 17 boxes:

cd /lib/systemd/system
for i in abrt* auditd* sendmail* sm-client* firstboot* ip6tables* fedora*storage* plymouth-*.* lvm2-monitor.* mdmonitor*.*;
do
  systemctl mask $i
done
for i in livesys livesys-late spice-vdagentd ; do sudo chkconfig $i off;done

This is just a memory hook for myself. YMMV and of course what’s expendable depends on the configuration you use on your box.

For an explanation of the systemctl mask command have a look at Lennart Poettering’s systemd tutorial or the systemctl manpage.

rsync over ssh on non-default port

      1 Comment on rsync over ssh on non-default port

There are basically two ways of archiving this

Changing rsync’s rsh parameter

You can simply feed ssh with a different port parameter as remote shell to ssh:

$ rsync -a --inplace --rsh='ssh -p12345' file user@remotehost:dir/

Create a per host config for ssh

Add a Host entry to ~/.ssh/config

[...]
Host foobar
    Port 12345
    User user
    Hostname host.example

and invoke rsync with that alias

$ rsync -a --inplace file foobar:dir/

Bootstrapping a Fedora 17 rootserver

      No Comments on Bootstrapping a Fedora 17 rootserver

Quite a few things have changed since I made the Bootstrapping a Fedora 15 rootserver post, e.g. download urls, anaconda options and the way you add boot targets to grub2 (in contrast to legacy grub). So here’s an updated version…

Get initial ramdisk and kernel

This is basically still the same as with Fedora 15. The download links have changed a bit since download.fedora.redhat.com doesn’t exist any longer (but I’ve updated the old post anyway)

cd /boot/
wget http://dl.fedoraproject.org/pub/fedora/linux/releases/17/Fedora/x86_64/os/isolinux/initrd.img
wget http://dl.fedoraproject.org/pub/fedora/linux/releases/17/Fedora/x86_64/os/isolinux/vmlinuz

Add a boot target to grub

Edit /etc/grub.d/40_custom and add the following menu entry

[...]
menuentry 'Fedora 17 Install' {
  set root='hd0,2'
  echo    'Loading Linux'
  linux   /vmlinuz vnc vncpassword=SECRET ksdevice=link ks=http://server/ks.cfg
  echo    'Loading initial ramdisk ...'
  initrd  /initrd.img
}

Adjust the root parameter depending on the partition that contains the vmlinuz and initrd.img files (/dev/sda2 in this example, see also Adding custom boot target to GRUB2).

Also note, that I changed the ksdevice parameter from eth0 (which sets a specific interface) to link (which uses the first interface with link up) since NIC interface names are no longer predictable in recent kernel versions (p10p1, em1, eth0, etc.). For a list of all possible value of ksdevice hava a look at the corresponding Fedora wiki page.

After editing /etc/grub.d/40_custom, don’t forget to recreate grub.cfg by invoking

grub2-mkconfig -o /boot/grub2/grub.cfg

After rebooting, connect to the vnc server using the password you specified as usual.

F17vncInstall

click for full size image

Adding custom boot target to GRUB2

      No Comments on Adding custom boot target to GRUB2

In GRUB2 one doesn’t alter the main configuration file /boot/grub2/grub.cfg manually any more. Boot menu entries are automatically determined by the grub2-mkconfig script.

To add a custom menu entry, edit /etc/grub.d/40_custom

[...]
menuentry 'Custom Entry' {
  set root='hd0,msdos2'
  echo    'Loading Linux'  
  linux   /vmlinuz
  echo    'Loading initial ramdisk ...'
  initrd  /initramfs.img
}

Note that GRUB2 partition numbering starts with 1 (not 0 like GRUB) but disk numbering starts with 0, e.g. if your kernel and inital ramdisk are located on /dev/sda2, this translates to hd0,2.

On MS-DOS type partitions (which currently is the majority of partitions out there) hd0,2 and hd0,msdos2 are interchangeable.

To recreated grub.cfg with the added boot menu entry, invoke

grub2-mkconfig -o /boot/grub2/grub.cfg

Resources:
http://home.roadrunner.com/~computertaijutsu/grub2.html

Change GRUB2 default boot target

      2 Comments on Change GRUB2 default boot target

In GRUB, the default boot menu entry was determined by the order of entries in /boot/grub/menu.lst, the default one being the n-th specified by the default=n parameter.

In GRUB2 the main configuration file /boot/grub2/grub.cfg isn’t usually altered manually any more but automatically generated by invoking grub2-mkconfig. You can change the default boot target by changing the GRUB_DEFAULT paramater in /etc/default/grub. It takes three different values:

GRUB_DEFAULT=n specifies the n-th entry in /boot/grub2/grub.cfg. The first entry is selected with GRUB_DEFAULT=0, just like in GRUB.

GRUB_DEFAULT="String" chooses an entry by name (e.g. “Fedora (3.5.3-1.fc17.x86_64)”)

GRUB_DEFAULT=saved chooses the boot target specified in /boot/grub/grubenv regardless whether the order of entries has changed (e.g. due to a kernel update).

To manipulate /boot/grub/grubenv, you can list all possible entries

grep ^menuentry /boot/grub2/grub.cfg | cut -d "'" -f2

and specify the desired one with

grub2-set-default <menu entry title>

To verify the default menu entry, use

grub2-editenv list

Note that you have to run

grub2-mkconfig -o /boot/grub2/grub.cfg

if you make any changes to /etc/default/grub (e.g. change the GRUB_DEFAULT parameter). You don’t have to invoke it, if you just change the default target with grub2-set-default since this just alters grubenv but doesn’t make any changes to grub.cfg.

Resources:
http://fedoraproject.org/wiki/GRUB_2
http://www.linuxreaders.com/2011/11/fedora-16-how-to-change-boot-sequence-grub2.html