Tuesday, November 1, 2011

Disk managements

Disk Management simple partition

Your Ad Here In this series of article I will demonstrator you necessary disk managements skill for RHCE examinations.
Example Question : -
       Add a new logical partition having size 100MB and create the /data directory which will be the mount point for the new partition.
To accomplish this task you must be login form root account. So first login from root and verify your hard disk status with fdisk –l command ( This command will show that where your hard disk is mounted. You should use the mount point which show in the output of this command. For example if you see /dev/hda then you should use fdisk  /dev/hda in next command. Or if you see /dev/sdb then you should use fdisk  /dev/sdb in next command.
As you can see in image shown below that My hard disk is mounted as /dev/sda so I will use fdisk  /dev/sda)
fdisk linux command
Follow these steps at command prompt in same sequence
n
    press enter
      +100MB
    press enter
        w

#partprobe /dev/sda

fdisk commands is used to create new partitions. partprobe command is used to inform kernel about this change.
Create a /data folder and mount the partition with these commands
mount linux command
lost+found is a partition specific folder that will appear only in those directory that represent an active partitions.

How to mount simple partition permanently

Create a entry for newly created partition in /etc/fstab so that it can be mount automatically after reboot as shown in image
fstab linux file system
Reboot the system with this command
#reboot -f
If you got no error while system boot then run fdisk -l command to verify that partition has successfully mounted.
rhce linux partition
You have effectively accomplished the task given you now its time to remove these partition.
rhce linux fdisk partition
don't forget to remove entry from /etc/fstab files also otherwise you will get error on next boot.
rhce linux fstab

rhce linux fstab file



RHCE Linux lvm partitions

Your Ad Here Form the beginning of RHCE exam RedHat always includes a question about LVM partitions. So you must be able to create the LVM partition and mount them properly in
/etc/fstab

Example of questions

  • One Logical Volume named lv00 is created under vg00. The Initial Size of that Logical Volume is 100MB. Now you required the size 500MB. Make successfully the size of that Logical Volume 500M without losing any data. As well as size should be increased online.
  • One Logical Volume is created named as lv00 under vg00 volume group and is mounted. The Initial Size of that Logical Volume is 124MB. Make successfully that the size of Logical Volume 245MB without losing any data. The size of logical volume 240MB to 255MB will be acceptable.

Explanations of basic definitions

The LVM system organizes hard disks into Logical Volume (LV) groups. Essentially, physical hard disk partitions (or possibly RAID arrays) are set up in a bunch of equal sized chunks known as Physical Extents (PE). As there are several other concepts associated with the LVM system, here we will discuss only some basic definitions those require in rhce:
  • Physical Volume (PV) is the standard partition that you add to the LVM mix. Normally, a physical volume is a standard primary or logical partition. It can also be a RAID array.
  • Physical Extent (PE) is a chunk of disk space. Every PV is divided into a number of equal sized PEs. Every PE in a LV group is the same size. Different LV groups can have different sized PEs.
  • Logical Extent (LE) is also a chunk of disk space. Every LE is mapped to a specific PE.
  • Logical Volume (LV) is composed of a group of LEs. You can mount a filesystem such as /home and /var on an LV.
  • Volume Group (VG) is composed of a group of LVs. It is the organizational group for LVM.

Create lvm partition and resize them

Run fdisk   /dev/sda to invoke fdisk. Make sure your hard disk status via fdisk -l command before it. If you see /dev/hda in the output of fdisk -l command run fdisk  /dev/hda instead of fdisk /dev/sda linux command  fdisk -l
Now run these command in given sequence
n
press enter
+100M

n
press enter
+100M

n
press enter
+100M
linux fdisk command lvm partitons
after creating partition define their file type and save via w command. lvm partitions are denoted as 8e. run these command exactly ( caution:- change only the partition you create )
t
7
8e

t
8
8e

t
9
8e

w
linux lvm file type 8e
Now tell kernel about this change run partprobe command
fdisk -l show partitions
Create physical volume from newly created partition and then we will create a volume group to use these physical volumes.
lvm pvcreate command
Create 2 lvm partition from this volume group
lvm lvcreate
For format you can use either mke2fs with -j switch or just single command mkfs.ext3
I used both command for illustration
mke2fs and mkfs.ext3 command
mke2fs mkfs.ext3 command
now we will define mount point to use this partitions
lvm mount
We can use these partitions until system reboot if you are asked to mount these partition permanently use these steps.
Run vi /etc/fstab
vi /etc/fstab
( fstab :- file contain information about linux partition )
( vi :- editing command if have problem using vi follow this link)
Make entry of newly created lvm partition

/dev/vg00/lv00 /data/lv00 ext3  defaults 0 0
/dev/vg00/lv01 /data/lv01 ext3  defaults 0 0

in the end of files as shown in figure and save the file.
vi /etc/fstab
In this tutorial we learn how to create lvm partition and mount them permanently




Lvm Advance Management Extend Reduce Add Remove

Your Ad Here In our pervious article we learnt how to create lvm partition and mount them permanently in /etc/fstab . If you missed it we suggest reviewing
RHCE Linux lvm partitions
before going with advance lvm management. In this tutorial guide we will learn about advance lvm management. In our pervious article we have created two lvm partitions. Now we will manage them. First we will extend the size of lv00 our first lvm partition.
Check all these partition are functioning properly
Check the current size of lv00
lvdisplay linux command for displaying lvm
As you can see the current size of lv00 is 100MB. To extend it with 50MB space run these commands
lvm extend
Now we will reduce the size of 20MB from lvm partition.
If you have free space in lvm partition no data lose will happen. Lose in data will happen only when partition is full.
lvm reduce
at this moment you should be able to extend and reduce the size of lvm partition now we will remove these partitions
lvremove linux lvm command
don't forget to remove these partitions form /etc/fstab also
/etc/fstab
now use fdisk command to delete these partition form hard disk
#fdisk /dev/sda
fdisk
run partprobe command to tell kernel about change and verify it
lvm
Do these practical of lvm as much as you can as RHCE is performance based exam and none of us will want to retake it. We have summarized all important commands in a single table cram it.
Command Description
partprobe To notify kernel about the change in device
pvcreate To create physical volume
pvdisplay To display the size and other information about physical volume
pvremove To remove the physical volume
pvresize To modify the size of physical volume
pvscan To scan the physical volume
vgextend to extend the size of volume group
vgreduce to reduce the size of volume group
vgscan to scan the volume group for change
vgdisplay to display the status and information about volume group
lvdisplay will display the status of lvm
lvreduce to reduce the size of lvm
lvextend to extend the size of lvm
lvcreate to create the lvm
lvremove to remove the lvm partition
lvscan to scan lvm for change
fdisk -l To show the current partition status of hard disk
fdisk /dev/sda To invoke fdisk utility on /dev/sda
n to create new partition
t to define file types
d to delete partitions
w to save change




Raid partition step by step example and implementations

Your Ad Here A Redundant Array of Independent Disks (RAID) is a series of disks that can save your data even if a terrible failure occurs on one of the disks. While some versions of RAID make complete copies of your data, others use the so-called parity bit to allow your computer to rebuild the data on lost disks
RAID allows an administrator to form an array of several hard drives into one logical drive recognized as one drive by the operating system. It also spreads the data stored over the array of drives to decrease disk access time and accomplish data redundancy. The data redundancy can be used to recover data should one of the hard drives in the array crash.

RAID level 0, or striping,

Means that data is written across all hard drives in the array to accomplish the fast disk performance. No redundancy is used, so the size of the logical RAID drive is equal to the size of all the hard drives in the array. Because there is no redundancy, recovering data from a hard drive crash is not possible through RAID.

RAID level 1, or mirroring,

Means that all data is written to each disk in the array, accomplishing redundancy. The data is “mirrored” on a second drive. This allows for easy recovery should a disk fail. However, it does mean that, for example, if there are two disks in the array, the size for the logical disk is size of the smaller of the two disks because data must be mirrored to the second disk.

RAID level 5

Combines striping and parity. Data is written across all disks as in RAID 0, but parity data is also written to one of the disks. Should a hard drive failure occur, this parity data can be used to recover the data from the failed drive, including while the data is being accessed and the drive is still missing from the array.

RAID level 6

Data is written across all disks as in RAID 5, but two sets of parity data is calculated. Performance is slightly worse than RAID 5 because the extra parity data must be calculated and written to disk. RAID 5 allows for recovery using the parity data if only one drive in the array fails. Because of the dual parity, RAID 6 allows for recovery from the failure of up to two drives in the array.
In real life we never create raid on same hard disk. But its exam and examiner is not going to provide you three spare hard disk so you should be able to create three raid partition on same physical hard disk.
To create raid partition we will use fdisk utility.
Execute fdisk command with -l switch it will show your hard disks mount point

#fdisk -l
now use fdisk commands with proper hard disk options. I am using /dev/sda as you can see in image my hard disk is mounted on /dev/sda. you should the proper hard disk whatever you receive in the output of this commands for example it could be hdd sdb

#fdisk /dev/sda
now create a new partition and assign file type to raid

Command (m for help)n
First cylinder (1543-2610, deaults 1543): press enter
Using deafults value 1543
Last cylender ..............): +100M
linux fdisk commmad create new raid partitions
Now create two more partition repeating the same process don't forget to save with w commands.
linux raid partitions
Inform kernel about this change by partprobe commands and verify with fdisk -l commands

fdisk -l linux commands
Okey now you have 3 raid partitions and Linux will treat these partition same as three physical hard disks. You can create raid device with these partitions
Create raid 5 device with these partitions
create raid devices
Now format this newly created md0 raid device
mke2fs linux commands
To use this device you must have specify mount point. we are going to use this raid device on /data directory. So create a /data directory and mount md0 on it
mount Linux commands
This way will mount temporary. To permanently mount make its entry in /etc/fstab file
fstab Linux files
At this point you have successfully created a raid device md0 and permanently mounted it on /data.




Raid partition step by step example and implementations Part-II

Your Ad Here In our last article we created a raid device md0 from three hard disk partition. In this article we show you that how can you manage a raid device. This guide is the second part of our tutorial on raid devices if you have missed first part then read its first.
First verify all raid partition which we created in our pervious article are working properly and in active state.

#mdadm --detail /dev/md0

mdadm Linux commands
Alternately you can also use cat /proc/mdstat command to see run time status of raid device
raid devices linux
raid devices are mainly used for data backup. Data will be safe even if any hard disk get fail from raid devices. To test it first copy some data in /data directory which is the mount point of md0 raid devices.

#cp * /data
#ls /data
Now assume that one hard disk form raid device gets fail. This can be done by mdadm command with --fail options. Verify data it should be safe
mdam --fail
you can verify fail device status via mdadm commands with -- detail switch also

mdadm --detail
run time process can be checked via cat /proc/mdstat commands
cat /proc/mdstat
At this point you should have understand what exactly raid device do?. raid device keep your data safe even if hard disk got crashed. its give you enough time to replace faulty hard disk without losing data.
Now remove faulty devices.[ Note:- you must have to set fail status before removing it form raid devices ]
mdadm --remove
now replace faulty hard disk with good one. To add new disk in raid devices use --add options with mdadm commands
mdadm --add
Congratulations you have successful created raid device and changed faulty hard disk. We suggest you to clean these partition before doing further particular.

How to remove raid devices

First un-mount the raid partitions from /data directory
umount /data
Now stop /md0 devices and remove it form mdadm commands
mdadm --remove
Now remove entry form /etc/fstab
vi /etc/fstab
file /etc/fstab
use fdisk command to remove raid partition form hard disk
fdisk command with d options




Swap partition step by step example and implementations

Your Ad Here Linux uses the swap space configured on one or more hard drive partitions to store infrequently used programs and data. Swap space can extend the amount of effective RAM on your system.
However, if you don't have enough actual RAM, Linux may use the swap space on your hard drive as virtual memory for currently running programs. But you can't just buy extra RAM and eliminate swap space. Linux moves infrequently used programs and data to swap space even if you have gigabytes of RAM.
Normally, Linux (on a 32-bit Intel-style computer) can use a maximum 4GB of swap space in partitions no larger than 2GB. This 4GB can be spread over a maximum of eight partitions. The typical rule of thumb suggests that swap space should be two times the amount of RAM. For example if you have 1 GB of physical ram then need 2GB space for swap.
Generally Linux create swap during installation but for exam prospective you should be able to create it after installation. There are two method for it via fdisk utility of file method. We will create swap via both method.

Create Swap partition

