martedì 31 gennaio 2023

UBUNTU - Extend LVM Partition

Issue


Few months ago I installed Ubuntu on my MAC M1 apple Silicon to practice with a K8s LAB. I proceeded with a simple installation (for beginner) leaving any options set by default, choosing to use the entire disk (30 GB). I made up my configuration, set up minikube, realized some YAML file (just to test some environment in K8s), than weeks later upgraded the kernel .... and now a warnig telling me that I have terminated the space .... what the hell ... how i did?
Watching better the output of the "df -h" command, I realized that the size of the disk wasn't as expected.

Solution


During the initial installation phase I didn't pay to much attention on how the disk was really partitioned.
Let's perform a couple of commands to be sure on the real size of the disk.

lorenzo@ubuntu:~$ sudo lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL

lorenzo@ubuntu:~$ sudo fdisk -l

Verified that we have the original 30GB disk and space not allocated, what we have to do is to extend or resize the LVM partition to the available free space with the lvextend command.
Let's proceed by steps:
  1. Locate the partition to extend running the "df -h" command. We have seen that in our case is the root "/" (93% Used).
  2. With the following command, let's check in the volume group where are the free space:
    root@ubuntu:~# vgdisplay
  3. Let's run the below lvextend command to extend the file system.
    root@ubuntu:~# lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
  4. With previous lvextend command we have extended the file system to use 100% of the free space availabe, but still the file system is not updated untill we execute the following resize2fs command:
    root@ubuntu:~# resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
  5. Last but not least, check that the space has been expanded as desired, performing "df -h" command again.

That's it.

lunedì 2 gennaio 2023

How to retrieve the WWPN of a bunch of ESXi hosts using PowerShell

Issue


I need to quickly retrieve the WWNs of a list of ESXi hosts (not managed by a vCenter)

Solution


To solve this, I thought about making a script in powershell that connects to each ESXi hosts presents in "host-list.txt" file and retrieves the necessary information. As outcome, we create a csv file "wwpn-list.csv" with all gathered information.
What I'm assuming here, in my script is that all ESXi hosts have the same username and password (in my case respectively root and VMware1!).
Below is the script:


# get-wwpn.ps1
# 
# Lorenzo Moglie 
# Version: 1.0 (29.12.2022)
#
$user = 'root'
$pswd = 'VMware1!'
$Hosts = Get-Content -Path '.\host-list.txt'
$report = @()
foreach ($host in $Hosts){
	#Write-Host "Host:", $host
	Connect-VIServer -Server $host -User $user -Password $pswd
	$temp = Get-VMhost -Name $host | Get-VMHostHBA -Type FibreChannel | Select VMHost, Device, @{N "WWN";E={"{0:X}" -f $_.PortWorldWideName}} | Sort VMHost,Device
	$wwpn = @{}
	$wwpn.VMHost = $temp.VMHost.Name[0]
	$wwpn.vmhba64 = $temp.WWN[0]
	$wwpn.vmhba65 = $temp.WWN[1]
	$wwn = New-Object -TypeName PSObject -Property $wwpn
	Sreport += Swwn
	Disconnect-VIServer -Confirm:$false
}
$report | Select VMHost, vmhba64, vmhba65 | Sort-Object -Property VMHost | Export-Csv .\wwpn-list.csv

That's it.