Recover your images from your broken CF/SD card

During our last holiday I recognized that my 4GB CF card was not recognized any more by my camera and my mac. I was looking for a recovery service on the net but the prices charged there were too high, so we accepted that the images from 1 day were lost.

I did not reformat the card because I was interested in recovering or searching for a possibility to recover. Today I sat in front of my screen and recognized that I had a linux server now up and running and that there should be tools to read and rescue the data there. I started a more detailed search session for rescuing data from CF cards using linux and I discovered the tool ddrescue, do not mix up with dd_rescue which is a complete different thing. The packagename for installation is:

sudo apt-get install gddrescue

Afterwards you can use the ddrescue binary on your linux machine. I read this article and concentrated on the part just above point 5 in the text where the different rescue steps are describe. You should read the whole text to understand what ddrescue does, but you don’t have to.

What you need for rescuing:

  1. a linux system
  2. a card reader
  3. a shell
  4. ddrescue installed
  5. time
  6. TestDisk application (download the package you will need the photorec binary)

First you have to find out what device is used for your card. Most cards can not be mounted if there is a logical defect causing the behavior. You should do a

tail -f /var/log/messages

to check which device your card is on. Example entry:

Nov 18 08:18:33 raspberrypi kernel: [864751.809897] sd 1:0:0:0: [sda] 7813120 512-byte logical blocks: (4.00 GB/3.72 GiB)

Within my system the card was recognized as the sda device so I had to use /dev/sda. The below commands have been issued one after another. If you get any errors executing the next statement you sometimes have to eject the card an reinsert and the command will work again. Details for the commands you will find in the aforementioned gnu link.

  • Please replace /dev/sda with your device name.
  • Please replace <destination_image> with the full qualified path to your desired destination where ddrescue should create the rescue image file.
  • Please replace <logfile> with the full qualified path to your desired destination where ddrescue should create the log file.

sudo ddrescue -i0 -s50MiB /dev/sda /home/pi/rescue/hdimage /home/pi/rescue/logfile
sudo ddrescue -i0 -s1MiB /dev/sda /home/pi/rescue/hdimage /home/pi/rescue/logfile
sudo ddrescue -i30GiB -s10GiB /dev/sda /home/pi/rescue/hdimage /home/pi/rescue/logfile
sudo ddrescue -i230GiB -s5GiB /dev/sda /home/pi/rescue/hdimage /home/pi/rescue/logfile
sudo ddrescue /dev/sda /home/pi/rescue/hdimage /home/pi/rescue/logfile
sudo ddrescue -d -r3 /dev/sda /home/pi/rescue/hdimage /home/pi/rescue/logfile

You should be patient the different steps can take quite a while. I have not measured the overall process because I did some searching and testing in between. Afterwards I copied the image file to my mac for further processing. If you install TestDisk on your linux system you do not have to this.

Don’t try to mount the image it is a data image only so there will be no success. This image can now be used for image rescue software like TestDisk – photorec.

