Showing posts with label karmic. Show all posts
Showing posts with label karmic. Show all posts

Thursday, 14 October 2010

HOWTO: Syncing your /home with a server

Do you have a storage server where you keep your files? Do you think it would be a neat idea to keep a copy of your user files (home directory) on that storage in case your laptop or desktop suffers some sort of a catastrophe? Would you like an approximation of Windows roaming profiles?

If you answered yes to any of the above then read on! (However you should read the disclaimer at the end of this post.)

PLATFORM :
* Ubuntu (Tested with 10.04.1 Lucid but should work with any version)

PREREQUISITES :
* You must have passwordless SSH configured between the client and server users on the two hosts.
* rsync and openssh-server are installed on both hosts.

b) On the server;

The server part is pretty simple. First we will login as the root user;

sudo -i

We need a place to store the copies of the home folders. Create a folder;

mkdir -p /store/homes

Go back to the client;

Now assuming that we have keyless access to our server from the client we just need a script to do the syncing.

Create a script in /etc/init.d

root@hack:~# vi /etc/init.d/homesync
#!/bin/sh
### BEGIN INIT INFO
# Provides: homesync
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: sync homes at startup and shutdown
# Description:
### END INIT INFO

MODE=$1
TARGET="root@zen:/store/homes/"
EXCLUDE="/root/excludes.rsync"

case $MODE in

start)
rsync -parv --inplace $TARGET /home/
;;

stop)
rsync -parv --inplace --exclude-from=$EXCLUDE --delete /home/ $TARGET
;;

esac

Note: Of course you need to change TARGET= to suit your own environment. Also, if your SSH server is listening on a non standard port you will need to modify the rsync command as per this post

Make the script executable;

chmod +x /etc/init.d/homesync

If you look carefully, you will notice that the script will refer to /root/excludes.rsync for any files or folders that it should avoid syncing. We should create that file;

touch /root/excludes.rsync

Now, there are no files on the server yet so we should do an initial sync.
WARNING: If this is not the first (ie primary) client that you are setting this up on then don't run the following command as is or else it will wipe out the "backup" that is already on the server. In such a case you need to replace the "stop" in the command with "start" in order to retrieve the primary files from the server instead.

Perform an initial sync;

/etc/init.d/homesync stop
Note: Depending on how much stuff you have in your user homes this may take some time. You should also ensure that you have enough space to fit everything!


OK, assuming everything is working, the final step is to make sure the homesync script executes when the system stops and start. We do that with the update-rc.d command;

sudo update-rc.d -f homesync defaults

That's it. You can test your setup by adding or altering a file in your home folder and then shutting down your system. If you check the server you should see your changes appear there after it shuts down. If you delete or alter the file again on the server the change should appear on the client after reboot.

If you want to exclude particular files or directories then you may list them in the exludes.rsync file we created earlier.

Here is a sample list;

Junk*
oops*
.pulse*
.cache*
tmp*
temp*
gvfs*
.gvfs*
.Trash*
Trash*
*~
Thumbs.db*
desktop.ini*
lost+found*


DISCLAIMER: Be very careful using this setup in a multiuser environment where there is more than one PC (in use) at any one time. If a user is logged in on more than one PC then it is possible that they could lose data. Be sure you understand the limitations of this system before proceeding down such a path. Also note that the script only executes at startup and shutdown so if the PC is rarely restarted then this system will be of little value. I recommend using it for a simple home network only. It is not flexible or robust enough for use in a corporate network. And one final note, this does not work if you connect to the server using a wifi connection due to the way Ubuntu connects and disconnects after the user logs in. Any script such as this one that runs at boot time will not be able to connect to the network in order to do the sync. In such scenarios you could consider using a cron job or syncing manually.

Saturday, 24 April 2010

HOWTO: LDAP Client on 10.04 Lucid Lynx

This is essentially the same as my previous Hardy Heron LDAP howto but with some steps removed. Rather than edit the old article I thought I'd just reproduce it with the appropriate parts omitted. This howto is also relevant to Jaunty and Karmic. The LDAP Server howto can be found here.

