LVM: creating a new LV from unallocated space

A logical volume provides storage virtualization so you are not restricted to physical disks sizes. The hardware storage configuration is hidden and the logical volume can be resized and moved on the fly.

An LVM Logical Volume has three components:

  1. Physical Volumes (PV)
  2. Volume Groups (VG)
  3. Logical Volumes (LV)

First of all, you have to initialize a new PV using the pvcreate command:

pvcreate /dev/sdc*

You can create a PV from a whole disk rather than partitions.

Continue reading

Rescan SCSI bus

Sometimes when you add new storage to a running VM you won’t see it; the SCSI bus needs to be re-scanned to make the new disk visible.

echo "---" > /sys/class/scsi_host/hostX/scan

X is the number of the SCSI host to scan.
"---" tells the SCSI host to rescan all controllers, channels and LUNs.

To force a re-sync of the kernel for all the SCSI devices:

echo 1 > /sys/class/scsi_device/0\:0\:0\:0/device/rescan

where 0:0:0:0 is the device you want to sync.

If you increased the size of an existing disk but you are not able to see the new disk size:

echo "1" > /sys/class/block/sdX/device/rescan

"1" is a flag that will trigger re-scan on the SCSI host.

Check software RAID script

Here’s a Bash script to check software RAID that will send an e-mail reporting the array status:

#!/bin/bash
# check_raid.sh
EMAIL="your@email.com"

if egrep "\[.*_.*\]" /proc/mdstat  > /dev/null
 then
   logger -s "mdcheck: RAID devices ERROR"
   echo "Software RAID devices ERROR on ${HOSTNAME}" | /bin/mail -s \
   "$0: Software RAID devices ERROR on ${HOSTNAME}" ${EMAIL}
 else
   logger -s "mdcheck: RAID devices OK"
   echo "Software RAID devices OK on ${HOSTNAME}" | /bin/mail -s \
   "$0: Software RAID device OK on ${HOSTNAME}" ${EMAIL}
fi

 

Convert .ppk key to OpenSSH keys

OpenSSH is the de facto standard implementation of the SSH protocol.

If you use ssh-keygen with the default options, it will generate a private and a public key that will work with virtually any server.

Unfortunately, out there are Windows users that bother Linux admins with .ppk key generated by PuTTY; both keys are stored in this single proprietary file.

You can convert this file and obtain standard OpenSSH key pairs using puttygen provided with the putty package available on many distros.

puttygen your_key.ppk -O [output-type] -o [output-file]

output-type refers to they key type, private-openssh or public-openssh.

NTP time drift

I had to update a couple of NTP servers and after rebooting Nagios was returning an alert on the check_ntp_peer check, indicating a time drift.

To fix it, I forced a clock update with NTP servers:

systemctl stop ntpd
ntpdate -s ntp1.inrim.it
systemctl start ntpd