If you have downloaded the package, extract it in a desired folder and open the terminal. Go to the folder you put TestDisk to and you will find the binary photorec there. Start photorec (replace <image_file_name> with the path and name to your image ddrescue created:

photorec <image_file_name>

The software openes in a DOS like application window where you can move around using the arrow keys and I followed the onscreen instructions, a few minutes later I had my images back

Steps I did within photorec:

  1. Select the media of media listed
  2. Hit enter on proceed
  3. Select unknown partition
  4. Select other if you card is from a digital camera (FAT/NTFS/HFS+…)
  5. next steps are obvious and bang your images are back

This procedure restored almost all images I thought lost. Only a handful images where damaged. So cool. Saved 100 € minimum.

Extend logical volume on Linux

I am not a system administrator but I had to extend a logical volume on our search cluster nodes due to increased data usage and a storage shortage. I have not done this before and after asking a linux admin and googling some pages I discovered that all the information needed for someone not having done this before is quite insufficient and I decided to write a sum up which finally worked fine:

Preconditions for this solution:

  • System with one SCSI controller important for below scan because host0 is used, this can be different if you have more than one SCSI controller in place
  • cfdisk or fdisk installed
  • lvm ready
  • existing Volume should be extended by a new physical volume

Hints:

  • sdc was the device on my system can be another one on yours
  • sdc1 will also then have another name on your system after fdisk
  • VolGroup01 was made on my system yours can have another name
  • /san mountpoint is the name on my system your mountpoint can have a different name

For Runaways the fast way:

rescan SCSI bus_______: echo "- - -" > /sys/class/scsi_host/host0/scan
create lvm partitioin_: fdisk /dev/sdc
create physical volume: pvcreate /dev/sdc1
unmount volume________: umount /san/
extend volume group___: vgextend VolGroup01 /dev/sdc1
save changes__________: vgchange -a y VolGroup01
extend logical volume_: lvextend /dev/VolGroup01/san /dev/sdc1
check filesystem______: e2fsck -f /dev/VolGroup01/san
extend filesystem_____: resize2fs /dev/VolGroup01/san
mount volume__________: mount -t ext3 /dev/VolGroup01/san /san/
check changes_________: df -h
reboot for cowards____: shutdown -r now

Detailed Doing:

  • Example for ls -l /dev/sd* before rescan
  • brw-rw---- 1 root disk 8, 0 Nov 9 10:21 /dev/sda
    brw-rw---- 1 root disk 8, 1 Nov 9 10:21 /dev/sda1
    brw-rw---- 1 root disk 8, 2 Nov 9 10:21 /dev/sda2
    brw-rw---- 1 root disk 8, 16 Nov 9 10:21 /dev/sdb
    brw-rw---- 1 root disk 8, 17 Nov 9 10:21 /dev/sdb1
  • Rescan of the SCSI bus
  • echo "- - -" > /sys/class/scsi_host/host0/scan
  • Example for ls -l /dev/sd* after rescan, a new device sdc is now visible for the system
  • brw-rw---- 1 root disk 8, 0 Nov 9 10:21 /dev/sda
    brw-rw---- 1 root disk 8, 1 Nov 9 10:21 /dev/sda1
    brw-rw---- 1 root disk 8, 2 Nov 9 10:21 /dev/sda2
    brw-rw---- 1 root disk 8, 16 Nov 9 10:21 /dev/sdb
    brw-rw---- 1 root disk 8, 17 Nov 9 10:21 /dev/sdb1
    brw-rw---- 1 root disk 8, 32 Jan 3 13:52 /dev/sdc
  • Mark partition for LVM using cfdisk followed by device
  • fdisk /dev/sdc
    [root@tfdsypwpadmin.tdmz.hbd ~]# fdisk /dev/sdc
    Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
    Building a new DOS disklabel. Changes will remain in memory only,
    until you decide to write them. After that, of course, the previous
    content won't be recoverable.The number of cylinders for this disk is set to 2610.
    There is nothing wrong with that, but this is larger than 1024,
    and could in certain setups cause problems with:
    1) software that runs at boot time (e.g., old versions of LILO)
    2) booting and partitioning software from other OSs
    (e.g., DOS FDISK, OS/2 FDISK)
    Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)Command (m for help): m
    Command action
    a toggle a bootable flag
    b edit bsd disklabel
    c toggle the dos compatibility flag
    d delete a partition
    l list known partition types
    m print this menu
    n add a new partition
    o create a new empty DOS partition table
    p print the partition table
    q quit without saving changes
    s create a new empty Sun disklabel
    t change a partition's system id
    u change display/entry units
    v verify the partition table
    w write table to disk and exit
    x extra functionality (experts only)Command (m for help): n
    Command action
    e extended
    p primary partition (1-4)
    p
    Partition number (1-4):
    Value out of range.
    Partition number (1-4): 1
    First cylinder (1-2610, default 1):
    Using default value 1
    Last cylinder or +size or +sizeM or +sizeK (1-2610, default 2610):
    Using default value 2610
    Command (m for help): t
    Selected partition 1
    Hex code (type L to list codes): 8e
    Changed system type of partition 1 to 8e (Linux LVM)
    Command (m for help): p
    Disk /dev/sdc: 21.4 GB, 21474836480 bytes
    255 heads, 63 sectors/track, 2610 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes

    Device Boot Start End Blocks Id System
    /dev/sdc1 1 2610 20964793+ 8e Linux LVM

    Command (m for help): w
    The partition table has been altered!

    Calling ioctl() to re-read partition table.
    Syncing disks.

  • Example for ls -l /dev/sd* after creating new partition using fdisk
  • brw-rw---- 1 root disk 8, 0 Nov 9 10:21 /dev/sda
    brw-rw---- 1 root disk 8, 1 Nov 9 10:21 /dev/sda1
    brw-rw---- 1 root disk 8, 2 Nov 9 10:21 /dev/sda2
    brw-rw---- 1 root disk 8, 16 Nov 9 10:21 /dev/sdb
    brw-rw---- 1 root disk 8, 17 Nov 9 10:21 /dev/sdb1
    brw-rw---- 1 root disk 8, 32 Jan 3 13:52 /dev/sdc
    brw-rw---- 1 root disk 8, 33 Jan 3 13:58 /dev/sdc1
  • Create the physical volume
  • [root@tfdsypwpadmin.tdmz.hbd ~]# pvcreate /dev/sdc1
    Physical volume "/dev/sdc1" successfully created
  • Unmount the volume
  • [root@tfdsypwpadmin.tdmz.hbd ~]# umount /san/
  • Extend logical volume with created physical one. We have a volume group defined with the name VolGroup01, there we will add the additional physical volume. Listing of vgdisplay:
  • [root@tfdsypwpadmin.tdmz.hbd ~]# vgdisplay
    --- Volume group ---
    VG Name VolGroup01
    System ID
    Format lvm2
    Metadata Areas 1
    Metadata Sequence No 2
    VG Access read/write
    VG Status resizable
    MAX LV 0
    Cur LV 1
    Open LV 1
    Max PV 0
    Cur PV 1
    Act PV 1
    VG Size 29.97 GB
    PE Size 32.00 MB
    Total PE 959
    Alloc PE / Size 959 / 29.97 GB
    Free PE / Size 0 / 0
    VG UUID 1HFeZa-IJNC-v7Wh-KKN1-VtPx-J04n-MV7YZ6
    [root@tfdsypwpadmin.tdmz.hbd ~]# vgextend VolGroup01 /dev/sdc1
    Volume group "VolGroup01" successfully extended
  • Changes are currently not visible for the node only for the volumegroup, see VolGroup01 is still of size 30GB but should be 50GB by now
  • [root@tfdsypwpadmin.tdmz.hbd san]# df -h
    Filesystem Size Used Avail Use% Mounted on
    /dev/mapper/VolGroup00-root
    16G 14G 940M 94% /
    /dev/sda1 99M 15M 80M 16% /boot
    none 3.9G 0 3.9G 0% /dev/shm
    /dev/mapper/VolGroup01-san
    30G 76M 28G 1% /san
  • Make changes persistent unmount Volume, call vgchange -a y volumegroupname and mount again
  • [root@tfdsypwpadmin.tdmz.hbd ~]# vgchange -a y VolGroup01
    1 logical volume(s) in volume group "VolGroup01" now active
  • Extend the logical volume with the size of the prior created physical volume
  • [root@tfdsypwpadmin.tdmz.hbd ~]# lvextend /dev/VolGroup01/san /dev/sdc1
    Extending logical volume san to 49.94 GB
    Logical volume san successfully resized
  • Extend the filesystem
  • [root@tfdsypwpadmin.tdmz.hbd ~]# e2fsck -f /dev/VolGroup01/san
    e2fsck 1.35 (28-Feb-2004)
    Pass 1: Checking inodes, blocks, and sizes
    Pass 2: Checking directory structure
    Pass 3: Checking directory connectivity
    Pass 4: Checking reference counts
    Pass 5: Checking group summary information
    /dev/VolGroup01/san: 12/3932160 files (8.3% non-contiguous), 142845/7856128 blocks
    [root@tfdsypwpadmin.tdmz.hbd ~]# resize2fs /dev/VolGroup01/san
    resize2fs 1.35 (28-Feb-2004)
    Resizing the filesystem on /dev/VolGroup01/san to 13090816 (4k) blocks.
    The filesystem on /dev/VolGroup01/san is now 13090816 blocks long.[root@tfdsypwpadmin.tdmz.hbd ~]# mount -t ext3 /dev/VolGroup01/san /san/
    [root@tfdsypwpadmin.tdmz.hbd ~]# df -h
    Filesystem Size Used Avail Use% Mounted on
    /dev/mapper/VolGroup00-root
    16G 14G 941M 94% /
    /dev/sda1 99M 15M 80M 16% /boot
    none 3.9G 0 3.9G 0% /dev/shm
    /dev/mapper/VolGroup01-san
    50G 84M 48G 1% /san
  • FINISHED

