Computer Help Log


ecarlson - Posted on 24 October 2008

Matlab Stuff:


Crash problem with matlab 7 under x86_64: *** glibc detected *** malloc(): memory corruption: 0x00000000005a0770 ***

To fix, I add export LD_ASSUME_KERNEL=2.4.19 to $MATLAB/bin/.matlab7rc.sh before the following lines:

MATLABsave="$MATLAB"

MATLAB="$MATLABdefault"

This also fixes problem with symbolic math library

Linux Stuff:


Need to modify init scripts in the rc?.d directories? Try chkconfig

Want to rename a bunch of files? Use bash for loops! for i in $(ls *in); do res=`echo $i|sed -n 's/\(.*\)\.in/\1\.grr/ p'`; mv $i $res; done


Windows Stuff:


Differences between partition types: NTFS vs. FAT

Need to clone or resize NTFS? Try KNOPPIX, and use the ntfsclone and ntfsresize tools


QEMU Stuff:


If you have a qemu disk that you want to enlarge, try the following:

Create the new image: qemu-img create winxp_new.img 3500M

Download a recent KNOPPIX cd, and boot from it: qemu -hda winxp.img -hdb winxp_new.img -cdrom ~/KNOPPIX_V3.8-2005-02-28-CeBIT_Edition.iso -boot d

At the boot prompt, enter knoppix lang=us 2

Once the console comes up, type fdisk -l to make sure that everything looks right... you should see your original disk as hda, and a new, unpartitioned disk hdb

Clone hda onto the bigger hdb: dd if=/dev/hda of=/dev/hdb

Now type fdisk /dev/hdb

Type p and see the partition table of /dev/hdb... it should match /dev/hda

So now we have a clone of hda, but we haven't enlarged the partition yet...

