Monthly Archives: June 2012

How to reinstall Ubuntu without losing the old data with separate home partition

I came from Windows world and always think that if we want to reinstall the windows then we only need to format the C drive while data in other drives survive(e.g. Documents, Software etc.) but if we reinstall the Linux, then all of our data erased(If we used default partition scheme). In this tutorial, I will create separate home partition for my personal data and also want to make sure that it will survive during the clean installation of Linux.

I will use the recommended partition scheme for this tutorial, in which, I’ve created four primary partitions:

1) /boot – for bootloader, if you’re running multiple OS
2) swap – which should be a little larger than the amount of ram you have(double than your ram is recommended)
3) – the main file system directory for operating system
4)/home – for your data files

Suppose,I purchased a new Laptop and want to install Ubuntu 10.04 LTS on it and for this, I did the partition like this:

Note: I skipped the couple of steps until reach to the partition page.

When you come to the partition manager part of the install, then select the partition manually:

The new hard drive does not have a partition table, click on the “New Partition Table” to create one:

Click “Continue“:

As per recommendation, the first partition should be mounted at /boot, because Ubuntu is the solo OS on this disk then installer will create the first partition as a primary partition (300 MB space is sufficient for this partition).

Select the free space and click on Add to create /boot partition:

The second partition will be for Swap, which should be a little larger than the amount of ram you have (double than your ram is recommended).

Select the free space and click on Add to create Swap partition:

The third partition will be for /. The installer recommends ~4.0 GB of disk space for installing Ubuntu 10.04, but assign more, if you are installing a lot of applications(~ 20 to 50GB).

Select the free space and click on Add to create / partition:

The last partition will be for /home and you may use all the available disk space.

Select the free space and click on Add to create /home partition:

The main manual partitioning window shows us all the partitions that we just created, Click “Forward” to continue the installation:

Suppose,I used this laptop about 1 year and create some folders which contain my data at /home.

Meanwhile, Ubuntu 12.04 LTS released and I want to updated my laptop from Ubuntu 10.04 to 12.04 but want to make sure that all the data in my home partition will be survived.

Again,I skipped the couple of steps until reach to the partition page, Click “Something else“:

It will present us with the partitions that already created:

As we already follow the recommended partition scheme 1 year ago when we created the partitions on our new hard disk.

Choose the /boot partition(How I know that, it’s boot partition? Well we know that we created it ~300MB) then click on Change, specify the file system, select format and set the mount point as /boot.

Choose the Swap partition then click on Change and specify the file system as Swap.

Next choose the / partition then click on Change, specify the file system, select format and set the mount point as /.

Now choose the /home partition then click on Change, specify the file system, DO NOT SELECT format and set the mount point as /home.

In the main manual partitioning window, we can see all the partitions that just created. Click “Install Now”:

After the fresh installation of Ubuntu 12.04, I still have all of my old data (if you don’t have your old data then please don’t blame me).

Hope this will help you!

Please Remember me in your prayers!

Enjoy 🙂

Advertisements

How to find if a specific package(program) is Installed

If you want to find, that a specific program is installed or not on Ubuntu, then there is a really good command:

apt-cache policy <package-name> (no sudo needed)

Which tells you the install software with it’s version number as well,if not then which version is availabe on the repository.

If it is not installed:

If it is installed:

Or

dpkg: dpkg -l | grep <package name>

When it’s not installed won’t show output. When it is, it’ll show something like:

Credit for this post goes to Oli Warner.

Hope this will help you!

Please Remember me in your prayers!

Graphical Users & Groups Management Tool in Ubuntu 12.04

The old Gnome User and Groups management tool has been turned off in Ubuntu 12.04 LTS.

Although, There is User Accounts under the System setting, but the problem with the User Accounts is that you cannot administer groups.

 You need to install the gnome-system-tools from Ubuntu repository in order to be able to administer groups.

sudo apt-get install gnome-system-tools

After installing the tools, we’ll get back this old Users Settings tool:

Hope this will help you!

Please Remember me in your prayers!

Enjoy 🙂

How to install VNC server on CentOS 6

VNC is a protocol that is used to share the desktop with other users/computers over the network/Internet.In order to share a desktop, VNC server must be install and configure on the computer and VNC client must be run on the computer that will access the shared desktop.

When we install the minimal copy of CentOS Server, it only gives us the “Command Line” interface.

But some people prefer GUI instead and for this they install Full version of Gnome on CentOS. Actually there is a better way and that is to install VNC. VNC provides a lightweight virtual desktop than full blown version of Gnome.

To run the VNC Server on CentOS, we have to install these required packages:

