Honore With His Spouce IGA KUBUNTU! OWNER. BLOG SITE. This is My Child FUTURE COMPUTER TECHNOLOGY
blogger JavaScript Rocks.

Friday, 7 June 2013

redhat skills

Useful commands to check file system status

In RHEL6 several commands are available for file system managements. In this article we would discuss only those commands which you may need in RHCE6 exams. Before you start practice of creating and deleting partition it is better to do some practice with these commands.

df

This is handy command to check available free space. Run du command
df command
If you feel difficulty in understanding the blocks use -h switch with du command
df command with h switch
Now outputs of du command look more users friendly. You could skip tmpfs and /dev/sr0 as tmpfs stand for temporary space and /dev/sr0 is my media device. This output is very useful when you need to manage disk. You could get an idea about which partition need more space or which partition is has unused free space. Linux LVM gives you an ability to change partition size without losing any data. With LVM you could reduce the size of partition which has unnecessary free space or you could expand the size of partition which requires more space. du command is very helpful when you need to make such a decision. As output of this command show size of my root partition is 7.7G and currently I am using 2.3G and available free space is 5.1G which is fine. Currently none of my partition requires more space. During the practice of LVM we would use this more frequently.

du

This is useful command to check the size of file. While df commands show the available space in partitions, du commands show the size of files in partitions. you could use df command to check the space used by each partitions. if you need more detail about any specific partition like which file is consuming more space then you could use du command.
For example we would like to know
how much space is used by /boot partition?
how much space is available in /boot partition?
what is the size of each files and directories in /boot partition?
To get the answer of these questions we would first execute df command with -h switch. It would gives us the answer of first and second question. To know the answer of third question use du command with -h switch.
df with du
You may get confuse from output. As df commands show boot partition is using 27 MB while du command is showing that /boot is using 21 MB so where is remaining 6 MB space?. This space is used by hidden files. You could use du command with -a switch to show the hidden files.
du command with a switch

mount

mount is the another helpful command. During the practice we would create and format partitions. mount command would show the file system type of partition. and it also help to know to the type of mount.
mount command


fdisk utility

fdisk is available in all major operating system including Microsoft window and Mac Os. But we would discuss only linux version of fdisk. With fdisk utility you could create update and delete partitions. In this article we would explorer the fdisk command options. Later in this section we would use fdisk command to manage partitions.

Explore fdisk command options

How to check available switch of fdisk command
To check available switch with fdisk command run fdisk command without any switch
fdisk without switch
How to check available disk and partitions with fdisk command
To check available disk and partitions on file system use -l switch with fdisk command
fdisk with l switch
output show currently we have five partitions on /dev/sda disk. To manage disk with fdisk command we need to pass disk location as argument . Whenever you start working with fdisk command, fdisk -l command should be first on list. It would give you location of disk which is need by fdisk command.
Now we have mount point of disk so we could start fdisk command.
To start fdisk command pass mount point of disk as argument
fdisk command with disk arg
as you could see in output you would get a warning message. Whether you made recommended change or not result would be same. In exam we should focus on result. So simple ignore it. Whether or not recommended changes are made, fdisk provides the same prompt, where you can press m to list basic fdisk commands.
press m on fdisk command prompt to get the list of all available commands
fdisk command m help
During the exam never hesitate to take help. You should use all available resources. We use fdisk in next article so press q to quite form fdisk.


fdisk command q switch

how to create partition using fdisk

In this article we would use fdisk to create and manage partition. This article assumes that you have a new hard disk (or at least empty space on a current hard drive where you can add a new partition).

Simulated RHCE exam question

