Wednesday, 9 July 2014

Using SCCM reporting to get the GUID of PCs

I recently needed to get the GUID and PC name of every single PC in our organisation. I used the reporting feature in SCCM and put together a very simple SQL query. Here's the query, in case it is useful to someone else.
    v_R_System.Netbios_Name0, v_R_System.SMBIOS_GUID0
This returns the PC name and GUID of every single machine in the SCCM database.

Wednesday, 2 July 2014

Using dd and ssh to transfer LVM volumes over the network

Important: This article assumes that the volume that you are transferring is not mounted and is not in use. If you destroy your servers, or lose any data when following this article, it's entirely your fault. Make sure you understand the commands before executing them.

We have two Xen hosting servers that host HVM virtual machines with a mix of operating systems, backed by local LVM volumes. Using ssh and dd here's how we transferred an exact bit copy of an LVM volume from one server to another.

These commands will only work for volumes that are not in use and that are not mounted anywhere. Please don't use these commands on mounted volumes.

On the source server, dcamnode02, lvs shows the current disks available, we wanted to move the svn_root and svn_swap partitions to another server.
root@dcamnode02:~# lvs
  LV                VG   Attr   LSize   Origin Snap%  Move Log
  svn_root          vg01 -wi-a-  10.00g
  svn_swap          vg01 -wi-a-   4.00g

First, on the destination server, dcamnode01, we created new lvm volumes of the same size as the ones that we would be transferring.
root@dcamnode01:~# lvcreate -L 10G -n svn_root vg01
  Logical volume "svn_root" created
root@dcamnode01:~# lvcreate -L 4G -n svn_swap vg01
  Logical volume "svn_swap" created

Then on the source server, we used dd to copy the source lvm volumes to newly created lvm volumes on the the destination server.
root@dcamnode02:~# dd if=/dev/vg01/svn_root bs=8M conv=sync,noerror \
   | ssh -c blowfish root@ "dd of=/dev/vg01/svn_root bs=8M"
root@'s password: 
163840+0 records in
163840+0 records out
10737418240 bytes (11 GB) copied, 199.229 s, 53.9 MB/s
156+345822 records in
156+345822 records out
10737418240 bytes (11 GB) copied, 193.94 s, 55.4 MB/s
When you use dd and do not specify an output file using 'of=' then the output goes to standard output (the screen). Here we use a pipe to take standard output and pipe it to an ssh command. Ssh then then executes a remote command, 'dd' on the destination server, which is where we give the output file name. The result is that the dd image gets transferred over ssh to the remote server.

After the volume was transferred, an md5sum of the source and destination volumes can be performed to make sure the transfer happened correctly.
root@dcamnode02:~# md5sum /dev/vg01/svn_root 
0a310a5aaf3a1b7159c5f68e31525e27  /dev/vg01/svn_root

root@dcamnode01:~# md5sum /dev/vg01/svn_root 
0a310a5aaf3a1b7159c5f68e31525e27  /dev/vg01/svn_root
Both md5sums match. All is good.