2016
April
Standard

Migrate KVM Guest running on LVM to another KVM Hypervizor.

Sharing tutorial how I have migrated vm.belomor.nl…

**///////////////// Create the key pair:

# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
02:39:0b:41:de:2e:1c:65:dd:54:82:5a:64:68:1f:e0 [email protected]
The key's randomart image is:
+--[ RSA 2048]----+
| .o +=o+o..      |
| . *oo= ..       |
|  +.E+ .         |
| . +.+.          |
|  o o . S        |
|   .   .         |
|                 |
|                 |
|                 |
+-----------------+

**/////////////////Share pubkey between the two hosts from source server

# ssh-copy-id [email protected]
[email protected]'s password: 
Now try logging into the machine, with "ssh '[email protected]'", and check in:

  .ssh/authorized_keys

to make sure we haven’t added extra keys that you weren’t expecting.

**/////////////////Create Logical Volume on target:

# lvcreate -L 50G -n vm.belomor.nl vol_group_vm</strong>
  Logical volume "vm.belomor.nl" created

**/////////////////Pipe the volume to the target host:

# dd if=/dev/vol_group_vm/vm.belomor.nl | ssh [email protected] 'dd of=/dev/vol_group_vm/vm.belomor.nl'

104857600+0 records in
104857600+0 records out
53687091200 bytes (54 GB) copied, 2632.79 s, 20.4 MB/s

**/////////////////Cofee Brake :)
**/////////////////Cofee Brake :)
**/////////////////Dump the xml definition.

# virsh dumpxml vm.belomor.nl > vm.belomor.nl_dump.xml

**/////////////////Transfer xml-file:

# scp vm.belomor.nl_dump.xml [email protected]:/root/
vm.belomor.nl_dump.xml

**/////////////////Define the machine on target:

# virsh define vm.belomor.nl_dump.xml

Domain vm.belomor.nl defined from vm.belomor.nl_dump.xml

**/////////////////Start transferred machine:

# virsh start vm.belomor.nl

#######################AFTER SUCCESSFUL MIGRATION YOU CAN PROCEED WITH CLEAN UP PROCEDURE:

# virsh undefine vm.belomor.nl
Domain vm.belomor.nl has been undefined

# lvremove /dev/vol_group_vm/vm.belomor.nl 
Do you really want to remove active logical volume vm.belomor.nl? [y/n]: y
  Logical volume "vm.belomor.nl" successfully removed

Done...
# date
Tue Apr  5 13:56:10 AZT 2016

[email protected]; [email protected]

more
Standard

Linux partition space alert script

A simple bash script to send email if /local mount point is used more than 90%:

# cat /root/disk.sh 
#!/bin/bash
CURRENT=$(df /local | grep /local | awk '{ print $5}' | sed 's/%//g')
THRESHOLD=90

if [ "$CURRENT" -gt "$THRESHOLD" ] ; then
    mail -s '!!!Disk Space Alert ORACLE oracle.belomor.nl!!!' [email protected] -c [email protected] -c [email protected] -c [email protected] << EOF
Oracle partition remaining free space is critically low. Used: $CURRENT%
EOF
fi

##############

hourly run script:

# crontab -l | grep disk
@hourly /root/disk.sh
# date

Fri Apr  1 14:31:27 AZT 2016

more