Gentoo Archives: gentoo-user

From: Mick <michaelkintzios@×××××.com>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Preserving the initial partionin/formatting of an usbstick
Date: Tue, 29 Mar 2016 19:52:17
Message-Id: 3122067.TRAjuv2GPj@dell_xps
In Reply to: Re: [gentoo-user] Preserving the initial partionin/formatting of an usbstick by Meino.Cramer@gmx.de
1 On Tuesday 29 Mar 2016 19:53:45 Meino.Cramer@×××.de wrote:
2
3 > The real thing:
4 > The usbstick has a partition table, which was the reason to ask
5 > for a way to preserve it.
6
7 OK, I wasn't sure if it did.
8
9 In this case as I suggested, fdisk will show you the number and size of
10 partitions. minfo will show you the geometry of the partition, should you
11 wish to manually recreate it in the future. However, there are tools to help
12 avoid manual partitioning! ;-)
13
14 To answer exactly what you asked, copy the partition table (assuming all the
15 USB stick contains is a single primary partition) by using good ol' dd:
16
17 dd if=/dev/sdX of=~/mbr.img bs=512 count=1
18
19
20 Reverse the command to paste the MBR and partition table back. That should
21 bring you back where you started when you first bought the USB stick. If for
22 some weird reason the USB stick partitioning scheme included extended and
23 logical partitions, then read one additional step below.
24
25
26 > Again my questions:
27 > Where are the partioning/format defining on the device?
28 > If there are only stored the beginning of the device: How
29 > much do I need to copy?
30 > If there are tools to extract all needed informations of the
31 > partioning/formatting and to recreate exactly that kind of
32 > partitioning/formatting later with that or other tools:
33 > Which tools do I need and how to use them?
34
35 First copy the MBR and partition table using dd as I suggested above. Then
36 use sfdisk --dump to create a text file with information on the size and
37 positioning of the remaining partitions.
38
39 sfdisk --dump /dev/sdX > sdX.dump
40
41
42 To restore first run dd in the reverse order:
43
44 dd if=~/mbr.img of=/dev/sdX bs=512 count=1
45
46 Then change the file director on the sfdisk --dump command:
47
48 sfdisk --dump /dev/sdX < sdX.dump
49
50 Needless to say you will need both 'mbr.img' and 'sdX.dump' files to restore
51 the drive partitioning scheme to its original state, if it contains more than
52 one primary partition. When you are restoring the partition tables, double
53 check the /dev/sdX name or you could damage some other disk in your system!
54
55 --
56 Regards,
57 Mick

Attachments

File name MIME type
signature.asc application/pgp-signature

Replies