Search This Blog

Wednesday 17 April 2019

Managing Partitions and File Systems



1.  What is partition?
A partition is a contiguous set of blocks on a drive that are treated as independent disk.

2. What is partitioning?
Partitioning means to divide a single hard drive into many logical drives.

Why we have multiple partitions?
Encapsulate our data.
Since file system corruption is limited to that partition only.
So we can save our data from accidents.
We can increase the disk space efficiency
. Depending on our usage we can format the partition with different block sizes.
So we can reduce the wastage of the disk.
We can limit the data growth by assigning the disk quotas.

4. What is the structure of the disk partition?
The first sector of the O/S disk contains the MBR (Master Boot Record).
The MBR is divided into 3 parts and it's size is 512 bytes.
 The first part is IPL (Initial Program Loader)
        Secondary Boot Loader. So, IPL  is responsible for booting the O/S and it's size is 446 bytes
 The second part is PTI (Partition Table Information).
 It contains the number of partitions on the disk, sizes of the partitions and type of the partitions
.
5   Explain the disk partition criteria?
Every disk can have max. 4 partitions.
The 4 partitions are 3 Primary partitions and 1 Extended partition.
The MBR and O/S will install in Primary partition only. The Extended partition is a special partition and can be further divided into multiple logical partitions.

6. How to identify the disks?
In Linux different types of disks will be identified by different naming conventions.
IDE) drives will be shown as /dev/hda, /dev/hdb, /dev/hdc, ...etc.,  and the partitions are /dev/hda1,  /dev/hda2, /dev/hda3, ...etc.
iSCSI/SCSI  and SATA drives will be shown as /dev/sda, /dev/sdb, /dev/sdc, ...etc.,  and the partitions are /dev/sda1, /dev/sda2, /dev/sda3, ...etc.,
Virtual drives will be shown as /dev/vda, /dev/vdb, /dev/vdc, ...etc.,  and the partitions are /dev/vda1, /dev/vda2, /dev/vda3, ...etc.,
IDE  ----->  Integrated Drive Electronics.
iSCSI  ----->  Internet Small  Scale System Interface.
SCSI  ----->  Small Scale System Interface.

7.What is file system?
It is a method of storing the data in an organized fashion on the disk. Every partition on the disk except MBR and Extended partition should be assigned with some file system in order to make them to store the data. File system is applied on the partition by formatting it with a particular type of file system.

8. What are the different types of file systems supported in Linux?
The Linux supported file systems are ext2, ext3, ext4, xfs, vfat, cdfs, hdfs, iso9660 ...etc.,
The ext2, ext3, ext4 file systems are widely used in RHEL-6 and xfs file system is introduced on RHEL-7.
The vfat file system is used to maintain a common storage between Linux and Windows O/S.
The cdfs file system is used to mount the CD-ROMs and the hdfs file system is used to mount DVDs.
The iso9660 file system is used to read CD/DVD.iso image format files in Linux O/S.




9. How to create different types of partitions?
# fdisk -l
# fdisk /dev/sdc
Command (m for help) : n               (type n for new partition)
(p - primary) or e - extended) : p               (type p for primary partition or type e for extended                                                                                        partition)
First cylinder :  (press Enter for default first cylinder)
Last cylinder :  + <size in KB/MB/GB/TB>
Command (m for help) : t         (type   t   to change the partition id)
 (for example:    8e for Linux LVM,   82  for Linux Swap   and  83  for  Linux normal partition)
Command (m for help) : w        (type   w   tosave the changes into the disk)
# partprobe /partx  -a/kpartx   /dev/sdc1       (to update the partitioning information in partition table)

10. How to make a file system in Linux?
# mkfs.ext2/ext3/ext4/xfs/vfat <device name> ( for example/dev/sdc1)

11. How to mount the file systems temporarily or permanently?
# mkdir /mnt/oracle
# mount /dev/sdc1  /mnt/oracle   (temporary mount)
# vim /etc/fstab
          /dev/sdc1 /mnt/oracle        xfs defaults 0 0
Esc+:+wq!
# mount   -a  (permanent mount)

