Saturday, 18 August 2018

How to cast movies from Kodi to Chromecast on a PC

There are lots of guides out there showing how to cast media from an android device via Kodi to Chromecast, but just a few for how to cast from a PC.

After doing some research, I found that I can cast from Kodi to Chromecast by using VLC media player as an external player. Note that you will need VLC v3.0+ for this to work, since Chromecast support was added after this version.

The steps below show how I did it on my Ubuntu laptop, but same procedure should work on ther Linux distros as well. Also, same logic should apply on Windows machines.


Steps

  • Install latest version of Kodi
  • Install latest version of VLC media player (v3.0+)
  • Copy the following content and create this file in your home folder .kodi/userdata/playercorefactory.xml . This is basically saying to Kodi to use VLC to playback the media content instead of its built in player.Please modify any settings according to your specific setup.
  • Open Kodi and start a movie.
  • Wait for VLC to open, it should start the playback shortly.
  • In order to cast to Chromecast, use Playback , Renderer , Chromecast Device


Before this method, I was using Google Chrome to do the playback, by using its "cast tab" option, but the playback was very choppy compared to VLC.


Saturday, 11 August 2018

Xorg unable to detect screens in CentOS7

Summary

On a machine with  2 graphics card, one on-board Intel graphics and one NVidia graphics, Xorg is not able to properly detect the 2 screens connected to NVidia card. As a result of this, GUI login screen (GDM) does not show up. 


Some background

BIOS is configured to use NVidia card as the primary graphics card however Xorg is unable to detect the screens. The following lines are logged at the end of the /var/log/Xorg.0.log file ...

[    22.885] (EE) No devices detected.
[    22.902] 
Fatal server error:
[    22.902] no screens found
[    22.902] 
Please consult the The X.Org Foundation support 
         at http://wiki.x.org
 for help. 
[    22.902] Please also check the log file at "/var/log/Xorg.0.log" for additional information.
[    22.902]


The reason

This behaviour occurs due to the fact that the machine has 2 graphics card. Somehow the onboard Intel card takes priority over the NVidia card, even though the latter is set as the primary card in BIOS.As a result of this, Xorg is unable to detect the monitors, which are connected to NVidia card.


The solution

The solution for me was to create the following file /etc/X11/xorg.conf.d/10-nvidia.conf and add the following lines..

Section "Device"
    Identifier     "Device0"
    Driver         "nvidia"
    VendorName     "NVIDIA Corporation"
    BusID          "PCI:1:0:0"
EndSection

By doing this you are basically telling Xorg to use NVidia card as the primary card. One thing to note is the BusID line. You should find the correct bus id entry for your card. You can do so by using the following command...

# lspci | grep VGA

00:02.0 VGA compatible controller: Intel Corporation Xeon E3-1200 v3/4th Gen Core Processor Integrated Graphics Controller (rev 06)
01:00.0 VGA compatible controller: NVIDIA Corporation GM107GL [Quadro K620] (rev a2)

Also, note that the format is slightly different in 10-nvidia.conf,  (1:0:0) instead of (01:00.0).


Monday, 30 July 2018

Issues booting to CentOS7 after resizing its root/swap LV

I recently faced the following strange issue...

Some background first

I installed  CentOS7 on a VM, its assigned vhd size was 10G, nothing fancy so far ...
Installation was successful and I was able to boot into the O/S without issues.

Later, at some point, I decided to increase vhd size from 10G to 13GB. To accomplish that I followed the steps below...

- Turned off the VM
- Resized the vhd to the new size
- Turned on the VM
- Booted from LiveCD [CentOS7 dvd]

  •     lsblk    

    [root@localhost ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   13G  0 disk
├─sda1            8:1    0  500M  0 part /boot
└─sda2            8:2    0 12.5G  0 part
  ├─centos-root 253:0    0 11.5G  0 lvm  /
  └─centos-swap 253:1    0    1G  0 lvm  [SWAP]  
     

  •        fdisk /dev/sda

    Here, I deleted the second partition (/dev/sda2), which is the LVM partition where centos/root and centos/swap LVs reside on. Then, I recreated it, by making sure that start sector was the same as before deleting the partition. Obviously, the end sector will be different as we increased vhd size. Finally, set partition type to 8e (LVM), saved settings and exited. By the way this is an 'extended' partition type.

  •        pvresize /dev/sda2        


  •        lvresize -l +100%FREE centos/root

     
       [root@localhost ~]# lvdisplay centos/root
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                1rlD1f-BSw4-R3rl-z22I-GtDN-rykj-cxdlXL
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2018-07-27 23:06:39 +0100
  LV Status              available
  # open                 1
  LV Size                <11 .52="" font="" gib="">
  Current LE             2948
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

     
So far, so good...centos/root LV , which is the backing device for root file system (/), has its size increased.


  •      mkdir /mnt/root   #create a temp directory to mount centos/root LV
  •      mount /dev/mapper/centos-root /mnt/root   #mount centos/root to /mnt/root
  •      xfs_growfs  /mnt/root   #increase root fs filesystem to match centos/root LV size. Did I mention that root fs is XFS ?
  •      umount /mnt/root   #unmount root fs 
  •      reboot   #reboot the system, and boot from hdd this time [not LiveCD]


The issue

After rebooting from LiveCD to the normal hard drive (now 13G), the following happened ...

     - GRUB menu appeared and loaded default kernel (3.10.0-862.9.1.el7.x86_64).
     - kernel loads and initial boot sequence starts.
     - kernel hands over to initramfs (initrd).
     - initrd fails to detect/active centos/root and centos/swap LVs, so after a while I'm being dropped to dracut shell...
      In dracut shell, I execute the following commands:
           - lvm lvchange -ay centos/root   #success
           - lvm lvchange -ay centos/swap  #success
           - ln -s /dev/mapper/centos-root /dev/root   #required for boot process to continue to the real root fs (/).
           - exit  #exit dracut shell

At this point boot process continues and finally I can login to the normal CentOS7 installation. But the question remains, why I have to do all these stuff? wasn't this supposed to happen automatically ? The answer is, yes, it should,  ....but something went wrong (obviously)... and now it needs my manual intervention to succeed.

The solution

After 5 days of continuous search, finally a solution was found. The problem was not in initramfs, but on the fact that /dev/sda2 partition(PV),  after I resized it, somehow got 2  partition table signatures.
One was set as a "dos" partition with an offset "0x1fe" and second was set as "LVM_member" with an offset "0x8e".
This confused blkid in initramfs, during the initial boot stage, thinking that /dev/sda2 is *not* an LVM_member but rather a simple "dos" partition, hence refused to activate centos/root and centos/swap LVs which were required to boot the machine to the O/S.
What's interesting is that neither fdisk or parted were showing this second signature, however there was a trace of it in the dracut report file (/run/initramfs/rdsosreport.txt), specifically the one below..

+ blkid
/dev/sr0: UUID="2016-10-28-12-18-36-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos" 
/dev/sda1: UUID="a620a180-3a8c-4b5f-ad30-804f131a7261" TYPE="xfs" 
/dev/sda2: PTTYPE="dos" 
+ blkid -o udev
ID_FS_UUID=2016-10-28-12-18-36-00
ID_FS_UUID_ENC=2016-10-28-12-18-36-00
ID_FS_LABEL=CentOS_7_x86_64
ID_FS_LABEL_ENC=CentOS\x207\x20x86_64
ID_FS_TYPE=iso9660
ID_PART_TABLE_TYPE=dos
To fix this problem, I booted the system from a livecd and used "wipefs" utility to erase the problematic signature "dos" and leave only the correct one "LVM_member".


The exact command was: 'wipefs -o 0x1fe -ff /dev/sda2' 

Then a reboot and voila system booted without issues ...



Sunday, 29 July 2018

Configuring LINSTOR [DRBD9] storage plugin for Proxmox VE 5.x

DRBD9 is an opensource block level, replicated distributed storage system [link]. It can replicate the available local storage space of an existing computer node to one or more other nodes. It works similarly to the way RAID1 works on RAID controllers, but DRBD uses the network to replicate the data. DRBD9 operates at the block level, so it should perform faster on some workloads, as virtualisation for example, compared to other file system based distributed storage systems.

  • The main difference between DRBD8 and DRBD9, is that the former is limited to only two storage nodes. However DRBD8 is still heavily used in the industry, perhaps more than DBRD9, at least for now ...


In this article we'll see how we can configure DRBD9 management system, called LINSTOR, to work with Proxmox VE, a well known opensource hypervisor. We assume that you already have a working Proxmox cluster (at least 3 nodes).

The next step will be to configure Linbit's (the company behind DRBD) repository on Proxmox, to download the necessary packages, required for DRBD9/Linstor to work. Below follows a breakdown of these components:


  • DRBD9 kernel module
  • DRBD low-level admin tools
  • LINSTOR management tools
  • LINSTOR storage plugin for Proxmox

On all Proxmox nodes, install Linbit repository, make sure you modify PVERS variable value to match your PVE version (here is 5).

# wget -O- https://packages.linbit.com/package-signing-pubkey.asc | apt-key add -
# PVERS=5 && echo "deb http://packages.linbit.com/proxmox/ proxmox-$PVERS drbd-9.0" \ > /etc/apt/sources.list.d/linbit.list
 
# apt-get update && apt-get install linstor-proxmox
This will install the DRBD9 Proxmox storage plugin only. For an up to date guide about this plugin, please follow this link. To install the rest of DRBD9 components follow the steps below...

#apt install pve-headers
#apt install drbd-dkms drbd-utils
#rmmod drbd; modprobe drbd
#grep -q drbd /etc/modules || echo "drbd" >> /etc/modules


  • Important! Kernel headers must be installed on each node, prior to installing drbd-dkms package, otherwise it will fail to build.


The next step is to install LINSTOR satellite and controller components. A satellite is a node which provides access on the low level storage system (LVM,ZFS) to DRBD9. A controller is a node which orchestrates satellite nodes and manages other things like resource assignments, volume management etc. A node can be a satellite and a controller at the same time.

  • Important! There must be only one controller node active on a DRBD9 cluster.
  • You must install packages below to all Proxmox nodes, with the exception of controller, which must be installed only on one of the Proxmox nodes.


#apt install linstor-controller linstor-satellite linstor-client


  • Enable and start the satellite service on each node.

#systemctl start linstor-satellite
#systemctl enable linstor-satellite


  • Now, you must decide which node will be the "controller" node. Once you decide install linstor-controller package on it and start the service.

    [Update] It's now supported to deploy Linstor Controller as a separate HA VM  within PVE cluster. For more on this, please check latest Linstor documentation.
#systemctl enable linstor-controller
#systemctl start linstor-controller

  • Verify that the services are up and running on all nodes.

#systemctl status linstor-satellite
#systemctl status linstor-controller    #only on controller node.

If the above were successful, we can now proceed further to configure the backing storage system for LINSTOR. In my example, I'm using LVM thin as a storage provider. You can also use ZFS if you wish to. LVM can be used to manage a hardware RAID array, MD Raid or a single disk (only for testing). So, at the high level, the storage configuration will be the following ...

(RAID ARRAY)--- <-->(LVM)---<--->(DRBD9)---<--->(VM)
  • Suppose we have a storage array with a device assignment as /dev/sdb, let's configure LVM Thin on it..
#vgcreate vg_hdd /dev/sdb


# pvs
  PV         VG     Fmt  Attr PSize  PFree
  /dev/sda3  pve    lvm2 a--  19.75g 2.38g
  /dev/sdb   vg_hdd lvm2 a--  30.00g    0

# vgs
VG     #PV #LV #SN Attr   VSize  VFree
pve      1   3   0 wz--n- 19.75g 2.38g
vg_hdd   1   4   0 wz--n- 30.00g    0

We've created a volume group named vg_hdd which is using /dev/sdb [RAID array], for storage space provider.

  • Create a LVM ThinPool on this Volume Group. This ThinPool will be called "drbdthinpool" and it will be later used by LINSTOR to allocate LVs for the DRBD resources, which in their turn will be used as VM virtual hard disks.

#lvcreate -L 29G -T vg_hdd/drbdthinpool

# lvs
  LV                  VG     Attr       LSize  Po
  data                pve    twi-a-tz--  8.25g
  root                pve    -wi-ao----  4.75g
  swap                pve    -wi-ao----  2.38g
  drbdthinpool        vg_hdd twi-aotz-- 29.96g

  • Important! You must create drbdthinpool on all satellite nodes.
Now that we configured drbdthinpool on all (3) PVE nodes, we can proceed  configuring LINSTOR for using this pool to allocate LVs for the DRBD resources.

  • Important! All LINSTOR commands below must be executed on the LINSTOR controller node. First check the nodes status.

#linstor n l    #show LINSTOR nodes and their status.

╭───────────────────────────────────────────╮
┊ Node ┊ NodeType ┊ IPs            ┊ State  ┊
╞┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄╡
┊ pve1 ┊ COMBINED ┊ 192.168.198.20 ┊ Online ┊
┊ pve2 ┊ COMBINED ┊ 192.168.198.21 ┊ Online ┊
┊ pve3 ┊ COMBINED ┊ 192.168.198.22 ┊ Online ┊
╰───────────────────────────────────────────╯

  • Then, create a Storage Pool Definition (SPD) on LINSTOR.

#linstor spd c drbdpool   #drbdpool will be the name of the SPD.

  • Next, create the Storage Pools (SP) for each PVE nodes on LINSTOR.
# linstor sp c lvmthin pve1 drbdpool vg_hdd/drbdthinpool


A breakdown of the above parameters:
-----------------------------------------------
sp (storage pool)
c (create)
pve1 (first proxmox node)
drbdpool (storage pool definition, we created this above)
lvmthin (use lvm thin driver)
vg_hdd (LVM Volume Group we created previously)
drbdthinpool (LVM thin pool we created previously)
------------------------------------------------

  • Repeat the above command to add SP for each individual PVE node on LINSTOR, i.e replace pve1 parameter with pve2 and pve3 respectively. When done it should look like below ...

root@pve1:~# linstor sp l
   ───────────────────────────────╮-----------------------------------
┊ StoragePool ┊ Node ┊ Driver        ┊ PoolName            ┊   Free ┊ SupportsSnapshots ┊
╞┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
┊ drbdpool    ┊ pve1 ┊ LvmThinDriver ┊ vg_hdd/drbdthinpool ┊ (thin) ┊ true              ┊
┊ drbdpool    ┊ pve2 ┊ LvmThinDriver ┊ vg_hdd/drbdthinpool ┊ (thin) ┊ true              ┊
┊ drbdpool    ┊ pve3 ┊ LvmThinDriver ┊ vg_hdd/drbdthinpool ┊ (thin) ┊ true              ┊
╰─────────────────────────────────────────────────

  • At this point we should have finished configuring LINSTOR, so we can proceed configuring its Proxmox storage plugin. To do so, we must add the following lines in Proxmox storage configuration file /etc/pve/storage.cfg ...
drbd: drbdstorage
        content images,rootdir
        controller 192.168.198.20
        redundancy 3

A breakdown of the above parameters:
----------------------------------------------
drbd (a hardcoded by Proxmox, definition for DRBD storage type, this cannot be changed.)
drbdstorage (a arbitrary name selected to define this storage backend on PVE, this can be changed)
content images,rootdir (this storage type supports Qemu VM and LXC type containers)
controller (this defines which node acts as LINSTOR controller. It's mandatory to type that node's IP address correctly, otherwise Proxmox will fail to create VM/LXCs on DRBD).
redundancy 3 (How many replicas will be created for each VM/LXC, minimum should be 2)
-----------------------------------------------
  • By now we should be ready to go, so let's open PVE webgui management and create a Qemu VM or LXC container on DRBD9 storage...




  • You should be able to see also the associated LV Thin Volumes for each individual DRBD resource/VM...
  root@pve1:~# lvs
  LV                  VG     Attr       LSize  Pool         Origin Data%  Meta%  Move Log Cpy%Sync Convert
  data                pve    twi-a-tz--  8.25g                     0.00   0.01
  root                pve    -wi-ao----  4.75g
  swap                pve    -wi-ao----  2.38g
  drbdthinpool        vg_hdd twi-aotz-- 29.96g                     22.32  17.44
  vm-100-disk-1_00000 vg_hdd Vwi-aotz-- 13.01g drbdthinpool        23.12
  vm-101-disk-1_00000 vg_hdd Vwi-aotz--  9.01g drbdthinpool        10.60
  vm-102-disk-1_00000 vg_hdd Vwi-aotz-- 10.00g drbdthinpool        27.22


  • If you have any problems, please read carefully DRBD9/LINSTOR documentation at Linbit's web site, to familiarise yourself with LINSTOR command line or subscribe to DRBD mailing list.




Troubleshooting mirrored dynamic disks on Windows Server 2008 R2

Problem Description:
You have a Windows Server 2003 or 2008 (R2) Server configured with mirrored dynamic disks. One of disks fails and you need to replace failed disk with a new one. You buy the new disk, connect it to the slot where the failed disk was and power on your server. You go to disk management convert the new disk to dynamic disk and remove old (missing mirror). Now you are ready to create the mirror again but suddenly you get the following error message “All disks holding extents for a given volume must have the same sector size
As described here , what this message says is that your old disk in the mirrored array (500gb dell  in my case) and the new disk (1 tb wd black in my case) have different  sector sizes (512 bytes for 500gb disk and 4096 bytes for 1 tb disk).The new 1 tb disks was an Advanced Formatted Disk, as a result I cannot create a mirrored volume between them.I need to buy another 1 tb 4K formatted hdd , clone or create backup image & restore the old (500gb) disk to the new disk and finally create the mirrored array between 1 tb disks.
Ok, so I bought another 1 tb wd black and I was ready to clone the data from the old disk to the new one. The 1st problem that I faced is that most of Imaging programs cannot handle Dynamic Disks at all. For example Acronis, needs a special add-on called “Plus Pack” to be able to create an Image of dynamic disk (you must break the mirror first, because mirrored volumes are not supported) and then restore it to the new one.
Solution:
Personally I followed the steps below:
  1. Downloaded Hiren’s boot cd and used Norton Ghost to clone 500gb hdd -> 1tb hdd.
  2. After cloning I had  a BASIC 1 tb with all the data inside. Removed 500gb disk and left only this 1tb disk on slot and booted the machine.
  3. Got “0xc000000e Info: The boot selection failed because a required device is inaccessible”.
  4. I put Windows Server 2008 R2 dvd on dvd-rw and booted from there. Fortunately boot cd found the bootloader problems and automatically fixed them. If that did’t worked for you, try this article.
  5. Rebooted again and voila, finally the system booted correctly!
  6. Powered off the server, put the 2nd 1tb hdd, powered on, converted both disks to dynamic disks and finally enabled mirroring between them.

Make Windows Installer work under safe mode

To make Windows Installer work under safe mode, you need to create a registry entry for every type of safe mode you are logged in to.
  1. Safe Mode.
    Type this in a command prompt:
    REG ADD "HKLM\SYSTEM\CurrentControlSet\Control\SafeBoot\Minimal\MSIServer" /VE /T REG_SZ /F /D "Service"
    
    
    and then
    net start msiserver
    
    
    This will start the Windows Installer Service.
  2. Safe Mode with Network
    REG ADD "HKLM\SYSTEM\CurrentControlSet\Control\SafeBoot\Network\MSIServer" /VE /T REG_SZ /F /D "Service"
    
    
    and followed by
    net start msiserver 
    
    
    This will start the Windows Installer Service.

How to enable ‘Out of Office’ in a Office 365 Distribution Group

Step-by-step guide

  1. 1. Connect to Exchange Online with Windows PowerShell.
    2. Run the cmdlet:
    Set-DistributionGroup -Identity  -SendOofMessageToOriginatorEnabled $trueNotice
  2. If it is a DDG, please use this command:
    Set-DynamicDistributionGroup -Identity -SendOofMessageToOriginatorEnabled $true
  3. Configure a user’s mailbox (which is a member of the DG) in your Outlook and set the OOOM.
  4. Send a test message to the DG to confirm.
  5. In case that Office 365 is syncing with on premises Active Directory then login on clients AD
  6. Locate the Distribution Group -> Properties -> Attribute Editor (Enable Advanced attributes first)
  7. Locate the filed ‘oOFReplyToOriginator‘ and set it to ‘TRUE
  8. Open Powershell and Sync with Office 365 :
  9. Import-Module DirSync
  10. Start-OnlineCoexistenceSync
  11. Configure a user’s mailbox (which is a member of the DG) on your Outlook and set the OOOM.
  12. Send a test message to the DG to confirm