sudo yum groupinstall Desktop

sudo yum install tigervnc-server

sudo yum install xorg-x11-fonts-Type1

This is optional:

sudo yum install vnc

To start VNC Server on boot

sudo chkconfig vncserver on

To setup users’ VNC password:

vncpasswd

Edit the /etc/sysconfig/vncservers file:

sudo nano /etc/sysconfig/vncservers

Add the following to the end of the file:

VNCSERVERS="1:arbab"
VNCSERVERARGS[1]="-geometry 1024x600"

The iptables rules need to be amended to open the VNC ports:

sudo iptables -I INPUT 5 -m state --state NEW -m tcp -p tcp -m multiport --dports 5901:5903,6001:6003 -j ACCEPT
sudo service iptables save
sudo service iptables restart

Restart the VNC Server:

sudo service vncserver restart

Now kill the VNC Server:

vncserver -kill :1

Edit the xstartup file in .vnc directory:

nano .vnc/xstartup

Comment the last line and run the Gnome:

#twm & 
exec gnome-session &

Restart the service:

sudo service vncserver restart

Now, download VNCViewer onto our desktop computer from which we want to access the shared desktop. Connect using ServerIP/Name:1 (:1 is for the VNC server window), In my case it is centos:1.

Enter the password that we created using the vncpasswd command:

We now have GUI access to our server.

Ability to connect for multiple users:

Create a local user, using the following command:

sudo adduser ali

Create a password for newly created user:

sudo passwd ali

Switch to the newly created user and run vncpasswd command for it:

su ali
vncpasswd

Edit the /etc/sysconfig/vncservers file:

sudo nano /etc/sysconfig/vncservers

Add these lines for new user:

VNCSERVERS="1:arbab 2:ali"
VNCSERVERARGS[1]="-geometry 1024x600"
VNCSERVERARGS[2]="-geometry 1024x600"

Restart the VNC service:

sudo service vncserver restart

Kill the vncserver session for new user and edit the xstartup file:

su ali
vncserver -kill :2
cd ~
nano .vnc/xstartup

Modify the file so it looks like this:

#twm & 
exec gnome-session &

Restart the VNC service:

sudo service vncserver restart

Connect with newly created user using centos:2, Where centos is my server name:

Enter the password that we created using the vncpasswd command:

We now have GUI access to our server for newly created user.

Hope this will help you!

Please Remember me in your prayers!

Enjoy 🙂

How to install VNC server on Ubuntu Server 12.04

   VNC is a protocol that is used to share the desktop with other users/computers over the network/Internet.In order to share a desktop, VNC server must be install and configure on the computer and VNC client must be run on the computer that will access the shared desktop.

When we install the fresh copy of Ubuntu Server, it only gives us the “Command Line” interface.

But some people prefer GUI instead and for this they install Full version of Gnome on Ubuntu Server. Actually there is a better way and that is to install VNC. VNC provides a lightweight virtual desktop than full blown version of Gnome.

To install the core components of gnome, use this command:

sudo apt-get install gnome-core 

To install a virtual desktop, use this command:

sudo apt-get install vnc4server

In order to use VNC, we need to setup a password using the following command:

vncserver

To make a tweak in startup script, we need to kill the session that we just created:

vncserver -kill :1

Now open up the file that we need to edit:

cd ~
nano .vnc/xstartup

And Modify the file so it looks like this:

#!/bin/sh
# Uncomment the following two lines for normal desktop:
unset SESSION_MANAGER
#exec /etc/X11/xinit/xinitrc
gnome-session --session=gnome-classic &

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
#x-terminal-emulator -geometry 1280x1024+10+10 -ls -title "$VNCDESKTOP Desktop" &
#x-window-manager &

Next, create the VNC Session once more:

vncserver -geometry 1024x600

Now, download VNCViewer onto our desktop computer from which we want to access the shared desktop. Connect using ServerIP/Name:1 (:1 is for the VNC server window), In my case it is tendo:1.

Enter the password that we created using the vncserver command:

We now have GUI access to our server.

After reboot the server, we will not be able to connect to the server with VNC, this is because the “vncserver -geometry 1024×600” command that we typed above is not persistent. To solve this problem, we will use an excellent script of Justin Buser.

As sudo user create the file (and directory if it doesn’t exist):

sudo mkdir -p /etc/vncserver
sudo touch /etc/vncserver/vncservers.conf
sudo nano /etc/vncserver/vncservers.conf

Add servers as needed for each user by adding something like the following to the vncservers.conf file we just created:

VNCSERVERS="1:arbab"
VNCSERVERARGS[1]="-geometry 1024x600 -depth 24"

