Showing posts with label Ubuntu. Show all posts
Showing posts with label Ubuntu. Show all posts

Monday, November 25, 2019

How to update to Ubuntu 14.04 LTS on Linux Server


Before upgrading it is always recommended that you create a backup first.
Step 1 : Check the current version of Ubuntu
uname -mrs
lsb_release -a
This should return an output in the following format :
Linux 3.2.0-51-generic x86_64
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 12.04.4 LTS
Release: 12.04
Codename: precise
Step 2 : Now we need to update the package list and install the update-manager-core package if it is not already installed:
apt-get update
apt-get install update-manager-core
Step 3 : Upgrade to the latest LTS release of Ubuntu, using the below mentioned command. This command will open up a upgrade tool. Just follow the on screen instructions to complete :
do-release-upgrade
In case you get the following message from this command, it means taht there is no newer LTS version available :
Checking for a new Ubuntu release
No new release found
But if you still want to upgrade to the latest version of Ubuntu, regardless of it have LTS (Long term support), you can use the same command but with a ‘-d’ option :
do-release-upgrade -d
Step 4 : After the installation is completed, it is recommended that you reboot the server and check the new settings :
reboot
lsb_release -a
uname -mrs
Continue reading...

How to search or find a File / Folder on your Linux Server ?


To locate files or folders on your Linux server through command line or bash, you can use the ‘find‘ command.
The syntax for the find command is as follows :
find {dirctory_to_search} {search_by} {pattern_to_search} [action]
For Example, if you wish to search a file called ‘filename.php’ by name on the entire server.
fine / -name filename.php 
Some of the popular ‘search by’ options are :
– -name pattern : This option finds the filenames of the given pattern.

For Example : Find a file named ‘myfile.txt’ in the ‘home’ folder of the server.
find /home -name myfile.txt
– -user username : Finds files owned by the given user name.

For Example : Find Files owned by the user ‘WPOven’ in the ‘/var/usr’ folder of the server
find /var/usr -user WPOven
– -perm permission : Finds files of the given permissions.

For Example : Find all files with permission as ‘665’ in the ‘/srv’ folder
find /srv -perm 665
– -type X : Search files of type X. Here X can be :
f – File
d – Directory
l – Symbolic Link
For Example : Find a directory with name like ‘mydir’ in the ‘/var/www’ folder
find /var/www -type d -name mydir
– -print File : Print the result full filename followed by a new line.

For Example : Find the files with name temp in the /srv folder and delete them
find /srv -type f -name temp -print | rm -f
Continue reading...

How to create a swap partition on Ubuntu 12.04 VPS

What is a Swap Partition ?

A linux swap partition is like an overflow for your system’s RAM. If your RAM gets full, then your swap partition will run the other applications. So does this mean this is a great alternative to having a large RAM ? No ! because a swap partition on a hard drive can never be as fast as a RAM from a hardware point of view. Even with the growing popularity of Solid State Drives (SSD), they still cannot match the hardware capabilities of a RAM.

Step 1 : Check for any existing swaps

sudo swapon -s
This should show an empty list like :
FileName                    Type             Size         Used           Priority
If you see an empty list like this, it means there is no swap currently on your system.

Step 2 : Create the Swap

Now that we have established that there is no previous Swap on the server, we will now check whether or not there is any space available for the swap on the server, by running the following command :
df -h
This command will show the memory stats for the server (in GB). Something like this :
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        20G  9.6G  9.1G  52% /
none            4.0K     0  4.0K   0% /sys/fs/cgroup
udev            235M  4.0K  235M   1% /dev
tmpfs            50M  356K   49M   1% /run
none            5.0M     0  5.0M   0% /run/lock
none            246M     0  246M   0% /run/shm
none            100M     0  100M   0% /run/user
After confirming that we have enough space on the server for a swap, we now create the swap using the ‘dd’ command :
sudo dd if=/dev/zero of=/swapfile bs=1024 count=1024k
This creates a swap of 1 GB on the server, in the file name ‘swapfile’, and should return an output like :
1048576+0 records in
1048576+0 records out
1073741824 bytes (1.1 GB) copied, 4.35649 s, 246 MB/s
We need to now create a linux swap area
sudo mkswap /swapfile
This command should output like :
Setting up swapspace version 1, size = 1048572 KiB
no label, UUID=3e7247a1-d330-4c34-833c-a3020d99d25c

Step 3 : Activate the Swap

To activate the swap we need to run the following command :
sudo swapon /swapfile
Now check if the swap has been succesfully created and activated
swapon -s
Should return
Filename                                Type            Size    Used    Priority
/swapfile                             
Continue reading...

How to create a swap on Ubuntu 14.04

What is a Swap Partition ?

A linux swap partition becomes useful when your server’s RAM gets full. When your RAM gets full, then your swap partition will act as a RAM for your other applications. But does not this mean this is a great alternative to having a large RAM, because a swap partition on a hard drive (even SSD) can never be as fast as a RAM from a hardware point of view.
Step 1 : Check for any existing SWAP on the server by running the following command
sudo swapon -s
If you get the following output, that means you DO NOT have any swap space allocated as of now
Filename                Type        Size    Used    Priority
You may also check for swaps on the server using
free -m
Should show Swap values as zero :
             total       used       free     shared    buffers     cached
Mem:          3998       1483       2515         64         93       1089
-/+ buffers/cache:        300       3698
Swap:          0          0        0
Step 2 : Once we have established that there are no existing swaps on the server, we will then check for the available space on the server
df -h
This will show the server disk usage in the following format :
Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda        89G  1.9G   86G   3% /
none            4.0K     0  4.0K   0% /sys/fs/cgroup
devtmpfs        2.0G  4.0K  2.0G   1% /dev
none            400M  212K  400M   1% /run
none            5.0M     0  5.0M   0% /run/lock
Step 3 : Once we have established that there is sufficient space on the server disk to create a swap, we will create our swap file, in the root directory.
cd /
sudo dd if=/dev/zero of=/swapblock bs=256M count=4
The above mentioned ‘dd’ command will specify 4 blocks each of size of 256 Megabyte. Totalling to a swap size of 1 GB. It should provide an output in the following format
4+0 records in
4+0 records out
1294728296 bytes (1.3 GB) copied, 6.6227 s, 231 MB/s
To check that the swap has been allocated correctly, execute the following command
ls -lh /swapblock 
This should display the swap block with it’s size
Step 4 : Now the swapblock is created and the space has been allocated on the server, but the system does not know what to do with the space allocated yet. To solve this we will enable the swap on your ubuntu 14.04 server.
sudo mkswap /swapblock 
This command will set up the swap space on the ubuntu server. It should display an output of the format
Setting up swapspace version 1, size = 1194300 KiB
no label, UUID=e2f1e9cf-c0a9-4ed4-b8ab-714b8a7d6944
Once the swap space is set up, we will then enable it
sudo swapon /swapblock 
This will enable the swap file on your Ubuntu 14.04 server.
Step 5 : Check that the Swap file is enabled on the server
sudo swapon -s
This should display an output like
Filename                Type        Size    Used    Priority
/swapblock              file        1194300 0       -1
Step 6 : Once we have confirmed that the swap file is setup and enabled, we then need to make the swap permanent on the server, so that we do not loose the changes if the server is reboot or restarted.
Open the fstab file using your favourite editor. We will use nano for this example.
sudo nano /etc/fstab
and add the following line at the bottom of this file
/swapblock  none    swap    sw    0   0
Continue reading...