maxieduncan
Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Wednesday, 2 March 2011

Automatically start vncserver

Assuming you have already set a VNC password for your users you can automatically start vncserver on linux by editing /etc/sysconfig/vncservers.

Uncomment the VNCSERVERS line and configure a list of display to user mappings:

VNCSERVERS="1:userA 2:userB"



You also need to make sure that vnc is starting automatically:

/sbin/chkconfig --list vncserver
vncserver 0:off 1:off 2:off 3:off 4:off 5:off 6:off
/sbin/chkconfig --level 5 vncserver on
/sbin/chkconfig --list vncserver
vncserver 0:off 1:off 2:off 3:off 4:off 5:on 6:off


A really good resource for configuring vnc on linux is http://www.walkernews.net/2008/06/20/configure-vnc-server-to-auto-start-up-in-red-hat-linux/.

"Device eth0 has different MAC address than expected, ignoring."

I recently copied a VM from my mac to a linux server. The VM didn't work so I created a new one using the vmdk from the original VM. When started there was no network configuration and trying to start one using "/sbin/ifup eth0" resulted in the message "Device eth0 has different MAC address than expected, ignoring.".

To fix this I had to update the mac address for the eth0 device which was found here:
/etc/sysconfig/network-scripts/ifcfg-eth0

For reference view this thread

Friday, 21 May 2010

Using Gnome with vncserver

Setting up vncserver on linux to use a different window manager than twm (the minimalistic default) is actually pretty straightforward if you know where to look and what to change.


If you just want to use your default desktop you can uncomment the lines at the start of ~/.vnc/xstartup

If you want to use a specific window manager the following steps should work:
  1. Open ~/.vnc/xstartup
  2. For KDE, replace "twm &" with "startkde &"
  3. For Gnome, replace "twm &" with "gnome-session &"
  4. restart vncserver if it's already running

Saturday, 10 April 2010

Creating bootable Linux USB sticks on the mac

This post is primarily aimed at creating Ubuntu as that's what I've used lately.

From a disk image (.img)

Ubuntu originally provided the Ubuntu Netbook Remix as a .img that made creating a bootable USB as simple as the steps below.

  1. Download the desired .img file
  2. Open a Terminal (under Utilities)
  3. Run diskutil list to get the current list of devices
  4. Insert your flash media
  5. Run diskutil list again and determine the device node assigned to your flash media (e.g. /dev/disk2)
  6. Run diskutil unmountDisk /dev/diskX where X is the number of disk determined above
  7. Execute sudo dd if=/path/to/downloaded.img of=/dev/diskX bs=1m again using the disk number from the last step and the actual path to your img.
  8. Run diskutil eject /dev/diskX and remove your flash media when the command completes

From a iso image (.iso)

Since Ubuntu 9.10, Canonical has only supplied iso image files and it's not possible to create a bootable USB drive from the Ubunto iso on a mac. If you follow the steps below you'll see the error Could not validate source - error 254. Mac OSX only supports restoring images in particular formats and the one that Ubuntu use (ISO 9660) isn't supported by Apple.

On the mac the default application supplied for changing this is Disk Utility. You can find this in the Utilities directory in the Applications directory.

To create the USB disk do the following:
  1. First make sure that the disk is bootable and that the Partition Map Scheme used is Master Boot Record
  2. After that it's simply a matter of using the Disk Utility Restore functionality to write the iso image to the USB disk
    • Drag the iso image into Source from the Finder
    • Drag the USB disk into Destination from the list in Disk Utility

Sunday, 25 October 2009

Backup script using rsync and crontab

Below is a very simple script that I've used to back up data from a remote machine with rsync. I've also scheduled it to be run daily using crontab.

#!/bin/bash
# Simple script to back up the contents of my website
#

host=HOSTNAME
user=USERNAME
dest=BACKUP_DESTINATION

#SSH_AUTH_SOCK need to declare for rsync to work via a cronjob, you may need to use a different value
export SSH_AUTH_SOCK=/tmp/launch-LaeM5h/Listeners

echo "Starting Website Backup" `date`;

function sync() {
 if [ ! -e $2 ]
 then
  mkdir $2;
 fi
 echo "Backing up $host:$1 to $2";
 rsync -raz -e "ssh -i $HOME/.ssh/id_dsa" $user@$host:$1 $2;
}

sync "/home/$user" "$dest";

dir=ZIP_DESTINATION/`date "+Backup_%d_%m_%y"`;
echo "Copying files to " $dir;

tar -czf $dir.tar.gz $dest

echo "Finished Website Backup" `date`;

Crontab setup

The first thing you need to do is setup up Passwordless ssh with NO passphrase.

You then need to set up a cronjob to run the script daily.

For example create a file crontab.txt with the following content:

0 12 * * * /PATH_TO_SCRIPT/backup.sh > /PATH_TO_LOG/backup.log 2>&1

Next load this file into crontab (this will delete other cronjobs if they exist but aren't included).

crontab crontab.txt

To check that your cronjob has been loaded run:

crontab -l

Passwordless ssh

Setting up passwordless ssh is fairly straight forward and plenty of documentation on it can be found.

Firstly you need to need to generate a key on your local machine:

ssh-keygen -t dsa

You most likely want to accept the default location when asked, i.e. $HOME/.ssh/id_dsa

For a passphrase it is recommended to choose something other than the ssh login password.

Two files will have been generated, id_dsa and id_dsa.pub.  You want to copy the second of these, or at least it contents to the remote machine.

e.g. scp $HOME/.ssh/id_dsa.pub <login>@<remote>:.

On the remote machine open $HOME/.ssh/authorised_keys (create it if it doesn't exist) and add the contents of the id_dsa.pub from your local machine.

e.g. cat id_dsa.pub >> $HOME/.ssh/authorized_keys

Now you should be able to ssh and scp to the remote machine without supplying the login password. You will instead be asked for your passphrase but once you enter it your OS should provide you with the option of remembering it and you shouldn't have to enter it again.

Creating swap files

In addition to a swap partition you can add a swap file

dd if=/dev/zero of=/swap_file bs=1M count=FILE_SIZE_IN_MB
chown root:root /swap_file
chmod 600 /swap_file
mkswap /swap_file
swapon /swap_file

To enable at start up open /etc/fstab and add:

/swap_file       none            swap    sw              0       0
Unfortunately this doesn't seem to be supported on all virtualised servers