To accomplish this task you must be login form root account. So first login from root and verify your hard disk status with fdisk –l command ( This command will show that where your hard disk is mounted. You should use the mount point which show in the output of this command. For example if you see /dev/hda then you should use fdisk  /dev/hda in next command. Or if you see /dev/sdb then you should use fdisk  /dev/sdb in next command.
As you can see in image shown below that My hard disk is mounted as /dev/sda so I will use fdisk  /dev/sda)
fdisk linux command
file type of swap space is 82 so change file type to 82 of this newly created partition and save and exit from fdisk with w options. Run partprobe command to update kernel
change file to swap
verify with fdisk -l command that partition is successfully created
fdisk commands
now format swap partition and on it
mkswap swapon
To permanently mount this partition makes its entry in /etc/fstab as shown in image
#vi /etc/fstab
fstab with swap partition

Create swap from file method

To use file method for swap space create a blank file of 100MB
touch
Now format this file with mkswap and on this swap space. To keep it on after reboot make its entry to rc.local file
mkswap swapon
editing in rclocal
You have created swap space with both method you can verify its run time status in /proc file system
proc swap

To remove these partition and files

  • Turn off swap space with swapoff command
  • Remove entry from rc.local
  • Remove entry from /etc/fstab
  • Reboot system

RHCE Linux Disk Quota Implementation

Your Ad Here Disk quotas are commonly used by ISPs, by Web hosting companies, on FTP sites, and on corporate file servers to ensure continued availability of their systems.
Quotas are used to limit a users or a group of users ability to consume disk space. This prevents a small group of users from monopolizing disk capacity and potentially interfering with other users or the entire system.
Without quotas, one or more users can upload files on an FTP server to the point of filling a file system. Once the affected partition is full, other users are effectively denied upload access to the disk. This is also a reason to mount different file system directories on different partitions. For example, if you only had partitions for your root (/) directory and swap space, someone uploading to your computer could fill up all of the space in your root directory (/). Without at least a little free space in the root directory (/), your system could become unstable or even crash.
You have two ways to set quotas for users. You can limit users by inodes or by kilobyte-sized disk blocks. Every Linux file requires an inode. Therefore, you can limit users by the number of files or by absolute space. You can set up different quotas for different file systems. For example, you can set different quotas for users on the /home and /tmp directories if they are mounted on their own partitions. Limits on disk blocks restrict the amount of disk space available to a user on your system. Older versions of Red Hat Linux included LinuxConf, which included a graphical tool to configure quotas. Red Hat no longer has a graphical quota configuration tool. Today, you can configure quotas on RHEL only through the command line interface.
Lets look few basic terms used for implementation of disk quota
  • Soft limit
    This is the maximum amount of space a user can have on that partition. If you have set a grace period, this will act as an alarm. The user will then be notified she is in quota violation. If you have set a grace period, you will also need to set a hard limit. A grace period is the number of days a user is allowed to be above the given quota. After the grace period is over, the user must get under the soft limit to continue. By default grace period have seven days limits.
  • Hard limit
    Hard limits are necessary only when you are using grace periods. If grace periods are enabled, this will be the absolute limit a user can use. Any attempt to consume resources beyond this limit will be denied. If you are not using grace periods, the soft limit is the maximum amount of available space for each user.
  • Grace Periods
    Linux has provided the default of seven days for both inodes and block usage. That is, a user may exceed the soft limit on either resource for up to seven days. After that, further requests by that user to use files will be denied.
Reference Table
Soft Limit Disk space a user can use
Hard limit Absolute limit a user can use
Grace Periods Time duration till user can use hard limit space
1 inode 1 KB
dd used to create a blank file of specific size
required RPM quota-3.13-1.2.3.2.el5
/etc/fstab options usrquota, grpquota
Quota files aquota.user, aquota.group
Necessary command mount, quotaon, quotacheck, edquota, quotaoff

Quota Tools

Quota checks can be implemented on the file system of a hard disk partition mounted on your system. The quotas are enabled using the quotacheck and quotaon programs. They are executed in the /etc/rc.d/rc.sysinit script, which is run whenever you start up your system. Each partition needs to be mounted with the quota options, usrquota or grpquota. usrquota enables quota controls for users, and grpquota works for groups.
You also need to create quota.user and quota.group files for each partition for which you enable quotas. These are the quota databases that hold the quota information for each user and group. You can create these files by running the quotacheck command with the -a option or the device name of the file system where you want to enable quotas.

edquota

