Sunday, May 5, 2024
6
rated 0 times [  6] [ 0]  / answers: 1 / hits: 3894  / 1 Year ago, mon, february 6, 2023, 6:27:08

What I am looking for is a way to clone hard drives (mainly windows partitions) while staying inside of the Ubuntu OS. I do not want to create a partition on the hard drive to boot off of and I am not wanting to use a boot cd. The only thing I can even think of that is close is the 32bit version of ghost that can run from the desktop in windows.



It doesn't have to be clonezilla, but that is the only linux cloning software I have used and have almost used it exclusively since I discovered it. If there is no way to use clonezilla from the desktop, then I will accept an alternative program. The main thing is that it clones drives and runs from within Ubuntu.



Thank you for your time in advance


More From » software-recommendation

 Answers
4

Clonezilla uses dd behind the scenes.



About disks and partitions



A whole disk is a device like /dev/sda. This is the first disk, the second disk is /dev/sdb, the third /dev/sdc, etc. Older disks connected through an IDE cable are named like hda, hdb, ... A disk can have multiple partitions like /dev/sda1. The second partition on disk /dev/sda is /dev/sda2 and so on. An image (literal copy of bytes) can be made from both a partition and disk. Note that first 512 bytes of a disk contains the MBR (Master Boot Record).



A partition should not be mounted when creating or restoring images, otherwise data loss may occur when reading from it (creating an image) or unexpected bahavior and data corruption if you're writing to it (restoring from a image).



In the below examples, /dev/sda1 is the partition from which an image should be created.



Partitions and disk devices in /dev are only writable by the superuser (root) and users of the disk group. I dislike running everything as root, so for safety (in case you made a typo for example), I change the group temporary to myself, so I can read and write to it:



sudo chgrp my_user_name /dev/sda1


If you skip the above command, you've to prefix the below dd commands with sudo.



Basics



The basic command for creating an image from a partition is:



dd if=/dev/sda1 of=disk.img


if means "input file", of means "output file". Everything in Linux is a file, even devices.



To restore such an image, run:



dd if=disk.img of=/dev/sda1


The order does not matter, you could have written the above as dd of=/dev/sda1 if=disk.img too.



Compressed images



Since partitions are generally big, it's recommended to compress the data before writing it to the image:



dd if=/dev/sda1 | gzip > disk.img.gz


This works because if of is omitted, the output is written to "standard output" which is the pipe to the compress program gzip. The output of that is written to disk.img.



To restore such a compressed image, run:



gunzip -c disk.img.gz | dd of=/dev/sda1


Here, gunzip is the reverse command of gzip. -c causes the output be written to standard output which is the pipe to the dd command. Because if is omitted on dd, the input is read from "standard input" which is the output of gunzip.



Reading from an image without restoring it



Uncompressed images can be mounted so you can read from it. Should you've compressed your partition images, uncompress them first (disk.img.gz will be removed, disk.img will be created. Be sure to have enough space!):



gunzip disk.img.gz


Alternatively, uncompress an image without touching the image itself:



gunzip -c disk.img.gz > disk.img


Now create a directory on which the disk can be mounted and mount the image read-only (ro):



sudo mkdir /mnt/wind
sudo mount -o ro disk.img /mnt/wind


You can now view your files in /mnt/wind. When done, unmount it and remove the obsolete mount point:



sudo umount /mnt/wind
sudo rmdir /mnt/wind


Less size, more CPU usage, longer backup and restore duration



If time is not an issue and you don't have much storage space, you could use the bzip2 compression format. Simply replace gzip by bzip2 in the above. It's common to use the .bz2 extension for bzip2-compressed files, so do so.


[#44078] Monday, February 6, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
feeous

Total Points: 102
Total Questions: 122
Total Answers: 119

Location: Netherlands
Member since Thu, Jul 1, 2021
3 Years ago
feeous questions
Sat, Jul 23, 22, 23:21, 2 Years ago
Mon, Jul 5, 21, 19:59, 3 Years ago
Mon, Aug 16, 21, 11:42, 3 Years ago
Sun, Mar 19, 23, 21:03, 1 Year ago
;