Proxmox: Adding Existing Logical Volumes

February 11th, 2014 No comments

Adding existing logical volumes to the list of virtual disks is non-obvious.
First add the VG to Proxmox using the “Storage|Add” UI. Once done, adding existing LV to Proxmox must be done via LVM command line tools.
A logical volume needs to have the correct naming, and (surprise!) an LVM tag set. For the correct tag (and LV name) format, use the UI to create a sample volume (VM|Hardware|Add|Hard Disk).
Note: LV names must fit a certain pattern. However, names like this seem to work: vm-110-timemachine.
The example below shows a pre-existing LV (vg1/vm-110-disk-2) without the “pve-vm-110″ tag Proxmox requires.
Subsequent steps add the tag, after which the volume appears in Proxmox.

# lvs -o vg_name,lv_name,lv_tags
VG     LV              LV Tags
pve    data
pve    root
pve    swap
vg0    vm-110-disk-1   pve-vm-110
vg0    vm-110-disk-2   pve-vm-110
vg1    vm-110-disk-1   pve-vm-110
vg1    vm-110-disk-2

To see LV tags:

# lvs @pve-vm-110
LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert
vm-110-disk-1 vg0 -wi-ao--- 500.00g
vm-110-disk-2 vg0 -wi-ao--- 750.00g
vm-110-disk-1 vg1 -wi-ao--- 750.00g

To add missing tags:

# lvchange --addtag pve-vm-110 /dev/vg1/vm-110-disk-2

Refresh the Proxmox Storage UI to see the new LV.

Categories: Linux Tags: , , , , , ,

bootstrap-scrollspy

August 17th, 2013 No comments

There are plenty of broken jsfiddles for this, so to save time, here is some code that works: boostrap-scrollspy

or preview (or download) here

Categories: Development Tags: , , ,

Angular Services in CoffeeScript

August 15th, 2013 No comments

This jsbin demonstrates how to use a CoffeeScript class to implement an Angular Service, using Service, Factory and Provider styles. You may have to click “Run with JS” to update Output pane. Download gist from github.

Update: by itself this is not enough, since services usually have to inherit other resources, and look something like this:


angular.module("app")
.service('thumbService', ['$log', '$q', ($log, $q) ->
...

A working example (using .factory instead of .service) from the angular-grunt-coffeescript seed app:

###
Example of a service shared across views.
Wrapper around the data layer for the app. 
###
name = 'common.services.dataSvc'

class DataSvc

	constructor: (@$log, @$http, @env) ->

	_get: (relPath)->
		return @$http.get("#{@env.serverUrl}/#{relPath}")

	getPeople: () ->
		return @_get('people')

	getPerson: (id) ->
		return @_get("person/#{id}")

angular.module(name, []).factory(name, ['$log','$http', 'common.services.env', ($log, $http, env) ->
	new DataSvc($log, $http, env)
])

Go uintptr from interface{}

June 28th, 2013 No comments

Some C functions accept more than one type of struct, so I wanted a Go wrapper able to pass a uintptr derived from an interface{}. Go’s reflect package makes this easy:

package main

import (
  "fmt"
  "reflect"
)

type USN_JOURNAL_DATA struct {
  UsnJournalID    int
  FirstUsn        uint32
  NextUsn         uint32
  LowestValidUsn  uint32
  MaxUsn          uint32
  MaximumSize     uint32
  AllocationDelta uint32
}

func doitA(ujd *USN_JOURNAL_DATA) (size uintptr, align int, p uintptr) {
  v := reflect.ValueOf(ujd)
  t := v.Elem().Type()
  size = t.Size()
  align = t.Align()
  p = v.Pointer()
  return
}

func doitB(i interface{}) (size uintptr, align int, p uintptr) {
  v := reflect.ValueOf(i)
  t := v.Elem().Type()
  size = t.Size()
  align = t.Align()
  p = v.Pointer()
  return
}

func main() {
  a := USN_JOURNAL_DATA{1, 2, 3, 4, 5, 6, 7}
  size, align, p := doitA(&a)
  fmt.Println(size, align, p)
  size, align, p = doitB(&a)
  fmt.Println(size, align, p)
}

Interestingly, as demonstrated above, the same implementation can be used for a func accepting either a struct pointer or an interface{}.

Go import

June 18th, 2013 No comments

Go is a wonderful language, able to build complex applications with very minimal configuration information. For many apps, only import statements are required.

However, there are a couple of special import cases worth knowing about:

import . “github.com/user/repo”

From golang.org: “If a program imports a standard package using import . “path”, additional names defined in the imported package in future releases may conflict with other names defined in the program. We do not recommend the use of import . outside of tests, and using it may cause a program to fail to compile in future releases.”

import _ “github.com/user/repo”

From Andrew Gerrand (Google): “Prefixing an import
with an underscore causes the package to be imported for its
side-effects only. (that is, it’s init functions are executed and
global variables initialized)”

Categories: Development Tags: ,

Raspberry Pi & Cubieboard Benchmarks

January 17th, 2013 No comments
Simple write test: dd bs=1M count=1000 if=/dev/zero of=test
Ignore first run results
Copy of 13,000+ files: cp -a /var/* …
O/S
Test
Raspberry Pi
Cubieboard
android (busybox to nvram)
4.8 M/B/s
berryboot (raspbian squashfs) 4G(c4)
200M 16 +/- .5MB/s 7.8 +/- .1 MB/s
1G 11 +/- .5MB/s 8.3 +/- 1 MB/s
200M to SATA HD 63 +/- 2MB/s
1G to SATA HDD 45 +/- 2MB/s
13,727 files (/usr) from SD -> HDD (ext4) 9.2 sec
13,727 files (/usr) from HDD -> SD 38 sec
debian (drazbian) 16G(c10)
200M 22 +/- 2 MB/s
1G 7.6 +/- .5 MB/s
Categories: Linux Tags: , , , ,

Make squashfs Disk Image

January 17th, 2013 No comments

Raspberry Pi (and Cubieboard) SD disk images typically have two (or three) partitions: the first is Fat32 (50-100MB) and includes the boot files, while the second (>1GB) contains the main Linux image. With compression, the combined image can be reduced from several GB (of mostly empty space) to a couple hundred MB.

With a regular Linux desktop computer that has kpartx and mksquashfs installed, you can convert the second partition to SquashFS like this:

$ sudo kpartx -av image_you_want_to_convert.img
add map loop0p1 (252:5): 0 117187 linear /dev/loop0 1
add map loop0p2 (252:6): 0 3493888 linear /dev/loop0 118784
$ sudo mount /dev/mapper/loop0p2 /mnt
$ sudo mksquashfs /mnt converted_image.img -comp lzo -e lib/modules
$ sudo umount /mnt
$ sudo kpartx -d image_you_want_to_convert.img

dd with gzip

January 16th, 2013 No comments

You can save a lot of space by compressing dd image files.
These examples use gzip but many other compression apps will work just as well.

backup with dd and gzip

dd if=/dev/wd0a | gzip -9 > /mnt/backup.gz

restore backup

gunzip /mnt/backup.gz – | dd of=/dev/wd0a

Categories: Linux, OS X Tags: , , , , , ,

XCode and Older iOS Devices

January 16th, 2013 No comments

With a bit of hacking, it’s possible to target older iOS devices than those normally supported by the latest SDK:

http://stackoverflow.com/questions/7760946/is-it-possible-to-target-older-ios-versions-when-using-xcode-4-2-and-ios-5-sdk

Categories: Development, OS X Tags: , , , , , , , ,

SourceTree from Command Line

January 16th, 2013 No comments

Download SourceTree command line tools from:

https://downloads.sourcetreeapp.com/SourceTreeAppStoreCmdLineToolInstaller.pkg

To open repo in current folder:

stree .

Categories: Development, OS X Tags: , , ,