Thursday 21 September 2017

Error getting authority: Error initializing authority: Could not connect: No such file or directory (g-io-error-quark, 1)

When trying to disaster recover a VM from backup files you need all the disk, partitions, LVM info to match up the new system with the old. When you get this error message:
Error getting authority: Error initializing authority: Could not connect: No such file or directory (g-io-error-quark, 1)
It usually mean that it is referencing a disk, partition or LVM volume that it can't fine. Check out the /etc/fstab and remove those entries. For example, the original VM had this fstab configuration:
#
# /etc/fstab
# Created by anaconda on Tue Jun  9 09:18:57 2015
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root /                       ext4    defaults        1 1
UUID=f3371e3a-e4f9-4423-9bf3-dd7242ce4de9 /boot                   ext4    defaults        1 2
UUID=F7BA-C6DF          /boot/efi               vfat    umask=0077,shortname=winnt 0 0
/dev/mapper/centos-home /home                   ext4    defaults        1 2
/dev/mapper/centos-opt  /opt                    ext4    defaults        1 2
/dev/mapper/centos-tmp  /tmp                    ext4    defaults        1 2
/dev/mapper/centos-var  /var                    ext4    defaults        1 2
/dev/mapper/centos-swap swap                    swap    defaults        0 0
The restored files went on to a system that had no /dev/mapper/centos-tmp LVM volume. This caused the error at boot asking for root password for maintenance!

Tuesday 12 September 2017

Mounting LVM with same PV, LV, VG names as system

What happens when we try to use a disk that has the same LVM names as our system?
[root@st ~]# pvs
  WARNING: Not using lvmetad because duplicate PVs were found.
  WARNING: Use multipath or vgimportclone to resolve duplicate PVs?
  WARNING: After duplicates are resolved, run "pvscan --cache" to enable lvmetad.
  WARNING: PV aP2MDZ-3scA-JYFj-cX1A-22JX-tj1p-iaNIZl on /dev/sdb3 was already found on /dev/sda3.
  WARNING: PV aP2MDZ-3scA-JYFj-cX1A-22JX-tj1p-iaNIZl prefers device /dev/sda3 because device is used by LV.
  PV         VG     Fmt  Attr PSize  PFree
  /dev/sda3  centos lvm2 a--  99.00g 4.00m

[root@st ~]# lvs
  WARNING: Not using lvmetad because duplicate PVs were found.
  WARNING: Use multipath or vgimportclone to resolve duplicate PVs?
  WARNING: After duplicates are resolved, run "pvscan --cache" to enable lvmetad.
  WARNING: PV aP2MDZ-3scA-JYFj-cX1A-22JX-tj1p-iaNIZl on /dev/sdb3 was already found on /dev/sda3.
  WARNING: PV aP2MDZ-3scA-JYFj-cX1A-22JX-tj1p-iaNIZl prefers device /dev/sda3 because device is used by LV.
  LV   VG     Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  home centos -wi-ao----  6.99g
  opt  centos -wi-ao---- 20.00g
  root centos -wi-ao---- 32.00g
  swap centos -wi-ao----  4.00g
  tmp  centos -wi-ao----  4.00g
  var  centos -wi-ao---- 32.00g

[root@st ~]# vgdisplay
  WARNING: Not using lvmetad because duplicate PVs were found.
  WARNING: Use multipath or vgimportclone to resolve duplicate PVs?
  WARNING: After duplicates are resolved, run "pvscan --cache" to enable lvmetad.
  WARNING: PV aP2MDZ-3scA-JYFj-cX1A-22JX-tj1p-iaNIZl on /dev/sdb3 was already found on /dev/sda3.
  WARNING: PV aP2MDZ-3scA-JYFj-cX1A-22JX-tj1p-iaNIZl prefers device /dev/sda3 because device is used by LV.
  --- Volume group ---
  VG Name               centos
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  8
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                6
  Open LV               6
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               99.00 GiB
  PE Size               4.00 MiB
  Total PE              25343
  Alloc PE / Size       25342 / 98.99 GiB
  Free  PE / Size       1 / 4.00 MiB
  VG UUID               u5BLZG-ds9z-6dRh-0AI7-kAxD-n6lh-cvkKEw

