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 17:35:49
Message-Id: 20160330173533.GB5173@solfire
In Reply to: Re: [gentoo-user] Preserving the initial partionin/formatting of an usbstick by Mick
1 Mick <michaelkintzios@×××××.com> [16-03-30 17:12]:
2 > On Wednesday 30 Mar 2016 05:28:29 Meino.Cramer@×××.de wrote:
3 > > Mick <michaelkintzios@×××××.com> [16-03-30 03:56]:
4 > > > On Tuesday 29 Mar 2016 19:53:45 Meino.Cramer@×××.de wrote:
5 > > > > The real thing:
6 > > > > The usbstick has a partition table, which was the reason to ask
7 > > > > for a way to preserve it.
8 > > >
9 > > > OK, I wasn't sure if it did.
10 > > >
11 > > > In this case as I suggested, fdisk will show you the number and size of
12 > > > partitions. minfo will show you the geometry of the partition, should you
13 > > > wish to manually recreate it in the future. However, there are tools to
14 > > > help avoid manual partitioning! ;-)
15 > > >
16 > > > To answer exactly what you asked, copy the partition table (assuming all
17 > > > the USB stick contains is a single primary partition) by using good ol'
18 > > > dd:
19 > > >
20 > > > dd if=/dev/sdX of=~/mbr.img bs=512 count=1
21 > > >
22 > > >
23 > > > Reverse the command to paste the MBR and partition table back. That
24 > > > should
25 > > > bring you back where you started when you first bought the USB stick. If
26 > > > for some weird reason the USB stick partitioning scheme included extended
27 > > > and logical partitions, then read one additional step below.
28 > > >
29 > > > > Again my questions:
30 > > > > Where are the partioning/format defining on the device?
31 > > > > If there are only stored the beginning of the device: How
32 > > > > much do I need to copy?
33 > > > > If there are tools to extract all needed informations of the
34 > > > > partioning/formatting and to recreate exactly that kind of
35 > > > > partitioning/formatting later with that or other tools:
36 > > > > Which tools do I need and how to use them?
37 > > >
38 > > > First copy the MBR and partition table using dd as I suggested above.
39 > > > Then
40 > > > use sfdisk --dump to create a text file with information on the size and
41 > > > positioning of the remaining partitions.
42 > > >
43 > > > sfdisk --dump /dev/sdX > sdX.dump
44 > > >
45 > > >
46 > > > To restore first run dd in the reverse order:
47 > > >
48 > > > dd if=~/mbr.img of=/dev/sdX bs=512 count=1
49 > > >
50 > > > Then change the file director on the sfdisk --dump command:
51 > > >
52 > > > sfdisk --dump /dev/sdX < sdX.dump
53 > > >
54 > > > Needless to say you will need both 'mbr.img' and 'sdX.dump' files to
55 > > > restore the drive partitioning scheme to its original state, if it
56 > > > contains more than one primary partition. When you are restoring the
57 > > > partition tables, double check the /dev/sdX name or you could damage some
58 > > > other disk in your system!
59 > > Hi Mick,
60 > >
61 > > yeah! That's the informations I needed! Great, thank you.
62 > >
63 > > By the way, somehow "half offtopic":
64 > >
65 > > In the past I did hd-cloning (full contents, not only partition
66 > > schemes etc.) with dd. For a 1TB-disk this tooks quite a while.
67 >
68 > I think by default dd will use bs=512 which will take forever when copying a
69 > large drive. In this case increase the block size to something more
70 > reasonable, like e.g. bs=4096.
71 >
72 > > Then I came accross an article, which uses "pv" for that purpose:
73 > >
74 > > pv < /dev/sda > /dev/sdb (as root...;)
75 > >
76 > > THAT was fast!
77 >
78 > PV probably uses larger block sizes by default. You could test this with a
79 > known file size and compare the transfer time between dd and pv.
80 >
81 >
82 > > I mentioned it here, because (may be) someone else wants to copy/clone
83 > > a complete flash drive for backup purposes for example and may
84 > > experience an increase speed with pv instead of dd.
85 > >
86 > > If one wants to copy only parts, dd is the winner.
87 >
88 > Also worth mentioning is dcfldd which unlike dd can show progress of the bit
89 > stream and also produce hashes of the transferred output. It has the same
90 > performance as the dd command though.
91 >
92 > --
93 > Regards,
94 > Mick
95
96 I had experimented a lot with the block size argument of dd
97 previously and it seems I never had find the sweet spot. May it was
98 simply an blind and unfortunate dance around it...who knows.
99 pv did it right from the beginning the correct way with a super
100 simple command: pv < /dev/sda > /dev/sdb
101 :)
102
103 I installed dcfldd just a momnent before and will experiment with it
104 - thanks for mentioning it!
105
106 By the way: For what stands the 'dd' for ?
107 (Think unix!)
108
109 :)
110
111 Best regards
112 Meino

Replies

Subject Author
Re: [gentoo-user] Preserving the initial partionin/formatting of an usbstick Neil Bothwick <neil@××××××××××.uk>