PLATFORMS TESTED: Ubuntu 10.04 LTS (Lucid), Ubuntu 11.04 LTS (Natty)

PREREQUISITES:
* A vanilla Ubuntu 10.04 (or later) desktop or server install.
* You have shared your user home directories from an NFS server
* You have successfully installed a working LDAP server

Network overview;
* domain name: tuxnetworks.com
* Servername/IP: ldap.tuxnetworks.com 10.1.1.5
* The user "brettg" is a valid LDAP user on your server.

We are going to set up a Lucid client connected to an LDAP server. We should aready have our home directories mounted via NFS.

~$ sudo apt-get install libpam-ldap libnss-ldap nss-updatedb libnss-db nscd ldap-utils

You will again be asked a bunch of questions;

LDAP server Uniform Resource Identifier: ldap://ldap.tuxnetworks.com
Distinguished name of the search base: dc=tuxnetworks,dc=com
ldap://ldap.tuxnetworks.com 3
Make local root Database admin: Yes
Does the LDAP database require login? No
LDAP account for root: cn=admin,dc=tuxnetworks,dc=com
LDAP root password: (The server LDAP root password)


Now we need to edit the following files;

~$ sudo vi /etc/ldap.conf

and edit these lines to look like this;

bind_policy soft

pam_password crypt


Find the line that begins with uri ldapi:// . . .

Comment the line out and replace it with a line like so;

uri ldap://ldap.tuxnetworks.com/

Edit this file;

~$ sudo vi /etc/ldap/ldap.conf

Edit it to look like this;
BASE    dc=tuxnetworks,dc=com
URI ldap://ldap.tuxnetworks.com

SIZELIMIT 0
TIMELIMIT 0
DEREF never

Edit nsswitch.conf

~$ sudo vi /etc/nsswitch.conf

Enter the following lines;

passwd: files ldap
group: files ldap
shadow: files ldap

hosts: files dns
networks: files

protocols: db files
services: db files
ethers: db files
rpc: db files

Now update nss to use ldap.

~$ sudo nss_updatedb ldap
passwd... done.
group... done.


Note:
If you get an error . . .
Failed to enumerate nameservice: No such file or directory

. . . then check that your uri line in /etc/ldap.conf is correct and the address is pingable.


You should now be able to check the server with;

~$ ldapsearch -x

That command should output a tonne of stuff from the server LDAP directory.

getent passwd

You should now be able to login to the client via ssh using the user "brettg"s credentials
brettg@jupiter:~$ ssh brettg@galileo
Welcome to Ubuntu 11.04 (GNU/Linux 2.6.38-8-generic x86_64)

* Documentation: https://help.ubuntu.com/

Last login: Fri Jun 24 14:13:05 2011 from 10.1.1.80
brettg@galileo:~$


Take a look at your passwd file to make double sure you are not logging in using local auth;

grep brettg /etc/passwd

If that returns a line then you are probably logged in using a local user. Remove that line from /etc/passwd and try again.

For Gnome Desktop users.

Assigning users to the correct groups at login, create a new file called group.conf and place the following line in it;
vi /etc/security/group.conf

gdm;*;*;Al0000-9000;floppy,audio,cdrom,video,plugdev,scanner


We also need to tell pam to use the group.conf settings;
vi /etc/pam.d/gdm 

Add this line;

auth optional pam_group.so

Reboot your PC and you should be able to login to gnome using ldap!

Wednesday, 24 March 2010

Network lockup during heavy load

Since karmic, the Realtek drivers for the 8169 card have become borked. If you try and copy large amounts of data your machine will hang and require a hard reset.

I got this solution from here;

1) Check to see if the r8169 module is loaded
lsmod | grep r816
r8168 41104 0
-> lspci -v
01:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168B PCI Express Gigabit Ethernet controller (rev 03)
Subsystem: ASRock Incorporation Device 8168
Kernel driver in use: r8169
Kernel modules: r8169


2) Download the official Realtek driver
Realtek RTL8111/RTL8168

Update: I'm using the 8.017 driver but the current driver on that website is 8.018. It is possible that this version contains the same regression fault that causes this lock up behaviour as I experienced trouble after installing it. If you have trouble, download the older driver from here and add a comment to this post.

3) Remove the r8169 module
rmmod r8169
mv /lib/modules/`uname -r`/kernel/drivers/net/r8169.ko ~/r8169.ko.backup
(Note: the ` is a backtick, it is not an apostrophe or single quote )

4) Build the new r8168 module for the kernel
bzip2 -d r8168-8.009.00.tar.bz2
tar -xf r8168-8.009.00.tar
cd r8168-8.009.00
make clean modules
make install


5) Rebuild the kernel module dependencies
depmod -a
insmod ./src/r8168.ko


6) Remove the r8169 module from initrd
mv /initrd.img ~/initrd.img.backup
mkinitramfs -o /boot/initrd.img-`uname -r` `uname -r`


7) Add r8168 module to /etc/modules
echo "r8168" >> /etc/modules


Reboot, You are done!

Thursday, 7 January 2010

grub-probe: error: Cannot find a GRUB drive for /dev/sdb1

I got this error;
grub-probe: error: Cannot find a GRUB drive for /dev/sdb1

after adding a drive to my laptop and running
sudo /usr/sbin/grub-mkconfig

I had to add an entry for the new drive in /boot/grub/device.map
sudo vi /boot/grub/device.map

I added the second line;
(hd0) /dev/sda
(hd1) /dev/sdb

I then regenerated the grub config
sudo /usr/sbin/grub-mkconfig

Finally, I updated grub with the new config
sudo update-grub2

Note: Initially, I failed to update grub with the new config and received another error "Invalid signature" when trying to boot Windows off the second drive.

Friday, 25 September 2009

Mixed Systems

I have a system that requires the 2.6.3x kernel because it is the only one that supports the motherboards onboard NIC.

I tried it with karmic alpha but unsurprisingly I ran into stability problems so I am going back to Jaunty.

However, I still need to run the newer kernel. I could of course compile it myself but I really prefer not to. I could manually download the deb and then install it and all it's dependencies myself but that would probably cause as many instability problems as just nursing Karmic along.

So, a mixed system it is.

On Debian systems, this is simply done by adding "APT::Default-Release "version";" to your apt.conf file and sticking "stable". "testing" or whatever in as the "version".

We can't do this on Ubuntu because they use a different naming system to Debian. If we were to set "version" to "jaunty" then we would no longer receive security updates because in Ubuntu Land these come from ubuntu-security instead.

Fortunately, there is a way around this and here it is.

Firstly, we copy our existing "jaunty" sources.list to /etc/apt/sources.list.d
sudo cp /etc/apt/sources.list /etc/apt/sources.list.d

Next, we change it to point to the "karmic" repositories.
sudo sed -i 's/jaunty/karmic/g' /etc/apt/sources.list.d/sources.list

Create a Ubuntu style preferences file
sudo vi /etc/apt/preferences

Here is the contents of my preferences file, it should be fairly self explanatory;
Package: *
Pin: release a=jaunty
Pin-Priority: 900

Package: *
Pin: release a=karmic
Pin-Priority: 500

Package: *
Pin: release a=jaunty-updates
Pin-Priority: 900

Package: *
Pin: release a=karmic-updates
Pin-Priority: 500

Package: *
Pin: release a=jaunty-backports
Pin-Priority: 900

Package: *
Pin: release a=karmic-backports
Pin-Priority: 500

Package: *
Pin: release a=jaunty-security
Pin-Priority: 900

Package: *
Pin: release a=karmic-security
Pin-Priority: 500

Package: *
Pin: release a=jaunty-proposed
Pin-Priority: 900

Package: *
Pin: release a=karmic-proposed
Pin-Priority: 500

Finally, we update aptitude
sudo apt-get update

To install the kernel package from the karmic repository we first need to know what version we want
apt-cache search linux-image

The one I'm interested in is "linux-image-2.6.31-10-386"
I can just install this kernel using its full name
sudo apt-get install linux-image-2.6.31-10-386

To install packages from the Karmic repository I can use the -t distribution parameter
sudo apt-get -t karmic install packagename

Or I can specify a package version
apt-get install nautilus=2.2.4-1

Tuesday, 4 August 2009

Virtualbox3 Headless with Bridged Networking

Note: This howto is now outdated due to changes introduced in Virtualbox 3.1x

See this post for an updated version.

As of karmic koala, Vbox 3 is provided via the standard Ubuntu repos. Unfortunately, this is the OSE version and it does not appear to work headless.

So, we have to download the "free" version from the Sun (soon to be Oracle?) website, which is currently here

At the time of writing there was no Karmic build, so I used the Jaunty package (virtualbox-3.0_3.0.4-50677_Ubuntu_jaunty_i386.deb)

Before we can install the deb, we will also need to install some dependencies.
sudo apt-get install python2.5 libcurl3 dkms libqt4-network libqtgui4 libxslt1.1

Now we can install the virtualbox deb that we downloaded earlier.
sudo dpkg -i virtualbox-3.0_3.0.4-50677_Ubuntu_jaunty_i386.deb

NOTE: When I installed this for the nth time I received the following error:
virtualbox-3.0.postinst: 118: /etc/init.d/vboxdrv: not found
I'm not sure if this was due to my previous installations of different versions or not. I figured it was so ignored it and things seemed to be OK. Of course YMMV.

Next, add your user account to the vboxusers group
sudo adduser brettg vboxusers

Virtualbox machines that you create will by default go in your home directory
/home/brettg/.VirtualBox/

Ensure vboxusers have appropriate permissions to the kernel
sudo vi /etc/udev/rules.d/40-permissions.rules

/etc/udev/rules.d/40-permissions.rules
KERNEL=="vboxdrv", GROUP="vboxusers", MODE="0660"

Creating a virtual machine
Create a machine named "io"
VBoxManage createvm -name io -register

Configure it with a nic bridged to eth0
VBoxManage modifyvm io --nic1 bridged --bridgeadapter1 eth0

Create a virtual DVD link called "dvd" to an ISO image on the server
VBoxManage registerimage dvd /store/archive/ISO/ubuntu-8.04-server-i386.iso

Connect the DVD to the virtual machine
VBoxManage modifyvm io -dvd /store/archive/ISO/ubuntu-8.04-server-i386.iso

Assign "io" 128Mb RAM, enable acpi and set to boot from DVD
VBoxManage modifyvm io -memory 128MB -acpi on -boot1 dvd 

Create an 8Gb virtual HDD named "io-sda.vdi"
VBoxManage createvdi -filename io-sda.vdi -size 8000 -register

Assign that Virtual Drive Image to "io"
VBoxManage modifyvm io -hda io-sda.vdi

Because we are installing Ubuntu Server as a guest we need to enable PAE
VBoxManage modifyvm io -pae on


Using the virtual machine
Start the machine
VBoxHeadless -startvm "io" &

On a GUI workstation, establish a remote desktop connection to the machine
rdesktop -a 16 io:3389


Congratulations, you are now up and running!

After you have installed the OS, you need to remove the DVD and instruct the machine to boot from the hdd.
VBoxManage modifyvm "io" -dvd none

You can also deregister the dvd image if you don't intend to use it again.
VBoxManage unregisterimage dvd /store/archive/ISO/ubuntu-8.04-server-i386.iso

Note: When I installed Ubuntu Server the network autodetection didn't work. After installation was completed there was no eth0 present. I simply added the following to /etc/network/interfaces
auto eth0
iface eth0 inet dhcp

and was then up and running

Other useful commands;
VBoxManage showvminfo io
VBoxManage list hdds
VBoxManage list runningvms
VBoxManage controlvm io poweroff
VBoxManage controlvm "io" savestate