[root@st ~]# vgrename aP2MDZ-3scA-JYFj-cX1A-22JX-tj1p-iaNIZl recover
  WARNING: Not using lvmetad because duplicate PVs were found.
  WARNING: Use multipath or vgimportclone to resolve duplicate PVs?
  WARNING: After duplicates are resolved, run "pvscan --cache" to enable lvmetad.
  WARNING: PV aP2MDZ-3scA-JYFj-cX1A-22JX-tj1p-iaNIZl on /dev/sdb3 was already found on /dev/sda3.
  WARNING: PV aP2MDZ-3scA-JYFj-cX1A-22JX-tj1p-iaNIZl prefers device /dev/sda3 because device is used by LV.
  WARNING: PV aP2MDZ-3scA-JYFj-cX1A-22JX-tj1p-iaNIZl on /dev/sdb3 was already found on /dev/sda3.
  WARNING: PV aP2MDZ-3scA-JYFj-cX1A-22JX-tj1p-iaNIZl prefers device /dev/sda3 because of previous preference.
  Volume group "aP2MDZ-3scA-JYFj-cX1A-22JX-tj1p-iaNIZl" not found
  Cannot process volume group aP2MDZ-3scA-JYFj-cX1A-22JX-tj1p-iaNIZl
We can use vgimportclone to rename the extra volume names and then use. However if we do this the volume group will be permanently renamed. To mount on a target system with the original name, we need to boot from CDROM and rename the volume back.
[root@pe-test-st ~]# vgimportclone --basevgname recover /dev/sdb3
  WARNING: PV aP2MDZ-3scA-JYFj-cX1A-22JX-tj1p-iaNIZl on /dev/sdb3 was already found on /dev/sda3.
  WARNING: PV aP2MDZ-3scA-JYFj-cX1A-22JX-tj1p-iaNIZl prefers device /dev/sda3 because device is used by LV.

[root@pe-test-st ~]# lvs
  LV   VG      Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  home centos  -wi-ao----  6.99g
  opt  centos  -wi-ao---- 20.00g
  root centos  -wi-ao---- 32.00g
  swap centos  -wi-ao----  4.00g
  tmp  centos  -wi-ao----  4.00g
  var  centos  -wi-ao---- 32.00g
  home recover -wi-------  6.99g
  opt  recover -wi------- 20.00g
  root recover -wi------- 32.00g
  swap recover -wi-------  4.00g
  tmp  recover -wi-------  4.00g
  var  recover -wi------- 32.00g

[root@pe-test-st ~]# vgchange -a y  recover
  6 logical volume(s) in volume group "recover" now active

[root@pe-test-st ~]# ls /dev/recover/
home  opt  root  swap  tmp  var

[root@pe-test-st ~]# mount /dev/recover/root /mnt

[root@pe-test-st ~]# ls /mnt
1    boot   dev  home  lib64       media  nsr  proc  run   srv  tmp  var
bin  cdrom  etc  lib   lost+found  mnt    opt  root  sbin  sys  usr

Thursday 17 August 2017

How to delete files with strange characters

If you have files that you can not delete due to strange characters, find the inode and delete them via that.
root@server puppetlabs # ls
activemq      code          enterprise                        installer    license.key.2016  orchestration-services  puppetserver  r10k
client-tools  code-staging  --exclude-dirs=code,code-staging  license.key  mcollective       puppet                  pxp-agent
[2017-08-17 16:03:42]
root@server puppetlabs # rm --exclude-dirs\=code\,code-staging
rm: unrecognized option '--exclude-dirs=code,code-staging'
Try 'rm ./'--exclude-dirs=code,code-staging'' to remove the file ‘--exclude-dirs=code,code-staging’.
Try 'rm --help' for more information.
[2017-08-17 16:02:30]
No chance with the above, so use:
root@server puppetlabs # ls -i
918314 activemq      918427 code-staging                      917739 installer         918184 mcollective             918048 puppetserver
918293 client-tools  918390 enterprise                        945600 license.key       918298 orchestration-services  918212 pxp-agent
918146 code          927457 --exclude-dirs=code,code-staging  934089 license.key.2016  918195 puppet                  918294 r10k
[2017-08-17 16:04:36]
root@server puppetlabs # find . -inum 927457 -delete
[2017-08-17 16:04:59]
root@picard puppetlabs # ls
activemq      code          enterprise  license.key       mcollective             puppet        pxp-agent
client-tools  code-staging  installer   license.key.2016  orchestration-services  puppetserver  r10k
[2017-08-17 16:04:59]

Friday 4 August 2017

iSCSI on Oracle Linux

Install the iSCSI utils:
# yum install iscsi-initiator-utils
Check out the initiator file to get the IQN:
# cat /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.1988-12.com.oracle:acbd8bf16757

Monday 31 July 2017

Can not write to web app directory - selinux issue

Is the content directory of some web app living somewhere that selinux is enforcing it policy? Perform the following to make directory writeable:

root@icinga2-p0 etc # semanage fcontext -a -t httpd_sys_rw_content_t "/etc/icingaweb2(/.*)?"


root@icinga2 etc # restorecon -Rv /etc/icingaweb2
restorecon reset /etc/icingaweb2 context system_u:object_r:etc_t:s0->system_u:object_r:httpd_sys_rw_content_t:s0
restorecon reset /etc/icingaweb2/setup.token context unconfined_u:object_r:etc_t:s0->unconfined_u:object_r:httpd_sys_rw_content_t:s0
restorecon reset /etc/icingaweb2/modules context system_u:object_r:etc_t:s0->system_u:object_r:httpd_sys_rw_content_t:s0
restorecon reset /etc/icingaweb2/modules/translation context system_u:object_r:etc_t:s0->system_u:object_r:httpd_sys_rw_content_t:s0
restorecon reset /etc/icingaweb2/modules/translation/config.ini context system_u:object_r:etc_t:s0->system_u:object_r:httpd_sys_rw_content_t:s0
restorecon reset /etc/icingaweb2/modules/setup context system_u:object_r:etc_t:s0->system_u:object_r:httpd_sys_rw_content_t:s0
restorecon reset /etc/icingaweb2/modules/setup/config.ini context system_u:object_r:etc_t:s0->system_u:object_r:httpd_sys_rw_content_t:s0

Monday 17 July 2017

Update, compare kernel versions - reboot within 6hours period - CentOS

#!/bin/sh
host=`hostname -f`
date=`date`

# run updates to get latest software and kernel
yum -y update
maxdelay=$((6*60))
rdelay=$(($RANDOM%maxdelay))
sdelay=$(($rdelay*60))
kernel=`uname -r`
latest=`rpm -q kernel --queryformat '%{installtime} %{version}-%{release}.%{arch}\n' | sort -n -k1 | tail -1 | cut -d ' ' -f 2`
sdate=`date`

if [ "$kernel" = "$latest" ];
then
        echo "No need to reboot..."
        echo "You are running the latest kernel: $kernel"
else
        echo "There is a new kernel. You need a reboot..."
        echo "Current kernel: $kernel"
        echo "The latest kernel: $latest"
        echo "$sdate\nCurrent kernel: $kernel\nLatest kernel: $latest"
        echo "Sleeping for $sdelay seconds..."
        sleep $sdelay
        echo "Waking up and rebooting..."
        /sbin/reboot
fi

Monday 19 June 2017

Install GRUB loader when Debian fails to boot

mount /dev/sdXY /mnt

mount --bind /dev /mnt/dev &&
mount --bind /dev/pts /mnt/dev/pts &&
mount --bind /proc /mnt/proc &&
mount --bind /sys /mnt/sys

chroot /mnt

grub-install /dev/sdX
grub-install --recheck /dev/sdX