12. How to delete the partition?
# fdisk  /dev/sdc
Command (m for help) :d          (type   d   for delete the partition)
Partition number :  (specify the partition number)
Command (m for help) : w      (type   w   to write the changes into disk)
# partprobe/partx  -a/kpartx   /dev/sdc1(to update the partition table without restarting the system)
13. What is mounting and in how many types can we mount the partitions?
Attaching a parititon to a directory under root is known as mounting.
There two types of mountings in Linux/Unix.
Temporary Mounting :
In a temporary mounting first we create a directory and mount the partition on that directory. But this type mounting will last only till the system is up and once it is rebooted the mounting will be lost.
Example:# mount   <options><device name><directory name (mount point)>
Permanent Mounting :
In this also first we create the directory and open the /etc/fstab file and make an entry as below,
<device name><mount point><file system type><mount options><take a backup or not><fsck value>
Whenever the system  reboots mount the partitions according to entries in /etc/fstab file. So, these type of mountings are permanently even after the system is rebooted.
# mount   -a          to mount the partitions without reboot)

14. What are differences between the ext2, ext3, ext4 and xfs file systems?

S.No. Ext2 Ext3 Ext4  
1. Stands for Second Extended file system.
        Stands for Third Extended file system.
        Stands for Fourth Extended file system.  
2. Does not having Journaling feature.
       Supports Journaling feature.
       Supports Journaling feature.  
3. Max. file size can be from 16 GB to 2 TB.
        Max. file size can be from 16 GB to 2 TB.
        Max. file size can be from 16 GB to 16 TB.  
4. Max. file system size can be from 2 TB to 32 TB
        Max. file system size can be from 2 TB to 32 TB
        Max. file system size can be from 2 TB to 1 EB
                                                                         *1EB = 1024 Peta bytes.


15. Which files are related to mounting in Linux?
/etc/mtab  ---->  is a file which stores the information of all the currently mounted file systems and                                 this file is    dynamic  and keep on changing.
/etc/fstab  ---->  is keeping information about the permanent mount points. If we want to make our                                mount point  permanent then make an entry about the mount point in this file.
/etc/fstab  entries are:
       1         2 3             4      5 6
device name     mount point       F/S type mount options Dump                    FSCK

16. The partitions are not mounting even though there are entries in /etc/fstab. How to solve this problem?
First check any wrong entries are there in /etc/fstab file. If all are ok then unmount all the                    partitions by executing the below command,
# umount    -a
Then mount again mount all the partitions by executing the below command,
# mount   -a
17. When trying to unmounting it is not unmounting, how to troubleshoot this one?
Some times directory reflects error while unmounting because,
(i) you are in the same directory and trying to unmount it, check with # pwdcommand.
(ii) some users are present or accessing the same directory and using the contents in it, check this with
# fuser -cu  <device name>       (to check the users who are accessing that partition)
# lsof  <device name>     (to check the files which are open in that mount point)
# fuser   -ck   <opened file name with path>      (to kill that opened files)
Now we can unmount that partition using   # umount     <mount point>

18. How to see the usage information of mounted partitions?
# df   -hT       (to see device name, file system type, size, used, available size, use% and mount point)

19. How to see the size of the file or directory?
# du   -h   <filename or directory  name>     (to see the size of the in that directory)
# du   -h       (to see all the file sizes which are located in the present working directory)
# du  .| sort  -nr | head  -n10      (to see the biggest files from current location)
# du  -s * | sort  -nr | head  -n10     (to see the biggest directories from that partition)
# ncdu     (to list biggest files and directories, we have to install the ncdu package  before executing                      this)

20. How to assign a label to the partition?
# e2label   <device name or partition name><label name>      (to assign the label to that                                                                                                                              partition)
Example :    # e2label  /dev/sdb1  oradisk      (to assign oradisk label to /dev/sdb1 partition)
# mount   -l       (to list all the mounted partitions along with their labels)

21. How to mount a partition temporarily or permanently using label?
# mount   LABEL=<label name><mount point>
ex :  # mount   LABEL=oradisk     /mnt/oracle    (to mount the oradisk label on /mnt/oracle directory)
# vim  /etc/fstab
LABEL=oradisk /mnt/oracle ext4 defaults 0 0
Esc+:+wq!    (to save and exit the file)
# mount    -a       (to mount the partitions)
# mount (to verify whether it is mounted or not)

22. How mount the partition permanently using block id (UUID)?
# blkid   <partition name or disk name>       (to see the UUID or block id of that partition)
Example :  #blkid   /dev/sdb2       (to see the UUID or block id of the /dev/sdb2 partition)
Copy that UUID with mouse and paste it in /etc/fstab file and make an entry about that.
Example:  # vim /etc/fstab
UUID="{.......................}"  /mnt/oracle ext4 defaults 0 0
Esc+:+wq!      (to save and exit)
23. What is the basic rule for swap size?
(i) If the size of the RAM is less than or equal to 2GB, then the size of the swap = 2 X RAM size.
(ii) If the size of the RAM is more than 2GB, then the size of the swap = 2GB + RAM size.

24. How to create a swap partition and mount it permanently?
# free   -m       (to see the present swap size)
# swapon  -s     (to see the swap usage)
# fdisk   <disk name> (to make a partition)
Example:  # fdisk   /dev/sdb
Command (m for help) :  n    (to create a new partition)
First cylinder :  (press Enter to take as default value)
Last cylinder :  +2048M   (to create 2GB partition)
Command (m for help) :   t     (to change the partition id)
Enter the partition No.:  2      (to change the /dev/sdb2 partition id)
Enter the id :  82    (to change the partition id Linux to Linux Swap)
Command (m for help) :  w    (to save the changes into the disk)
# partprobe  /dev/sdb        (to update the partition table information)
# mkswap  <device or partition name>     (to  format the partition with swap file system)
Example :  # mkswap   /dev/sdb2        (to format the /dev/sdb2 partition with swap file system)
# swapon    <device or partition name>     (to activate the swap space)
Example :  # swapon   /dev/sdb2       (to activate /dev/sdb2  swap space)
# free   -m       (to see the swap size)
# vim /etc/fstab    (to make an entry to permanent mount the swap partition)
/dev/sdb2 swap swap defaults 0 0
Esc+:+wq!     (to save and exit)

25. What are the attributes of the file system?
(i) Inode number
(ii) File name
(iii) data block

26. What is inode number and what is the use of it?
Inode numbers are the objects the Linux O/S uses to record the information about the file.
Generally inode number contains two parts.
(a) Inode first part contains information about the file, owner, its size and its permissions.
(b) Inode second part contains pointer to data blocks associated with the file content.
That's why using the inode number we can get the file information quickly.

27. How to check the integrity of a file system or consistency of the file system?
# fsck   <device or partition name>command we can check the integrity of the file system.
But before running the fsck command first unmount that partition and then run fsck command.

28. What is fsck check or what are the phases of the fsck?
(a) First it checks blocks and sizes of the file system
(b) Second it checks file system path names
(c) Third it checks file system connectivity
(d) Fourth it checks file system reference counts (nothing but inode numbers)
(e) Finally it checks file system occupied cylindrical groups

29. Why the file system should be unmount before running the fsck command?
If we run fsck on mounted file systems, it leaves the file systems in unusable state and also deletes the data. So, before running the fsck command the file system should be unmounted.

30. Which type of file system problems you face?
(i) File system full
(ii) File system corrupted

31. How to extend the root file system which is not on LVM?
By using # gparted command we can extend the root partition, otherwise we cannot extend the file systems which is not on LVM.

32. How to unmount a file system forcefully?
# umount    -f    <mount point>
# fuser    -ck    <mount point>

33. How to know the file system type?
# df   -hT       (command gives the file system type information)

34. How to know which file system occupy more space and top 10 file systems?
# df   -h   <device or partition name>  | sort   -r  |  head    -10

35. What is the command to know the mounted file systems?
# mount    or  # cat  /etc/mtab

36. How to know whether the file system is corrupted or not?
First unmount the file systems and then run fsck command on that file system.

37. How to recover if a file system is corrupted or crashed?
If the normal or not related to O/S file system is corrupted first unmount that file system and run fsck command on that file system and if the O/S related file system is corrupted then boot the system with CDROM in single user mode and run the fsck command.
If the normal or not related to O/S file system is crashed then restore it from the recent backup and if the O/S related file system is crashed then boot the system with CDROM in single user mode and restore it from the recent backup.

38. How to create a file with particular size?
# dd  if=/dev/zero of=/orafile   bs=1MB  count=500 (to create 500MB size  /orafile with 4KB blocksize)

39. How to find how many disk are attached to the system?
# fdisk    -l     (to see how many disk are attached to the system)

40. What is journaling?
It is a dedicated area in the file system where all the changes are tracked when the system                    crashed. So the possibility of the file system corruption or crashes is less because of this                      journaling  feature.


No comments:

Post a Comment