12 November 2012

279. Formatting and adding a disk with fdisk

I've got a box with two harddrives -- sda (160 gb) has debian and sdb has CentOS (500 gb). I never use CentOS and I need the space for debian.

sudo fdisk -l
WARNING: GPT (GUID Partition Table) detected on '/dev/sda'! The util fdisk doesn't support GPT. Use GNU Parted. Disk /dev/sda: 160.0 GB, 160041885696 bytes 255 heads, 63 sectors/track, 19457 cylinders, total 312581808 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 Device Boot Start End Blocks Id System /dev/sda1 1 312581807 156290903+ ee GPT Disk /dev/sdb: 500.1 GB, 500107862016 bytes 255 heads, 63 sectors/track, 60801 cylinders, total 976773168 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x0007e385 Device Boot Start End Blocks Id System /dev/sdb1 * 63 32772599 16386268+ 83 Linux /dev/sdb2 32772600 40965749 4096575 83 Linux /dev/sdb3 40965750 43006004 1020127+ 82 Linux swap / Solaris /dev/sdb4 43006005 976768064 466881030 5 Extended /dev/sdb5 43006068 976768064 466880998+ 83 Linux

We're in 'luck' since we're only interested in killing sdb, and gparted wants a Display (this is done remotely).
So
sudo fdisk /dev/sdb
Command (m for help): d Partition number (1-5): 1 Command (m for help): d Partition number (1-5): 2 Command (m for help): d Partition number (1-5): 3 Command (m for help): d Partition number (1-5): 4 Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.

So did it work?
 sudo fdisk -l
WARNING: GPT (GUID Partition Table) detected on '/dev/sda'! The util fdisk doesn't support GPT. Use GNU Parted. Disk /dev/sda: 160.0 GB, 160041885696 bytes 255 heads, 63 sectors/track, 19457 cylinders, total 312581808 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 Device Boot Start End Blocks Id System /dev/sda1 1 312581807 156290903+ ee GPT Disk /dev/sdb: 500.1 GB, 500107862016 bytes 255 heads, 63 sectors/track, 60801 cylinders, total 976773168 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x0007e385 Device Boot Start End Blocks Id System
Time to create a new partition
sudo fdisk /dev/sdb
Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p Partition number (1-4, default 1): Using default value 1 First sector (2048-976773167, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-976773167, default 976773167): Using default value 976773167 Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.

Did it work?
sudo fdisk -l /dev/sdb
Disk /dev/sdb: 500.1 GB, 500107862016 bytes 81 heads, 63 sectors/track, 191411 cylinders, total 976773168 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x0007e385 Device Boot Start End Blocks Id System /dev/sdb1 2048 976773167 488385560 83 Linux
Create a file system:
sudo mkfs.ext4 /dev/sdb1
mke2fs 1.42.5 (29-Jul-2012) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 30531584 inodes, 122096390 blocks 6104819 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=4294967296 3727 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 102400000 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done
Let's automount it:
mkdir /home/me/scratch

and edit /etc/fstab
/dev/sdb1  /home/me/scratch    ext4    defaults        0       2

You're done.

11 November 2012

278. Monitoring your office with a webcam and zoneminder on debian

Update: so this worked fine with my thinkpad sl410 camera, but I'm having a lot of trouble getting an image off of my usb Pixio cam (Z-Star Microelectronics Corp. USB 1.1 Webcam) with "Got signal 11 (Segmentation fault), crashing" and "'zmc -d /dev/video0' exited abnormally, exit status 11". Zoneminder feels annoyingly temperamental at times. Anyway, I ended up hacking together a poor but functional solution by using a shell script and streamer to save stills every few seconds, then letting zoneminder analyse and capture. Setting up two Airlink 101 AIC250W was remarkably easy though (although I remember having a lot of trouble in the past). I've also experimented with motion,  and although I'm having issues with the image colours it's working very well.

Original post
While I figured that the head of school might have a universal key allowing access to all the offices in the department (the cleaners do), finding out that he had used it to open my office for a trivial purpose has ticked me off.

While you may not have an expectation of privacy at your company office, I certainly do when it comes to my department office.

So I'm not too happy about that, and while monitoring my office will not prevent future breaches of privacy, it will at least ease some of the paranoia if it turns out that my office doesn't routinely get entered.

This post only deals with a locally attached webcam -- I struggled with remote wifi-connected webcams a few years ago with little luck.
sudo apt-get install zoneminder
sudo apt-get install v4l-conf v4l2ucp
sudo cp /etc/zm/apache.conf /etc/apache2/sites-enabled/zm.conf
sudo service apache2 restart

Figure out what video devices you have:
ls /dev/video* 
/dev/video0
and make sure www-data can access them
sudo adduser www-data video

You can now navigate to http://localhost/zm
Click on 'add monitor'

These settings are fine.

Note: these settings did NOT work. Keep reading the post...

Setting up the camera seemed deceptively easy -- everything went fine, except actually getting an image.

note the red colour for the video device. No good.

Looking at the log I was getting
Failed to set video format: Invalid argument
'zmc -d /dev/video0' exited abnormally, exit status 255


which is when I googled and found this post: http://rainbow.chard.org/2012/04/24/using-zoneminder-with-a-cheap-cctv-camera/

Basically, getting the settings absolutely right matters!
v4l-info

which told me
video capture
    VIDIOC_ENUM_FMT(0,VIDEO_CAPTURE)
 index                   : 0
 type                    : VIDEO_CAPTURE
 flags                   : 0
 description             : "YUV 4:2:2 (YUYV)"
 pixelformat             : 0x56595559 [YUYV]
    VIDIOC_ENUM_FMT(1,VIDEO_CAPTURE)
 index                   : 1
 type                    : VIDEO_CAPTURE
 flags                   : 1
 description             : "MJPEG"
 pixelformat             : 0x47504a4d [MJPG]
    VIDIOC_G_FMT(VIDEO_CAPTURE)
 type                    : VIDEO_CAPTURE
 fmt.pix.width           : 1600
 fmt.pix.height          : 1200
 fmt.pix.pixelformat     : 0x47504a4d [MJPG]
 fmt.pix.field           : NONE
 fmt.pix.bytesperline    : 0
 fmt.pix.sizeimage       : 5760000
 fmt.pix.colorspace      : unknown
 fmt.pix.priv            : 0

so changed my settings to
It took a bit of trial and error

Next, I was receiving
Got unexpected memory map file size 49153524, expected 230401524
and this post helped me:
http://jared-oberhaus-tech-notes.blogspot.com.au/2011/12/im-trying-to-capture-video-from-device.html

Our old friend shmmax eh? Apparently I had about 32 mb set up (!) on my laptop, so I changed it to 671088640 (640 mb)

sudo sysctl -w kernel.shmmax=671088640

See this post for how to make it permanent.

Anyway, once all is well you will hopefully see something like this (note the colours -- the /dev/ is a nice orange, although the log is still an unhappy red)
Now we can actually do things. Click on the name of your device (here: laptop) and you should get something like

You can now click on Zones in the main menu and add one (takes a little bit of trial and error, but you'll get there). To get motion detection, and thus get ZM to save things, change the mode from Monitor to e.g. modec

Your files will  be found under /usr/share/zoneminder/events but you can change that using the setting menu which you can access in the top right corner in the main window.

So that's pretty much it. There are a couple of settings you might want to fiddle with:
You might want to set up ffmpeg to allow for generation of video fles


So I got fed up with one of my cameras not working together with zoneminder. As a temporary fix I set zoneminder to use 'file' instead of 'local' or 'remote'. So now zoneminder looks at ~/webcam/current.jpg.
In that directory, a script is running (you need to install streamer):

#!/bin/bash
while true
do streamer -c /dev/video0 -b 24 -s 640x480 -o current.jpeg -q 2> /dev/null
        sleep 1
done

Also, I created a directory and symmlinked it to /usr/share/events to prevent my root partition from filling up:
mkdir zm/
chown www-data zm/
sudo rm /usr/share/zoneminder/events -rf
sudo ln -s /home/me/webcam/zm /usr/share/zoneminder/events

07 November 2012

277. Compiling LSDALTON on debian testing/wheezy

I'm writing this as a separate post even though it's really an integral part of the compilation of Dalton 2011 which I described here: http://verahill.blogspot.com.au/2012/11/compiling-dalton-2011-on-debian.html

LSDALTON supports Open MP which is neat -- it means you can't run across nodes, but it'll automatically take advantage of the resources on the node it's run on.

Anyway.

Assuming you've followed that post, you're now ready to compile LSDALTON.

cd ~/tmp/Dalton2011_release/LSDALTON/
./configure

There are fewer questions this time so I won't list them -- basically, use gfortran and gcc, and compile with OpenMP support.

This gives you a Makefile.config -- edit it as shown. Note that I have the debian libblas3 and libgomp1 packages installed.

ARCH        = linux
FMMDIR      = mm
#
#
CPPFLAGS      = -DSYS_LINUX -D_FILE_OFFSET_BITS=64 -D'INSTALL_BASDIR="/opt/dalton/basis"' -DGFORTRAN=471 -DVAR_LINSCA -DIMPLICIT_NONE
F77            = gfortran
F90            = gfortran
FLNK           = gfortran
CC             = gcc
RM             = rm -f
FFLAGS         = -march=native -O1 -ffast-math -funroll-loops -ftree-vectorize -ffloat-store -fno-whole-file
F90OPTFLAGS    = -march=native -O1 -ffast-math -funroll-loops -ftree-vectorize -ffloat-store -I. -x f95-cpp-input -ffloat-store -fopenmp -fno-whole-file
SAFEFFLAGS     = -march=native -O1 -ffast-math -funroll-loops -ftree-vectorize -ffloat-store -fno-whole-file
CFLAGS         = -march=native -O1 -ffast-math -funroll-loops -ftree-vectorize -std=c99 -DRESTRICT=restrict -DFUNDERSCORE=1 -ffloat-store -DUSE_UNDERSCORES
INCLUDES       =  
LIBS           = -lblas -lgomp 
INSTALLDIR     = /opt/dalton/bin
PDPACK_EXTRAS  = linpack.o eispack.o gp_dlapack.o gp_zlapack.o
AR             = ar
ARFLAGS        =  rvs
#
default : linux.x
#
# Suffix rules C
#
.SUFFIXES : .F90 .f90 .F .o .c

.F90.o:
        $(F90) $(INCLUDES) $(CPPFLAGS) $(F90OPTFLAGS) -c $*.F90

.f90.o:
        $(F90) $(INCLUDES) $(CPPFLAGS) $(F90OPTFLAGS) -c $*.f90

.F.o:
        $(F77) $(INCLUDES) $(CPPFLAGS) $(FFLAGS) -c $*.F

.c.o:
        $(CC) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) -c $*.c

Now compile!
make

Test your installation:
cd test/
 ./TEST all
[..]
-----------------------------------------------------------
TEST ENDED PROPERLY

#####################################################################
                              Summary
#####################################################################

ALL TESTS ENDED PROPERLY!
date and time         : Wed Nov  7 14:57:29 EST 2012