Ubuntu 11.04 and nxclient

Hi, I had some troubles using our existing terminalserver environment when moving to Ubuntu 11.04. Within 11.04 you can select more detailed keyboard layouts, especially when you are in Austria it is possible to select Austrian, which is nice from an personal viewpoint but it seems that mixes up the nxclient which obviously does know nothing about the keyboardlayout of the small country between the alps. You get a unusable keyboard layout where you are not able to type pipes, the key up, down does not work and so on. Solution: Move to German/Germany and everything is fine till nxclient will be introduced to Austria too.

sshmenu Tool for the admin

Again a blog post maybe interesting for you out there. I have to do quite a bunch of server administration throughout the day and have to connect using ssh many times a day. What gnome lacks here for me is a nice tool where you can manage your connections. I found this tool for me, called sshmenu. Nice tool, you can configure your ssh connection setting also including different profiles gnome-terminal provides. Due to the fact that I was a developer (a developer will always stick to developing) I saw that I had a bunch of connection to configure there but I won’t do that by hand. So I have written a little shell script which reads the server, user and gnome-terminal profile name (you saved your customized profiles with) from a file and generates the .sshmenu config file which is located in your $HOME directory automatically from the list. Here you find the sshmenu generating shell script you have to rename from .sh.txt to .sh only (wordpress does not gulp .sh files) and an example connection list file to test the script with.

