View | Details | Raw Unified | Return to bug 186377
Collapse All | Expand All

(-)disks/chapter.xml (+137 lines)
Lines 252-257 Link Here
252
    <screen>&prompt.root; <userinput>mount /newdisk</userinput></screen>
252
    <screen>&prompt.root; <userinput>mount /newdisk</userinput></screen>
253
  </sect1>
253
  </sect1>
254
254
255
  <sect1 xml:id="disks-growing">
256
    <info>
257
      <title>Resizing and Growing Disks</title>
258
259
      <authorgroup>
260
	<author>
261
	  <personname>
262
	    <firstname>Allan</firstname>
263
	    <surname>Jude</surname>
264
	  </personname>
265
	  <contrib>Originally contributed by </contrib>
266
	</author>
267
      </authorgroup>
268
    </info>
269
270
    <indexterm>
271
      <primary>disks</primary>
272
      <secondary>resizing</secondary>
273
    </indexterm>
274
275
    <para>This section describes how to resize (grow) an existing disk
276
      in &os;.  This procedure is most common with virtual machines,
277
      but can also apply to images written to USB devices or other
278
      cases where the partitions written to a disk do not match the
279
      actual size of the disk.</para>
280
281
    <para>Determine the device name of the disk that needs to be
282
      resized by inspecting <filename>/var/run/dmesg.boot</filename>.
283
      In this example, there is only one <acronym>SATA</acronym> disk
284
      in the system, so the drive will appear as
285
      <filename>ada0</filename>.</para>
286
287
    <indexterm><primary>partitions</primary></indexterm>
288
    <indexterm>
289
      <primary><command>gpart</command></primary>
290
    </indexterm>
291
292
    <para>List the partitions on the disk to determine what needs to
293
      be done to resize the desired partition:</para>
294
295
    <screen>&prompt.root; <command>gpart show <replaceable>ada0</replaceable></command>
296
=>      34  83886013  ada0  GPT  (48G) [CORRUPT]
297
        34       128     1  freebsd-boot  (64k)
298
       162  79691648     2  freebsd-ufs  (38G)
299
  79691810   4194236     3  freebsd-swap  (2G)
300
  83886046         1        - free -  (512B)</screen>
301
302
    <note>
303
      <para>If the disk was formatted with the <link
304
	  xlink:href="http://en.wikipedia.org/wiki/GUID_Partition_Table">
305
	<acronym>GPT</acronym></link> partitioning scheme, it may show
306
	as corrupted because <acronym>GPT</acronym> stores a backup
307
	of the partition table at the end of the drive, which has now
308
	moved.</para>
309
310
      <screen>&prompt.root; <command>gpart recover <replaceable>ada0</replaceable></command>
311
ada0 recovered</screen>
312
    </note>
313
314
    <para>Now the additional space on the disk is available:</para>
315
316
    <screen>&prompt.root; <command>gpart show <replaceable>ada0</replaceable></command>
317
=>       34  102399933  ada0  GPT  (48G)
318
         34        128     1  freebsd-boot  (64k)
319
        162   79691648     2  freebsd-ufs  (38G)
320
   79691810    4194236     3  freebsd-swap  (2G)
321
   83886046   18513921        - free -  (8.8G)</screen>
322
323
    <para>It is only possible to resize a partition into contiguous
324
      free space, however the last partition on the disk is the swap
325
      partition, rather than the partition to be resized.  Since swap
326
      does not contain any non-volatile data, it can safely be deleted
327
      and recreated after.</para>
328
329
    <screen>&prompt.root; <command>swapoff <replaceable>/dev/ada0p3</replaceable></command>
330
&prompt.root; <command>gpart delete -i <replaceable>3</replaceable> <replaceable>ada0</replaceable></command>
331
ada0p3 deleted
332
&prompt.root; <command>gpart show <replaceable>ada0</replaceable></command>
333
=>       34  102399933  ada0  GPT  (48G)
334
         34        128     1  freebsd-boot  (64k)
335
        162   79691648     2  freebsd-ufs  (38G)
336
   79691810   22708157        - free -  (10G)</screen>
337
338
    <para>Next resize the partition, leaving room to recreate a swap
339
      partition of the desired size.</para>
340
341
    <note>
342
      <para>There is risk involved with modifying a live file system,
343
	it is best to perform the following steps while running off of
344
	a live CD or USB device.  However it can be done on a live
345
	system with the following work around:
346
347
	<screen>&prompt.root; <command>sysctl kern.geom.debugflags=16</command></screen>
348
      </para>
349
    </note>
350
351
    <screen>&prompt.root; <command>gpart resize -i <replaceable>2</replaceable> -s <replaceable>47G</replaceable> <replaceable>ada0</replaceable></command>
352
ada0p2 resized
353
&prompt.root; <command>gpart show <replaceable>ada0</replaceable></command>
354
=>       34  102399933  ada0  GPT  (48G)
355
         34        128     1  freebsd-boot  (64k)
356
        162   98566144     2  freebsd-ufs  (47G)
357
   98566306    3833661        - free -  (1.8G)</screen>
358
359
    <para>Next, recreate the swap partition:</para>
360
361
    <screen>&prompt.root; <command>gpart add -t freebsd-swap <replaceable>ada0</replaceable></command>
362
ada0p3 added
363
&prompt.root; <command>gpart show <replaceable>ada0</replaceable></command>
364
=>       34  102399933  ada0  GPT  (48G)
365
         34        128     1  freebsd-boot  (64k)
366
        162   98566144     2  freebsd-ufs  (47G)
367
   98566306    3833661     3  freebsd-swap  (1.8G)
368
&prompt.root; <command>swapon <replaceable>/dev/ada0p3</replaceable></command></screen>
369
370
    <para>Finally, grow the UFS file system on the resized
371
      partition:</para>
372
373
    <note>
374
      <para>growing a live UFS file system is only possible in &os;
375
	10.0-RELEASE and later, for earlier versions, the file system
376
	must not be mounted.</para>
377
    </note>
378
379
    <screen>&prompt.root; <command>growfs <replaceable>/dev/ada0p2</replaceable></command>
380
Device is mounted read-write; resizing will result in temporary write suspension for /.
381
It's strongly recommended to make a backup before growing the file system.
382
OK to grow filesystem on /dev/ada0p2, mounted on /, from 38GB to 47GB? [Yes/No] <userinput>Yes</userinput>
383
super-block backups (for fsck -b #) at:
384
 80781312, 82063552, 83345792, 84628032, 85910272, 87192512, 88474752,
385
 89756992, 91039232, 92321472, 93603712, 94885952, 96168192, 97450432</screen>
386
387
    <para>The partition has now been resized to make use of all
388
      available space on the disk.</para>
389
390
  </sect1>
391
255
  <sect1 xml:id="usb-disks">
392
  <sect1 xml:id="usb-disks">
256
    <info>
393
    <info>
257
      <title>USB Storage Devices</title>
394
      <title>USB Storage Devices</title>

Return to bug 186377