Next, create an empty init script and make it executable:

sudo touch /etc/init.d/vncserver
sudo chmod +x /etc/init.d/vncserver
sudo nano /etc/init.d/vncserver

Add the following to /etc/init.d/vncserver:

#!/bin/bash
unset VNCSERVERARGS
VNCSERVERS=""
[ -f /etc/vncserver/vncservers.conf ] && . /etc/vncserver/vncservers.conf
prog=$"VNC server"
start() {
 . /lib/lsb/init-functions
 REQ_USER=$2
 echo -n $"Starting $prog: "
 ulimit -S -c 0 >/dev/null 2>&1
 RETVAL=0
 for display in ${VNCSERVERS}
 do
 export USER="${display##*:}"
 if test -z "${REQ_USER}" -o "${REQ_USER}" == ${USER} ; then
 echo -n "${display} "
 unset BASH_ENV ENV
 DISP="${display%%:*}"
 export VNCUSERARGS="${VNCSERVERARGS[${DISP}]}"
 su ${USER} -c "cd ~${USER} && [ -f .vnc/passwd ] && vncserver :${DISP} ${VNCUSERARGS}"
 fi
 done
}
stop() {
 . /lib/lsb/init-functions
 REQ_USER=$2
 echo -n $"Shutting down VNCServer: "
 for display in ${VNCSERVERS}
 do
 export USER="${display##*:}"
 if test -z "${REQ_USER}" -o "${REQ_USER}" == ${USER} ; then
 echo -n "${display} "
 unset BASH_ENV ENV
 export USER="${display##*:}"
 su ${USER} -c "vncserver -kill :${display%%:*}" >/dev/null 2>&1
 fi
 done
 echo -e "\n"
 echo "VNCServer Stopped"
}
case "$1" in
start)
start $@
;;
stop)
stop $@
;;
restart|reload)
stop $@
sleep 3
start $@
;;
condrestart)
if [ -f /var/lock/subsys/vncserver ]; then
stop $@
sleep 3
start $@
fi
;;
status)
status Xvnc
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart|status}"
exit 1
esac

We’ll need to run vncserver command AT LEAST ONCE AS EACH USER that want to login as. I put that in caps because if you skip that step none of it will work.

Finally, do the following:

sudo update-rc.d vncserver defaults 99

Now, restart the service by typing:

sudo service vncserver restart

Ability to connect for multiple users:

Create a local user, using the following command:

sudo adduser hussain

Switch to the newly created user and run vncserver command for it:

su hussain
vncserver

Move to the home directory and edit the xstartup file:

cd ~
nano .vnc/xstartup

Modify the file so it looks like this:

 
#!/bin/sh
# Uncomment the following two lines for normal desktop:
unset SESSION_MANAGER
#exec /etc/X11/xinit/xinitrc
gnome-session --session=gnome-classic &

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
#x-terminal-emulator -geometry 1280x1024+10+10 -ls -title "$VNCDESKTOP Desktop" &
#x-window-manager &

Now open up the /etc/vncserver/vncservers.conf file as sudo user:

sudo nano /etc/vncserver/vncservers.conf

Add servers for newly created user by adding something like this:

VNCSERVERS="1:arbab 2:hussain"
VNCSERVERARGS[1]="-geometry 1024x600 -depth 24"
VNCSERVERARGS[2]="-geometry 1024x600 -depth 24"

Restart the service:

sudo service vncserver restart

Connect with newly created user using tendo:2, Where tendo is my server name:

Enter the password that we created using the vncserver command:

We now have GUI access to our server for newly created user.

Preventing Gnome to start on boot on the server:

Gnome is automatically started on boot in Ubuntu 12.04 LTS, if we connect a monitor to our server we will see that GUI sitting there waiting for us to log in.

To prevent it, edit the gdm.conf file:

sudo nano /etc/init/gdm.conf

Comment these six lines:

#start on ((filesystem
# and runlevel [!06]
# and started dbus
# and (drm-device-added card0 PRIMARY_DEVICE_FOR_DISPLAY=1
# or stopped udev-fallback-graphics))
# or runlevel PREVLEVEL=S)

Reboot the server and that GUI log-in screen will no longer appear:

VNC encrypted through the ssh tunnel:

By default, VNC is not secure protocol.VNC uses encryption during initial connection and login (passwords are not sent in plain-text). Once, we connected then all the VNC data is unencrypted and hacker could sniff our VNC session. It is better (safer) to start VNC server only on 127.0.0.1(localhost) and tunnel it over secure SSH tunnel (For this,there are options in Putty).

