Project

General

Profile

BackupTheDataPartition » History » Version 19

Denis 'GNUtoo' Carikli, 11/09/2020 08:54 PM
implement unmount and loop-delete

1 1 Denis 'GNUtoo' Carikli
h1. How to backup the data partition
2
3
{{toc}}
4
5
h2. /!\ Warning: Draft
6
7
This article is in draft form and is being written:
8
* Everybody is welcome to contribute
9
* Some things might not be accurate yet, so beware before using the information contained in it.
10
11 3 Denis 'GNUtoo' Carikli
h2. What does the data partition contains?
12 1 Denis 'GNUtoo' Carikli
13 8 Denis 'GNUtoo' Carikli
See [[DataPartition]] for more details.
14 1 Denis 'GNUtoo' Carikli
15
h2. Howto
16
17 15 Denis 'GNUtoo' Carikli
h3. Setup ADB
18
19
Follow the instructions for [[ADB|setting up ADB on your computer]] so that you can access a root shell on your device.
20
21
*NOTE*: when prompted on your Replicant device, make sure that you check the box that says *Always allow from this computer* when you grant your computer USB debugging permissions. Otherwise, you will be unable to obtain root shell access on your Replicant device when you reboot it into the recovery OS to actually perform the backup.
22
23
*NOTE*: for security reasons, you may want to [[ADB#Revoking-all-computers-USB-debugging-permissions|revoke these non-expiring permissions]] once the backup is complete.
24
25
h3. Reboot into the recovery
26
27
To reboot in the recovery, you can follow the instructions in the [[RebootIntoTheRecovery]] wiki page.
28
29 16 Denis 'GNUtoo' Carikli
h3. Making sure that the data partition isn't mounted
30 1 Denis 'GNUtoo' Carikli
31
First, you need to make sure that the data partition is not mounted. 
32
33
To do that, you can run this command:
34
<pre>
35
adb shell "umount -l /data"
36
</pre>
37
38 18 Denis 'GNUtoo' Carikli
If the /data partition was mounted, it will unmount it, and your command and its output will look more or less like that:
39 1 Denis 'GNUtoo' Carikli
<pre>
40
$ adb shell "umount -l /data"
41
$ 
42
</pre>
43
44 18 Denis 'GNUtoo' Carikli
If it was not mounted, it will instead show an error that we can ignore. In this case your command and its output will look more or less like that:
45 1 Denis 'GNUtoo' Carikli
<pre>
46
$ adb shell "umount -l /data"
47
umount: /data: Invalid argument
48
</pre>
49
50 16 Denis 'GNUtoo' Carikli
h3. Backuping the data partition
51
52
Once we verified that the data partition isn't mounted, we can finally backup the partition.
53
54
h4. Galaxy S III (GT-I9300)
55
56
For the Galaxy S III (GT-I9300), you can use the following command:
57 1 Denis 'GNUtoo' Carikli
<pre>
58
adb pull /dev/block/platform/dw_mmc/by-name/USERDATA ./USERDATA.img
59
</pre>
60 16 Denis 'GNUtoo' Carikli
61
h4. Other devices.
62
63
We don't have instructions yet for other devices yet.
64
65
Feel free to request instructions for the device you have on IRC, the mailing list, or to add the instructions here if you're confortable enough with the command line.
66
67 10 Denis 'GNUtoo' Carikli
68
h2. Using the backup
69
70
h3. Restoring the partition
71
72
TODO
73
74
h3. Restoring individual application data.
75
76
Here we will use the @udisksctl@ command instead of the more classical @mount@ and @losetup@ as it integrates better with graphical environments like Gnome or KDE.
77
78
As the partition backup is now in a file, to access its data we will make it available as a partition again. This can be done with the following command:
79
<pre>
80
udisksctl loop-setup -f  USERDATA.img
81
</pre>
82
83
If that doesn't work you might need to use @sudo@ like that:
84
<pre>
85
sudo udisksctl loop-setup -f  USERDATA.img
86
</pre>
87
88
Or you may also need to verify that your current users has the right to read and write the file that contains the partition (here USERDATA.img) file.
89
90
If this works, it should produce an output that looks more or less like that:
91
<pre>
92
Mapped file USERDATA.img as /dev/loop0.
93
</pre>
94
95 19 Denis 'GNUtoo' Carikli
Here you can see that it made the file content available in the @/dev/loop0@ partition. 
96 10 Denis 'GNUtoo' Carikli
97
We can then reuse this information to mount that partition. We can do that with the following command:
98
<pre>
99
udisksctl mount -b /dev/loop0 -o ro
100
</pre>
101
102
The @-o ro@ option will make sure that the partition is mounted in read only mode. This will make sure that we don't accidentally change its content.
103
104
The command above should produce an output that looks more or less like that:
105
<pre>
106
Mounted /dev/loop0 at /run/media/gnutoo/2Of967c7-ac7e-7ae0-ef5b-30f0b6e2dc41
107
</pre>
108
109
It most probably change a bit from the output above as:
110
* Your username is probably not @gnutoo@.
111
* The @2Of967c7-ac7e-7ae0-ef5b-30f0b6e2dc41@ is a randomly created identifier for the partition that is created when formatting it.
112
* Even @/run/media/@ can change depending on the GNU/Linux distribution and its version. For instance between Parabola and Trisquel 8 it is different.
113
114
You can write down the location of the directory where this partition is mounted (here @/run/media/gnutoo/2Of967c7-ac7e-7ae0-ef5b-30f0b6e2dc41@) as we will need it later on.
115 1 Denis 'GNUtoo' Carikli
116 19 Denis 'GNUtoo' Carikli
We will also reuse the partition location (here @/dev/loop0@) at the end.
117
118 10 Denis 'GNUtoo' Carikli
Now that this partition is mounted, we will be able to use the RestoreApplicationInternalData tutorial to make a backup of the data of a specific application and restore it.
119
120
To do that, locate the following command in the [[RestoreApplicationInternalData#Backuping-Silences-data-from-the-old-device|Backuping Silence's data from the old device]] section of the RestoreApplicationInternalData wiki page:
121
<pre>
122 12 Denis 'GNUtoo' Carikli
cd /data/data
123 10 Denis 'GNUtoo' Carikli
</pre>
124
125
You will then need to replace it by a command that looks like that:
126
<pre>
127
cd /run/media/gnutoo/2Of967c7-ac7e-7ae0-ef5b-30f0b6e2dc41/data/
128
</pre>
129
130
In the command above, you'll need to replace @/run/media/gnutoo/2Of967c7-ac7e-7ae0-ef5b-30f0b6e2dc41/@ by the location of the directory where the partition is mounted.
131
132
In addition you might not have the permissions to access the applications data. 
133
134 17 Denis 'GNUtoo' Carikli
For instance we can look at the permissions of the silence data with the following command:
135 1 Denis 'GNUtoo' Carikli
<pre>
136 17 Denis 'GNUtoo' Carikli
ls -ld org.smssecure.smssecure/
137
</pre>
138
139
And it should give you something that looks more or less like that:
140
<pre>
141 11 Denis 'GNUtoo' Carikli
drwxr-x--x 9 10063 10063 4096 26 oct.  19:44 org.smssecure.smssecure/
142
</pre>
143 1 Denis 'GNUtoo' Carikli
144 11 Denis 'GNUtoo' Carikli
See the [[RestoreApplicationInternalData#How-to-find-which-directory-holds-the-internal-data-of-an-application|How to find which directory holds the internal data of an application]] section in the RestoreApplicationInternalData wiki page for more details to understand why @org.smssecure.smssecure@ directory has the Silence application's data.
145
146
In the output above, the first @10063@ is the user ID and the second @10063@ is the group id. 
147
148
This is because Android sandboxes applications as part of their security model: each applications run in their own user and group ID. The result is that theses are most likely present on your phone but not on your GNU/Linux computer.
149
150 10 Denis 'GNUtoo' Carikli
To fix that you can become root with the following command:
151
<pre>
152
sudo su
153
</pre>
154
155 1 Denis 'GNUtoo' Carikli
Now you can then continue to follow the RestoreApplicationInternalData tutorial.
156 19 Denis 'GNUtoo' Carikli
157
h4. Unmount and close the loop
158
159
Once you are finished with the RestoreApplicationInternalData tutorial, it would be a good idea to umount the data partition and make it inaccessible again.
160
161
To umount the data partition we can use a command that looks like that:
162
<pre>
163
udisksctl unmount -b /dev/loop0
164
</pre>
165
Here the @/dev/loop0@ may differ, so make sure to use the partition location you used earlier.
166
167
The output of that command will look like that:
168
<pre>
169
Unmounted /dev/loop0.
170
</pre>
171
172
Once it is unmounted you can make it inaccessible again with the following command:
173
<pre>
174
udisksctl unmount -b /dev/loop0
175
</pre>
176
177
Again here may will need to replace @/dev/loop0@ by your partition location if it differs.
178
179
The output of that command should then show something that looks like that:
180
<pre>
181
Unmounted /dev/loop0.
182
</pre>
183 1 Denis 'GNUtoo' Carikli
184
h2. See also
185
186
* The [[BackupsResearch]] page has information on why the backup is done this way. It might also be useful to read and contribute to it if you intend to change the way the backups are done.