Showing posts with label Linux admin. Show all posts
Showing posts with label Linux admin. Show all posts

Sunday, 10 June 2012

What is Swap Space?

Swap space in Linux is used when the amount of physical memory (RAM) is full. If the system needs more memory resources and the RAM is full, inactive pages in memory are moved to the swap space. While swap space can help machines with a small amount of RAM, it should not be considered a replacement for more RAM. Swap space is located on hard drives, which have a slower access time than physical memory.
Swap space can be a dedicated swap partition (recommended), a swap file, or a combination of swap partitions and swap files.


The size of your swap should be equal to twice your computer's physical RAM for up to 2 GB of physical RAM. For physical RAM above 2 GB, the size of your swap should be equal to the amount of physical RAM above 2 GB. The size of your swap should never less than 32 MB


Using this basic formula, a system with 2 GB of physical RAM would have 4 GB of swap, while one with 3 GB of physical RAM would have 5 GB of swap
To remember:
File systems and LVM2 volumes assigned as swap space cannot be in use when being modified. For example, no system processes can be assigned the swap space, as well as no amount of swap should be allocated and used by the kernel. Use the free and cat /proc/swaps commands to verify how much and where swap is in use.



Adding Swap Space

You have three options: create a new swap partition:
1. Create a new swap file.
2. Extend swap on an existing LVM2 logical volume.
3. Creating an LVM2 Logical Volume for Swap.


1. Creating a Swap File:
Determine the size of the new swap file in megabytes and multiply by 1024 to determine the number of blocks. For example, the block size of a 64 MB swap file is 65536.
# dd if=/dev/zero of=/swapfile bs=1024 count=65536
Setup the swap file with the command:
# mkswap /swapfile
To activate the swap file:
# swapon /swapfile
To enable it at boot time, edit /etc/fstab to include the following entry:
/swapfile swap swap defaults 0 0
The next time the system boots, it enables the new swap file.
After adding the new swap file and enabling it, verify it is enabled by viewing the output of the command cat /proc/swaps or free.


2. Extend swap on an existing LVM2 logical volume.
Disable swapping for the associated logical volume:
# swapoff -v /dev/VolGroup00/LogVol01
Resize the LVM2 logical volume by 256 MB:
# lvm lvresize /dev/VolGroup00/LogVol01 -L +256M
 Format the new swap space:
# mkswap /dev/VolGroup00/LogVol01
Enable the extended logical volume:
# swapon -va
Test that the logical volume has been extended properly:
# cat /proc/swaps
# free


3. Creating an LVM2 Logical Volume for Swap. Create the LVM2 logical volume of size 256 MB: #lvm lvcreate VolGroup00 -n LogVol02 -L 256M Format the new swap space: # mkswap /dev/VolGroup00/LogVol02 Add the following entry to the /etc/fstab file: /dev/VolGroup00/LogVol02 swap swap defaults 0 0 Enable the extended logical volume: # swapon –va Test that the logical volume has been extended properly: # cat /proc/swaps

Wednesday, 16 May 2012

Linux Directory structure

A simple description of the UNIX system, also applicable to Linux, is this:

"On a UNIX system, everything is a file; if something is not a file, it is a process."

This statement is true because there are special files that are more than just files (named pipes and sockets, for instance), but to keep things simple, saying that everything is a file is an acceptable generalization. A Linux system, just like UNIX, makes no difference between a file and a directory, since a directory is just a file containing names of other files. Programs, services, texts, images, and so forth, are all files. Input and output devices, and generally all devices, are considered to be files, according to the system.

Unix & Linux File System

 Linux File system

  /Root

  • Every single file and directory starts from the root directory.
  • Only root user has write privilege under this directory.
  • To Remember:  /root is root user’s home directory, which is not same as /.

  /bin – User Binaries

  • Contains binary executables.
  • Commands used by all the users of the system are located here.

/sbin – System Binaries

  • It also contains executables binary.
  • The linux commands located under this directory are used typically by system aministrator, for system maintenance purpose.

 /etc – Configuration Files

  • It contains configuration files required by all programs.
  • This also contains startup and shutdown shell scripts used to start/stop individual programs.
  • For example: /etc/resolv.conf, /etc/logrotate.conf

 /dev – Device Files

  • Contains device files.
  • These include terminal devices, usb, or any device attached to the system.
  • For example: /dev/tty1, /dev/usbmon0

