Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,28 @@ This is an application which allows the SD card inserted into the Pi to be copie
To build, run autogen.sh, then ./configure and make.

To generate a Debian package for piclone:
1/ run autogen.sh
2/ run dpkg-buildpackage -us -uc
3/ install the deb package with sudo dpkg -i piclone_0.?_armhf.deb
1/ run dpkg-buildpackage -us -uc
2/ install the deb package with sudo dpkg -i piclone_0.?_armhf.deb


You can also create a dump image of a SDcard on a USB hard drive for archive

1/ create an empty file on your harddrive about the size of your SD card (for example 32GB)

cd /mnt/myharddrive
dd if=/dev/zero of=PicloneSAVE_YYYY_MM_DD.bin bs=100M count=320

2/ attach the file to a loopback device (example "/dev/loop0")

sudo losetup /dev/loop0 PicloneSAVE_YYYY_MM_DD.bin

3/ use piclone with /dev/loop0 as target

4/ detach loop device

sudo losetup -d /dev/loop0

5/ you can use md5sum / sha1sum / sha256sum on the file PicloneSAVE_YYYY_MM_DD.bin as usual

6/ you can zip the image using 7zip or another compression tool

67 changes: 52 additions & 15 deletions src/piclone.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,25 +141,41 @@ static int get_dev_name (char *dev, char *name)
char buffer[256];
FILE *fp;

sprintf (buffer, "sudo parted -l | grep -B 1 \"%s\" | head -n 1 | cut -d \":\" -f 2 | cut -d \"(\" -f 1", dev);
fp = popen (buffer, "r");
if (fp == NULL) return 0;
if (fgets (buffer, sizeof (buffer) - 1, fp) == NULL)
{
pclose (fp);
return 0;
}
pclose (fp);
buffer[strlen (buffer) - 2] = 0;
strcpy (name, buffer + 1);
return 1;
if (!strncmp (dev, "/dev/loop", 9))
{
sprintf (buffer, "sudo losetup -a | grep -B 1 \"%s\" | head -n 1 | cut -d \"(\" -f 2 | cut -d \")\" -f 1", dev);
fp = popen (buffer, "r");
if (fp == NULL) return 0;
if (fgets (buffer, sizeof (buffer) - 1, fp) == NULL)
{
pclose (fp);
return 0;
}
pclose (fp);
buffer[strlen (buffer) - 1] = 0;
strcpy (name, buffer);
}
else
{
sprintf (buffer, "sudo parted -l | grep -B 1 \"%s\" | head -n 1 | cut -d \":\" -f 2 | cut -d \"(\" -f 1", dev);
fp = popen (buffer, "r");
if (fp == NULL) return 0;
if (fgets (buffer, sizeof (buffer) - 1, fp) == NULL)
{
pclose (fp);
return 0;
}
pclose (fp);
buffer[strlen (buffer) - 2] = 0;
strcpy (name, buffer + 1);
return 1;
}
}


static char *partition_name (char *device, char *buffer)
{
if (!strncmp (device, "/dev/mmcblk", 11))
sprintf (buffer, "%sp", device);
if (!strncmp (device, "/dev/mmcblk", 11) || !strncmp (device, "/dev/loop", 9))
sprintf (buffer, "%sp", device);
else
sprintf (buffer, "%s", device);
return buffer;
Expand Down Expand Up @@ -733,6 +749,7 @@ static void on_drives_changed (void)
gtk_combo_box_set_active (GTK_COMBO_BOX (from_cb), 0);
src_count++;

// add existing physical disk as source or target (excepted boot device mmcblk0)
fp = popen ("sudo parted -l | grep \"^Disk /dev/\" | cut -d ' ' -f 2 | cut -d ':' -f 1", "r");
if (fp != NULL)
{
Expand All @@ -753,6 +770,26 @@ static void on_drives_changed (void)
}
pclose (fp);
}

// add existing loopback devices as target
fp = popen ("sudo losetup -a | cut -d ' ' -f 1 | cut -d ':' -f 1", "r");
if (fp != NULL)
{
while (1)
{
if (fgets (device, sizeof (device) - 1, fp) == NULL) break;

if (!strncmp (device + 5, "loop", 4) )
{
device[strlen (device) - 1] = 0;
get_dev_name (device, name);
sprintf (buffer, "%s (%s)", name, device);
gtk_combo_box_append_text (GTK_COMBO_BOX (to_cb), buffer);
dst_count++;
}
}
pclose (fp);
}

if (dst_count == 0)
{
Expand Down