about summary refs log tree commit diff stats
path: root/tools/storage.html
blob: 121c802a05254cfd3e0705c0b40539845c44fc28 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
<!DOCTYPE html>
<html dir="ltr" lang="en">
    <head>
        <meta charset='utf-8'>
        <title>Storage</title>
    </head>
    <body>

        <a href="index.html">Systools Index</a>

        <h1>Storage</h1>

        <h2 id="mv">Moving partitions</h2>

        <pre>
        var
        (parted) mkpart primary ext4 57GiB 200GiB
        </pre>
        <pre>
        swap
        (parted) mkpart primary linux-swap 29GiB 57GiB
        </pre>
        <pre>
        home
        (parted) mkpart primary ext4 57GiB 200GiB
        </pre>
        <pre>
        srv
        (parted) mkpart primary ext4 200GiB 100%
        </pre>

        <p>Reboot into single-user mode where services aren't started and networking is offline.<p>
        <pre>
        # init 1
        </pre>

        <p>Copy the data:</p>
        cp -apx /srv/* /mnt/srv

        <p>Rename directory, for later backup;</p>

        <pre>
        mv /srv /srv.old
        mkdir /srv
        </pre>

        <p>Edit the <a href="../conf/etc/fstab">/etc/fstab</a>file:</p>

        <pre>
        # Server Data /srv
        UUID=6fadcb98-e442-4af7-a5f2-1ddb6100a8c4 /srv            ext4    defaults        0       2
        </pre>

        <p>Reboot in normal mode.</p>

        <h2 id="lvm">1.2. LVM</h2>

        <p>Read <a href="https://raid.wiki.kernel.org/index.php/RAID_setup">Raid Setup</a>,
        the only thing you will need outside system is:
        "Patience, Pizza, and your favorite caffeinated beverage.".
        <a href="https://wiki.archlinux.org/index.php/Software_RAID_and_LVM">Arch Wiki</a>
        article about Sofware RAID and LVM.</p>

        <p>Basic idea behind RAID is to deal with independent disks
        as an array of drives. Raid 0 uses two or more disks as one,
        with performance gains without fault-tolerance. From raid 1
        to 6 they offer diferent fault tolerance mechanisms.</p>

        <p>LVM or Logic Volume Manager bring one more layer, read
        <a href="http://www.tuxradar.com/content/lvm-made-easy">Lvm made easy</a>.
        Partitions under lvm are easy to be resized, moved and there is
        a tool to help encrypt. There is more freedom to name physical
        disk names exp; production, development, backups...</p>


        <p>Until now "from install" there is only one partition,
        it is good idea to have a system with diferent partitions for each
        propos. If is a "fresh install";</p>

        <pre>
        # cd /iso/crux/opt/
        # pkgadd lvm2#2.02.107-1.pkg.tar.xz
        #
        </pre>

        <h3>Multiple Partition</h3>

        <p>Create a LVM partition, fdisk should
        show something like this;</p>

        <pre>
        # fdisk /dev/sdb

        Welcome to fdisk (util-linux 2.26.1).
        Changes will remain in memory only, until you decide to write them.
        Be careful before using the write command.


        Command (m for help): p
        Disk /dev/sdb: 232.9 GiB, 250059350016 bytes, 488397168 sectors
        Units: sectors of 1 * 512 = 512 bytes
        Sector size (logical/physical): 512 bytes / 512 bytes
        I/O size (minimum/optimal): 512 bytes / 512 bytes
        Disklabel type: gpt
        Disk identifier: E37FE96F-9845-45A4-B6DA-BF3F8E47511A

        Device     Start      End  Sectors  Size Type
        /dev/sdb1   2048     8056     6009    3M BIOS boot
        /dev/sdb2   8192 18440191 18432000  8.8G Linux filesystem

        Command (m for help):
        </pre>

        <p>I use defaults unless to define system partition last sector,
        where in this example is size, +80G</p>

        <pre>
        Command (m for help): n
        Partition number (3-128, default 3):
        First sector (8057-488397134, default 18440192):
        Last sector, +sectors or +size{K,M,G,T,P} (18440192-488397134, default 488397134): +80G

        Created a new partition 3 of type 'Linux filesystem' and of size 80 GiB.

        Command (m for help):

        Command (m for help): t
        Partition number (1-3, default 3):
        Hex code (type L to list all codes): 23

        Changed type of partition 'Linux filesystem' to 'Linux LVM'.

        Command (m for help): n
        Partition number (4-128, default 4):
        First sector (8057-488397134, default 186212352):
        Last sector, +sectors or +size{K,M,G,T,P} (186212352-488397134, default 488397134):

        Created a new partition 4 of type 'Linux filesystem' and of size 144.1 GiB.

        Command (m for help): t
        Partition number (1-4, default 4):
        Hex code (type L to list all codes): 23

        Changed type of partition 'Linux filesystem' to 'Linux LVM'.

        Command (m for help): w
        The partition table has been altered.
        Calling ioctl() to re-read partition table.
        Syncing disks.

        #
        </pre>

        <h3>Create Phisical Volume</h3>


        <pre>
         # pvcreate /dev/sdb3
          Physical volume "/dev/sdb3" successfully created
         #
         # pvcreate /dev/sdb4
          Physical volume "/dev/sdb4" successfully created
         #
        </pre>

        <h3>Create Volume Group</h3>

        <pre>
        # vgcreate systemvg /dev/sdb3
          Volume group "systemvg" successfully created
        # vgcreate homevg /dev/sdb4
          Volume group "homevg" successfully created
        #
        </pre>

        <h3>Create Logical Volume</h3>

        <pre>
        # lvcreate -L 15G -n distfileslv systemvg
          Logical volume "distfileslv" created.
        # lvcreate -L 8G -n packageslv systemvg
          Logical volume "packageslv" created.
        # lvcreate -L 4G -n swaplv systemvg
          Logical volume "swaplv" created.
        # lvcreate -L 80G -n homelv homevg
          Logical volume "homelv" created.
        #
        </pre>

        <pre>
        # mkfs.ext4 /dev/systemvg/distfileslv
        # mkfs.ext4 /dev/systemvg/packageslv
        # mkswap /dev/systemvg/swaplv
        # mkfs.ext4 /dev/homevg/homelv
        </pre>

        <h3>Activate Deactivate</h3>

        <p>Deactivate logical volumes;</p>

        <pre>
        # lvchange -a -n /dev/systemvg/packageslv
        # lvchange -a -n /dev/systemvg/distfileslv
        # swapoff /dev/systemvg/sawplv
        # lvchange -a -n /dev/systemvg/swaplv
        </pre>

        <p>Deactivate volume group;</p>

        <pre>
         # vgchange -a n systemvg
         0 logical volume(s) in volume group "systemvg" now active
         #
        </pre>

        <p>Activate volume group;</p>
        <pre>
        # vgchange -a y systemvg
          3 logical volume(s) in volume group "systemvg" now active
        #
        </pre>

        <h3>Search Volume Groups</h3>

        <pre>
        # vgscan
          Reading all physical volumes.  This may take a while...
          Found volume group "homevg" using metadata type lvm2
          Found volume group "systemvg" using metadata type lvm2
        #
        </pre>

        <h3>Reconfigure System</h3>

        <p>Start by mounting distfileslv and packageslv;</p>

        <pre>
        # mkdir -p /var/ports/distfiles
        # mkdir -p /var/ports/packages
        # mkdir -p /var/ports/work
        # mkdir -p /var/ports/pkgbuild
        # chown -R pkgmk:pkgmk /var/ports
        #
        </pre>

        <pre>
        # vim /etc/pkgmk.conf

        # PKGMK_SOURCE_MIRRORS=()
        PKGMK_SOURCE_DIR="/var/ports/distfiles"
        PKGMK_PACKAGE_DIR="/var/ports/packages"
        PKGMK_WORK_DIR="/var/ports/work/$name
        </pre>

        <p>Edit /etc/prt-get.conf;</p>

        <pre>
        ### log options:
        writelog enabled           # (enabled|disabled)
        logmode  overwrite         # (append|overwrite)
        rmlog_on_success yes       # (no|yes)
        logfile  /var/ports/pkgbuild/%n.log
        </pre>

        <pre>
        #
        # /etc/fstab: static file system information
        #
        # <file system>        <dir>     <type>    <options>                        <dump> <pass>

        UUID=49031e4e-f899-499d-ac83-401ad12635f5       /       ext4    defaults,errors=remount-ro,noatime      0 1

        #/dev/mapper/homevg-homelv:
        UUID=c3158626-de78-4bfa-ab8a-9e7e157eca88     /home   ext4    defaults,noatime        0 2

        #/dev/mapper/systemvg-distfileslv:
        UUID=0aba2d28-8e3a-4a89-bff5-1698708e13d0       /var/ports/distfiles      ext4 defaults,noatime   0 2
        #/dev/mapper/systemvg-packageslv:
        UUID=b5a38930-2827-4f00-809a-a0c4d5488aa8       /var/ports/packages       ext4 defaults,noatime   0 2

        #/dev/mapper/systemvg-swaplv:
        UUID=08295a67-a056-4dea-9462-209f151e4cdf       swap    swap    defaults        0 0
        devpts                 /dev/pts  devpts    noexec,nosuid,gid=tty,mode=0620  0      0
        tmp                   /tmp      tmpfs     defaults                         0      0
        shm                   /dev/shm  tmpfs     defaults                         0      0

        pkgmk /var/ports/work tmpfs size=1G,uid=100,defaults 0 0
        # End of file
        </pre>

        <p>You can move home directory to new one with
        just one command; "usermod -m -d /home/new user".</p>

        <pre>
        # mount /var/ports/distfiles
        # mount /var/ports/packages
        # umount /home/pkgmk/work
        # mount /var/ports/work
        # mv /home/pkgmk/distfiles/* /var/ports/distfiles/
        # mv /home/pkgmk/packages/* /var/ports/packages/
        # rm -R /home/pkgmk
        # usermod -d /var/ports pkgmk
        </pre>

        <p>Check ownership, you may need recursive if partition
        has bin used on another system.</p>

        <pre>
        # chown pkgmk:pkgmk /var/ports/distfiles
        # chown pkgmk:pkgmk /var/ports/packages
        #
        </pre>

        <pre>
        # mkdir /home/tmp
        # mount /dev/homevg/homelv /home/tmp
        # mv /home/user /home/tmp
        # umount /home/tmp
        # rmdir /home/tmp
        # rm -R /home/user
        </pre>

        <h2>Maintenance</h2>

        <pre>
        # smartctl -t long /dev/sdb1
        # smartctl -a /dev/sdb1 | less
        </pre>


        <p><a href="https://wiki.archlinux.org/index.php/Badblocks">Non Destructive Test;</a></p>

        <pre>
        # badblocks -nsv /dev/sdb1
        </pre>


        <h2>Example gitolite volume</h2>

        <p>Lets create new lvm volume for repositories data;</p>

        <pre>
        # lvcreate -L 15G -n gitlv homevg
          Logical volume "gitlv" created.

        # mkfs.ext4 /dev/homevg/gitlv
         mke2fs 1.42.12 (29-Aug-2014)
         Creating filesystem with 3932160 4k blocks and 983040 inodes
         Filesystem UUID: 54c7dca5-1558-4f90-8d81-c01e4e50c6ae
         Superblock backups stored on blocks:
                 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208

         Allocating group tables: done
         Writing inode tables: done
         Creating journal (32768 blocks): done
         Writing superblocks and filesystem accounting information: done

         #
        </pre>

        <p>Edit fstab</p>

        <pre>
        UUID=54c7dca5-1558-4f90-8d81-c01e4e50c6ae       /srv/git                ext4 defaults,noatime   0 2
        </pre>

        <h2 id="btrfs">1.3. BTRFS</h2>

        <a href="index.html">Systools Index</a>
        <p>
        This is part of the c9-doc Manual.
        Copyright (C) 2016
        c9 team.
        See the file <a href="../fdl-1.3-standalone.html">Gnu Free Documentation License</a>
        for copying conditions.</p>
    </body>
</html>