June 23, 2010

Image hard drive using dd

Update: If your drive have bad sectors, this method does not work well. I tried Clonezilla, and the result is as bad. Either my disk is very bad (but windows XP is running fine) or there is a better way to do this.

  1. Boot from the live cdrom distribution such as puppy linux.
  2. Switch to root.
  3. Make sure NO partitions are mounted from the source hard drive.
  4. (optional) Fill the drive empty space with 0
 # dd if=/dev/zero of=/tmp/delete.me bs=8M; rm delete.me
  1. Mount the external HD.
      # mount -t vfat /dev/sda1 /mnt/sda1
  2. Backup the drive.
      # dd if=/dev/hda conv=sync,noerror bs=64K | gzip -c  > /mnt/sda1/hda.img.gz

    "dd" is the command to make a bit-by-bit copy of "if=/dev/hda" as the "Input File" to "of=/mnt/sda1/hda.img.gz" as the "Output File". Everything from the partition will go into an "Output File" named "hda.img.gz". "conv=sync,noerror" tells dd that if it can't read a block due to a read error, then it should at least write something to its output of the correct length. Even if your hard disk exhibits no errors, remember that dd will read every single block, including any blocks which the OS avoids using because it has marked them as bad. "bs=64K" is the block size of 64x1024 Bytes. Using this large of block size speeds up the copying process. The output of dd is then piped through gzip to compress it.

  3. To restore your system:
      # gunzip -c /mnt/sda1/hda.img.gz | dd of=/dev/hda conv=sync,noerror bs=64K
  4. Store extra information about the drive geometry necessary in order to interpret the partition table stored within the image. The most important of which is the cylinder size.
      # fdisk -l /dev/hda > /mnt/sda1/hda_fdisk.info

Notes:

One of the disadvantages of the dd method over software specifically designed for the job such as Ghost or partimage is that dd will store the entire partition, including blocks not currently used to store files, whereas the likes of Ghost understand the filesystem and don't store these unallocated blocks. The overhead isn't too bad as long as you compress the image and the unallocated blocks have low entropy. In general this will not be the case because the emtpy blocks contain random junk from bygone files. To rectify this, it's best to blank all unused blocks before making the image. After doing that, the unallocated blocks will contain mostly zeros and will therefore compress down to almost nothing.

Mount the partition, then create a file of zeros which fills the entire disk, then delete it again.

# dd if=/dev/zero of=/tmp/delete.me bs=8M; rm delete.me

source: http://www.linuxweblog.com/dd-image

June 21, 2010

mini_httpd and cgi

1. to specify the cgi pattern, you need to quote it and prepend with ./. For example, to make *.cgi files as cgi, use "./*.cgi"

June 15, 2010

The smallest XML parser in C?

I always love to see things done small and nice. If you are looking for a simple XML parser, I found ezXML to be the best. One C file, One H file. Compiles without warning. Just great. Here is the link:

http://ezxml.sourceforge.net/

Vim: search/replace to change cases

The following command will change all upper case words to lower case

:%s/[A-Z]/\L&/g

The list of all special commands:

Replacement part of the S&R has its own special characters which we are going to use to fix grammar:

#
Meaning
#
Meaning
&
the whole matched pattern
\L
the following characters are made lowercase
\0
the whole matched pattern
\U
the following characters are made uppercase
\1
the matched pattern in the first pair of \(\)
\E
end of \U and \L
\2
the matched pattern in the second pair of \(\)
\e
end of \U and \L
...
...
\r
split line in two at this point
\9
the matched pattern in the ninth pair of \(\)
\l
next character made lowercase
~
the previous substitute string
\u
next character made uppercase

June 11, 2010

QML Module and Property Access

If the main QML file includes modules from other files, it CANNOT see ids or variables defined in those files. You will have to use

"property alias myvar: localmod_id"

to expose localmod_id to your main QML file. variable exposure was documented, but entire object id exposure is not documented in other places.

Qt QML setContextProperty

In order to use a C++ Class function in your QML file, you can expose the class itself using setContextProperty("myvar",pointer_to_your_class_instance), then call myvar.func() in your QML file. However, there is a trick to get this to work.

In your class definition file, these functions have to been exposed as "public Q_SLOTS:", otherwise QML cannot see it.

June 10, 2010

Convert FLV to 3GP file

ffmpeg\bin\ffmpeg.exe -i input.flv -s qcif -vcodec h263 -acodec libfaac -ac 1 -ar 8000 -r 25 -ab 32000 -y outputfile.3gp