Mounting a Windows share using CIFS

Windows shares can be mounted using cifs option:

mount -t cifs -o username=username,password=password //hostname/sharename /mnt

By default, Windows shares are mounted with 0777 permissions in Linux.

You can change the default permissions using dir_mode and file_mode options in mount:

mount -t cifs -o username=username,password=password,dir_mode=0755,file_mode=0755 //hostname/sharename /mnt

To make the mount persistent, add the entry to /etc/fstab:

//hostname/sharename    /mountpoint   cifs  _netdev,username=username,password=password,dir_mode=0755,file_mode=0755,uid=500,gid=500 0 0

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.