Friday, November 12, 2010

Ubuntu: Set up iSCSI initiator and target

There will be a lot of posts about iSCSI hereafter, as I am working on the SAN protocol for my graduate project. This was the source I used : http://www.howtoforge.com/using-iscsi-on-ubuntu-9.04-initiator-and-target

This is what I did:
Follow the set up till creating logical volume.
If your system got a partition (/dev/sdan - where n is any number between 1 and 9) which is free and doesn’t contain a partition table(no data or os in it). Use Gparted to format the disk to any type. Then follow the steps below:

sudo fdisk -l(lower case L) - This will list the device partitions size and ID

pvcreate /dev/sda3 - I’m using this partition - On success it would say “Physical volume /dev/sda3 successfully created

vgcreate vg0 /dev/sda3 - On success “Volume group vg0 successfully created”. vg0 - name of the volume group. Any format is fine.< lvcreate -L20G -n storage_lun1 vg0 - From the source 3. After creating the logical volume, follow the source instructions. At the place of iqn.2001-04.com.example:storage.lun1 192.168.0.100 substitute your IP address. I’m going to have both target and initiator at the same computer for now. So I’m using 127.0.0.1 in place of 192.168.0.100 in all forthcoming commands. However, 3260 port number is same and it is default for iSCSI.

------------------------------------------------------------------------------------------------------------------------------------
Now the above post is good but once I partition the sdb disk and changed some file I had problem logging to target. This is the error I got.

iscsiadm: Could not login to [iface: default, target: iqn.2001-04.com.example:storage.disk2.amiens.sys1.xyz, portal: 192.168.1.101,3260]: iscsiadm: initiator reported error (15 - already exists) iscsiadm: Could not log into all portals. Err 15.

I tried couple of solutions like deleting the devices modules and taking a look at the /var/log/messages. Then I jumped at this page and all I had to install tgtadm service and it was piece of cake from there and simple solution to create small portions to act as targets. Since our project is about able to replay the iscsi event with session details as original event for problem diagnosis, for testing during development we need to create small partitions. I would keep updating about this project. If you need more details, do drop me an email.

Sunday, November 7, 2010

Ubuntu: How to create full system backup

Since I'm playing around my computer to install iSCSI target and initiator, I needed to create volume groups. That involves partitioning and formatting of my hard drive. Hence I'm very sure this would result in the loss of files from my hard drive :) So I wanted to take full system back up of my Ubuntu. I found a very useful and simple to-do list here. I am going to list those steps here FMR(For My Reference).

The general idea in taking full system back up in Ubuntu(or any Linux for that matter), you can create one compressed archive of all the files with folder structure,then uncompress the archive when you want and viola you have saved your files! Unlike Windows, the creating back up and restoring can be done when the system is running. Warning: while restoring we have to be careful where we uncompress the files to avoid losing data. Here are the steps:

  • Become a root user using "sudo su". Warning: be cautious when you are a super user and execute a command from online, there is a single command which can destroy the entire filesytem!
  • Go to root of the filesystem using "cd /". This would be the place where your back up archive file would be created. Feel free to create the file in remote drives directly.
  • Then use the following single command to create the backup archive
    tar cvpzf backup.tgz --exclude=/proc --exclude=/lost+found --exclude=/backup.tgz --exclude=/mnt --exclude=/sys /

    This file would be really big and if you want to use better compression technique, you can also create bzip2 files.
    tar cvpjf backup.tar.bz2 --exclude=/proc --exclude=/lost+found --exclude=/backup.tar.bz2 --exclude=/mnt --exclude=/sys /

    This commands take a long time to create the file. The explanation for the command and the options:
    • c- compress, v- verbose, p- preserve permissions
    • backup.tar - filename for the backup file
    • You need to exclude the directories that doesn't contain useful files and the back up file itself. Remove any /mnt if you need to avoid backing up other mounted partitions too.
    • Ignore the error message like "tar: /: file changed as we read it
      tar: Exiting with failure status due to previous errors" which you might get at the end of the process.

  • Restoring:
    The command to restore the file from the same place as root of the filesystem,
     tar xvpfz backup.tgz -C /

    Make sure you create the folders that you excluded from the back up archive. So this would be the list of directories if you had used the above command:
    mkdir proc
    mkdir lost+found
    mkdir mnt
    mkdir sys
    etc...

    Then reboot the system to complete the process.
Thanks to the source: http://ubuntuforums.org/showthread.php?t=35087