Thursday, February 28, 2008

Extracting tar into chosen directory

Extracting tar is a common thing to do and everybody familiar with unix and linux knows how to do it. Usually the files will be extracted to the current directory. There is although one small trick to do to send the files to the desired location. Use the below command:

# tar -xvzf filename.tar.gz -C /desired/path

This command will extract(-x) verbosely(-v) tar gz(-z) file(-f) to the desired location. Hope this will help. Cheers

Resizing qemu image

Qemu uses its own type of file which is qcow that stands for Qemu Copy On Write. Sometimes after you have setup the image, you suddenly find that you need more space. Below are the proven steps on how you can add more space to your image.

  1. Convert qemu image to raw
    • # qemu-img convert -f qcow imagename -O raw imagename.raw
  2. Extend the image size using dd (In this example, to the size of 10G)
    • # dd bs=1 if=/dev/zero of=/path/to/imagename.raw seek=10G count=1 conv=notrunc
  3. Convert back to qemu image
    • # qemu-img convert -f raw imagename.raw -O qcow imagename
  4. Partition the extra disk space you have created using parted
That's all folk

Wednesday, February 13, 2008

Installing subversion with apache on centos

A step by step guide on installing subversion with http support on centos and redhat machine

  1. First of all, install apache/httpd
    • yum install httpd
  2. Make sure you apache is running. You can also type 'http://localhost' at your browser and apache test page should appear if your apache is running
    • /etc/init.d/httpd status
  3. Make it start by default on startup
    • chkconfig httpd on
  4. Edit the apache configuration to suit your need. If not sure, leave the default setting as it is
    • vi /etc/httpd/conf/httpd.conf
  5. Install subversion and mod_dav_svn for apache
    • yum install mod_dav_svn subversion
  6. Go to subversion.conf in /etc/httpd/conf.d/. Edit as below
    • cd /etc/httpd/conf.d/
    • vi subversion.conf
      1. This is the most basic configuration where anyone will have unrestricted access to the repos. Location is the name that will be used in the browser address bar. In this example it will be 'http://localhost/svn/repos' (Click for larger image)
      2. This is a configuration with username and password for the client (Click for larger image)
    • htpasswd -cm /etc/svn-auth-conf --- This command is not needed for the first configuration. To create the first user with password
    • htpasswd -m /etc/svn-auth-conf --- use this command to add another user
  7. Configure your repository
    • mkdir /var/www/svn --- create folder svn
    • cd /var/www/svn --- change diectory to the newly created svn directory
    • svnadmin create repos --- create svn repository named repos
    • chown apache.apache -R repos --- change ownership of 'repos' to apache
    • /etc/init.d/httpd restart --- restart apache
  8. Open you browser and type 'http://localhost/svn/repos'. You can see that a page with 'Revision 0:/' will appear. Congratulation, you just completed the setup for svn server with http.

Tuesday, February 12, 2008

Fedora 8 additional repository

If you are using fedora linux, here are a few additional repositories that you might want to install in addition to the official repository and the installation instruction.

  1. Livna rpm
    • Download the installer from here
    • Install the repository
      • rpm -Uvh livna-release-8.rpm
  2. freshrpms
    • Download the installer from here
    • Install the repository
      • rpm -Uvh freshrpms-release-1.1-1.fc.noarch.rpm
  3. atrpms
    • Import the atrpms signing key
      • rpm --import
    • Create atrpms.conf in /etc/yum.repos.d/
      • touch /etc/yum.repos.d/atrpms.conf
    • Add the below lines to the atrpms.conf file
      • [atrpms]
        name=Fedora Core $releasever - $basearch - ATrpms
You can start using yum to install any software and yum will pick source from these new repositories straight away.

Monday, February 11, 2008

Accessing data on xen lvm guest image

Accessing xen guest image is very easy if the image is not lvm partitioned. But the main problem arise when the image is of lvm format and normal mount command cannot be used. Here I will show both the way. The first is when ext filesystem is used, and the second is when lvm is used.

To mount xen guest image (without lvm)

1. check the partition on the image
# fdisk -lu
The result will be something like this:

2. Mount using offset option
# mount -o loop,offset=106929152 /path/to/image /mnt
where 106929152=208846*512, 208846 is the start of the partition. Using this way, you only mount the second partition and not the whole image

3. You can now access your image at /mnt

To mount xen guest image (with lvm)

1. Check the partition on the image
# fdisk -lu /path/to/image

2. You have to install kpartx to handle lvm partiton
# yum install kpartx

3. Run kpartx on the image
# kpartx -av /path/to/image

4. Run vgscan to scan volume group available
# vgscan

5. Run vgchange to activate the volume group in the image
# vgchange -ay VolGroup00

6. Use lvs to see what is the name of your low volume group
# lvs

7. Mount the low volume group
# mount /dev/VolGroup00/LogVol01 /mnt

8. You can access your lvm image at the mounted directory which is /mnt

9. To unmount it, a few commands have to be executed (umount for unmounting, vgchange -an to deactivate volume group, kpartx -d to delete device map and losetup -d to delete loop device used)
# umount /mnt/
# vgchange -an VolGroup00
# kpartx -d /path/to/image
# losetup -d /dev/loop0

Hope this will be useful

Friday, February 1, 2008

Text viewer

To view text in linux, there are several tools that one can use. The purpose of the text viewer is to view the text file and not editing it. Some of it also equipped with search function to ease reading.
If you are using GUI, you can use gedit, which is available if you are using gnome desktop environment. Gedit works as both editor and viewer. If you are using KDE desktop, you can use KEdit.

In the absence of GUI, a few tools can be used, such as less and more. These 2 tools is quite similar with only the difference in name.
To use less:
# less filename

and similarly to use more:
# more filename

Another tool that can be used is cat. Cat's purpose is to concatenate 2 file into one, but if used to a single file, cat will display the file to standard output. To use cat:
# cat filename