recover sd card data with linux and gddrescue

Just to be clear about the setup, I’ll be using Debian 5 Linux and an 8 GB SD card with a SD to USB adapter over a USB 2.0 link.

gddrescue is included in the main Debian and Ubuntu repos, so in my case the install was just an “apt-get install gddrescue“.

Plug in your sd card and watch dmesg for the sd card. Mine was added to /dev/sda as one can see from the following output:

[ 2540.580007] usb 5-4: new high speed USB device using ehci_hcd and address 2
[ 2540.776619] usb 5-4: configuration #1 chosen from 1 choice
[ 2540.781484] scsi1 : SCSI emulation for USB Mass Storage devices
[ 2540.781939] usb 5-4: New USB device found, idVendor=090c, idProduct=6000
[ 2540.781947] usb 5-4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 2540.781953] usb 5-4: Product: USB2.0 Card Reader
[ 2540.781957] usb 5-4: Manufacturer: Generic , .
[ 2540.781961] usb 5-4: SerialNumber: 12345678901234567890
[ 2540.781977] usb-storage: device found at 2
[ 2540.781980] usb-storage: waiting for device to settle before scanning
[ 2545.780245] usb-storage: device scan complete
[ 2545.781307] scsi 1:0:0:0: Direct-Access Generic 6000 PQ: 0 ANSI: 0 CCS
[ 2545.783697] sd 1:0:0:0: [sda] 15855616 512-byte hardware sectors (8118 MB)
[ 2545.784973] sd 1:0:0:0: [sda] Write Protect is off
[ 2545.784983] sd 1:0:0:0: [sda] Mode Sense: 4b 00 00 08
[ 2545.784988] sd 1:0:0:0: [sda] Assuming drive cache: write through
[ 2545.787318] sd 1:0:0:0: [sda] 15855616 512-byte hardware sectors (8118 MB)
[ 2545.787949] sd 1:0:0:0: [sda] Write Protect is off
[ 2545.787958] sd 1:0:0:0: [sda] Mode Sense: 4b 00 00 08
[ 2545.787963] sd 1:0:0:0: [sda] Assuming drive cache: write through
[ 2545.788050] sda: unknown partition table
[ 2545.795255] sd 1:0:0:0: [sda] Attached SCSI removable disk

While logged in as root (or using sudo) make a copy of the sd card: ddrescue [/dev/device] [recovery image output] [logfile]

Now we will also need testdisk, so install that [Debian] [Ubuntu]: apt-get install testdisk

Testdisk can do some pretty cool stuff, but we are more interested in one of the subpackages it includes, photorec.

Now using photorec, let’s recover some photos: photorec /d [photo output dir] [recovery image output file from before]
And navigate through the menus and get your photos back. Usually the sd card is formatted in NTFS.

qwest actiontec gt701-wg PPOE on OpenWRT

I was having a difficult time yesterday trying to get my new OpenWRT install working on my Qwest DSL line. Here is how I got things working. I have yet to get the wireless interface working with WPA, I’ve just been using a different wireless access point I had lying around.

Telnet into your DSL modem, and cat /var/tmp/tr69para_pppoe (if you connect with PPoE) or cat /var/tmp/tr69para_pppoa (if you connect with PPoA).

Telnet into your gateway before flashing it and cat /proc/[###]/cmdline (where ### is the process number of pppd), this will get you the exact command used, along with the user/password that your gateway is using to login to the DSLAM. Save this command string for later!

I used the latest Kamikaze release (as of 03/28/2010) [download] and my Windows XP laptop connected via an Ethernet switch to my Actiontec. I was having trouble with tnftp on Debian, but I’ve heard it isn’t too hard to get that working. You have to be pretty fast, because as soon as you plug in your gateway you have ~3 seconds to ftp in. The username/password is adam2/adam2. No matter what IPv4 you have your gateway normally set to, it defaults to 192.168.0.1 on boot.

C:\Documents and Settings\Administrator\Desktop>ftp 192.168.0.1
Connected to 192.168.0.1.
220 ADAM2 FTP Server ready.
User (192.168.0.1:(none)): adam2
331 Password required for adam2.
Password:
230 User adam2 successfully logged in.
ftp> binary
200 Type set to I.
ftp> quote SETENV mtd5,0×90010000,0x903e0000
200 SETENV command successful
ftp> quote SETENV MAC_PORT,0
200 SETENV command successful
ftp> quote MEDIA FLSH
200 Media set to FLSH.
ftp> put “openwrt-ar7-squashfs.bin” “openwrt-ar7-squashfs.bin mtd5″
200 Port command successful.
150 Opening BINARY mode data connection for file transfer.
226 Transfer complete.
ftp: 2621444 bytes sent in 33.95Seconds 77.21Kbytes/sec.
ftp> quote REBOOT
221-Thank you for using the FTP service on ADAM2.
221 Goodbye.
Connection closed by remote host.
ftp> quit

C:\Documents and Settings\Administrator\Desktop>

Wait about 20 seconds before you telnet 192.168.1.1 to set the initial root password. Once you set the root password you are only allowed to login via SSH or the HTTP web interface.

SSH in to your new install and remove the existing options in /etc/ppp/options on your new OpenWRT install, and put the options we extracted earlier in the /etc/ppp/options file.

My /etc/ppp/options file ended up looking like this:

user [username]@qwest.net
password [password]
nodetach
defaultroute
usepeerdns
mru 1492
maxfail 10
lcp-echo-failure 4
lcp-echo-interval 30

And my /etc/config/network file for the wan portion:

config atm-bridge
option unit 0
option encaps llc
option vpi 0
option vci 32
option payload bridged # some ISPs need this set to ‘routed’

config interface wan
## PPPoE:
option ifname nas0
option proto pppoe

## PPPoA:
# option ifname atm0
# option proto pppoa
option encaps vc
option vpi 0
option vci 32

That should wrap things up. You might have to customize a few other things.

actiontec gt701-wg telnet modifications

I thought I might document some of the modifications I make to my Actiontec GT701-WG on a regular basis via Telnet. Sure these changes are not permanent, as they get reset every time you power-cycle the device. But I did not want to take the time to try and figure out how to recompile a whole new flash image, or chance bricking my only reliable Internet connection. Explanation follows semi-pastable.

echo "nameserver 208.67.222.222
nameserver 208.67.220.220" > /etc/resolv.conf

echo "127.0.0.1 localhost
192.168.0.1 gateway gateway.[yourdomain].com
192.168.0.# ntinstall [host] [host].[yourdomain].com" > /etc/hosts

echo "start 192.168.0.51
end 192.168.0.254
interface br0
opt router 192.168.0.1
opt dns 208.67.222.222 208.67.220.220
opt subnet 255.255.255.0
opt lease 86400
conflict_time 86400
lease_file /var/tmp/landhcps0.leases
siaddr 192.168.0.#
sname [hostname]
boot_file pxelinux.0" > /etc/udhcpd.conf

All of the code above assumes you are operating your network in the default 192.168.0.0/24 IPv4 local block. In addition, all of the changes happen nearly instantaneously in regards to reshaping network traffic.

The first chunk sets the default name servers that the gateway device uses to the fast OpenDNS servers. It also clears out the other crap that makes DNS queries time out trying to lookup domains in the actdsltmp local domain that is set by default. In the web interface I suggest setting the DNS servers to OpenDNS’s servers as well (those changes should be permanent).

The 2nd block is for those of you with your own domains that would like to set up the gateway so it refers to itself within your domain. The last line of the 2nd block – “192.168.0.# ntinstall [host] [host].[yourdomain].com” – overrides certain gateway DNS lookups and routes the particular name to an IPv4 address “192.168.0.#”. I use this line for my Unattended Windows installations, as it by default looks for a host by the name of “ntinstall” if you haven’t specified a hostname.

The 3rd pastie-grouping deals with the DHCP server that is built into the gateway. I enjoy the speed of OpenDNS queries on my LAN hosts as well, hence – “opt dns 208.67.222.222 208.67.220.220″. The last three lines of the 3rd block deal with my TFTP/PXE server. “siaddr 192.168.0.#” specifies a TFTP server at IPv4 address “192.168.0.#” (replace # with a number). “sname [hostname]” – replace “[hostname]” with the hostname of the server at address “192.168.0.#”. “boot_file pxelinux.0″ specifies that I wish to have my PXE client boot a file by the name of “pxelinux.0″ that is in the root of my TFTP server.

Did you know you can also run full websites off your gateway? Using a TFTP server on your network and built-in binaries on your gateway make it possible.

mkdir /var/www
chmod 755 /var/www
tftp -g -l /var/www/index.html -r public/gateway-site/index.html 192.168.0.#
chmod 644 /var/www/index.html
tftp -g -l /var/www/cgi.cgi -r public/gateway-site/cgi.cgi 192.168.0.#
chmod 755 /var/www/cgi.cgi
thttpd -d /var/www -u root -p 81 -c /var/www/**.cgi

To my knowledge, the /var directory on the Actiontec GT701-WG is the only directory one can write to. So first a directory is created for the website to reside in, and the necessary permissions (chmod) to make the site accessible. Then using the tftp client, “index.html” is grabbed from the “public/gateway-site/” directory on the tftp server at IPv4 address “192.168.0.#” (where # is a number), and this file is stuck in the “/var/www” directory. Then the “index.html” file is set to the proper permissions so it can be accessed – 644 for data/non-cgi files. A similar process happens for the cgi file, although this time it needs to be set to 755 so it can be executed when accessed.

I still can’t quite get cgi files compiled properly for the Actiontec GT701-WG, but I’m assuming one needs to do some cross-compiling to the MIPS 4KEc V4.8 32-bit chip that runs this. Article on compiling CGI stuffs: http://devhood.com/Tutorials/tutorial_details.aspx?tutorial_id=301.

Return top