Saturday, 26 July 2008

HOWTO: Mounting SSH directories

If you want to mount a directory on a remote PC then here is what you do.

Of course, to mount a folder via ssh the server must be running as a ssh server.

sudo apt-get install openssh-server

It is not necessary, but I strongly recommend that you set up passwordless ssh logins between the server and the client. The linked guide describes setting up SSH keys between two root users, so you do need to ensure that you configure things correctly for whatever pair of users you intend to use here.

From here on, all of the configuration we need to do is on the client.

1. Install SSHFS;

sudo apt-get install sshfs

2. Use the modprobe command to load fuse into the kernel;

sudo modprobe fuse

3. Set up the appropriate users & permissions;

sudo adduser username fuse
sudo chown root:fuse /dev/fuse
sudo chmod +x /bin/fusermount


If you've added yourself to the fuse user group, you need to logout and back in at this point.

To mount the home directory of "user";

sshfs user@host: mountpoint

Eg.

sshfs brett@server: ~/server_home

You can add a path after the colon.

Eg. to mount the "share" directory on the server (ie. /home/brett/share)

sshfs brett@server:/share ~/share

UPDATED: By default, only the user who has mounted the share has access to it. To allow access to root add the following option;

-o allow_root

For all users;

-o allow_other

To mount the share as read only;

-o ro

Eg. to mount the "share" directory on the server as read only and available to all users;

sshfs -o allow_other -o ro brett@server:/share ~/share

And that is all you need to do! Easy Peasy!

Backing up a directory

This method backups only files that have changed since the last backup. If a file has been deleted it will delete the equivalent file in the backup folder.

rsync -a source_directoy --delete destination

Usually, the backup location will be another PC, which can be done like this;

rsync --rsh=/usr/bin/ssh source_dir destIP:/destination_dir

eg:
rsync --rsh=/usr/bin/ssh ~ 10.1.1.2:/usr/backups/brett
will back up your home directory

Notes:
You can use a name instead of an IP address
Exclude unwanted files with the --exclude="filename" argument;
The above example will require a user account using the same name on both PC's
The destination PC will require ssh server software

sudo-apt-get install openssh-server

Bit-Copy a Hard Disk Over A Network

This method creates a disk image file for the backup using dd and nc (netcat). See also rsync

On the server (destination of the image file)
nc -l 5000 | of=disk.dd.gz

On the PC (disk to be backed up)
dd if=/dev/sda | gzip -9 | nc -q 5 hostname 5000

5000 is the listen port, you can choose any unused port you like

To restore the disk;

On the receiver (where the physical disk is)
nc -l 5000 | gunzip | dd of=/dev/sda

On the server (where the disk image is)
dd if=disk.dd.gz | nc -q 5 hostname 5000

Thursday, 10 July 2008

Creating an ISO image from a directory

If you want to create an ISO image from the files contained inside a directory you can use mkisofs;

mkisofs -J -r -o filename.iso path/to/files

If you get an error that the file will be bigger than 4GiB-1 then use this command;

mkisofs -allow-limited-size -udf -J -r -o filename.iso path/to/files

Tuesday, 8 July 2008

Switching between versions of Java

If you install Sun Java you may end up with two versions of java on your system. To select which one is active use this command;

sudo update-alternatives --config java

Thursday, 3 July 2008

Converting an RPM to a DEB

Sometimes the software you want to install is not available in the Ubuntu repo's and when you find it on the web you discover that "oh noes, it's only available as a Red Hat "rpm"

Never fear, it is usually possible to convert the rpm to a deb using alien. This should be done as a last resort however, it's always better to use a native deb package wherever possible.

The alien package is available from the multiverse repository. If you need to enable this repo see this post here

Install alien;

sudo apt-get install alien

To convert an rpm;

alien --to-deb --scripts package-xyz.rpm

As always, you should change package-xyz to the name of your package,