Linux backup entire disk drive image to a file or another drive with dd command

You can:

Clone from one hard drive to another of different size:
Backup a drive to another drive dd
Use dd command to image
Backup drive using linux
Linux dd backup drive or Linux disk image dd

This works with Windows 7, Mac OS X, Vista and any Linux.

Note: If you just want to backup or restore your partition table and or the MBR click here.

From Linux Questions Wiki:

Creating a hard drive backup directly to another hard drive, or linux backup entire disk.

# dd if=/dev/hda of=/dev/sda conv=noerror,sync bs=4k

This command is used often to create a backup of a drive (/dev/hda) directly to another hard drive (/dev/sda). The device name /dev/hda is typical of an IDE hard drive, the device /dev/sda is typical of a USB disk – key drive. This works only if the destination hard drive (of=) has enough storage to accommodate the source drive’s (if=) filesystem. The advantage of this is that you do not have to mount the hard drive to make a backup and the only reference to hda is in /dev and in the command which is usually in a script in cron. Another huge advantage of using dd to clone one hard drive to another is that this is the only way I know of that copies raw data instead of partitions, so you can clone an encrypted drive or one without partitions.

The option “bs=4k” is used to specify the block size used in the copy. The default for the dd command is 512 bytes: use of this small block size can result in significantly slower copying. However, the tradeoff with larger block sizes is that when an error is encountered, the remainder of the block is filled with zero-bytes. So if you increase your block size when copying a failing device, you’ll lose more data but also spend less time trying to read broken sectors. Tools like dd_rescue and dd_rhelp can provide a more flexible solution in such cases, combining the speed of a large block size for the regions without errors with finer-grained block-copies for regions with errors.

Creating a hard drive backup image or dd command image backup linux.

# dd if=/dev/hda | gzip > /mnt/hdb1/system_drive_backup.img.gz

Here dd is making an image of the first harddrive, and piping it through the gzip compression program. The compressed image is then placed in a file on a seperate drive. To reverse the process:

# gzip -dc /mnt/hdb1/system_drive_backup.img.gz | dd of=/dev/hda

Here, gzip is decompressing (the -d switch) the file, sending the results to stdout (the -c switch), which are piped to dd, and then written to /dev/hda.

To backup or copy a cd to a file with linux using dd is very easy:

dd if=/dev/cdrom of=image.iso bs=2k.

Samba server syncing files – Problem copying files from Windows to Linux, especially in Mepis

Problem: When file names with international character sets copy from Windows to Linux in Mepis the characters are not translated properly.

Detail: When your files copy from Windows to Linux and the international characters (like African and Brazilian song names) don’t copy correctly, all other filenames are fine, you need to edit your /etc/samba/smb.conf file which is the config file for samba.

Solution: Put this in to the head of the file to fix odd international characters from windows to linux copy:

unix charset = ISO 8859-1

Remember to stop and restart your Samba server: (Linux Mepis and Ubuntu) sudo /etc/init.d/samba restart

Problem: When your use a program to synchronize files from Windows to Linux (Mepis) and some files continually recopy even though they are the same (identical dates) on both machines.

Detail: You need to pay attention to the 2 second file date difference on an NTFS file system (tell your sync program to ignore it), as well as make sure that the Linux server uses the right file type designation for the incoming files from Windows.

Solution: While you are in your /etc/samba/smb.conf file go to the bottom share descriptions and add single line under each.

Put this in the individual share section to fix timestamps that cause file syncs to copy every time from windows to linux.

fstype = samba
Remember to stop and restart your Samba server: (Linux Mepis and Ubuntu) sudo /etc/init.d/samba restart

Sample: smb.conf file (sample code):

———–My Samba smb.conf from Mepis 3.4 to 7 works!————-
;*******************section global*****************
ldap ssl = No
restrict anonymous = no
guest ok = yes
map to guest = Bad User
domain master = no
hosts allow = 192.168.0. 192.168.1. 192.168.2. 127.
passdb backend = tdbsam guest
dns proxy = no
printing = cups
server string =
max protocol = NT
kernel oplocks = no
; Fix your workgroup name!
workgroup = WORKGROUP
server signing = Auto
security = server
paranoid server security = no
unix charset = ISO 8859-1
panic action = /usr/share/samba/panic-action %d
preferred master = no
max connections = 8
max log size = 1000
; Fix your servername!
netbios name = MYSERVERNAME
;*******************section homes*****************
comment = Home Directories
browseable = no
read only = no

case sensitive = no
msdfs proxy = no
path = /mnt/hdb1/MyFiles/
hide files = *.log/*.tmp/*.evt/*.bak/

path = /mnt/hde1/MoreFiles/
read only = no
case sensitive = no
msdfs proxy = no
fstype = Samba

path = /mnt/hde2/EvenMoreFiles/Subdirectory/
case sensitive = no
msdfs proxy = no

path = /mnt/hdg1/MediaFilesWritable/
read only = no
case sensitive = no
msdfs proxy = no

path = /home/myuser/ReadOnlyShared/
read only = yes
case sensitive = no
msdfs proxy = no
only user = yes
fstype = Samba

case sensitive = no
msdfs proxy = no
read only = no
path = /mnt/hdc1/FilesWritable/
fstype = Samba
———–END My Samba smb.conf from Mepis 3.4 works!————-
After editing your smb.conf remember to stop and restart your Samba server: (Linux Mepis and Ubuntu) sudo /etc/init.d/samba restart

Posted in Linux tips and tricks. Tags: . No Comments »