Recovering Data from a Corrupted SD Card

SD cards are used in digital cameras, phones and other devices, where their speed and large capacity makes them useful for storing pictures, video and other voluminous multi-media items. It is quite common these days for a mobile device to contain a 16 Gb or 32 Gb SD card.

With the devices being so mobile, backups are easily overlooked. And it is quite easy for an SD card to become corrupted, for example if the card is removed while the device is on, or the battery is taken out while a video is being shot.

I was given a corrupted 16 Gb card and asked to recover the files, if possible. The rest of this post explains how the data was safely restored using simple Linux tools. Continue reading

Relabel a FAT File System in Linux

The venerable fat16 and fat32 file systems are still in widespread use today. Devices such as digital cameras, satellite navigation systems, memory sticks and mp3 players all make use of FAT

Mount a FAT file system in Linux, and it will appear as something like this:

[root@pluto ~]# df
Filesystem     1K-blocks      Used Available Use% Mounted on
/dev/sdb         7716112   7274796    441316  95% /media/0EB5-6037
/dev/sdc1       15549952  14225152   1324800  92% /media/1FC3-3137

Those hex numbers on the left are the default volume labels, and pretty unfriendly they are. The two entries above actually correspond to an MP3 player (Sansa Clip+) and the player’s expansion SD card. I used mlable to allocate more meaningful volume names. Continue reading

Format and Relabel a Flash Drive in Linux

Flash drives (as in memory sticks) are a popular choice for backups. A 64 Gb drive can be bought for just over £20 at the time of writing. Once your data is backed up to the drive, it is easy to store in a safe place or transport off site for added protection. Actually that applies to any portable hard drive, as does the following procedure.

Most flash drives come formatted as FAT32. That is fine from day-to-day but there is a strict 4 GB limit applying to the size of any file. Backup software is likely to produce large archive files well over 4 GB, so won’t work well with FAT32. What’s needed therefore, is a better file system. Continue reading

vi: Terminal too wide

Workaround for vi “Terminal too wide” problem

Use the Unix command line and sooner or later, you will be editing text files. One of the best ways of doing that is with the vi editor. It is available as standard on almost every unix/linux system. While other editors are available (ed, emacs, vim, etc), vi is quick and convenient. It offers a good balance between usability and ubiquity.

This article offers a workaround for the annoying “Terminal too wide” problem encountered by vi users on Solaris.

Vi was originally written for screens (terminals) which were 80 characters wide. In a modern windowing environment, the terminal has been replaced by virtual terminal apps – xterm, lterm, Terminal and many others. The width of a virtual terminal depends on how much big you make the window. On a large screen it could easily be 200 characters or more. Continue reading

Sorting with "-k" on Unix and Linux

The “sort” command on Solaris has a “-k” switch for sorting by a particular field. For example, “sort -k 2” will sort by the second field on each line of input. Parts of fields can be further specified with “-k n.m“, says the man page.

For example, “sort -k 2.3” should sort by the second field, starting with the third character in that field. But the man page isn’t the clearest, and getting the “-k x.y” notation to work is tricky. Tricky until you realize it never works you also supply the “-b” argument. Same on Linux. Continue reading

Using Tcpdump to See Background DNS Requests

This post explains how to use tcpdump on Linux to detect and investigate DNS requests. One of our Red Hat client systems was making requests to an old DNS server, even though it had been adjusted, through a change to/etc/resolv.conf, to point to a new one.

Requests to the old server were identified as follows.

[root@pluto root]# tcpdump -i eth0 -l -vvv dst host 192.168.1.103 and dst port 53
(...waited 15 mins or so...)
tcpdump: listening on eth0
16:38:18.019703 pluto.mycompany.com.41783 > olddnsbox.mycompany.com: [bad udp cksum 48f5!]  21331+ A? somebox.mycompany.com. (42) (DF) (ttl 64, id 48623, len 70)
16:38:18.033461 pluto.mycompany.com.41783 > olddnsbox.mycompany.com: [bad udp cksum 5919!]  12099+ A? somebox.mycompany.com. (42) (DF) (ttl 64, id 48625, len 70)

192.168.1.103 is the ip address of the old DNS server. Tcpdump shows network packets sent to the standard DNS port (53) at that IP address. Requests were few so I had to wait 15 or 20 minutes to capture the above.

The client was last rebooted a year ago, many months before /etc/resolv.conf was last edited. Tcpdump shows that some application is still querying the old server. The fix was to reboot the client, restarting the erroneous application and stopping the outdated requests.

Profiling and Tracing Processes in Linux

This article shows how a Linux process can be traced and profiled. Using the “last” command as an example, profiling is used to explain why a process was very slow, and why another, very similar, process (dump-utmp) was much faster. “Tracing” here means seeing what a process is doing at any moment. “Profiling” means showing (afterwards) how long it spent doing different things.

Last” is a Linux command that reads and summarizes the utmp file, where login records are stored. I had a “last” command taking hours to complete because the utmp file had grown large (1.9 Gb). Used strace to see what it was doing. Continue reading

RPM Spec Files

Information on RPM spec files is hard to come by. Here’s what I have. It isn’t much but might help somebody trying to build an RPM package for the first time. See also http://blag.wiki.aktivix.org/Rpm_tips

What the Spec File Does Overall

The spec file is used by the “rpmbuild” command to create a distributable RPM file for a piece of software. The “software” can be a large application including source code, or it might just be the application binary files, or even just a script or two.

The RPM file is a single file containing the software and scripts needed to install/uninstall it on a target system. Continue reading

Samsung S3 Connection Settings for iCard Mobile

iCard mobile might be the UK’s cheapest PAYG mobile provider. Data connection settings for a Samsung S3 are described below. Although beyond the general scope of this blog, the information was hard to find and so worth repeating here.

At the time of writing, iCard charges customers 3p per minute to call fixed lines, 6p per min to other mobiles, 10p per megabyte of data and 6p per SMS text. All of which may represent good value for certain usage patterns. There is no roaming or picture messaging.

iCard data settings are very simple. From the home screen, hit the menu key -> Settings -> More settings -> Mobile networks -> Access Point Names. Hit the menu key again and select “New APN”. Enter the following values: Continue reading

Deleting Awkward Files

Deleting any file under Unix/Linux is usually a simple matter of using the “rm” command. Some files are more stubborn. If the file name contains special characters, or begins with a dash (“-“), it can be hard to get rid of:

bash-4.2$ ls -l
total 0
-rw-rw-r--. 1 james james 0 Aug 25 14:46 -a
-rw-rw-r--. 1 james james 0 Aug 25 14:46 logfile
-rw-rw-r--. 1 james james 0 Aug 25 14:45 some'file
bash-4.2$ rm some'file
> bash: unexpected EOF while looking for matching `''
bash: syntax error: unexpected end of file

A Few Alternatives

One obvious solution is to use a GUI. Highlight the awkward file in any file manager, hit the delete key, and it’s gone. But GUIs aren’t available everywhere. You may have only shell access to a server, for example. Continue reading