2013-12-27

Cool method to test analog & digital (DVB-T) TV receivers?

There seems to be a cool unconventional method to test your analogue (PAL / SECAM) or digital (DVB-T) TV receiver (set-top box, unit, tuner etc.);
all you need is a PC running Linux with X11 and a video card with analog VGA output (preferably not very old one),
just read the following article (by Fabrice Bellard, 2005):
(I've not tested it personally yet, but it looks promising enough).

2013-11-25

dd utility: the rescue versions

Apart from the traditional implementations of a Unix dd utility (e. g., one found in the GNU Core Utilities), there are some special versions of it, dedicated for rescuing the data from damaged (badly readable) disks:
  1. GNU ddrescue (by Antonio Diaz Diaz);
    seems to be the best choice from these two ones [1, 2];
    there's a GUI log viewer for it (ddrescueview), and also some other helper utilities (ddrutility);
  2. dd_rescue (by Kurt Garloff);
    there's also a wrapper script for it called dd_rhelp.
The Debian distribution software archives, starting from version 7.0 ("Wheezy"), have only the GNU ddrescue; you can install it the following way:
# apt-get install gddrescue
The convenient way to use this utility is to make an image (a binary dump) of the whole defective disk (FDD, HDD, CD, DVD etc.) with its help, and then apply data recovery / content extraction programs (e. g., TestDisk) directly to the disk image.

Anyway, regular backups & redundant data storage solutions should save you from data recovery problems :-)

References:
  1. Disk drive recovery: ddrescue, dd_rescue, dd_rhelp - System Administration Bits of Knowledge (by John Gilmore)
  2. Damaged Hard Disk - CGSecurity
---
Last updated: 2013-12-08

2013-10-08

Seagate: download finder

Just in case you're looking for downloads for your Seagate product (i. e., HDD firmware updates, manuals & software), here's a useful link:

2013-10-04

MS Windows installation on Sun / Oracle computer with SPARC CPU (video tutorial)

MS Windows XP & 7 (and more): installation on Sun Fire V240 server (with UltraSPARC IIIi CPU) — video tutorial (in Russian) :-)

2013-09-30

LCD display optimized video mode: CVT-R & Linux

Many modern LCD displays (ones with 60 Hz vertical refresh frequency) should support an improved video mode with reduced blanking intervals (CVT-R), which can save some signal bandwidth and reduce the cost of the cabling (sometimes you can use a single-link DVI / HDMI cable instead of a dual-link one to support some of the high-definition resolutions; due to reduced signal bandwidth, a longer, cheaper cable with a non-perfect shielding can be used with reduced risk of electromagnetic interference).
Unfortunately, the best mode sometimes can be missing from the display's EDID ("extended display identification data" accessed by computer through DDC), so your computer won't be able set the best mode automatically, and you'll need to do some manual configuration.
(The sample commands are for Debian GNU/Linux 7.0 "Wheezy", but should work for many other systems).
  1. First of all, find out the native resolution (e. g., 1920 x 1080) and refresh rate (should be a multiple of 60 Hz: 60 Hz, 120 Hz etc.) for your display.
  2. Try to calculate a suitable video mode string using cvt utility (from the xserver-xorg-core Debian package); 60 Hz is the default refresh rate, so it can be omitted:
    $ cvt -r 1920 1080
    # 1920x1080 59.93 Hz (CVT 2.07M9-R) hsync: 66.59 kHz; pclk: 138.50 MHz
    Modeline "1920x1080R"  138.50  1920 1968 2000 2080  1080 1083 1088 1111 +hsync -vsync
    $ cvt -r 1920 1080 120
    # 1920x1080 119.88 Hz (CVT) hsync: 137.14 kHz; pclk: 285.25 MHz
    Modeline "1920x1080R"  285.25  1920 1968 2000 2080  1080 1083 1088 1144 +hsync -vsync
  3. Check the current video mode of your display through the display's menu (and write down those values somewhere for reference). If the actual clock values are higher than calculated by cvt, then it's reasonable to test the freshly calculated video mode.
  4. For quick video mode changes, you can use xrandr utility (from the x11-xserver-utils Debian package):
    $ xrandr
    Screen 0: minimum 320 x 200, current 1920 x 1080, maximum 8192 x 8192
    DVI1 connected 1366x768+0+0 (normal left inverted right x axis y axis) 456mm x 123mm
       1920x1080      60.0*+ 
       1024x768       60.0  
       800x600        60.3     56.2  
       640x480        59.9  
    VGA1 disconnected (normal left inverted right x axis y axis)
    HDMI1 disconnected (normal left inverted right x axis y axis)
    $ xrandr --output DVI1 --mode 800x600
    $ xrandr --newmode "1920x1080R"  138.50  1920 1968 2000 2080  1080 1083 1088 1111 +hsync -vsync
    $ xrandr --addmode DVI1 1920x1080R
    $ xrandr --output DVI1 --mode 1920x1080R
    
  5. For permanent effect, you'll need to change X11 settings by putting the generated modeline into the proper section of the /etc/X11/xorg.conf config file:
    Section "Monitor"
        Identifier     "Monitor0"
        VendorName     "Vendor1"
        ModelName      "Model2"
        HorizSync       30.0 - 150.0
        VertRefresh     50.0 - 160.0
        Option         "DPMS" "true"
        Modeline       "1920x1080R"  138.50  1920 1968 2000 2080  1080 1083 1088 1111 +hsync -vsync
    EndSection
    
    Section "Screen"
        Identifier     "Screen0"
        Monitor        "Monitor0"
        DefaultDepth    24
        SubSection     "Display"
            Depth       24
            Modes      "1920x1080R"
        EndSubSection
    EndSection
    Don't forget to restart the X server for updated configuration to take effect.
  6. The video mode for Linux console probably can be changed using KMS (kernel mode setting); there's some good info about KMS settings on nouveau Wiki.

See also:

2013-08-31

HOWTO: configure the OS to use a 100 Hz refresh capable CRT monitor in Linux

  • Test environment.
    • Hardware
      • Monitor: Samsung SyncMaster 959NF
        • Test display resolution: 1024 * 768 @ 100 Hz
      • Video card: based on Nvidia GeForce2 MX400
        $ lspci | grep -i nvidia
        01:00.0 VGA compatible controller: NVIDIA Corporation NV11 [GeForce2 MX/MX 400] (rev b2)
      • CPU: x86-compatible (some old AMD Athlon one)
    • Software
      • OS: Debian GNU/Linux 7.0 "Wheezy" / i386
      • Video driver: nouveau
  • X11 graphical mode configuration.
    1. Use cvt utility to generate a modeline for X11:
      $ cvt 1024 768 100
      # 1024x768 99.97 Hz (CVT) hsync: 81.58 kHz; pclk: 112.25 MHz
      Modeline "1024x768_100.00"  112.25  1024 1096 1200 1376  768 771 775 816 -hsync +vsync
      
      Note: 100 Hz is a non-standard refresh rate for CVT.
      If CVT timings don't work for some ancient monitor, you can also try to use gtf utility to generate somewhat older GTF timings:
      $ gtf 1024 768 100
      
        # 1024x768 @ 100.00 Hz (GTF) hsync: 81.40 kHz; pclk: 113.31 MHz
        Modeline "1024x768_100.00"  113.31  1024 1096 1208 1392  768 769 772 814  -HSync +Vsync
      
      
      Both cvt & gtf utilities are part of xserver-xorg-core Debian package.
    2. Change X11 settings by putting the generated modeline into the proper section of the /etc/X11/xorg.conf file:
      Section "Monitor"
          Identifier     "Monitor0"
          VendorName     "Samsung"
          ModelName      "SyncMaster"
          HorizSync       30.0 - 110.0
          VertRefresh     50.0 - 160.0
          Option         "DPMS" "true"
          Modeline       "1024x768_100.00"  112.25  1024 1096 1200 1376  768 771 775 816 -hsync +vsync
      EndSection
      
      Section "Screen"
          Identifier     "Screen0"
          Monitor        "Monitor0"
          DefaultDepth    24
          SubSection     "Display"
              Depth       24
              Modes      "1024x768_100.00"
          EndSubSection
      EndSection
    3. Restart the X server for updated configuration to take effect.
  • Here are the sample settings for non-X11 user interfaces, put into /etc/default/grub (the GRUB2 config).
    For modified settings to make effect, don't forget to execute update-grub2 as superuser and then reboot.
    ...
    GRUB_CMDLINE_LINUX="video=VGA-1:1024x768M@100"
    ...
    # The resolution used on graphical terminal
    # note that you can use only modes which your graphic card supports via VBE
    # you can see them in real GRUB with the command `vbeinfo'
    GRUB_GFXMODE=1024x768
    ...
    Notes:
    1. The Linux command line option mentioned aboves allows to set a desirable video mode for virtual console using kernel mode setting (KMS).
      There's more info about KMS settings on nouveau Wiki.
    2. Display refresh rate doesn't seem to be specifiable for GRUB bootloader graphical mode. This initial graphic mode depends heavily on VBE.
    3. Other caveats: video play in console framebuffer (i. e., using mplayer) has not seemed to work for me in this test setup.

See also:

2013-08-04

HOWTO: get a high-quality image from an eBay listing

Well, sometimes you can find an interesting item on eBay, and then you want to take a nice look at the photos. Unfortunately, the pictures are often displayed in a low resolution (and without a "zoom in" option). Luckily, often you still have a chance to get good quality images (with resolutions up to 1600 * 1200; it depends on the original quality of the picture the seller has uploaded).

Notes. The sites are in process of migration to HTTPS, so you'll often see image URLs beginning with "https://" instead of plain "http://". And it should work for all regional eBay sites (i. e., ebay.com, ebay.co.uk, ebay.de etc.), and also for "eBay Kleinanzeigen" (German eBay classified ads site).
  1. An old image URL style.
    1. First of all, copy an URL of the needed image; you'll get something like this:
      http://i.ebayimg.com/t/Some-nice-item-For-sale-/00/s/S0mE-W1LD/$GaRb4gE~~60_12.JPG
    2. Then you'll need to modify the URL a little; just replace the last number found in the URL (it's preceded by a '_' and followed by a '.'; in this sample, it's "12") with "10":
      http://i.ebayimg.com/t/Some-nice-item-For-sale-/00/s/S0mE-W1LD/$GaRb4gE~~60_10.JPG
      or with "57" (I don't know what's actually better):
      http://i.ebayimg.com/t/Some-nice-item-For-sale-/00/s/S0mE-W1LD/$GaRb4gE~~60_57.JPG
    3. Just paste the modified image URL into your browser's address bar and enjoy!
  2. A new image URL style. The method remains similar.
    1. Get an image URL:
      http://i.ebayimg.com/images/g/GaRbaG3/s-l64.jpg
    2. Change the appropriate URL fragment to "1600":
      http://i.ebayimg.com/images/g/GaRbaG3/s-l1600.jpg
    3. ...
    4. Done!

References:
  1. getProductDetails : thumbnail How can I get high resolution picture of catalogued item. - eBay Developer Support / Customer Help
  2. getProductDetails - API Reference - Product API - eBay Developers Program
---
Last updated: 2017-03-14

2013-07-18

TestDisk & PhotoRec: nice tools to recover lost partitions & files

TestDisk + PhotoRec is a nice toolset to recover lost disk partitions (or at least rescue some files from corrupted filesystems) in case of storage media failures, re-partitioning errors etc.
Works for disk images too.
More to say, it's a free & open source (GPL v2+) cross-platform (Linux, *BSD, Apple Mac OS X, Oracle / Sun Solaris, MS-DOS, MS Windows) software.

Presently, in Debian-based Linux distros, TestDisk & PhotoRec have been packaged into a single testdisk package, so you can install both tools at once:
# apt-get install testdisk

2013-05-09

HOWTO: get hardware sensors info (temperature, fan speed, voltage etc.) in Linux

(Tested in Debian Wheezy).
  1. Install the lm-sensors software package:
    # apt-get install lm-sensors
  2. Run the interactive hardware monitoring chip detection script:
    # sensors-detect
    Usually, it asks a lot of questions, and you can automatically answer 'yes' on them (but be careful: on some systems a full scan can cause some problems, e. g., a false chip detection or even a system hang):
    # yes | sensors-detect
  3. After choosing to add the needed module names automatically to the /etc/modules config file, it's good to check it for duplicate entries (and possibly other garbage).
  4. Reboot (or try to load the newly added kernel modules manually).
  5. Finally, just execute the following command to print the sensors information:
    $ sensors

2013-04-14

HOWTO: radical lossless JPEG image optimization (in Linux)

(The sample commands are tested under Debian Wheezy).

First of all, don't forget to install the JPEG manipulating programs package:
# apt-get install libjpeg-progs
And it's the optimization itself:
$ jpegtran -copy none -progressive input.jpg > output.jpg
Notes:
  1. yes, it produces a progressive JPEG output image; if you don't like it (or it's unsupported in the target environment), use -optimize switch instead of -progressive (but the output image size will be bigger);
  2. there's also a non-recommended option (an -arithmetic switch) to enable arithmetic coding; it allows a more efficient compression than traditional Huffman coding does, but (unfortunately) it's not widely supported in JPEG decoders due to some historical patent restrictions;
  3. -copy none option removes all extra markers (comments, tags, thumbnails and other metadata) from the output; if you need to save them, use -copy comments (or even -copy all) option instead;
  4. you can add a -grayscale option, and it will omit color data from the output image without re-encoding (very useful for grayscale / black & white / monochrome images);
  5. more reading:

2013-04-11

HOWTO: convert audio CD image (FLAC + CUE) to MP3 tracks in Linux

Imagine you've archived your favourite audio CD into FLAC/CUE pair format (or maybe you've purchased some album in that digital downloadable lossless audio format, who knows), and now you want to convert it to the standard MP3 files for playing that album in your good old digital music player.

Let the files be processed in Debian GNU/Linux environment (sample commands tested in Debian 7.0 "Wheezy", and should also work for all Debian-based distros, e. g. Ubuntu, Mint etc.; Bash shell is assumed to be installed & used by default).

First of all, you should install all the necessary tools: FLAC (for decoding FLAC to WAV), LAME (to convert WAV to MP3), cuetools (to parse the CUE sheet) and shntool (to cut the big WAV file into smaller tracks according to the CUE sheet breakpoints).
# apt-get install flac lame cuetools shntool
Then the conversion process itself begins.
$ flac -d MyMusic.flac
$ cuebreakpoints MyMusic.cue | shnsplit MyMusic.wav
$ rm MyMusic.wav
$ for file in split-track*.wav; do lame -V0 $file; done
$ rm split-track*.wav
The output files are by default MP3 VBR V0, 44.1 KHz, Joint Stereo; it should be decent for most situations.
After conversion, you can process split-track*.mp3 files with your favourite media tagger application.
Enjoy.

2013-04-07

Default Sudo lecture

Here is a standard Sudo lecture, which can be seen at the user's first sudo run time (the following is an unmodified quote extracted from the sudo-$VERSION/plugins/sudoers/check.c source file found in the original sudo 1.8.6p7 source tarball):
#define DEFAULT_LECTURE "\n" \
    "We trust you have received the usual lecture from the local System\n" \
    "Administrator. It usually boils down to these three things:\n\n" \
    "    #1) Respect the privacy of others.\n" \
    "    #2) Think before you type.\n" \
    "    #3) With great power comes great responsibility.\n\n"
References:
  1. Sudo Main Page

2013-03-10

HOWTO: losslessly convert FLV video to MP4 in Linux (Debian)

Well, let's imagine we have a Flash Video (FLV/F4V) container file (possibly "unseekable" or with other minor problems) containing MPEG-4 AVC video & AAC (or MP3) audio.

We'll convert ("remux") it to MP4 without any transcoding (re-encoding), so it'll be very fast, and using only the free tools (available in the official Debian GNU/Linux repositories).

Note: unfortunately, old FLV videos containing VP6 and Sorenson video formats can't be remuxed into MP4 format; if you don't want re-encoding, you can try to remux them into MKV (Matroska); if you just want to fix the seek problems, you can just try FLV-to-FLV remuxing.

  • Method #1 (recommended): use ffmpeg (it's the main utility from the FFmpeg project).
    Install the "ffmpeg" package:
    # apt-get install ffmpeg
    Convert a FLV file to MP4, preserving audio & video:
    $ ffmpeg -i input.flv -codec copy output.mp4
    And even optimizing it for faster loading:
    $ ffmpeg -i input.flv -codec copy -movflags faststart output_optim.mp4
    To extract audio only:
    $ ffmpeg -i input.flv -codec copy -vn output_a.mp4
    To extract video only:
    $ ffmpeg -i input.flv -codec copy -an output_v.mp4
    Note: you can also use M4A (audio) / M4V (video) file extensions for output, if you like those Apple formats.
  • Method #2 (alternative): using avconv (it's a part of Libav project, a fork of FFmpeg).
    Install the "libav-tools" package:
    # apt-get install libav-tools
    Convert a FLV file to MP4, preserving audio & video:
    $ avconv -i input.flv -codec copy output.mp4
    To extract audio only:
    $ avconv -i input.flv -codec copy -vn output_a.mp4
    To extract video only:
    $ avconv -i input.flv -codec copy -an output_v.mp4
  • Method #3 (a somewhat ugly one): using MEncoder (a part of the MPlayer project).
    Install MEncoder:
    # apt-get install mencoder
    Convert a FLV file to MP4:
    $ mencoder input.flv -ovc copy -oac copy -of lavf -o output.mp4
    Note: according to the warning from MEncoder itself, output file can be corrupt:
    ** MUXER_LAVF *****************************************************************
    REMEMBER: MEncoder's libavformat muxing is presently broken and can generate
    INCORRECT files in the presence of B-frames. Moreover, due to bugs MPlayer
    will play these INCORRECT files as if nothing were wrong!
    *******************************************************************************
    So probably it suggests that you should better try the MEncoder's favorite AVI format:
    $ mencoder input.flv -ovc copy -oac copy -o output.avi
    (But that's not what we want here, right?)

Source software packages availability for Debian releases:
  • ffmpeg: up to Debian 6 "Squeeze", and then again from 9 "Stretch" (also in 8 "Jessie" backports);
  • libav: starting from 7 "Wheezy" (also in 6 "Squeeze" backports), up to 8 "Jessie";
  • mplayer: up to 7 "Wheezy", and then from 9 "Stretch".

And yes, it should work for Ubuntu too; any current FFmpeg version should also work in other GNU/Linux or *BSD distros, MS Windows, Apple Mac OS X etc.

References:
  1. ffmpeg Documentation
  2. Libav documentation : avconv
  3. 6.1. Selecting codecs and container formats - Chapter 6. Basic usage of MEncoder (MPlayer - The Movie Player documentation)
  4. Wikipedia:
    1. Flash Video
    2. MPEG-4 Part 14
    3. M4V
    4. H.264/MPEG-4 AVC
    5. Advanced Audio Coding
    6. Audio Video Interleave
---
Last updated: 2017-12-28

The Simpsons: Cisco

HOWTO: make MS VS 2005 work with WPF etc.

WPF ("Windows Presentation Fundation", just another MS Windows GUI API from .NET 3.0 "WinFX", this time XML-based) is fully supported in Microsoft Visual Studio 2008 and newer.
If you use VS 2005, you'll not find an option to create a WPF project from the New Project dialog (WPF was released as part of .NET Framework 3.0, while VS 2005 is for .NET 2.0).

Here are the required steps to get an ability to build WPF projects with VS 2005.
  1. Download .NET Framework 3.5 SP1 (if you don't have an up-to-date .NET 3.x version installed yet).
  2. Download a small add-on for VS 2005:
    Visual Studio 2005 extensions for .NET Framework 3.0 (WCF & WPF), November 2006 CTP
    Mirror: CNET | Download.com
    Note: MS has released that package as a CTP ("Community Technology Preview", MS' term for some kind of beta / preview SW releases); it's unsupported, so upgrade to VS 2008 or later is recommended.
  3. Install the downloaded MSI package.
    If the installer exits with an error (regarding the bad / already installed / newer .NET version), you should start it manually (i. e., from MS Windows Command Prompt, you know: <Win>+<R>, cmd, <Enter>) with a specific option:
    > cd P:\ath\To\Installer\Folder
    > msiexec /i vsextwfx.msi WRC_INSTALLED_OVERRIDE=1
    It allows to ignore that error and continue the installation process.
  4. After that, a new option titled Windows Application (WPF) should appear as part of (new!) .NET Framework 3.0 subcategory for C# language in the New Project dialog of the Studio.
    Enjoy!

See also:
  1. Visual Studio 2005 extensions for .NET Framework 3.0 (WF)
  2. Wikipedia: WCF / WPF / WF | .NET Framework

2013-02-05

JDownloader download manager

JDownloader is a very nice download manager:
  • it's a freeware (open source, though with some closed source parts);
  • it's written in Java, which doesn't make it super-fast, but cross-platform instead (runs well on MS Windows, GNU/Linux & Apple Mac OS X);
  • it allows [semi-]automated downloads from a lot of popular websites (i. e.: file sharing/"cloud" services, social networks, photo/music/video hostings etc.; the use of "premium" accounts is also possible).

Custom (manual) installation notes (primarily for GNU/Linux and other Unix-like OS users).
  1. Please install an up-to-date JRE (Java VM environment).
  2. The current major release is called "JDownloader 2". Go to the official download page and select the "Other" version for download.
  3. You should have a single file downloaded (JDownloader.jar). Please put into your favorite installation directory (e. g.: ~/Applications/JDownloader).
  4. Just run it (see below), and it should even auto-update itself!

Custom application launch notes.
  • Here is a sample shell script:
    #!/bin/sh
    cd ~/Applications/JDownloader
    java -Xmx512m -jar JDownloader.jar
    
  • The -Xmx Java option means the maximum allowed runtime RAM allocation (in this example, 512 MiB).
  • You can save it as JDownloader.sh on your desktop, or wherever you like (or even execute the commands manually, if you like).

Custom configuration notes.
  • In case the fonts in your JDownloader setup are displayed too small, you can try changing the configs:
    1. go to Settings → Advanced Settings;
    2. type "font" into the Filter Settings search box;
    3. increase the value of the "LAFSettings: Font Scale Factor" key (e. g., from the default 100 [percent] to something like 150);
    4. restart JDownloader.

P. S. Anyway, please be nice & respect the [copy-]rights of others ;-)

---
Last updated: 2018-10-10

Qualcomm Atheros device driver downloads site

Atheros has been acquired by Qualcomm, so currently the drivers for Atheros AR81xx and Lx network devices can be downloaded from Qualcomm Atheros corporate customer portal:
(these URLs seem to be interchangeable).

2013-01-25

HOWTO: make Jigdo use local APT cache

If you like to build Debian install CD images with Jigdo (i. e., with jigdo-lite), you may consider using packages from your local APT cache to save some network traffic.
To make it easily selectable from the Jigdo interface, make sure to add the following line to the ~/.jigdo-lite config file:
scanMenu='/var/cache/apt/archives/ /media/cdrom/'
BTW: /var/cache/apt/archives is a local APT cache directory (containing already downloaded DEB packages); /media/cdrom is a standard CD mount point, so you can reuse the files from the mounted CD image you've previously generated with Jigdo.

References:
  1. More About Scan Sources - Debian Jigdo mini-HOWTO

2013-01-15

FTP search engines: quick list

Usually, the conventional WWW (World Wide Web) search engines can do the Internet search job well, but sometimes (e. g., if you are looking for some particular file name) FTP search, cataloging & indexing engines can be of great help.
Here is a quick list of such sites.

2013-01-14

Free & open source data encryption software: quick list

Here is a quick list of free & open source on-the-fly filesystem (FS) encryption software.
  • Entire disk / volume / partition encryption & "virtual disk" (container file)-based software:
    • LUKS / dm-crypt [Linux (FS driver is implemented at kernel level); encrypted volumes are supported by FreeOTFE in MS Windows];
    • FreeOTFE [MS Windows];
    • DiskCryptor [MS Windows];
    • TrueCrypt [MS Windows, Mac OS X, Linux] (discontinued in 2014-05).
  • File-level encryption tools:
    • eCryptfs [Linux (FS driver is implemented at kernel level)];
    • EncFS [Linux (FUSE-based FS); experimental MS Windows port exists: encfs4win];
    • antigift (a ccrypt wrapper) [Linux, FreeBSD, Mac OS X, MS Windows].
---
Last updated: 2014-06-19

2013-01-06

HOWTO: stress-test a USB flash drive for bad blocks in Linux

Once upon a time you may like to test your USB flash drive [or maybe a SATA HDD, who knows] for bad blocks.

First of all, backup all the data stored on the target drive;
then you should unmount any mounted partitions located on that drive:
# umount /dev/sdz1
Then you can begin the tests (CAUTION: these tests will destroy all the stored data on the tested drive).

You can use dd utility to fill the drive with zeros:
# dd if=/dev/zero of=/dev/sdz
or with pseudorandom data:
# dd if=/dev/urandom of=/dev/sdz
and it will stop unexpectedly on a bad block.

And there's also a little more handy utility called badblocks:
# badblocks -wso /tmp/badblocks.log /dev/sdz
It will sequentially fill the entire /dev/sdz device with some patterns (0xAA, 0x55, 0xFF, 0x00), then read and compare the read data with an actual pattern. A list of bad blocks will be written to /tmp/badblocks.log file.

References: