LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-06-2012, 10:27 AM   #1
binary_dreamer
Member
 
Registered: Feb 2006
Distribution: debian squeeze
Posts: 199

Rep: Reputation: 31
backup of a cf card with a booting system


Hi.
i am running linux in a cf card (4GB) for an embedded system. that system has partitions in that cf card.
i would like to make a backup in .img of the whole cf so in case of disaster to create a new cf with the .img
the cf appears as /dev/sdb in my system.

could someone help me to create the .img backup, please?
 
Old 06-06-2012, 11:27 AM   #2
smoker
Senior Member
 
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279

Rep: Reputation: 250Reputation: 250Reputation: 250
Code:
dd if=/dev/sdb of=/path/to/your.img
Swap the infile and outfile parameters to write it back to a card.
 
Old 06-06-2012, 11:35 AM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
I'd suggest doing a wee bit more:
Code:
# Zero free space:
mount /dev/sdb /some/path && dd if=/dev/zero of=/some/path/.deleteme
rm -f /some/path/.deleteme; umount /some/path

# Create a hash for the drive first:
md5sum /dev/sdb > /path/to/sdb.md5

# Now dump disk contents to file:
dd if=/dev/sdb of=/path/to/sdb.dd

# Compare hashes to ensure you got it all:
md5sum /path/to/sdb.dd
cat /path/to/sdb.md5

# Finally compress the disk image:
bzip2 /path/to/sdb.dd

# Writing back then would be:
bzcat /path/to/sdb.dd.bz2 > /dev/some/device
 
Old 07-18-2012, 01:18 AM   #4
binary_dreamer
Member
 
Registered: Feb 2006
Distribution: debian squeeze
Posts: 199

Original Poster
Rep: Reputation: 31
Hi. it seems to work for me really good.
the only issue that i mentioned is that the original cf might be 2gb and the replacement card will be bigger size (eg 8gb). how could i make full use of the extra space? it would be really nice to resize the partitions in an easy way.
 
Old 07-18-2012, 01:27 AM   #5
frenchn00b
Senior Member
 
Registered: Jun 2007
Location: E.U., Mountains :-)
Distribution: Debian, Etch, the greatest
Posts: 2,561

Rep: Reputation: 57
I take it from my config. version 190.2.
.fvwm/scripts/clone-hdd.sh

never so much tested. It works with a busy box I think
Code:
#!/bin/sh

# init
rm /tmp/dialog.rep
rm /tmp/dialog.tmp
rm dialog.rep  
rm dialog.tmp 


LINES=$(tput lines)
COLUMNS=$(tput cols)


echo "Size console: $COLUMNS $LINES"
COL=$(( $COLUMNS -5 ))
LIG=$(( $LINES -3 ))


echo "Check your directory: "
pwd

if [ ! -f completed.wav ] ; then 
	echo "File completed.wav not found."
	echo "Please check your directory (pwd)"
	exit
fi




if [ "$1" != "--force"  ] ; then 
	if [ "$(whoami)" != "root" ]  ; then 
		echo "You are $(whoami) and not root."
		echo "Program exited."
		exit
	fi
fi



# clear
clear
echo "Current Path: $(pwd)"


# mode
rm /tmp/dialog.tmp
echo "Backup" > /tmp/dialog.tmp
echo "Restore" >> /tmp/dialog.tmp


	LISTOFFILES=` cat /tmp/dialog.tmp  `
	DIALOGLIST=` echo "${LISTOFFILES}" | sed 's/\ /_/g'   | awk -F ";" ' {  printf "\x22"NR"\x22"  " " "\x22"$0"\x22" " " }  '    `
	DIAG=$(dialog --menu "Choose one:" 60 800 80 ` echo "$DIALOGLIST" | head -n 1  `     2>&1 >/dev/tty  )
	if [ "$DIAG" = "" ] ; then
        	DIAG=""
	        exit
	fi
	CHOICE=`echo "${DIAG}" | sed 's/\"//g'`
	#[ "${CHOICE}" != ""  ] && echo "*$CHOICE*"
	echo "${LISTOFFILES}" | head -n "$CHOICE" | tail -n 1
	MODE=` echo "${LISTOFFILES}" | head -n "$CHOICE" | tail -n 1 `
	###MODE=`sh fvwmdialog.sh --sf dialog.tmp `



# mode restore
if [ "Restore" = "$MODE" ] ; then
	echo "Restore mode"
	aplay ding.wav

        # target now
        dialog --backtitle RESTORE  --fselect "$(pwd)/" 15 86  2>/tmp/dialog.rep
        SOURCEFILE=` cat /tmp/dialog.rep`
        echo "Source file: *$SOURCEFILE*"
        if [ ! -f "$SOURCEFILE" ]  ; then
                echo "You must enter a filename $SOURCEFILE that exists"
                exit
        fi

	# display info
	DESC=""

	IMGGZTEST=`echo "$SOURCEFILE"  | tail -c 8`
	IMGTEST=`echo "$SOURCEFILE"  | tail -c 5`
	[ "$IMGTEST" = ".img" ] && FORMATSRC="img"
	[ "$IMGGZTEST" = ".img.gz" ] && FORMATSRC="img.gz"


		[ "$IMGTEST" = ".img" ] &&  SOURCEFILEINFO=`echo "$SOURCEFILE" | awk ' {  gsub(".img",".info.txt") ; printf $0  }  '`
		[ "$IMGGZTEST" = ".img.gz" ] &&  SOURCEFILEINFO=`echo "$SOURCEFILE" | awk ' {  gsub(".img.gz",".info.txt") ; printf $0  }  '`

		if [  -f  "$SOURCEFILEINFO"    ] ; then 
			cat "$SOURCEFILEINFO" > /tmp/dialog.tmp
			dialog  --backtitle "RESTORE - Information file: ${SOURCEFILEINFO} "  --textbox /tmp/dialog.tmp 20 60
			DESC=` cat "$SOURCEFILEINFO"   `
			rm /tmp/dialog.tmp 
		fi
	echo "$SOURCEFILE"
	echo "$IMGTEST $IMGGZTEST : $SOURCEFILEINFO"
	echo "$FORMATSRC"


        ### select the disk
        if  [ "$(whoami)" != "root"  ] ; then
                sudo fdisk -l | grep "/dev/" | grep -v Disk > /tmp/dialog.tmp
                else
                fdisk -l | grep "/dev/" | grep -v Disk > /tmp/dialog.tmp
        fi
        file=`sh fvwmdialog.sh --sf /tmp/dialog.tmp `
        [ "$file" = "" ] && exit
        TARGETTMP=`echo "$file" | awk ' { print $1 } '`
        echo "Backup target: *$TARGETTMP*"

	# valid the disk with output
        dialog --backtitle RESTORE  --inputbox  output 20 60 "$TARGETTMP" 2>/tmp/dialog.rep
        TARGET=` cat /tmp/dialog.rep`
        echo "Target disk: *$TARGET*"
	echo "Src: $SOURCEFILE => $TARGET"



	# now cmdtd info
	if [ "$FORMATSRC" = "img.gz" ] ; then
		    CMDTDNFO="gunzip -c ${SOURCEFILE} | dd of=${TARGET}"
		echo "> $CMDTDNFO <$FORMATSRC> $CMDTDNFO "

	fi
	if [ "$FORMATSRC" = "img" ] ; then 
		 CMDTDNFO="dd  if=${SOURCEFILE} of=${TARGET}"
		echo "> $CMDTDNFO <$FORMATSRC> $CMDTDNFO "

	fi


        # confirm yes/no
        dialog  --backtitle RESTORE   --yesno "Command: \n $CMDTDNFO  \n \n Description:\n $DESC "  15 55  2>/tmp/dialog.rep


        # run it
        clear
        date
        echo " "
	echo " "
	echo "Disks: "
	fdisk -l | grep "${TARGET}"
	echo " " 
        echo "Command restore :  $CMDTDNFO  "
        echo "<Enter Return to start>"
        read enternowkey


        # run it
	echo "Start $(date)"
        if [  "$2" = "--debug"    ] || [ "$1" = "--debug" ] ; then
        	        echo "Debug"
                        else
				echo "	$FORMATSRC format: real mode - operation"
				# [ "FORMATSRC" = "img.gz" ] &&   gunzip -c ${SOURCEFILE} | dd of=${TARGET} 
				# [ "FORMATSRC" = "img" ] &&      dd  if="${SOURCEFILE}"  of="${TARGET}"

				echo "	source=${SOURCEFILE} - target=${TARGET}"

                                [ "$IMGTEST" = ".img" ]      &&  echo "	Operation img" 
                                [ "$IMGGZTEST" = ".img.gz" ] &&  echo "	Operation img.gz"
				# exit
				[ "$IMGTEST" = ".img" ]      &&  dd  if="${SOURCEFILE}"  of="${TARGET}"
			        [ "$IMGGZTEST" = ".img.gz" ] &&  gunzip -c ${SOURCEFILE} | dd of=${TARGET}

        fi
        echo "End $(date)"
        aplay completed.wav
fi





# mode backup
if [ "Backup" = "$MODE" ] ; then 
	aplay ding.wav
	echo "Backup mode"
	### select the disk
	if  [ "$(whoami)" != "root"  ] ; then 
		sudo fdisk -l | grep "/dev/" | grep -v Disk > /tmp/dialog.tmp
		else
		fdisk -l | grep "/dev/" | grep -v Disk > /tmp/dialog.tmp
	fi
	file=`sh fvwmdialog.sh --sf /tmp/dialog.tmp `
	[ "$file" = "" ] && exit
	SOURCETMP=`echo "$file" | awk ' { print $1 } '`
	echo "src: *$SOURCETMP*"


	# valid the disk with output
	dialog --backtitle BACKUP  --inputbox  output 20 60  "$SOURCETMP" 2>/tmp/dialog.rep
	SOURCE=` cat /tmp/dialog.rep`
	echo "Source disk: *$SOURCE*"


	# target now
	rm /tmp/dialog.rep
	dialog --backtitle BACKUP  --fselect "$(pwd)/"   16 85   2>/tmp/dialog.rep
	TARGETDSK=` cat /tmp/dialog.rep`
	echo "Targetdsk: *$TARGETDSK*"
	if [ -d "$TARGETDSK" ]  ; then 
		echo "You must enter a filename ex. test"
		exit
	fi

	# confirm yes/no 
	TARGETFILE="$TARGETDSK.img.gz"
	TARGETFILENFO="$TARGETDSK.info.txt"
	if [ -f "${TARGETFILE}" ]  ; then 
		echo "File exist"
		exit
	fi

	# editbox information
	DATENOW=`date +%Y%m%d-%H%M%S`
	echo "${DATENOW}" > /tmp/dialog2.tmp
	dialog  --backtitle "BACKUP - Edit Information file: ${TARGETFILE} "  --editbox /tmp/dialog2.tmp 20 60 2>/tmp/dialog.tmp
	INFODSK=`cat /tmp/dialog.tmp  ` 



	# yes / no
	dialog  --backtitle BACKUP   --yesno "Command:\n dd if=${SOURCE} | gzip -c9 > ${TARGETFILE} \n\n \n Information disk: \n${INFODSK} "  20 60 2>/tmp/dialog.rep


	# run it
	clear
	date
	echo " " 
	echo "Command:  dd if=${SOURCE} | gzip -c9 > ${TARGETFILE}"
	echo "<Enter Return to start>"
	read djksf
	# run it
	echo "Start $(date)"
	if [  "$2" = "--debug"    ] || [ "$1" = "--debug" ] ; then 
				echo "Debug - File: ${TARGETFILENFO} - DD : ${TARGETFILE}"
			else
				echo "$INFODSK" > ${TARGETFILENFO}
				[ "$1" != "--nodd" ] && [ "$2" != "--nodd" ]  && [ "$3" != "--nodd" ]    && dd if=${SOURCE} | gzip -c9 > ${TARGETFILE}
	fi
	echo "End $(date)"
	aplay completed.wav
fi




#end
rm /tmp/dialog.rep  
rm /tmp/dialog.tmp
 
Old 07-18-2012, 09:48 AM   #6
binary_dreamer
Member
 
Registered: Feb 2006
Distribution: debian squeeze
Posts: 199

Original Poster
Rep: Reputation: 31
sorry, but now i am lost.
what do i have to do?
 
Old 07-18-2012, 11:48 AM   #7
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,993

Rep: Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628
I'd remove the cf from the system to do all of this. I wouldn't use your embedded to load the OS use a different system on a cf card reader.

If you originally had a 2G it may be possible to dd or clone it to a larger drive. You can maybe just burn it and test to see if it will work. In almost all cases you need to run check file program on the cloned drive. Knowing what filesystem would help to select the correct app.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
dual boot system booting in Redhat linux but not booting in Windows XP sumitra Linux - Newbie 3 03-24-2011 09:42 AM
Phone System reload backup system addtheice Linux - Server 4 10-11-2010 11:54 AM
Backup system ala rdiff-backup, but without mirror and with dst encryption dr_dex Linux - Software 0 08-04-2008 03:39 AM
Embeded linux PCI card backup system Nigel_Tufnel Linux - Hardware 2 05-05-2004 05:36 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration