Gentoo Archives: gentoo-user

From: Meino.Cramer@×××.de
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Preserving the initial partionin/formatting of an usbstick
Date: Wed, 30 Mar 2016 03:28:43
Message-Id: 20160330032829.GA4629@solfire
In Reply to: Re: [gentoo-user] Preserving the initial partionin/formatting of an usbstick by Mick
1 Mick <michaelkintzios@×××××.com> [16-03-30 03:56]:
2 > On Tuesday 29 Mar 2016 19:53:45 Meino.Cramer@×××.de wrote:
3 >
4 > > The real thing:
5 > > The usbstick has a partition table, which was the reason to ask
6 > > for a way to preserve it.
7 >
8 > OK, I wasn't sure if it did.
9 >
10 > In this case as I suggested, fdisk will show you the number and size of
11 > partitions. minfo will show you the geometry of the partition, should you
12 > wish to manually recreate it in the future. However, there are tools to help
13 > avoid manual partitioning! ;-)
14 >
15 > To answer exactly what you asked, copy the partition table (assuming all the
16 > USB stick contains is a single primary partition) by using good ol' dd:
17 >
18 > dd if=/dev/sdX of=~/mbr.img bs=512 count=1
19 >
20 >
21 > Reverse the command to paste the MBR and partition table back. That should
22 > bring you back where you started when you first bought the USB stick. If for
23 > some weird reason the USB stick partitioning scheme included extended and
24 > logical partitions, then read one additional step below.
25 >
26 >
27 > > Again my questions:
28 > > Where are the partioning/format defining on the device?
29 > > If there are only stored the beginning of the device: How
30 > > much do I need to copy?
31 > > If there are tools to extract all needed informations of the
32 > > partioning/formatting and to recreate exactly that kind of
33 > > partitioning/formatting later with that or other tools:
34 > > Which tools do I need and how to use them?
35 >
36 > First copy the MBR and partition table using dd as I suggested above. Then
37 > use sfdisk --dump to create a text file with information on the size and
38 > positioning of the remaining partitions.
39 >
40 > sfdisk --dump /dev/sdX > sdX.dump
41 >
42 >
43 > To restore first run dd in the reverse order:
44 >
45 > dd if=~/mbr.img of=/dev/sdX bs=512 count=1
46 >
47 > Then change the file director on the sfdisk --dump command:
48 >
49 > sfdisk --dump /dev/sdX < sdX.dump
50 >
51 > Needless to say you will need both 'mbr.img' and 'sdX.dump' files to restore
52 > the drive partitioning scheme to its original state, if it contains more than
53 > one primary partition. When you are restoring the partition tables, double
54 > check the /dev/sdX name or you could damage some other disk in your system!
55 >
56 > --
57 > Regards,
58 > Mick
59
60
61 Hi Mick,
62
63 yeah! That's the informations I needed! Great, thank you.
64
65 By the way, somehow "half offtopic":
66
67 In the past I did hd-cloning (full contents, not only partition
68 schemes etc.) with dd. For a 1TB-disk this tooks quite a while.
69
70 Then I came accross an article, which uses "pv" for that purpose:
71
72 pv < /dev/sda > /dev/sdb (as root...;)
73
74 THAT was fast!
75
76 I mentioned it here, because (may be) someone else wants to copy/clone
77 a complete flash drive for backup purposes for example and may
78 experience an increase speed with pv instead of dd.
79
80 If one wants to copy only parts, dd is the winner.
81
82 Best regards and thanks again for your explanations!
83 Meino

Replies

Subject Author
Re: [gentoo-user] Preserving the initial partionin/formatting of an usbstick Mick <michaelkintzios@×××××.com>