Linux File System and LVM


In this post, I'll share my experience with the Linux file system with error and creating custom Linux partitions using LVM based on the user's request at my work. 

What is the file SystemAny file system is a layer on top of the operating system and file system handled by OS and which provide storage for store files and information.
Ex: Ext, Ext2, Ext3, Ext4, XFS,...


When we Install Linux we'd choose the different file systems as per our requirement.
In my case, I haveing Linux with Ext4 with journalling File System.
Which Linux File System Should You Use?

Okay, I'll come to the point why am I talking about this.

Why?
At my work, I often add disks to VM or any server based on user requirements. read my previous article here https://stateofstudy.blogspot.com/2018/07/extending-disk-space-of-windows.html
 In some other cases, I need to maintain Linux servers as well. though, I had to understand Linux file System and LVM.

One day, I had an issue with the boot time on the Linux machine due to unclean shutdown.



Note: /dev/Sda1 is a storage disk attached to the Linux machine.
So, Disk is corrupted due to the unclean shutdown. thought, the system was thrown an error at the boot time.
To fix this,
1. go to your grub menu.
2. type the command below

  fsck -f /dev/sda1

fsck- file check and error correct
-f - do this forcefully

let's go back to file system selection on Linux installation to understand the above scenario.

we have plenty of option file systems to select and each file system provides its functionality to make system or storage work faster.
Example: ext4 faster than ext3 and xfs file system much more faster than ext4.

One important thing you’ll notice when choosing between file systems is marked as a “journaling” file system and some aren’t. This is important.

Journaling is designed to prevent data corruption from crashes and sudden power loss. Let’s say your system is partway through writing a file to the disk and it suddenly loses power. Without a journal, your computer would have no idea if the file was completely written to disk. The file would remain there on the disk, corrupted.

Journal - when file in the process, journal is spacial allocation on disk where write are stored in in transaction and after writes completes, commits the changes to the file system.  

with that journaling process it finds out the corrupted file and it refers to metadata (logs) using i-node value to fix corrupted file system on the disk.

if your system uses xfs file system use xfs_repair to fix error.

let's move on to LVM

LVM
I often have request ticket in wich ask to add more storage to a file system.
Example: 3 mount points as /data1, /data2 and /data3 each with 50 GB disk space for oracle database recovery.

What, Why LVM?
Logical Volume Management (LVM) makes it easier to manage disk space. If a file system needs more space, it can be added to its logical volumes from the free spaces in its volume group and the file system can be re-sized as we wish. If a disk starts to fail, replacement disk can be registered as a physical volume with the volume group and the logical volumes extents can be migrated to the new disk without data loss.



Let's do it,

1. Add disk (150gb) to the server. then,  issue command fdisk -l to view all available disk
   Note: /dev/ is a special directory in which holds the device attached to the system.
 Assume, my new attached disk is /dev/sdb

2. Partition the /dev/sdb disk
    fdisk /dev/sdb  then type option below 

              -p [To print partition table]
              -n [To create new partition]
              -p [To create new primary partition]
              -w [To save changes]

3. Create a new physical volume using the partition created above “pvcreate <partition>
pvscreate /dev/sdb1
    To view details of physical volume- pvdisplay

4. Add our new physical volume to the volume group vgextend <volume group name> <partition>
  vgextend volgrup01 /dev/sdb1

Note: if the volume group does not exist create volume group with available partition vgcreate <volume group name> <partition>

5. Create logical volume 3 with 50 GB
vcreate -L <capacity>G -n <logical group name> <Name of volume group>

lvcreate -L 50G -n point1 volgrup01 
lvcreate -L 50G -n point2 volgrup01 
lvcreate -l 100%FREE -n point3 volgrup01 

6. make a suitable file system on top of these logical volumes (format the storage)
In my case, I choose xfs file system type because this is being used for DR
mkfs.<file system type> /dev/<Name of volume group>/<logical group name>

mkfs.xfs /dev/volgrup01/point1
mkfs.xfs /dev/volgrup01/point2
mkfs.xfs /dev/volgrup01/point3

7. Mount the logical volume to mount points 
Create directory using “mkdir {/data1, /data2 and /data3}"
then, Mount-it!

mount /dev/volgrup01/point1 /data1
mount /dev/volgrup01/point2 /data2

mount /dev/volgrup01/point3 /data3

8. If you reboot the system, the mount points will be removed. In order to make them persistent, open “fstab” file and add the below entries.

vim etc/fstab


/dev/volgrup01/point1 /data1 xfs defaults,nofail 0 0
/dev/volgrup01/point2 /data1 xfs defaults,nofail 0 0
/dev/volgrup01/point3 /data1 xfs defaults,nofail 0 0


Voila! 
That's it for today, Peace!

, , , , , , ,

1 comment:

  1. Transferring Knowledge is a best practice for learning society. The word strength derive from the knowledge. Most of the professionals were keeping update to maintain the shoulders with the dynamic world.
    Good job & keep it up......!

    ReplyDelete