You can set disk quotas using the edquota command. With it, you can access the quota record for a particular user and group, which is maintained in the disk quota database. You can also set default quotas that will be applied to any user or group on the file system for which quotas have not been set. edquota will open the record in your default editor, and you can use your editor to make any changes. To open the record for a particular user, use the -u option and the username as an argument for edquota

quotacheck, quotaon, and quotaoff

The quota records are maintained in the quota database for that partition. Each partition that has quotas enabled has its own quota database. You can check the validity of your quota database with the quotacheck command. You can turn quotas on and off using the quotaon and quotaoff commands. When you start up your system, quotacheck is run to check the quota databases, and then quotaon is run to turn on quotas.

repquota

As the system administrator, you can use the repquota command to generate a summary of disk usage for a specified file system, checking to see what users are approaching or exceeding quota limits. repquota takes as its argument the file system to check; the -a option checks all file systems.



Disk Quota Implementation RHCE Linux

Your Ad Here In our pervious article we learn about basic necessary concept used for disk quota implementation. Now we will first look at the outline of question that may be asked in RHCE exam.
Example 1
Quota is implemented on /home but not working properly. Find out the Problem and implement the quota to vinita to have a soft limit 50 inodes (files) and hard limit of 100 inodes (files).
Example 2
vinita user tried by:
dd if=/dev/zero of=/home/vinita/test bs=1024 count=50
files created successfully. Again vinita tried to create file having 100k using following command:
dd if=/dev/zero of=/home/vinita/test1 bs=1024 count=100
But she is unable to create the file. Make the user can create the file less then 100K.

Solutions

Example 2 is extremely complicated question from Redhat. Actually question is giving scenario to you to implement quota to vinita user. You should apply the quota to vinita user on /home that vinita user shouldn’t occupied space more than 100K.
To solve disk quota question follow these guides
Check the quota RPM (installed by default)
disk quota rpm
Now open /etc/fstab file to enable quota entry

/etc/fstab
You can tell Linux to start tracking user quotas by adding the keyword usrquota under the options column. Similarly, you can tell Linux to start tracking group quotas with the grpquota option.
I add both user and group quotas to the /home directory filesystem
/etc/fstab
Either Reboot the System or remount the partition and verify it
 remount home partition
The next step is to create quota files. For user and group quotas, you will need the aquota.user and aquota.group files in the selected filesystem before you can activate actual quotas.
You can do it either manually or the appropriate quotacheck command creates them automatically.
For the /home directory described earlier, you would use the following commands:
# mount -o remount /home
# quotacheck -cugm /home
The options for quotacheck are
  • -c Performs a new scan.
  • -v Performs a verbose scan.
  • -u Scans for user quotas.
  • -g Scans for group quotas.
  • -m Remounts the scanned filesystem.
This will check the current quota information for all users, groups, and partitions. It stores this information in the appropriate quota partitions. Once the command is run, you should be able to find the aquota.user and aquota.group files in the configured directory.

or you can create these files manually
#touch /home/aquota.group
#touch /home/aquota.user
aquota.group aquota.user files
On this quota by quotaon command and create an example user named vinita. use edquota command to set quota on vinita user.
edquota command will edits the aquota.user or aquota.group file with the vi editor. In our example, we have a user named vinita, and we want to restrict how much disk space she is allowed to use.
Set softlink to 50 and 100 to hard link

You can also set grace period for user ( set only if you are asked by examiner)

We will change default 7 days grace period to 10 days.


Remount the partition and verify it
 remount home partition
Verify that you have successfully implemented disk quota

Now login from vinita
When testing quotas, there is one useful technique that creates a blank file of the desired size. For example, if you want to create a 100MB file named test in the local directory, run this command
dd if=/dev/zero of=test bs=1k count=100000 .
impletementing disk quota
When user vinita run dd command first time to create a blank file more then 50 Mb she got an warning and the file was created. As she is allowed to exceed her soft limit for 10 days.
Second time she tried to create a file of 500 Mb. As you can see in image she was able only to create a file of 20 Mb. As she can not exceed her hard limit that is set to 100 inode.
In third time she is denied to use any more space as she have already crossed her hard limit.
You can verify the space of created file by du command with -h options.
After successfully completing your practical remove quota entry /etc/fstab

Now turn off quota by quotaoff command and remount home partition for further practical

No comments:

Post a Comment