On Ubuntu, edit /etc/vncserver/vncservers.conf:

sudo nano /etc/vncserver/vncservers.conf

Add the option “-localhost“:

VNCSERVERS="1:arbab 2:hussain"
VNCSERVERARGS[1]="-geometry 1024x600 -depth 24 -localhost"
VNCSERVERARGS[2]="-geometry 1024x600 -depth 24 -localhost"

Restart the service:

sudo service vncserver restart

Here is visual, how to connect to VNC Server through PuTTY(SSH) from Windows Machine.

Run PuTTY,enter the IP address or hostname of the VNC Server:

On the left-hand panel, Go to Connection -> SSH -> Tunnels:

Source Port:590x(Where x is a value that we set in vncservers.conf,like 1 for arbab)
Destination:localhost:590x(Same x value that we used above in source port)

Click Open button in order to connect to the Server via SSH:

Login to the Ubuntu (VNC Server) with username and password:

Upon successful connection to VNC Server, we’ll find port 5901 is in listening mode on localhost:

netstat -a

Run VNC Viewer and enter the localhost:1(:1 is for arbab user, that we defined in vncservers file):

Enter the password, in order to connect to the VNC Server:

Now, we are connected to remote VNC Server through ssh tunnel:

Hope this will help you!

Please Remember me in your prayers!

Enjoy 🙂

How to find the Linux Distribution Name and Version

In this post, I will try to show you that how we can check the version of Linux (Debian, Fedora, Ubuntu, CentOS), a particular system is running. Sometime we login to the system but we don’t know that which Linux distribution is running on it, So in this post, we will try to find it by using the lsb_release command that displays certain Linux Standard Base(LSB) and distribution-specific information.

To show the release number of installed distribution:
lsb_release -r

To show the distributor ID:
lsb_release -i

 To show all of the above information:
lsb_release -a

To find Out the Kernel Version by using this command:
uname -mrs

Where:

Linux – Kernel name
3.2.0-24-generic – Kernel version
x86_64 – Kernel is 64-bit

Hope this will help you!

Please Remember me in your prayers!

How to delete a file in linux with spaces

If you create a file in Linux with special character like %,$, * etc then you cannot remove it simply with rm command. In order to delete this kind of file, you need to use the inode number of this file. In this tutorial, I will try to show you that how we can delete the file in Linux that contains the special character and spaces in it’s name.

First, we will create a file with special character as well as spaces in it’s name:

touch "$this is %a +bad -example"

Let’s check the created file and it’s ownership information:

ls -l

From the ownership information, it is clear that I have rights to delete this file, now we try to delete this file:

rm is %a +bad -example

Note: You can if you add the \ before the name, but you’d have to guess as a user that it was used in the file creation.

To delete this file, we need to know it’s inode number by using this command:

ls -il

Then use the find command to delete the file by it’s inode:

find . -inum 270016 -exec rm -i {} \;

Hope this will help you!

Please Remember me in your prayers!

Enjoy 🙂

How to backup data from crashed Windows system

Sometimes, our Windows systems crashed for no reason because it is windows and it doesn’t need a reason to crash 🙂

But sometimes in this situation, we want to access our important files on urgent basis. So, in this tutorial, I will try to show you, how we can do this.

First download the latest version of Ubuntu Desktop and burn the ISO image on a CD or make a bootable USB.Put the Ubuntu CD/USB in the System that has been crashed and wait for the desktop to load:

Click on “Try Ubuntu” and it will present you with the Live Desktop of Ubuntu:

In order to open the Terminal,press “Ctrl + Alt + T”  and type:

gksudo nautilus

By typing this command, it will start temporary windows in which you have full access to all the files like Root user, then within the nautilus windows, click on your hard disk and copy your desired files to an external USB/Media.

Hope this will help you!

Please Remember me in your prayers!

Enjoy 🙂

How to change the Solaris Shell to Bash

“sh is a command language described by the POSIX standard. It has many implementations (ksh88, dash, …). bash can also be considered an implementation.

Another point of view on bash is that it is a separate language, a dialect of sh. Indeed it supports huge number of features beyond POSIX specification.”

Personally, I like bash over sh. But on Solaris 10, sh is the default shell. So, in this post, I will show you that how to change the shell from sh to bash.

First verify the shell for current  user (In my case, it’s arbab):

grep arbab /etc/passwd

Now switch to root user and enter the following command:

usermod  -s  /usr/bin/bash arbab

Now go back as user arbab(that’s for me, you will use your’s) and verify the change:

grep arbab /etc/passwd

We are done 🙂

Hope this will help you!

Please Remember me in your prayers!

%d bloggers like this: