Tuesday, November 3, 2015

Mount partition from multi-partition drive image

I've had to do this a few times. Linux is awesome for dealing with devices and images. From http://askubuntu.com/ is the simple procedure.

Get the partition layout of the image
$ sudo fdisk -lu sda.img
...
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
...
  Device Boot      Start         End      Blocks   Id  System
sda.img1   *          56     6400000     3199972+   c  W95 FAT32 (LBA)
 
 
Calculate the offset from the start of the image to the partition start
Sector size * Start = (in the case) 56 * 512 = 28672
Mount it on /dev/loop0 using the offset
$ sudo losetup -o 28672 /dev/loop0 sda.img
 
Now the partition resides on /dev/loop0. You can fsck it, mount it etc
$ sudo fsck -fv /dev/loop0
$ sudo mount /dev/loop0 /mnt
 
Unmount
$ sudo umount /mnt
$ sudo losetup -d /dev/loop0

Tuesday, September 29, 2015

JavaScript Contexts and Scopes

It took me a LONG LONG LONG time to figure out why my code re-factorization wouldn't work in JavaScript. I finally found the page ryanmorr.com/understanding-scope-and-context-in-javascript which led me in the right direction and this developer.mozilla.org page which showed me a more concrete example.

Basically, I wasn't using the "bind" function for my object references.


// Define the class.
var Construct = Construct  || (function() 
{
    // Constructor.
    var Construct = function(name) {};
   
    // Additional functions.
    Construct.prototype = 
    {
        sayHello: function() { alert("Hello"); }
        schedule_WRONG: function() { setTimeout(this.sayHello, 1500); },
        schedule_RIGHT: function() { setTimeout(this.sayHello.bind(this), 1500); },
    };
   
    // Return the type.
    return Construct;
})();

$(function()
{
    // Construct the object.
    var f = new Construct();
    f.schedule();

});

Friday, July 10, 2015

Disable debug logging in KDE 5

KDE 5 or Plasma or KF5 or whatever the hell it goes by logs WAY too much crap in the journal.

According to https://bbs.archlinux.org/viewtopic.php?id=193123 its an easy fix to disable debug logging although the kdebugdialog5 program doesn't actually do anything.

Add the lines:
QT_LOGGING_RULES="*.debug=false"
export QT_LOGGING_RULES
to /usr/bin/startkde near the top.

Friday, April 17, 2015

Directing stdout and stderr

Some interesting syntax I wasn't aware of from this stack overflow thread.


# Send stdout to sample.s, stderr to sample.err
myprogram > sample.s 2> sample.err

# Send both stdout and stderr to sample.s
myprogram &> sample.s # New bash syntax
myprogram > sample.s 2>&1 # Older sh syntax

# Log output, hide errors.
myprogram > sample.s 2> /dev/null

Thursday, April 9, 2015

Formatting code on blogger.com

This post is a work in progress, trying to get the syntax formatting code from this www.craftyfella.com, and relating to the script by Alex Gorbatchev entry to work.

For instance, the HTML code to highlight python *should be* something like this.

<h1>Highlighted Python</h1>
<pre class="brush: python; highlight: [5, 15]; html-script: true">
    Python code goes in here
</pre>
# Testing with Python here
if x > 5:
    """ Print stuff """
    print("x is more than 5")
print("done")

These are the includes you can use.

<link href="http://alexgorbatchev.com/pub/sh/current/styles/shCore.css" rel="stylesheet" type="text/css"></link>
<link href="http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css" rel="stylesheet" type="text/css"></link>
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js" type="text/javascript"></script>
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCpp.js" type="text/javascript"></script>
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCSharp.js" type="text/javascript"></script>
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js" type="text/javascript"></script>
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js" type="text/javascript"></script>
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js" type="text/javascript"></script>
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPhp.js" type="text/javascript"></script>
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js" type="text/javascript"></script>
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushRuby.js" type="text/javascript"></script>
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js" type="text/javascript"></script>
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushVb.js" type="text/javascript"></script>
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js" type="text/javascript"></script>
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPerl.js" type="text/javascript"></script> 

Sunday, March 15, 2015

Playing DVDs in Arch


I've never had this much trouble before, most of my DVDs simply wouldn't play at all. I installed tons of libraries, cleaned scratches, nothing... And no error messages from any of several programs gave me a clue as to the problem.



Finally I found a post mentioning having no region set on a DVD drive. I found and downloaded "regionset" and sure enough that did the freaking trick.




~ $ regionset /dev/sr0
Current drive parameters for /dev/sr0:
RPC Type: Phase II (Hardware)
RPC Status: no region code set (bitmask=0xFF)
Vendor may reset the RPC 4 times
User is allowed change the region setting 5 times
Would you like to change the region setting for this drive? [y/n]: y
Enter the new region number for your drive [1..8]: 1
New RPC bitmask is 0xFE, ok? [y/n]: y
Region code set successfully.


After which everything played just peachy.

Thursday, February 5, 2015

Gnu Parallel

I had never heard of this til now, but it looks like it can make some tasks in Bash much simpler/faster.

From: https://en.wikipedia.org/wiki/GNU_parallel

The idea is to convert code such as:

for x in `cat list` ; do
do_something "$x"
done | process_output


Into


cat list | parallel do_something | process_output


Another simple example someone posted on the Arch Wiki (s/printf/echo/):


printf "world\nasynchronous processing" | parallel "echo hello, {}"

hello, world
hello, asynchronous processing

Wednesday, February 4, 2015

OpenSSL: Find certificate whose CSR was generated by a given private key


It can be confusing to determine which certificate file and which private key go together if you don't know exactly what you are looking for. At least one way to determine whether a given key was used to generate the Certificate Signing Request of a given cert is to compare their modulus values (shortened/obscured by md5 hashing).




Show the value for the private key.



$ openssl rsa -noout -modulus -in private_key.key | openssl md5

(stdin)= cab197... some stuff ... c68caa2



Show the value for the cert.




$ openssl x509 -noout -modulus -in signed_cert.crt | openssl md5

(stdin)= cab197... same stuff ... c68caa2




If the values match they go together.

I got my certificates in a bunch of formats and couldn't figure out which to use, so I brute forced the solution:



$ for file in `ls *c[er][rt]` ; do echo -n $file && openssl x509 -noout -modulus -in $file | openssl md5 ; done
some_file.crt (stdin)= cab197... c68caa2

other_file.cer (stdin)= 2241f7... D08923

...

Convert ide bus to virtio in Windows guests on Proxmox

Surprisingly simple to do this:


This is the exact procedure from http://forum.proxmox.com/threads/5248-Is-it-possible-to-convert-to-Virtio:

With "BUS" you mean IDE I suppose. Yes, it's possible, just you could risk that Win2008 ask you for a reactivation (hardware change can trigger it).
Sure on the wiki you find the answer, that is the same way you usually follow when installing as Virtio from the beginning.
In short, shutdown Win2008 and simply add a very small HD (like 1GB) with Virtio type to your Win2008 guest from web interface, and have the cdrom pointing to the ISO with the virtio drivers for kvm (latest and greatests, virtio-win-1.1.11-0.iso at the moment, see http://alt.fedoraproject.org/pub/alt...st/images/bin/).
Boot Win2008 that will detect the new 1GB HD and ask you for drivers. Install them (the ones in P { margin-bottom: 0cm; }'Wlh' dir on the .iso) and shutdown. Remove the additional hd AND your current HD (will be listed beyond as unused HD), and then re-add it picking it from the unused section, but this time with VIRTIO interface. Boot the VM and enjoy!
Of course, I don't take resposability for the success of the above, so do a backup first, just in case...


By the way, we have a VSphere setup here now, I have been messing with it for a week and it is HORRENDOUS by comparison to Proxmox as far as ease of use and administration. The interface is the most unintuitive jumbled unorganized thing I have ever seen. Now I grant you that I am still new at it, but things that are SO obvious on proxmox are either difficult or impossible on VCenter.
There are many different interfaces for doing the same things, some options are allowed some places not others, its really confusing.

Tuesday, February 3, 2015

Copy contact between address books in Thunderbird

There is NO WAY to do this via menus, right clicks etc... that I have found. But there is a secret means I found:

"Hold down the Ctrl key at the same time as you drag and drop the contact record from one book to another in order to copy rather than move the data."

Thank you to http://forums.mozillazine.org/viewtopic.php?f=39&t=1970171

Thursday, January 29, 2015

Associating MS Office file types with Wine Applications

I've posted on this previously, but this one is just a bit different. I have associations that for instance start MS Word when I click a .docx file but, the file is not loaded. The launcher was executing:

env WINEPREFIX="/home/tward/.msoffice2010" wine /home/tward/.msoffice2010/dosdevices/c\:/Program\ Files/Microsoft\ Office/Office14/WINWORD.EXE %U

After seeing this post I changed it to simply tell wine to launch the proper application:
env WINEPREFIX="/home/tward/.msoffice2010" wine C:\\windows\\command\\start.exe /Unix %U

And its working now.

Friday, January 23, 2015

Set or change timezone in Debian

Just something I can't seem to remember when I need it:

~ $ sudo dpkg-reconfigure tzdata

Friday, January 16, 2015

Scripting user passwords in Proxmox 3.3

Proxmox has had a bug in their pveum code for some time now in that it won't let you directly script the user passwords when adding a user, or when changing a user's password. The usage info SAYS you can give passwords on the command line, but it doesn't work.

Well, I figured out a workaround. After realizing that pveum is a perl script, I found this post at this post at perlmonks.org which led me to make a small change to the line which reads the password to allow for redirected text to be accepted.

The change is in a subroutine beginning with "my $read_password = sub {" (line 49 on my system) to accept redirection. The blue is from the original file, the red reflects my change.

# diff pveum.original pveum.fixed
49c49
<     my $term = new Term::ReadLine ('pveum');
---
>     my $term = new Term::ReadLine ('pveum', \*STDIN, \*STDOUT);

So now I can update a password by redirecting the password string from Bash.

# printf "mypassword\nmypassword\n" | pveum passwd myuser@pve