Useful commands to check file system status
df
This is handy command to check available free space. Run du commandIf you feel difficulty in understanding the blocks use -h switch with du command
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.
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.
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.fdisk utility
Explore fdisk command options
How to check available switch of fdisk commandTo check available switch with fdisk command run fdisk command without any switch
To check available disk and partitions on file system use -l switch with fdisk command
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
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
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.
how to create partition using fdisk
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
Start fdisk command.
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
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
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
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.
If you got failed message reboot system to take effect.
After reboot login back with root and use fdisk command with -l switch
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
mount partition and test it. lost+found is a special directory and it automatically created on mount point of any partition.
linux maintain filesystem information in /etc/fstab take its backup first
to mount this partition permanently open /etc/fstab
make a entry for this partition in end of file
/dev/sda6 /test ext4 defaults 0 0
to test reboot system and check mounted partition
Now we have created and mounted partition. You could use it.
how to delete partition from fdisk command
Use mount command to locate mount point of partition.
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.
Now run fdisk command
use p at fdisk command prompt to print current file system
We want to delete /dev/sda6 partition use d at command prompt
Now give partition number which we want to delete in our case it would 6
Use w at command prompt
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
remove entry from fstab
now reboot the system
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.
how to create swap 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.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
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
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
it would list all available file type
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
now save with w command
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 system
After reboot we need to format swap partition. swap volumes are formatted with the mkswap command. format swap partition
activate with the swapon command
If the new swap volume is recognized, you would see it in the /proc/swaps file
to make it available after reboot open /etc/fstab
at end of the file
add a line for swap and save it
to check it restart the system
after reboot verify that our swap is on and working properly
As output show our swap volume is mounted and working properly
what is lvm
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.
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.
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
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.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
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
Now check rpm cryptsetup-luks
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.
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.
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.
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
To make it writable we need to create a filesystem, So format it
Now we need to make its entry in /etc/crypttab and in /etc/fstab so be available even after restart.
open /etc/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
save and exit from /etc/crypttab file
now create mount point and make its entry in the /etc/fstab file in order to configure automounting on boot
Add the following in end of file:
/dev/mapper/secure_data /secure_data ext4 defaults 0 0
Now when you reboot the system it would ask for passphrases type the passphrases to unlock the partition, try first entering some worng passphrases
you could only be able to access secured partition by entering correct passphrases, after entering correct passphrases check the partition
Ok you have successfully implemented LUKS. Now it’s time to remove it. open /etc/fstab
and remove the entry
now remove entry from /etc/crypttab
now delete it from fdisk command
after reboot confirm that we have removed LUKS
repeat this process until you feel comfort with LUKS.
0 comments:
Post a Comment