Cisco vpnclient with Ubuntu Gutsy

Alternative for Cisco vpnclient – vpnc

I have found a better solution then the one below, follow this link to get (sorry only german) description on how to use vpnc instead of cisco vpnclient. I try to translate this here:

Install the vpnc package, please check yourself what sources you have to enable.

sudo apt-get install vpnc

Now you have to create a file as root in /etc/vpnc, name it like your profile e.g. myvpncprofile.conf! Fill in the information into the file as listed below:

IPSec gateway
IPSec ID
IPSec secret
Xauth username XXXXXXXX
Xauth password YYYYYYYY

Fill in den gateway ip, vpn name for the cisco group password do the following: in your .pcf file you find an entry prefixed enc_grouppwd which contains an encoded group password. Copy it to your clipboard and click this link, there you will get the encoded password in plain text which you the fill into IPSec secret part of the file.

After you have done all this you can use vpnc-connect command:
vpnc-connect /ect/vpnc/yourprofile.conf

to connect to your vpn. I left the Xauth password empty because I have a token and the vpnc asks me for the password. So far so good so simple. DONE. vpnc-disconnect kills the vpn connection which is pushed to the background.

For all who want to use the cisco vpnclient package, follow this instrucktion:

I tried to install vpnclient for cisco vpn connections with the packages out of the known internet sources and did not succeed. I found

this link http://linux-support.hiwi.rz.uni-kon…1.0640.tar.bz2 within the ubuntu forum here . Extract the package, and run ./vpn_install, answer the usual questions and finished. If you have an existing profile import it as mentioned here.