create a new partition of 100 MB using fdisk, format it with ext4 filesystem, and configure it on the /test1 directory in /etc/fstab so that the new partition is properly mounted the next time you boot Linux.
As you have learnt from previous article fdisk command need hard disk mount point as argument. Check hard disk mount point
fdisk with l switch
Start fdisk command.
fdisk start
At the fdisk command line prompt, start with the print command (p) to print the partition table. This allows you to review the current entries in the partition table. As discuss in previous article it is not necessary to switch off DOS mode. So it is up to you whether you want to follow the recommendations or not. If you want to follow the recommendations execute following command or if you want to ignore the recommendation skip this
fdisk p c u switch
you could have up to four primary partitions, which would correspond to numbers 1 through 4. If you need more partitions you could redesignated one partition as an extended partition. after redesignated you could create logical partitions form extended partition. fdisk now supports the creation of more than 16 partitions on a drive. The remaining partitions are logical partitions, numbered 5 and above.
To create new partition type n press enter
If free space is available, fdisk normally starts the new partition at the first available sector or cylinder. The actual size of the partition depends on disk geometry. Press enter of First cylinder line
fdisk n
give the size of partition. Keep notice of format size. it is a + sign followed by size . K = Kilobyte M = Megabyte, G= Gigabyte . We want to create 100MB partition so give +100MB and press enter
fdisk last line
to save and exit type w and press enter
You may get temporary fail error if another partition on that drive has been formatted and mounted.
fdisk w save
From command prompt you could try with partprobe command if linux is able to unmount existing partition it would return with success or if it is failed it would return with busy error message.
partprobe command
If you got failed message reboot system to take effect.
reboot with f switch
After reboot login back with root and use fdisk command with -l switch
fdisk with l after reboot
We have successfully created new partition /dev/sda6 but we would not be able to use it. Because it does not contains any filesystem. To make it useable we need to format it first. ext3 was the default filesystem of RHEL5. From RHEL6 ext4 is the default filesystem. with ext4 means that filesystems can be as large as 1 exabyte (EB). with ext3 it was just 16 terabytes (TB). The ext4 filesystem reduces fragmentation, guarantees space for files, supports faster checks, and more. It even supports file timestamps in nanoseconds. it is proven technology. Given its speed and reliability, Red Hat even uses ext4 as the default filesystem for partitions dedicated to the /boot directory. you can format it to the ext4 filesystem using one of the following commands
# mkfs -t ext4 /dev/sda6
# mke2fs -t ext4 /dev/sda6
# mkfs.ext4 /dev/sda6
mkfs format partition
Now create a mount point as given in question
mkdir test
mount partition and test it. lost+found is a special directory and it automatically created on mount point of any partition.
mount and check partition
linux maintain filesystem information in /etc/fstab take its backup first
fdisk cp
to mount this partition permanently open /etc/fstab
vi etc fstab
make a entry for this partition in end of file
/dev/sda6 /test ext4 defaults 0 0
entry in fstab
to test reboot system and check mounted partition
after reboot check partition
Now we have created and mounted partition. You could use it.

how to delete partition from fdisk command

In our previous article we have created a simple partition of 100MB using fdisk command. Now in this article I would show you how you could delete partition using fdisk command.
Use mount command to locate mount point of partition.
mount
As output show our newly created partition /dev/sda6 is mounted on /test. Before we remove any partition we need to unmount it. Use umount command to unmount it.
unmount
Now run fdisk command
start fdisk
use p at fdisk command prompt to print current file system
fdisk p
We want to delete /dev/sda6 partition use d at command prompt
fdisk d
Now give partition number which we want to delete in our case it would 6
fdisk partition number
Use w at command prompt
fdisk w
As we have discussed in our previous article if kernel is unable to unmount the partition; it would return with error code 16. It require a reboot to locate new partition table. We should remove entry from fstab before do reboot. open /etc/fstab
vi fstab
remove entry from fstab
fstab with partition entry
after removing entry from fstab save file and quite.
fstab removed
now reboot the system
reboot with f
after restart check the status of mount point. As you have learnt from our previous article that if a partition is mounted on any directory, it would contain lost + found folder.






check after restart


how to create swap partition

RHEL use swap space as overflow for RAM. For rhce6 exam you could be able to create new swap space. In this article I would create swap space using fdisk command. In previous article you have learnt how to create partitions with fdisk, just one additional step is required to set up that partition for swap space. Before you start make use sure you have enough free and unparted space to create new partition.
Simulator Exam Question:- Check currently configured swap space. And add additional 100MB space to swap. And verify that it is successfully added.

Create partition for swap space

Start fdisk command.
fdisk start
To create new partition type n press enter
If free space is available, fdisk normally starts the new partition at the first available sector or cylinder. The actual size of the partition depends on disk geometry. Press enter of First cylinder line
fdisk n
give the size of partition. Keep notice of format size. it is a + sign followed by size . K = Kilobyte M = Megabyte, G= Gigabyte . We want to create 100MB partition so give +100MB and press enter
fdisk last line
we need to change file type of partition, otherwise fdisk would make it ext4 which is default filesystem for rhel6
type l at command prompt
fdisk type l
it would list all available file type
fdisk available type
type t at command prompt
fdisk t
as output of l command show the partition ID for swap is 82 so we need to change file type to 82. First press the number of our partition and then type the partition ID for swap partition
fdisk change type 82
now save with w command
fdisk w create partiton

If you did not get error code 16 it means kernel has written new partition table. you could run partprobe command, which would reflect the new change. As we get error code 16, it means kernel could not write new partition table we need to do restart to locate the change in partition table. reboot the systemreboot with f switch
After reboot we need to format swap partition. swap volumes are formatted with the mkswap command. format swap partition
mkswap
activate with the swapon command
swapon
If the new swap volume is recognized, you would see it in the /proc/swaps file
check swap before reboot
to make it available after reboot open /etc/fstab
vi etc fstab
at end of the file
fstab with swap entry
add a line for swap and save it
to check it restart the system
reboot with f switch
after reboot verify that our swap is on and working properly
check swap after reboot
As output show our swap volume is mounted and working properly

what is lvm

Logical volume management provides a higher−level view of the disk storage on a computer system than the traditional view of disks and partitions. This gives the system administrator much more flexibility in allocating storage to applications and users.The logical volume manager also allows management of storage volumes in user−defined groups, allowing the system administrator to deal with sensibly named volume groups such as "development" and "sales" rather than physical disk names such as "sda" and "sdb".

Advantage of Logical Volume Management

One of the difficult decisions facing a new user installing Linux for the first time is how to partition the disk drive. The need to estimate just how much space is likely to be needed for system files and user files makes the installation more complex than is necessary and some users simply opt to put all their data into one large partition in an attempt to avoid the issue.
Once the user has guessed how much space is needed for /home /usr / (or has let the installation program do it) then is quite common for one of these partitions to fill up even if there is plenty of disk space in one of the other partitions.
With logical volume management, the whole disk would be allocated to a single volume group and logical volumes created to hold the / /usr and /home file systems. If, for example the /home logical volume later filled up but there was still space available on /usr then it would be possible to shrink /usr by a few megabytes and reallocate that space to /home.
Another alternative would be to allocate minimal amounts of space for each logical volume and leave some of the disk unallocated. Then, when the partitions start to fill up, they can be expanded as necessary.
LVM allows administrators to divide hard drive space into physical volumes (PV), which can then be combined into logical volume groups (VG), which are then divided into logical volumes (LV) on which the filesystem and mount point are created.
what is lvm
As shown in image because a logical volume group can include more than one physical volume, a mount point can include more than one physical hard drive, meaning the largest mount point can be larger than the biggest hard drive in the set. These logical volumes can be resized later if more disk space is needed for a particular mount point. After the mount points are created on logical volumes, a filesystem must be created on them.
LVM is used by default during installation for all mount points except the /boot partition, which cannot exist on a logical volume. But you could create LVM after the installation. In our next article I would show you how to create and update LVM in


how to secure data with luks

In linux world security is the top priority. Best way to secure the data is encryption. RHEL use LUKS (Linux Unified Key Setup) for encryption. Encryption with LUKS works on a block level. If a hard disk encrypted with LKUS is lost, data within is at least more secure as LUKS protected data require a passphrase to access it.  You could enable encryption during the installation or after the installation. From RHCE6 question about LUKS is added in exam. In this article I would show you both methods.

Encryption during the installation

Best way to prepare a LUKS-encrypted volume is during the installation process. Entire system can be encrypted easily during the installation.
luks during installation
To encrypt a volume during the installation check the encrypt check box and you are done.

Encryption after the installation

In RHCSA requirement :- you need to know how to create, configure, mount, and unmount LUKS-encrypted filesystems.
As configuration of LUKS is added RHCSA exam objective. You should also learn how to configure LUKS after installation.
Pre quest for LUKS
  • dm_crypt modules
  • cryptsetup-luks rpm
  • /test test partition for practice
LUKS require dm_crypt modules and cryptsetup-luks rpm.
Check dm_crypt modules. dm_crypt module is installed as part of the baseline RHEL 6 kernel package. run lsmod | grep dm_crypt command. You should get following output
dm_crypt    12860   0
dm_mod      76856   dm_crypt,dm_mirror,dm_log
 
if you do not get this output run # modprobe dm_cryptmodules
Now check rpm cryptsetup-luks
rpm
Before creating an encrypted filesystem, you need a partition. You could use logical volume or even more advance raid array for this but for exam purpose you should practice with regular partition. Create a simple partition of 100MB using fdisk.
create partition

after reboot fill the newly created partition with random data. don't do it on an exam unless you're specifically asked to do so. Because it take time and in exam time is everything.dd
Now set up the passphrase for the filesystem with cryptsetup command You would be prompted for confirmation and a passphrase.
The passphrases that you type in are not shown at the console. If you type in yes in lowercase, the command does not prompt for a passphrase, and the volume is not encrypted.
cryptsetup
Now that we have encrypted the partition, we would open it and give it a label. The label is the name that it will show up as under /dev/mapper/
Once the partition is setup and luks encrypted, it will be available in the /dev/mapper/ directory. You can do an ls on the /dev/mapper/ directory to confirm it
ls dev mapper
To make it writable we need to create a filesystem, So format it
mkfs secure data
Now we need to make its entry in /etc/crypttab and in /etc/fstab so be available even after restart.
open /etc/crypttab
vi crypttab
In the /etc/crypttab file you would simply place the name of the encrypted device, as well as the path to the device:
secure_data     /dev/sda6
entry in crypttab
save and exit from /etc/crypttab file
cat crypttab
now create mount point and make its entry in  the /etc/fstab file in order to configure automounting on boot
mkdir open fstab

Add the following in end of file:
/dev/mapper/secure_data    /secure_data     ext4    defaults    0 0
fstab with entryThats it. You should run the mount command in order to verify your entries are correct in fstab, to prevent any boot issues.
mount check before restart
Now when you reboot the system it would ask for passphrases type the passphrases to unlock the partition, try first entering some worng passphrases
prompt for password after restart
you could only be able to access secured partition by entering correct passphrases, after entering correct passphrases check the partition
check partition
Ok you have successfully implemented LUKS. Now it’s time to remove it. open /etc/fstab
vi etc fstab
and remove the entry
fstab withput swap entry
now remove entry from /etc/crypttab
check removed entry from crypttab
now delete it from fdisk command
fdisk remove partition
after reboot confirm that we have removed LUKS
check remove partition
repeat this process until you feel comfort with LUKS.








0 comments:

Post a Comment