In fdisk, type d, this should delete the partition (or you'll be asked which partition to delete).

Now type n, which creates a new partition, and type p to create a primary partition. You can just press enter on the next prompts to have the new partition start at the begining and extend to the end of the new disk

By default, the new partition is of type 'Linux' and is not bootable, so press t, and set the type to 7, NTFS.

Next, press a and make partition 1 active

Ok, now we have the partition filling the disk, but the filesystem is only taking up the original size, so let's grow it...

First, enter ntfsresize --info /dev/hdb1, and make sure everything looks ok and there are no errors

Next, enter ntfsresize --no-action --size 3500M /dev/hdb1

If that completed successfully, you should be ready to try it for real...

ntfsresize --size 3500M /dev/hdb1

Hopefully that went ok, and you'll see something like 'NTFS had been successfully resized on device '/dev/hdb1',' good job!

Just to make sure everything is ok, run ntfsresize --info --force /dev/hdb1 and see that it checks out ok.

Now, try restarting qemu with the new disk and watch it go! The disk is marked 'dirty' by ntfsresize, so windows will check it on boot (don't panic).


LATEX Stuff:


Convert png/jpg to epsfiles:

use bmeps .png.eps

Supposedly, the following command can convert from eps to png, but it doesn't work with matlab eps files...

inkscape -export-png=newlogo2.png -export-dpi=300 newlogo2.eps

Want a way to underline that will break across lines? Add \usepackage{ulem} to the preamble, then use \uline instead of \underline

Need .png (or other) graphics for pdf's that can't use postscripts? Add \usepackage{graphicxs} to the preamble, and use \includegraphics to add the picture.

To use forward and reverse dvi viewing (this is great! Let's you jump right to the point in the dvi where you're cursor is in code, and visa versa!), add this to your preamble: \usepackage[active]{srcltx}

To mess with the spacing in lists (way to much, IMHO), add \usepackage{tweaklist} to your preamble, then add commands like the following to the top of your document:

\renewcommand{\enumhook}

{\setlength{\topsep}{0pt}

\setlength{\parsep}{0pt}

\setlength{\itemsep}{0pt}}

\renewcommand{\itemhook}

{\setlength{\topsep}{0pt}

\setlength{\parsep}{0pt}

\setlength{\itemsep}{0pt}}


Before doing that, you'll have to download tweaklist.sty and put it somewhere in your LaTeX path... I have mine in '/usr/share/texmf/tex/latex/misc/'. After saving it there, I had to run mktexlsr as root to update the LaTeX search paths.

Sick of badboxes and underfull warnings? Stick this at the top of your document: \setlength{\hbadness}{10000}

DVD Ripping


  • k3b's video encoder
  • k9copy
  • dvd::rip (urpmi Video-dvdrip)

Creating DVDs


  • Slideshows: manslide - creates dvd's from images with background sounds
  • Custom dvd's: mandvd - creates menus and such for you dvd, and can create the DVD structures and an iso file. Be careful... if you use the "burn with k3b" button, it doesn't seem to burn it as a video dvd and you get a coaster.
  • Burning: after you have the VIDEO_TS directory and IFO files and stuff from the other programs, use the "video project" in k3b from file->projects
  • Custom production: cinelerra, a good nonlinear video editor

DVD from video file


The easiest way is with some of the tools above (e.g. mandvd). If you don't have that, I used the following series of commands to resize a video and add black bars (mplayer), convert into something that dvdauthor could work with, make the dvd structure, then save to an image I could burn to disk:

mount /mnt/cdrom
cp -a /mnt/cdrom/* ./DVD # You will have to use dvdbackup if the dvd is encrypted
  1. The following scales to 50% original (after aspect ratio is taken into account... if yours is 1.5, use 360:240), then takes that result and expands canvas to 720:540

mencoder -dvd-device ./DVD/ dvd://1 -vf scale=360:270,expand=720:540:180:105:0:0:1 -o predvd.mpg -oac lavc -ovc lavc -lavcopts -acodec=ac3:abitrate=224:vcodec=mpeg2video:vhq

  1. Also look at the -aspect option to change aspect ratio (e.g. -aspect 1.33 or aspect 1.5)
  2. ffmpeg -i predvd.mpg -y -target ntsc-dvd -sameq final.mpg # I don't think this is necessary if input source is 720x480 already

dvdauthor --title -o dvd -f final.mpg
dvdauthor -o dvd -T
mkisofs -dvd-video -o dvd.iso dvd/

If ffmpeg doesn't work (I've had some problems with 'buffer underrun'), try mplayer (info from http://www.mplayerhq.hu/DOCS/HTML/en/menc-feat-vcd-dvd.html)


  1. NTSC DVD:

mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=dvd:tsaf -vf scale=720:480,harddup -srate 48000 -af lavcresample=48000 -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:keyint=18:vstrict=0:acodec=ac3:abitrate=192:aspect=16/9 -ofps 30000/1001 -o movie.mpg movie.avi

  1. PAL DVD:

mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=dvd:tsaf -vf scale=720:576,harddup -srate 48000 -af lavcresample=48000 -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:keyint=15:vstrict=0:acodec=ac3:abitrate=192:aspect=16/9 -ofps 25 -o movie.mpg movie.avi

Linux Wacom


For mandriva 2007 spring, I had to still download the sources from http://linuxwacom.sourceforge.net/ and compile from scratch. I did the following to get it working:

cd /usr/src/linux
cp /boot/config-2.6.17-13mdk ./.config
vi Makefile # change EXTRAVERSION to read "-13mdv" instead of "-13mdvcustom"
make oldconfig
make
make modules
cd
./configure --libdir=/usr/local/lib64 --enable-wacom --enable-hid
make
cd src/2.6.16
gzip usbhid.ko
gzip wacom.ko
cd /lib/modules/2.6.17-13mdv/kernel/drivers/usb/input
mv usbhid.ko.gz usbhid_bak.ko.gz
mv wacom.ko.gz wacom_bak.ko.gz
cd -
cp usbhid.ko.gz wacom.ko.gz /lib/modules/2.6.17-13mdv/kernel/drivers/usb/input/
shutdown -r now

I'd been having problems that the cursor would get stuck on the left edge of the screen whenever I put it on the pad. After doing a cat /proc/bus/usb/devices I saw that usbmouse was being used for the wacom, which isn't right. The only other problem is making sure your xorg.conf is correct.

Mandriva on a Dell Inspiron 700m


Stretched video mode


Resolution is supposed to be 1280x800, but was being set to 1024x768 and stretched in width. Solved by installing the 915resolution package, then editing /etc/sysconfig/915resolution to read:
MODE=38
XRESO=1280
YRESO=800
BIT=24

With the previous version of mandriva I didn't see the 915resolution package, but was using 855resolution. I was calling it from my rc.sysinit with the following:
855resolution 7d 1280 800

Xinerama vs. Single Headed


When the laptop is at home I wanted to be able to plug in a second monitor and have the desktop expanded to fill both, but when I'm away I wanted it to only use the laptop's monitor. I wasn't sure how to make this automatic, so I modified the boot menus to have a 'linux' and a 'linux-home' option. The difference between the two is shown in the following excerpt from lilo.conf:
image=/boot/vmlinuz
label="linux"
root=/dev/hda1
initrd=/boot/initrd.img
append="resume=/dev/hda5 splash=silent"
vga=788
image=/boot/vmlinuz
label="linux-home"
root=/dev/hda1
initrd=/boot/initrd.img
append="splash=silent location=home resume=/dev/hda5"
vga=788
The location=home section makes that an environment variable when the computer starts. All I have to do then is test what that's set to, and I can rearrange xorg.conf files appropriately before xorg starts. I chose to do this in /etc/rc.d/rc.sysinit:
if [ "$location" = "home" ]; then
echo I am home
cp -f /etc/X11/xorg.conf.home /etc/X11/xorg.conf
else
echo I am away
cp -f /etc/X11/xorg.conf.away /etc/X11/xorg.conf
fi

Palm on Linux


Making a full backup


Usually I'm successful with kpilot, but I've had some problems so lately I've taken to using pilot-xfer:
pilot-xfer -b ./ -p /dev/ttyUSB2
That backs up to the current directory, with the palm connected to ttyUSB2 (press the sync button before starting the command). This let's me backup all of my palm databases and keep several snapshots of the palm incase I have to go back

Restoring from a backup


Using the pilot-xfer backup, I can restore like this:
pilot-xfer --restore ./ -p /dev/ttyUSB2

Corrupted Address Book


Somehow my address book got corrupted... it looked like all of my appointments ever got set to reoccur on every day! Argh. Luckily I've setup my computer to backup my homedirectory every day, and that includes my kpilot entries, memos, and schedule info from KOrganizer. After clearing out my palm and restoring from an old backup, I tried copying my previously working schedule file (~/.kde/share/apps/korganizer/std.ics) back from a previous backup. That kept corrupting things, so eventually I tried restoring the palm datebook from a previously good palm backup, ran the dbScan utility from pimlico to scan for errors, remove deleted entries, etc, clearing my std.ics, then importing the palm entries into that.

VPN


The vpn at my work has never worked correctly, so I set one up at home that I have a server at work connect to, then use ip masquerading to connect to all of the rest of the computers at work.

IP Masq


I wanted to be able to connect to all of the work computers from home... to get this working, I added the following (these are from http://www.debian-administration.org/articles/489):

/etc/rc.d/rc.local:
iptables -t nat -A POSTROUTING -s 10.57.93.0/24 -d 172.30.0.0/16 -j SNAT --to 172.30.6.1
Where my home server (and vpn server) is 10.57.93.1 and my work server is 172.30.6.1.

/etc/sysctl.conf:
net.ipv4.conf.default.forwarding=1

If you want it to take effect immediately, enter the iptables command and then run
echo 1 > /proc/sys/net/ipv4/ip_forward

On my home server, I added the following to rc.local redirect 172.30.0.0 traffic to work, and to be able to access my home computers from work:
route add -net 172.30.0.0/16 gw 10.57.93.202
iptables -t nat -A POSTROUTING -s 172.30.0.0/16 -d 10.57.93.0/24 -j SNAT --to 10.57.93.1

Port Forwarding


I wanted to be able to access certain ports of computers directly from the outside (e.g. from my treo) without sshing home, then into work. This was accomplished as follows:

BitTorrent


Without my firewall set correctly, bittorrent was super slow... had to add the following to my rules:
bittorrent 6881-6999 UDP&TCP

Software RAID


This took me quite a while to get working right, but now it is and I really like it. I don't remember the commands I originally used to get things setup, but here are some useful ones:
mdadm -Es # Scans to see what's going on
mdadm --add /dev/md0 /dev/sdf1 # Adds a drive that had been offline
cat /proc/mdstat # See what the current status of the arrays is

My /etc/mdadm.conf file looks like this:
# cat /etc/mdadm.conf
DEVICE /dev/sd*1
ARRAY /dev/md0 num-devices=2 UUID=7ab95296:12ea3eb1:e5b2d3d8:d2c2895a auto=yes

The UUID was automatically set when I originally assembled the array... this configuration allows for the drives to come up with different lettering (e.g. sda/sdb/sdc/sdd/...), but still be recognized correctly.

Fixes for errors


Locate: Permission Denied


After upgrading to Mandriva 2007.1, I found that users could no longer use locate. When they tried, they would get this message:
$ locate file
locate: can not open `/var/lib/mlocate/mlocate.db': Permission denied
It turns out that mandriva installed mlocate instead of slocate. The problem is that the locate executable was owned by root:106, where there was no group with gid 106. Also, /var/lib/mlocate/mlocate.db was owned by root:slocate. I added a group for mlocate in the following way:
groupadd -g 106 mlocate
Then changed ownership of the database file:
chown root:mlocate /var/lib/mlocate/mlocate.db

klauncher could not be reached via dcop


This error was periodically showing up on my laptop... it turned out that the problem was that the dhcp settings allowed the hostname to be set by the network. When I would connect to a new wireless network or whatever, my hostname would be changed from what it was supposed to be, and linux in general doesn't seem to like that. The solution was to set NEEDHOSTNAME=no in /etc/sysconfig/network-scripts/ifcfg-eth0 (change for you device).

IMAP Connections


At one point I needed to find all the different emails that people have used to contact me at my domain. To do this I needed to sort through my ~4000 emails in my inbox, make a list of the @carlsonhome.net address used to reach me, and find the unique entries on the list... fun! Luckily, it wasn't too hard...
  1. Connect to my imap server: openssl s_client -connect :993
  2. Login: . login
  3. See the folders available: . list "" "*"
  4. Tell it I want to use my inbox: . select INBOX
  5. Fetch the "To" fields: . fetch 1:5000 (BODY[HEADER.FIELDS ("to")])
  6. I was using konsole, so I just saved my history to a text file in my home directory
  7. This had a lot of extra crap, so I used grep to get the lines in that file that had "carlsonhome.net" in them, and sed to take out everything except the address: grep -P "[^\s<\"]*@carlsonhome\.net" all_headers.txt | sed -n 's/.*[ <"]\(.*\@carlsonhome\.net\).*/\1/ p' | sort | unique > uniqueCarlsonhomeAddresses.txt. This command gets all of the lines that have a string in the form "not a space, '<', or '"'"@carlsonhome.net, then it replaces each of those lines with just the address part (the part from the space or < or " to the end of the .net). That list will contain a lot of duplicate entries in no order, so first it sorts the list, then only keeps the unique entries.
  8. Done! Next I went through and decided which aliases I wanted to keep, and set them up on my new mail server. Yea for linux!

To do the same thing for gmail was a little harder, but not much... since they use pop over SSL I couldn't just use telnet, but I could setup KMail to connect and download all my messages. Once in KMail (or outlook/thunderbird/etc...) I wasn't sure how to use the gui to make the list I wanted, but it saves all of it's messages in Maildir format. To access this directly I could call the imap server myself and tell it to use that folder as the source directory, then interact with it like before. The only caveat seems to be that it wants to look at folders starting with a '.', and KMail doesn't save things like that. To get this to work I just made a symlink from KMail's directory to a .-version I could access with imap: ln -s gmail_composerangel .gmail_composerangel. The steps were as follows:

  1. Setup KMail as described on GMail's website, download all my messages
  2. Get into the mail directory: ~/.kde/share/apps/kmail/mail
  3. Make the link: ln -s gmail_composerangel .gmail_composerangel
  4. imapd ./
  5. You can then continue as above, selecting the folder (. select INBOX.gmail_composerangel) and downloading the messages, then saving the konqueror session. An easier way is to put your commands in a text file like this:
    a

bc

. select INBOX.gmail_composerangel
. fetch 1:5000 (BODY[HEADER.FIELDS ("to")])
If I save this in ~/getlist.txt, I can then run this command: imapd ./ < ~/getlist.txt > ~/messages.txt. This reads input from your getlist.txt file, and saves its output to messages.txt. Now you can proceed as above to process it.

If you really want to go crazy, you can try a command like this :) :


imapd ./ < ~/getlist.txt | grep -P "[^\s<\"]*@angellam\.com" | sed -n 's/.*[ <"]\(.*\@angellam\.com\).*/\1/ p'|sort|uniq

That's going to start the imap server on your inbox, read its commands from your getlist file, send the output to grep to search for lines with addresses, send to send to extract only the address parts, sort that list, and find the unique entries :-D

Gallery Tips


Getting Resizes done on a server that limits CPU usage


I recently moved to Bluehost for hosting my website, and so far I like them a lot. The only problem I've had is that they limit cpu usage to such an extent that when I moved my Gallery2 install to them I could only resize about 500 pictures before I'd get a cpu usage exceeded message and have to wait ~10 minutes to try again. Since I had about 55000 resizes that needed to be processed, manually going through this process would be horrible... luckily I found a programmatic way. I first tried just doing wget for the gallery url that requests the photo resize operation, but since wget hadn't "logged in", that didn't work. I found someone's tip that you could do exactly what I wanted by running wget with the save-cookies option to the login page, then again with load-cookies to the resize link... wget would login and save the cookie it got from doing so, then the second time you run it, it loads the cookie and uses it to authenticate and login to start the resizes. Unfortunately, Gallery programmers thought security was more important than my convenience and so in fixing a cross-site scripting vulnerability they broke that method. Finally I found a workable solution... it turns out that gallery has an api you can plug-in to, and you can create a page that wget can request which will start the resize operation. Here's the php file I used, just save it as a .php file in your webspace... technically it is a security hole, so you may want to use a .htaccess file to limit what ips can access it or something:

<?php
/* Adjust the path to point to your gallery2 folder */
require_once('./embed.php');

/*
* Initialize G2 (includes all necessary classes,
* puts G2 into a state ready to process your calls)
*/
$ret = GalleryEmbed::init(array('fullInit' => true));
check($ret);

/* Grab the authToken */
global $gallery;
$session =& $gallery->getSession();
$authToken = $session->getAuthToken();
GalleryUtilities::putRequestVariable('authToken', $authToken);

/* Here we could either call any API mehtods or declare the controller request params */
GalleryUtilities::putRequestVariable('controller', 'core.AdminMaintenance');
GalleryUtilities::putRequestVariable('form[action][runTask]', 1);
GalleryUtilities::putRequestVariable('taskId', 'BuildDerivativesTask');

/* Execute the above defined controller request */
$data = GalleryEmbed::handleRequest();

/* $data['bodyHtml'] contains the resulting HTML */

function check($ret) {
if ($ret) die($ret->getAsHtml());
}

?>


With that in place, I just needed something to call it repeatedly until everything was done...

count=1;
status=;
while [ true ]; do
wget --http-user=xxxx --http-password=xxxxx http://www.domain.net/gallery2/makeThumbs.php;
if [ -f makeThumbs.php ]; then
echo found make;
status=`tail -50 makeThumbs.php |grep Processing | tail -1 | sed -n 's/.*image \([0-9]\+\) of \([0-9]\+\).*/\1 of \2/ p'`;
rm -f makeThumbs.php;
fi;
rm -f highload.html*;
echo "Sleeping...";
echo "Count = " $count;
count=$(($count+1));
echo Status = $status;
sleep 600;
done;

This script can be saved as a file, or as I did, just run right from the command line. I made it go into an infinite loop, but you could make it stop when it's finished by separating status, which I have in the form "30 of 5000", into "30" and "5000", then test when the "30" part equals the "5000" part. In the loop, the script uses wget to get my php file with my gallery username and password. If it succeeds there will be a makeThumbs.php file, which it checks for. If that exists it runs that long command to make status... the file consists of a huge list of lines of the form ...30 of 5000... which updates as the process progresses. I only really want the last update which is the most recent one and grepping through the whole file takes a long time. After just taking the last few lines, I grep to extract the matching ones and take the most recent (tail -1), then get rid of all the crap before and after the actual status update with sed. Here's where you could add a line and have "finished=.../\1/ p'..." and "total=.../\2/ p'". Then you could have changed your while loop to stop when they equal. The wget fails when the cpu is exceeded, after it stops I print out some status info and delete the old files, then wait for 10 minutes before restarting everything. After ~10 hours, all 55000 were done!

How to make Windows Usable (or as close as possible)


Change "Documents and Settings" location


One thing about any os, and especially windows, is that it's great to be able to reinstall the OS w/out wiping out all of your settings. I like to have one partition of ~10 gigs for my OS (either linux/win), then the rest of the drive for my files. Once I have all my programs installed and configured how I want them, I just image the 10 gig drive and back that up. If it gets messed up (e.g. viruses, spyware, whatever), just copy the image back and your documents and stuff are still in place (as long as they're not infected...). In linux, this is a simple matter of making a few symlinks or editing the /etc/passwd file. In windows, however...

Q. How do I change the directory in which the system stores profiles?

A. Windows NT 4.0 and earlier versions of NT store profiles in the %systemroot%\Profiles folder. Windows 2000 stores profiles in %systemdrive%\Documents and Settings, but the OS lets you specify a different location. To change the location, take the following steps:

  1. Create a new folder to host the profiles.
  2. Copy all existing profiles from the %systemdrive%\Documents and Settings folder to the folder you just created. (Note: If you're copying from NTFS to NTFS, use the XCOPY command with the /o switch to maintain any ACLs on the files.)
  3. Launch regedit.exe, and go to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList.
  4. Double-click ProfilesDirectory.
  5. Enter the path to the new folder, and click OK.

You can change the profile Win2K uses for default users by modifying the DefaultUserProfile string value, and you can change the profile Win2K uses for all users by modifying AllUsersProfile.

That was easy... not! Have fun copying the documents and settings folders if all you have is windows, too... I've never been able to do it, because whoever you're logged in as, windows is always using files in that directory. Since windows locks anything it's accessing, it won't let you copy it. The only way I've ever been able to do this is boot to linux (yea for knoppix!) and make the copy from there. So many windows problems can only be fix through linux... oh, the irony.

= Convert to Quicktime =
This is from http://www.mplayerhq.hu/DOCS/HTML/en/menc-feat-quicktime-7.html:

mencoder dvd://1 -o /dev/null -ovc x264 -x264encopts threads=auto:pass=1:turbo:bitrate=900:bframes=1: me=umh:partitions=all:trellis=1:qp_step=4:qcomp=0.7:direct_pred=auto:keyint=300 -oac faac -faacopts br=192:mpeg=4:object=1 -channels 2 -srate 48000 -ofps 24000/1001

mencoder dvd://1 -o outfile.avi -ovc x264 -x264encopts threads=auto:pass=2:turbo:bitrate=900:bframes=1: me=umh:partitions=all:trellis=1:qp_step=4:qcomp=0.7:direct_pred=auto:keyint=300 -oac faac -faacopts br=192:mpeg=4:object=1 -channels 2 -srate 48000 -ofps 24000/1001

mplayer outfile.avi -dumpaudio -dumpfile outfile.aac

mplayer outfile.avi -dumpvideo -dumpfile outfile.h264

mp4creator -create=outfile.aac outfile.mp4
mp4creator -create=outfile.h264 -rate=23.976 outfile.mp4

mp4creator -hint=1 outfile.mp4
mp4creator -hint=2 outfile.mp4
mp4creator -optimize outfile.mp4

mp4creator -list outfile.mp4