
Friday, December 3, 2010
Tutorials & Help
There would be times when we forget things which we have been using for a long time. Then you would want to go to basic tutorial and read all about it. There is no good re-writing the commands and explanations here in blog but it is good to have links to the tutorials and help documents. This post will contain links to well-written help documentation for everything I will need. Please contribute to it, if you wish.


Ubuntu: Terminal display help
Here are the few tricks up your sleeve for utilizing the scripts to customize the terminal display.
1. To have the shell prompt always start at the left hand side of terminal:
When you have long pathname for the current working directory and you have a even longer command to execute, the display gets all screwed up. So it always helps you to have the shell prompt start at left hand side of terminal. You have to change the PS1 - to customize your bash prompt.
In the fig, you can't distinguish where the dir name ends and where the command starts. So open ".bashrc" file in home folder
PS1=$'\[\e]2; \h::\]$PWD\[\a\]\[\e]1;\]$(basename "$(dirname "$PWD")")/\W\[\a\] \w\n\T \$ '
Then the bash prompt becomes like this,
The current working directory name in first line(s) and in a new line current time followed by $ for you to type in the command.
Much better huh, what exactly does the code do? Let's review from back
\$ - if the effective UID is 0, a #, otherwise a $
\T - the current time in 12-hour HH:MM:SS format
\n - newline
\w - current working directory with ~ instead of $HOME directory
\[ \] - begin and end of a series of non-printing characters
\W - basename of the current working directory with ~ instead of $HOME directory
\e - escape character
\h - hostname
Source: to customize you bash prompt you can follow this help document.
You can also create aliases for opening and refreshing bashrc file like this (if you have to change it frequently)
In "~/.bashrc" file add the following code,
Happy customization!
1. To have the shell prompt always start at the left hand side of terminal:
When you have long pathname for the current working directory and you have a even longer command to execute, the display gets all screwed up. So it always helps you to have the shell prompt start at left hand side of terminal. You have to change the PS1 - to customize your bash prompt.
In the fig, you can't distinguish where the dir name ends and where the command starts. So open ".bashrc" file in home foldergedit ~/.bashrc
and add the following code. Note: as a good coding practice, add a line of comment saying when and why added the piece of code and add the new code at the end of the file.PS1=$'\[\e]2; \h::\]$PWD\[\a\]\[\e]1;\]$(basename "$(dirname "$PWD")")/\W\[\a\] \w\n\T \$ '
Then the bash prompt becomes like this,
The current working directory name in first line(s) and in a new line current time followed by $ for you to type in the command.Much better huh, what exactly does the code do? Let's review from back
\$ - if the effective UID is 0, a #, otherwise a $
\T - the current time in 12-hour HH:MM:SS format
\n - newline
\w - current working directory with ~ instead of $HOME directory
\[ \] - begin and end of a series of non-printing characters
\W - basename of the current working directory with ~ instead of $HOME directory
\e - escape character
\h - hostname
Source: to customize you bash prompt you can follow this help document.
You can also create aliases for opening and refreshing bashrc file like this (if you have to change it frequently)
In "~/.bashrc" file add the following code,
alias refprofile=' source ~/.bashrc'
alias editprofile='vi ~/.bashrc'
whereas, editprofile - opens the file for editing and refprofile - refreshes the file to reflect the change made.
alias editprofile='vi ~/.bashrc'
whereas, editprofile - opens the file for editing and refprofile - refreshes the file to reflect the change made.
Happy customization!
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.
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:
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.
- c- compress, v- verbose, p- preserve permissions
- 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.
Sunday, September 26, 2010
Ubuntu: Configuring Webcam and Microphone in Lenovo Y530
I have a Lenovo Y530 laptop. I had Windows then being the devoted Linux girl, I installed Ubuntu 9.10 on it. The laptop has built-in webcam(1.3M pixels). It was working fine with windows but got screwed up in ubuntu. So I set out to find out how to fix it. At first glance it looked like there was no proper solution available online. But after hours of search, I found the easy steps buried under a bunch of useless/complex solutions. So I wanted to document the exact steps I followed to configure the webcam.
Later added: As I mentioned in the post, I accidentally removed pulseaudio from my system. So when I tried to do skype call, both sides webcam worked fine. But audio had too much static noise. So I had to install pulseaudio. Then reinstalled skype. Skype call works fine. But still if I use the system's music player, then try skype calls again audio has static noise. I read from a forum that "sudo killall pulseaudio" and then restarting skype helps. But that is not efficient solution. If someone has permanent solution to this please drop a comment. Thanks in advance.
- I tried installing cheese(webcam booth tool for linux) and used Ekiga softphone. You can use either of this tool to check if the webcam is listed in video devices list. In Cheese, the screen had this test screen and both the tools din't recognize the webcam.
- Then in Terminal, try "lsusb". It would list all the USB devices connected to the computer. A sample lsusb would look like this (this has no webcam)
The 8 digit number followed by ID is the unique ID of the hardware device. If at all you want to search for solutions for any device use this number in your searches and you will more likely land in the page you want. When I ran this cmd, the output din't have any device listed in it. Then in some thread in Ubuntu forums(an excellent place to start your search), someone asked to use hot keys to toggle the webcam. In Lenovo Y530, its Fn+Esc. After that, lsusb listed the device as in,
Bus 005 Device 002: ID 0483:2016 SGS Thomson Microelectronics Fingerprint Reader
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 003: ID 046d:c016 Logitech, Inc. M-UV69a/HP M-UV96 Optical Wheel Mouse
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hubBus 002 Device 002: ID 04f2:b105 Chicony Electronics Co., Ltd - Now, I searched the ID with all related keywords, it landed here. I checked for my device and saw that it was complaint and all i have to do is download the v4l dvb drivers and viola.
- Then follow the steps listed in this link. I downloaded the latest version of V4L/DVB via web browser and following cmds "make", "make install". [don't forget to do, "sudo make install" - I know its simple but trust me you don't want to miss it]
- In Terminal, use this cmd
lspci -v | grep -i audio
The result would print out the Audio device if configured right. In my case, it returned empty result. - So I downloaded the alsa drivers, util, lib files from here. Followed this steps
- copy the tar.gz files to "/usr/src/alsa" - if you have the folder already or create one if you don't
- Then unzip the files using "sudo tar xjf alsa-driver*". Similarly util and lib files(change tar options as you require)
- Then we have to go each directory and do "./configure", "make", "make install".
- During the "./configure" if any error pops, you have to clear that for the installation to complete. I am just listing the problems I faced.
- Problem: During the "make" of Util files
xmlto man alsactl_init.xml
/bin/bash: xmlto: command not found
Solution:sudo apt-get install xmlto
- Problem: During the "./configure" of Util files
checking for new_panel in -lpanelw... no
configure: error: panelw library not found
Solution: Create soft links to the library files. click here for sourcesudo ln -s libpanelw.so.5 /usr/lib/libpanelw.so
sudo ln -s libformw.so.5 /usr/lib/libformw.so
sudo ln -s libmenuw.so.5 /usr/lib/libmenuw.so
sudo ln -s libncursesw.so.5 /lib/libncursesw.so
- Problem: During the "make" of Util files
Later added: As I mentioned in the post, I accidentally removed pulseaudio from my system. So when I tried to do skype call, both sides webcam worked fine. But audio had too much static noise. So I had to install pulseaudio. Then reinstalled skype. Skype call works fine. But still if I use the system's music player, then try skype calls again audio has static noise. I read from a forum that "sudo killall pulseaudio" and then restarting skype helps. But that is not efficient solution. If someone has permanent solution to this please drop a comment. Thanks in advance.
Sunday, September 12, 2010
Servlets
Servlets are replacing CGI script at most enterprise computing. They both perform similar operations of creating and displaying HTML pages dynamically. The basic differences between the two:
- CGI - Platform dependent, hence they cannot utilize server's capabilities; spawns new process for every request, hence resource intensive;
- Servlets - Since written in Java they can be executed in servers without any modifications as per "write once, run anywhere"; spawns new threads within the server process, hence lite weight.
- init() - initializes the servlet
- service(ServletRequest , ServletResponse) - all url's access this method and here we delegate to other service methods of form doXXX(HttpServletRequest , HttpServletResponse)
- destroy() - destroys the servlet
Thursday, September 9, 2010
Reset root password for phpmyadmin/mysql
I recently faced an issue where I forgot the root password for mysql and ended up searching for simple procedure to unlock it by resetting the password. So I want to save here the steps to unlock the phpmyadmin if I should loose my root password again. Then I can skip the searching-for-an-hour part and go straight to the unlocking part. (Thanks to fredanthony and for source thread: click here)
The error message you get when you enter wrong password in the login page is : "#1045 - Access denied for user 'root'@'localhost' (using password: NO) "
Steps:
P.S: List of useful SQL command syntax - source
METHOD 2:
This step is to change the MYSQL root password. Source: Ubuntu help documentation. In a terminal enter the following command:
"sudo dpkg-reconfigure mysql-server-5.1"
However verify you have mysql-server-5.1 in your system. To find that, in terminal type "mysql -V". The result would print out details about the mysql server installed in your system.Sample result was
"mysql Ver 14.14 Distrib 5.1.41, for debian-linux-gnu (i486) using readline 6.1". Hence I use 5.1 in the above command. When you run the reconfigure command, it will prompt you to enter password and restarts the mysql daemon.
The error message you get when you enter wrong password in the login page is : "#1045 - Access denied for user 'root'@'localhost' (using password: NO) "
Steps:
- Stop mysql - $ /etc/init.d/mysql stop
- Kill all mysql related processes. The ps list can be pretty big and confusing so better use grep to filter mysql processes and use only those pids in kill command. - $ ps waux | grep mysql, $kill -9 pids
- Open a new session of mysql by skipping permissions - $ /usr/bin/mysqld_safe --skip-grant-tables
- While the above session is open, in a new tab open a new session of mysql - $ /usr/bin/mysql
- Inside the new session,change the database - (inside mysql)$use mysql;
- The critical part of our unlocking process is resetting the password for root user -(inside mysql) $UPDATE user SET Password=PASSWORD('YOUR_PASSWORD_HERE')
WHERE Host='localhost' AND User='root'; - This step sets new password for the root user. - Then quit the mysql sessions and restart the mysql - $quit, $/etc/init.d/mysql restart
- try logging into phpmyadmin with new password you set in update command and viola!
P.S: List of useful SQL command syntax - source
METHOD 2:
This step is to change the MYSQL root password. Source: Ubuntu help documentation. In a terminal enter the following command:
"sudo dpkg-reconfigure mysql-server-5.1"
However verify you have mysql-server-5.1 in your system. To find that, in terminal type "mysql -V". The result would print out details about the mysql server installed in your system.Sample result was
"mysql Ver 14.14 Distrib 5.1.41, for debian-linux-gnu (i486) using readline 6.1". Hence I use 5.1 in the above command. When you run the reconfigure command, it will prompt you to enter password and restarts the mysql daemon.
Subscribe to:
Posts (Atom)