Showing posts with label rhel. Show all posts
Showing posts with label rhel. Show all posts

Monday, 15 January 2024

Symbolic link

Symbolic link


Symbolic links are files that points to another file or directory. It is also called symlink or soft link. It is simply a pointer to the original directory. As a system administrator, we need to have a good understanding of these symlink and its working.  In this blog we will see simulating different situations around symbolic link and how things work.


Create symlink

Symlink can be created using ln command as shown below, 

#ln -s orginal_directory_path symlink_filename

1.1 Create symlink


We can identify if a file is just a regular file or symlink by looking at the "ls -ltr" command output, where we see "l" in first place in the permission column - which denotes link. 

1.2 List symlink

We can also compare the inodes of both original and symlink to see if both are same and it should be same. 

1.3 Inode for files

When we create or change anything inside the symlink, it will reflect in source/original directory.
Let's try creating and deleting files inside of the symlink to demonstrate same. 

1.4 Create files under symlink

1.5 Delete files under symlink

Now we are quite clear that contents of symlink are same as the original directory and any change will impact both destination.

Let's now take it further to change the symlink file itself and see what will happen.

Remove symlink

We can remove a symlink we can use "rm" or "unlink" command. however when using rm command ensure you are not using / in the end as it will remove the contents instead of removing the symlink file.

1.6 Remove symlink with rm command

1.7 Remove symlink with unlink command

Notice that when we try / in the end using unlink comamnd it will throw error saying not a directory, however when we use it with rm it will delete contents. Its always safe to use unlink command to delete a symlink rather than rm comamnd to avoid accidently removing the original files.

1.8 Remove original file


However when we remove the original file tagged to the symlink, will break the symlink to work as shown above. 
Symlink allows us to be created in a different filesystem, in this example i have created symlink in a different mount /data whereas the source directory exist in the /home directory. 

1.9 Filesystem structure used in this blog


Update symlink

What if we renamed the original directory, let's explore now. 

When we rename the original directory the symlink becomes unusable the referenced pointer is no longer exist as it is moved to a different. however all the files are still available in the original directory in the moved place and to access them we can directly go to the original directory using the moved path. 
 
1.10 Rename original directory


Now to fix this, we need to update the symlink file, this is simply run the symlink command with force option to remove the existing symlink file and create new symlink file with new destination. 

#ln -sf /original_directory symbolic_link_file 

1.11 Update symlink path


Now everything looks back normal. 

Thursday, 4 January 2024

Extend LVM without partition table

 Extend LVM without partition table


This Blog is continuation of my previous blog Create LVM without partition table

In this scenario, we will extend the size of disk on VM instead of adding new disk.

Login to the VM and check if the increased size is visible. we can do this by rescanning the block device as shown below, 

#echo 1 > /sys/class/scsi_device/2:0:1:0/device/rescan --> where 2:0:1:0 is the scsi interface of  the device connected this can be identified using the lun number we have extended from vm portal and matching with lsscsi output.

#echo 1 > /sys/class/block/sdb/device/rescan --> Where sdb is the block device.

Now we will be able to see the new increased size for the disk using fdisk -l /dev/sdb or lsblk command. 

1.1 Disk Rescan

Next we can resize the PV since we have not used or created a partition table. 

Command to resize as below,
#pvresize /dev/sdb

1.2 Resize PV


Once we resize the PV, we can see the changes using pvs or pvdisplay command,

VG will be reflecting the free space available automatically we do not have to extend anything as we are using the same PV instead of new PV. 

We can see the VG status using vgs or vgdisplay.

1.3 vgs output

Lets proceed with resize of LV directly using below command, 

#lvresize -l +100%FREE lv_name

1.4 LV resize


Now we can see the lv has been resized with lvs or lvdisplay command.

Now the LV has required space, filesystem can be grown using below command, 

#xfs_growfs /mount_point_name

1.5 Resize Filesystem

Once the filesystem is extended, we can see the change using df -h and its usable now. 

1.6 Resized mount

We have increased the disk space without downtime and partition table. 

Caution: When we use a partitionless LVM, we also need to be careful at later point in time when we add more disk, where our old disk used as LVM may also show as no partition in fdisk or parted commands. So, its recommended to use pvdisplay or pvs command validate and confirm its usage.