/proc – Process Information

  • Contains information about system process.
  • This is a virtual filesystem with text information about system resources. For example: /proc/uptime

/var – Variable Files

  • This includes — system log files (/var/log); packages and database files (/var/lib); emails (/var/mail); print queues (/var/spool); lock files (/var/lock).

/tmp – Temporary Files

  • Directory that contains temporary files created by system and users.
  • To Remember: Files under this directory are deleted when system is rebooted.

/usr – User Programs

  • Contains binaries, libraries, documentation, and source-code for programs.
  • /usr/lib contains libraries for /usr/bin and /usr/sbin
  • /usr/local contains users programs that you install from source. For example, when you install apache from source, it goes under /usr/local/apache2

 /home – Home Directories

  • Home directories for all users to store their personal files.
  • For example: /home/jack, /home/shiv

/boot – Boot Loader Files

  • Contains boot loader related files.
  • Kernel initrd, vmlinux, grub files are located under /boot
  • For example: initrd.img-2.6.32-24-generic, vmlinuz-2.6.32-24-generic

/lib – System Libraries

  • Contains library files that supports the binaries located under /bin and /sbin

/opt – Optional for Applications

  • add-on applications should be installed under either /opt.

/mnt – Mount Directory

  • Temporary mount directory where sysadmins can mount filesystems.

 /media – Removable Media Devices

  • Temporary mount directory for removable devices.
  • For examples, /media/cdrom for CD-ROM; /media/floppy for floppy drives; /media/cdrecorder for CD writer.

Linux User

How to check all user in linux


Every user who has access to a Linux system needs a login and a password. Each user must belong to a primary group and for security or access purposes can belong to several secondary groups.
In order to create new logins, modify or delete users, you must already be logged in as root.  The root login is the highest level and only certain individuals should have access to the root account.

#useradd shiv

 Options:

  • -d home directory
  • -s starting program (shell)
  • -p password
  • -g (primary group assigned to the users)
  • -G (Other groups the user belongs to)
  • -m (Create the user's home directory

Example: To add a new user with

  • a primary group of users
  • a second group operation
  • starting shell /bin/bash
  • password of xxxx
  • home directory of shiv
  • create home directory
  • a login name of shiv
#useradd –g users –G operation –s /bin/shell –p xxxx –d /home/shiv -m shiv
 

usermod - Modifying existing user

Options:
  • -d home directory
  • -s starting program (shell)
  • -p password
  • -g (primary group assigned to the users)
  • -G (Other groups the user belongs to)

Example: To add the group 'others' to the user shiv

#usermod –G accounts shiv

Userdel : Deleting a user

Options:
  • -r (remove home directory)
Example: To remove the user 'shiv' and his home directory

#userdel -r shiv


passwd : User’s Password


Options:
  • user's name (Only required if you are root and want to change another user's password)
Example: To change the password for the account you are currently logged in as...
passwd
Enter existing password
Enter new password
Enter new password again (to validate)

Example: To change the password for the user 'shiv' (only you are logged in as root)...

#passwd shiv
Enter existing password (can be either roger's password or root's password)
Enter new password
Enter new password again (to validate)


Where user and group information stored

 

User names and primary groups are stored in /etc/passwd. This file can be directly edited using the 'vi' editor, although this is not recommended. Format of the file is...
  • User (name normally all lower case)
  • Password (encrypted - only contains the letter 'x')
  • User ID (a unique number of each user)
  • Primary Group ID
  • Comment (Normally the person's full name)
  • Home directory (normally /home/<user name>
  • Default shell (normally /bin/bash)
Each field is separated by a colon.
Passwords for each user are stored in /etc/shadow. This file should only be changed using the passwd command.
Group information is stored in /etc/group. This file can be directly edited using the 'vi' editor. Format of the file is...
  • Group name
  • Group password (hardly ever used)
  • Group ID
  • User names (separated by commas)
Each field is separated by a colon.
Default files
When a new user is created, the default files and directories that are created are stored in /etc/skel.
This directory can be modified to fit your needs. Modifications only effect new users and does not change anything for existing users.

Su : Switch User

To switch to another user, use the su command. This is most commonly used to switch to the root account.
Example: To switch to root account...
#su
Enter root's passwd
Example: To switch to the user 'roger'...
#su shiv
Enter shiv's or root's passwd
To return to original user, enter exit

 
Design by Wordpress Theme | Bloggerized by Free Blogger Templates | coupon codes