This is default featured slide 1 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured slide 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured slide 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured slide 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

Friday 30 November 2012


Mounting Linux Partitions in Ubuntu

If you plug in an external hard drive with a Linux filesystem, it will automount and show up on your desktop, just like any external media. But what if you have an internal hard drive or partition with a Linux filesystem? Well, that's what this tutorial is about.Warning: The tutorial on this page is for an internal drive that will serve as an extra data partition. If you would like to mount a separate drive or partition as /home instead, you want a different tutorial.
First you have to determine what the partition is called and what filesystem it is. One quick way to do it if you know what filesystem you formatted the drive as (Ext3, for example) is to just type the terminal command
sudo fdisk -l

Here's how it could come out:
Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000eb4baDevice Boot Start End Blocks Id System
/dev/sda1 * 1 524 4208006 83 Linux
/dev/sda2 525 1044 4176900 83 Linux
As you can see, I'm able to locate that /dev/sda2 is my Linux partition, but inSystem, I don't find out if it's Ext3, Ext4, Reiserfs, or what it is. If I happen to know it's Ext4, cool.
But let's say I didn't know. Well, one way to find out for sure is to install GParted and find out:

sudo apt-get update
sudo apt-get install gparted gksu
gksudo gparted
 
You can go to System > Administration > GParted and enter your password to get it started.

Ah, now I can definitely see it's Ext4 for sure. Under Partition I see it's /dev/sda2, and under Filesystem, I see it's Ext4.
If you have a second physical hard drive (not just another partition), you might have to click on the top-right corner to focus on the second hard drive. (Click on the down-pointing arrow to get the drop-down menu.)
So now I'll create a mount point for that partition:
sudo mkdir /storage
Next, I want to determine the UUID of my partition.***
ls -l /dev/disk/by-uuid
and I get back this output:
total 0
lrwxrwxrwx 1 root root 10 2010-04-26 12:00 20bfd80a-a96b-461c-a63d-c96ff8e95872 -> ../../sda1
lrwxrwxrwx 1 root root 10 2010-04-26 19:19 d1d0cf46-958f-4a12-a604-0ac66040648b -> ../../sda2
Then I'll edit my /etc/fstab file:
sudo cp /etc/fstab /etc/fstab_backup
sudo nano /etc/fstab
Once in there, I should add in this line:
UUID=d1d0cf46-958f-4a12-a604-0ac66040648b /storage ext4 defaults 0 0
Then I can save (Control-X), confirm (Y), and exit (Enter).
Since we've made changes to the /etc/fstab file, we need to have Ubuntu acknowledge those changes:
sudo mount -a
Now I need to give it the proper permissions. Let's just assume, for this example, that my username is jessica.
sudo chown -R jessica:jessica /storage
sudo chmod -R 755 /storage
Now the partition is mounted in the /storage folder and is ready for use!
*** Yes, I could just use the name of it (/dev/sda2), but UUID is more precise. It's unlikely that I'll unplug my internal drive, plug in a new internal drive, and then plug back in my original internal drive so that the partition names are reassigned. Still, it's safer to use the exact partition identifier in /etc/fstab.

COMMAND LINE PARTITIONING


You'll be using "fdisk" to accomplish this. Refer back to the logical name you noted from earlier. For illustration, I'll use /dev/sdb, and assume that you want a single partition on the disk, occupying all the free space.
If the number of cylinders in the disk is larger than 1024 (and large hard drives always have more), it could, in certain setups, cause problems with:
  1. software that runs at boot time (e.g., old versions of LILO)
  2. booting and partitioning software from other OSs (e.g., DOS FDISK, OS/2 FDISK)
Otherwise, this will not negatively affect you.
1) Initiate fdisk with the following command:
  •   sudo fdisk /dev/sdb 
2) Fdisk will display the following menu:
  •   Command (m for help): m 
    Command action
    a   toggle a bootable flag
    b   edit bsd disklabel
    c   toggle the dos compatibility flag
    d   delete a partition
    l   list known partition types
    m   print this menu
    n   add a new partition
    o   create a new empty DOS partition table
    p   print the partition table
    q   quit without saving changes
    s   create a new empty Sun disklabel
    t   change a partition's system id
    u   change display/entry units
    v   verify the partition table
    w   write table to disk and exit
    x   extra functionality (experts only)
    
    Command (m for help):
3) We want to add a new partition. Type "n" and press enter.
  Command action
e   extended
p   primary partition (1-4)

4) We want a primary partition. Enter "p" and enter.
  Partition number (1-4):

5) Since this will be the only partition on the drive, number 1. Enter "1" and enter.
  Command (m for help):

If it asks about the first cylinder, just type "1" and enter. (We are making 1 partition to use the whole disk, so it should start at the beginning.)
6) Now that the partition is entered, choose option "w" to write the partition table to the disk. Type "w" and enter.
  The partition table has been altered!

7) If all went well, you now have a properly partitioned hard drive that's ready to be formatted. Since this is the first partition, Linux will recognize it as /dev/sdb1, while the disk that the partition is on is still /dev/sdb.

Command Line Formatting


To format the new partition as ext3 file system (best for use under Ubuntu):
  •   sudo mkfs -t ext3 /dev/sdb1
To format the new partition as fat32 file system (best for use under Ubuntu & Windows):
  •   sudo mkfs -t fat32 /dev/sdb1
As always, substitute "/dev/sdb1" with your own partition's path.

Modify Reserved Space (Optional)


When formatting the drive as ext2/ext3, 5% of the drive's total space is reserved for the super-user (root) so that the operating system can still write to the disk even if it is full. However, for disks that only contain data, this is not necessary.
NOTE: You may run this command on a fat32 file system, but it will do nothing; therefore, I highly recommend not running it.
You can adjust the percentage of reserved space with the "tune2fs" command, like this:
 sudo tune2fs -m 1 /dev/sdb1

This example reserves 1% of space - change this number if you wish.
  • {i} Using this command does not change any existing data on the drive. You can use it on a drive which already contains data.

Create A Mount Point


Now that the drive is partitioned and formatted, you need to choose a mount point. This will be the location from which you will access the drive in the future. I would recommend using a mount point with "/media", as it is the default used by Ubuntu. For this example, we'll use the path "/media/mynewdrive"
  •   sudo mkdir /media/mynewdrive
Now we are ready to mount the drive to the mount point.

Mount The Drive


You can choose to have the drive mounted automatically each time you boot the computer, or manually only when you need to use it.

AUTOMATIC MOUNT AT BOOT


You'll need to edit /etc/fstab:
  •   gksu gedit /etc/fstab
Add this line to the end (for ext3 file system):
  •   /dev/sdb1    /media/mynewdrive   ext3    defaults     0        2
Add this line to the end (for fat32 file system):
  •   /dev/sdb1    /media/mynewdrive   vfat    defaults     0        2
    The defaults part may allow you to read, but not write. To write other partition and FAT specific options must be used. If gnome is being used, use the right-click, mount method. Then launch the mount command from terminal, no options. The last entry should be the FAT drive and and look something like:
      /dev/sda5 on /media/mynewdrive type vfat
  • (rw,nosuid,nodev,uhelper=hal,shortname=mixed,uid=1000,utf8,umask=077,flush)
  • 
    All of the parts between the parenthesis are the mount options and should replace "defaults" in the fstab file. The "2" at the end instructs your system to run a quick file system check on the hard drive at every boot. Changing it to "0" will skip this. Run 'man fstab' for more info here.
You can now run "sudo mount -a" (or reboot the computer) to have the changes take effect.
If you want to allow a normal user to create files on this drive, you can either give this user ownership of the top directory of the drive filesystem: (replace USERNAME with the username)
  •   sudo chown -R USERNAME:USERNAME /media/mynewdrive
or in a more flexible way, practical if you have several users, allow for instance the users in the plugdev group (usually those who are meant to be able to mount removable disks, desktop users) to create files and sub-directories on the disk:
  •   sudo chgrp plugdev /media/mynewdrive
    sudo chmod g+w /media/mynewdrive
    sudo chmod +t /media/mynewdrive
The last "chmod +t" adds the sticky bit, so that people can only delete their own files and sub-directories in a directory, even if they have write permissions to it (see man chmod).

MANUALLY MOUNT


Alternatively, you may want to manually mount the drive every time you need it.
For manual mounting, use the following command:
sudo mount /dev/sdb1 /media/mynewdrive 

When you are finished with the drive, you can unmount it using:
sudo umount /media/mynewdrive
That's it :)

Tuesday 27 November 2012


List of commands determine system info/resources/partitions/process in Ubuntu Linux

Following lists frequently-used commands to determine ubuntu info,resources,partitions,network,process and so on.First,open terminal fromApplications/Accessories/Terminal and type the commands.
System infomation
uname -a
#kernel/operating system/CPU info in brief.
head -n 1 /etc/issue
#see the ubuntu version,same tocat /etc/issue
hostname
#hostname
lspci -tv 
#list all PCI devices
lsusb -tv
#list all USB devices
lsmod
#list loaded kernel modes
env
#environment variable
Resources
free -m
#see the usage of memory and swap
df -h
#the usage of partitions
du -sh 
#see the size of the directory in M.
grep MemTotal /proc/meminfo
#total size of RAM
grep MemFree /proc/meminfo
#free size of RAM
uptime 
#system running time,users,load average
cat /proc/loadavg
#load average
Disk and Partition
mount | column -t
#mount info about partitions
fdisk -l
#list all partitions,need root permission
swapon -s
#list all swap partitions
hdparm -i /dev/sda
#list disk info (only for IDE)
Network
ifconfig
#list IP informations
route -n 
#list route tables
netstat -lntp
#list listening ports
netstat -antp
#list established links
Process
ps -ef
#list all processes
top
#list processes and usage of system resource
User
id username
#list the user info.
last 
#list login record
cut -d: -f1 /etc/passwd 
#list all users
cut -d: -f1 /etc/group
#list all groups
crontab -l 
#list scheduled tasks of current user
Service
chkconfig --list
#list all services
chkconfig --list | grep on
#list all running services


Edit PDF on Ubuntu with PDF Editor

PDFedit is free and open source library for manipulating PDF documents, released under terms of GNU GPL version 2. It includes PDF manipulating library based on xpdf, GUI and set of command line tools.
Multiplatform library working on Unix systems, Windows32/64 and also Windows CE and others. You can use it to read, change and extract information from a PDF file. It is based on xpdf library.Graphical interface based on QT3.x which heavily depends on scripting; therefore, any user can modify the behaviour by scripts and plugins.

Ubuntu user can easily install PDFedit by this command:
sudo apt-get install pdfedit


Check your Hardware/System infomation in Ubuntu with Hardinfo

HardInfo can gather information about your system’s hardware and operating system, perform benchmarks, and generate printable reports either in HTML or in plain text formats.
It can also be easily extended, for developer documentation and full source code (released under GNU GPL version 2) is available.
To install Hardinfo,just click:
apt:hardinfo
and launch hardinfo from Applications->System Tools->System Profiler and Benchmark


Add a User in Ubuntu

useradd
The useradd command will let you add a new user easily from the command line:
useradd 
This command adds the user, but without any extra options your user won’t have a password or a home directory.
You can use the -d option to set the home directory for the user. The -m option will force useradd to create the home directory. We’ll try creating a user account with those options, and then use the passwd command to set the password for the account. You can alternatively set a password using -p on the useradd command, but I prefer to set the password using passwd.
sudo useradd -d /home/testuser -m testuser
sudo passwd testuser
This will create the user named testuser and give them their own home directory in /home/testuser. The files in the new home directory are copied from the /etc/skel folder, which contains default home directory files. If you wanted to set default values for your users, you would do so by modifying or adding files in that directory. If we take a look at the new home directory for the user:

geek@ubuntuServ:/etc/skel$ ls -la /home/testuser
total 20
drwxr-xr-x 2 testuser testuser 4096 2006-12-15 11:34 .
drwxr-xr-x 5 root root 4096 2006-12-15 11:37 ..
-rw-r–r– 1 testuser testuser 220 2006-12-15 11:34 .bash_logout
-rw-r–r– 1 testuser testuser 414 2006-12-15 11:34 .bash_profile
-rw-r–r– 1 testuser testuser 2227 2006-12-15 11:34 .bashrc

You’ll notice that there are bash scripts in this directory. If you wanted to set default path options for all new users, you would do so by modifying the files in /etc/skel, which would then be used to create these files by the useradd command.
adduser :-
The adduser command is even easier than the useradd command, because it prompts you for each piece of information. I find it slightly funny that there are two virtually identically named commands that do the same thing, but that’s linux for you. Here’s the syntax:
adduser
Example:
geek@ubuntuServ:/etc/skel$ sudo adduser thegeek
Password:
Adding user `thegeek’…
Adding new group `thegeek’ (1004).
Adding new user `thegeek’ (1004) with group `thegeek’.
Creating home directory `/home/thegeek’.
Copying files from `/etc/skel’
Enter new UNIX password:
Retype new UNIX password:
No password supplied
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for thegeek
Enter the new value, or press ENTER for the default
Full Name []: The Geek
Room Number []: 0
Work Phone []: 555-1212
Home Phone []: 555-1212
Other []:
Is the information correct? [y/N] y


Recover root password under linux with single user mode

It happens sometime that you can't remember root password. On Linux, recovering root password can be done by booting Linux under a specific mode:single user mode.
This tutorial will show how to boot Linux in single user mode when using GRUB and finally how to change root password.
During normal usage, a Linux OS runs under runlevels between 2 and 5 which corresponds to various multi-user modes. Booting Linux under runlevel 1 will allow one to enter into a specific mode, single user mode. Under such a level, you directly get a root prompt. From there, changing root password is a piece of cake.

1. ENTERING RUNLEVEL 1

Some Linux distribution, such as Ubuntu for instance, offer a specific boot menu entry where it is stated "Recovery Mode" or "Single-User Mode". If this is your case, selecting this menu entry will boot your machine into single user mode, you can carry on with the next part. If not, you might want to read this part.
Using GRUB, you can manually edit the proposed menu entry at boot time. To do so, when GRUB is presenting the menu list (you might need to press ESC first), follow those instructions:
  • use the arrows to select the boot entry you want to modify.
  • press e to edit the entry
  • use the arrows to go to kernel line
  • press e to edit this entry
  • at the end of the line add the word single
  • press ESC to go back to the parent menu
  • press b to boot this kernel
The kernel should be booting as usual (except for the graphical splash screen you might be used to), and you will finally get a root prompt (sh#).
Here we are, we have gained root access to the filesystem, let's finally change the password.

2. CHANGING ROOT PASSWORD

As root, changing password does not ask for your old password, therefore running the command:
# passwd
will prompt you for your new password and will ask you to confirm it to make sure there is no typo.
That's it, you can now reboot your box and gain root access again