|
1 <stránka |
|
2 xmlns="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/strana" |
|
3 xmlns:m="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/makro"> |
|
4 |
|
5 <nadpis>Renaming VG in /etc/fstab using relpipe-tr-sed</nadpis> |
|
6 <perex>sed-like substitutions in the relational stream</perex> |
|
7 <m:pořadí-příkladu>00700</m:pořadí-příkladu> |
|
8 |
|
9 <text xmlns="http://www.w3.org/1999/xhtml"> |
|
10 |
|
11 <p> |
|
12 Assume that we have an <code>/etc/fstab</code> with many lines defining the mount-points (directories) of particular devices (disks) and we are using LVM. |
|
13 If we rename a volume group (VG), we have to change all of them. The lines look like this one: |
|
14 </p> |
|
15 |
|
16 <pre>/dev/alpha/photos /mnt/photos/ btrfs noauto,noatime,nodiratime 0 0</pre> |
|
17 |
|
18 <p> |
|
19 We want to change all lines from <code>alpha</code> to <code>beta</code> (the new VG name). |
|
20 This can be done by the power of regular expressions<m:podČarou>see <a href="https://en.wikibooks.org/wiki/Regular_Expressions/Simple_Regular_Expressions">Regular Expressions</a> at Wikibooks</m:podČarou> and this pipeline: |
|
21 </p> |
|
22 |
|
23 <m:pre jazyk="bash"><![CDATA[relpipe-in-fstab \ |
|
24 | relpipe-tr-sed 'fstab' 'device' '^/dev/alpha/' '/dev/beta/' \ |
|
25 | relpipe-out-fstab]]></m:pre> |
|
26 |
|
27 <p> |
|
28 The <code>relpipe-tr-sed</code> tool works only with given relation (<code>fstab</code>) and given attribute (<code>device</code>) |
|
29 and it would leave untouched other relations and attributes in the stream. |
|
30 So it would not replace the strings on unwanted places (if there are any random matches). |
|
31 </p> |
|
32 |
|
33 <p> |
|
34 Even the relation names and attribute names are specified as a regular expression, so we can (purposefully) modify multiple relations or attributes. |
|
35 For example we can put zeroes in both <code>dump</code> and <code>pass</code> attributes: |
|
36 </p> |
|
37 |
|
38 <m:pre jazyk="bash"><![CDATA[relpipe-in-fstab | relpipe-tr-sed 'fstab' 'dump|pass' '.+' '0' | relpipe-out-fstab]]></m:pre> |
|
39 |
|
40 <p> |
|
41 n.b. the data types must be respected, we can not e.g. put <code>abc</code> in the <code>pass</code> attribute because it is declared as <code>integer</code>. |
|
42 </p> |
|
43 |
|
44 </text> |
|
45 |
|
46 </stránka> |