Showing posts with label VM. Show all posts
Showing posts with label VM. Show all posts
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,...
for more read here https://likegeeks.com/linux-file-system/
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?
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.
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]
-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
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
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
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
/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!
Extend the disk space of Windows 2012/2016 VMs running on Hyper-V
Why?
I often encountered VMs power down issues in my workplace. When I referred to the logs related to the issues are, storage was not sufficient. Then, I increase the size of the virtual hard disk. Voila!
but, let's say we have tons of VMs or often VMs power-down due to the storage issue, manually upgrading virtual disks are not possible. this where automation comes in.
So, I've decided to extend the disk space of Windows 2012/2016 VMs running on Hyper-V (I'll write a blog for Vms running on VMWare as well in my next post).
In this blog, I'll show how to increase and extend the C drive. In order to do this, we need to consider some cases mentioned below.
1. Get list of VMs Name
2. Get particular VM's virtual disk path
3. Resize the VHD/VHDx
4. Remote to the VM and Extend it's C drive Size.
Before we do this, I want you to understand about Virtual HardDisk (VDH/VDHx)
Hyper-V uses two different formats for virtual hard disk files: the original VHD and the newer VHDX.
You can resize any of Hyper-V’s three layout types (fixed, dynamically expanding, and differencing). However, you cannot resize an AVHDX file (a differencing disk automatically created by the checkpoint function).
Resizing a virtual disk file only changes the file. It does not impact its contents. Meaning that we need to go VMs Specific drive to extend otherwise, Disk which was extended remain unallocated space to the VMs File System.
Requirements for VHD/VHDX Disk Resizing
- If the virtual machine is Off, any of its disks can be resized as though no one owned them
- If the virtual machine is Saved or has checkpoints, none of its disks can be resized
- If the virtual machine is Running, then there are additional restrictions for resizing its virtual hard disks
In this tutorial I'm gonna resize running VMs only (if so, VDHx type Virtual Disk can only be partitioned. In my case, I'm Running 2016 server which is typically VDHx type)
How to check VDH type
Get-VM -VMName $VM | Select-Object VMId | Get-VHD
Get-VM -VMName $VM | Select-Object VMId | Get-VHD
1. Get list of VMs Name
$path = Read-Host "provide path or list of VM file EG: C:vm.txt"
2. Get VM's Guest username and password
2. Get VM's Guest username and password
So that, we login vm and extend C drive
Write-Host "enter the vm user password (valid user name and password for login VMs)" $UserVM = zss\fayasak $PasswordVM= Read-Host -Prompt " Guest Password for VM `n" $Crendential= New-Object System.Management.Automation.PSCredential ($UserVM, $PasswordVM)
3. Get particular VM's virtual disk path
$VMs = Get-Content $path
Foreach ($VM in $VMs)
{
#get the VHDX path of the particular VM
$vhdxpath=Get-VM | Select-Object VMId | Get-VHD | select path
4. Resize the VHD/VHDx
I resized with 30gb
Resize-VHD -Path $vhdxpath -SizeBytes 30gb
5. Remote to the VM and Extend it's C drive Size.
store the login session into the variable and $credential provide the username password which was given earlier.
$pss=New-PSSession -VMName $VM -Credential $Crendential
Invoke-Command -SciptBlock {command here}
Above mentioned script is to execute PowerShell script to the specified VM
Using Invoke-Command and Session which was stored earlier below script is being used to remotely execute PowerShell command to the VM.
Invoke-Command -Session $pss -VMName $VM -ScriptBlock {'Update-Disk -Number 0;$m=(Get-PartitionSupportedSize -DriveLetter c).sizeMax;Resize-Partition -DriveLetter c -Size $m' }
Write-Host "enter the vm user password (valid user name and password for login VMs)" $UserVM = zss\fayasak $PasswordVM= Read-Host -Prompt " Guest Password for VM `n" $Crendential= New-Object System.Management.Automation.PSCredential ($UserVM, $PasswordVM)
3. Get particular VM's virtual disk path
$VMs = Get-Content $path
Foreach ($VM in $VMs)
{
#get the VHDX path of the particular VM
$vhdxpath=Get-VM | Select-Object VMId | Get-VHD | select path
4. Resize the VHD/VHDx
I resized with 30gb
Resize-VHD -Path $vhdxpath -SizeBytes 30gb
5. Remote to the VM and Extend it's C drive Size.
store the login session into the variable and $credential provide the username password which was given earlier.
$pss=New-PSSession -VMName $VM -Credential $Crendential
Invoke-Command -SciptBlock {command here}
Above mentioned script is to execute PowerShell script to the specified VM
Using Invoke-Command and Session which was stored earlier below script is being used to remotely execute PowerShell command to the VM.
Invoke-Command -Session $pss -VMName $VM -ScriptBlock {'Update-Disk -Number 0;$m=(Get-PartitionSupportedSize -DriveLetter c).sizeMax;Resize-Partition -DriveLetter c -Size $m' }
Find full PowerShell script here
That's it! and Peace!!!!
Subscribe to:
Posts (Atom)


