From nobody@FreeBSD.org  Sun Feb  2 15:21:33 2014
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1])
	(using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by hub.freebsd.org (Postfix) with ESMTPS id 6D7BE9EF
	for <freebsd-gnats-submit@FreeBSD.org>; Sun,  2 Feb 2014 15:21:33 +0000 (UTC)
Received: from oldred.freebsd.org (oldred.freebsd.org [IPv6:2001:1900:2254:206a::50:4])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by mx1.freebsd.org (Postfix) with ESMTPS id 57D2D1489
	for <freebsd-gnats-submit@FreeBSD.org>; Sun,  2 Feb 2014 15:21:33 +0000 (UTC)
Received: from oldred.freebsd.org ([127.0.1.6])
	by oldred.freebsd.org (8.14.5/8.14.7) with ESMTP id s12FLW3R008038
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 2 Feb 2014 15:21:32 GMT
	(envelope-from nobody@oldred.freebsd.org)
Received: (from nobody@localhost)
	by oldred.freebsd.org (8.14.5/8.14.5/Submit) id s12FLWk5008019;
	Sun, 2 Feb 2014 15:21:32 GMT
	(envelope-from nobody)
Message-Id: <201402021521.s12FLWk5008019@oldred.freebsd.org>
Date: Sun, 2 Feb 2014 15:21:32 GMT
From: Allan Jude <freebsd@allanjude.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: new handbook section - growing disks
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         186377
>Category:       docs
>Synopsis:       new handbook section - growing disks
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    wblock
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun Feb 02 15:30:01 UTC 2014
>Closed-Date:    Thu Feb 06 04:04:21 UTC 2014
>Last-Modified:  Thu Feb  6 04:10:00 UTC 2014
>Originator:     Allan Jude
>Release:        9.2-RELEASE
>Organization:
ScaleEngine Inc.
>Environment:
FreeBSD Trooper.HML3.ScaleEngine.net 9.2-RELEASE FreeBSD 9.2-RELEASE #0 r255898: Thu Sep 26 22:50:31 UTC 2013     root@bake.isc.freebsd.org:/usr/obj/usr/src/sys/GENERIC  amd64

>Description:
A new section in the freebsd handbook to cover resizing/growing a disk

Applies to:

raspberry pi and other embedded images
file system images written to USB sticks
virtual machines and VPSs where a smaller image is used, or where the disk size is increased after-the-fact
>How-To-Repeat:

>Fix:


Patch attached with submission follows:

Index: disks/chapter.xml
===================================================================
--- disks/chapter.xml	(revision 43726)
+++ disks/chapter.xml	(working copy)
@@ -252,6 +252,143 @@
     <screen>&prompt.root; <userinput>mount /newdisk</userinput></screen>
   </sect1>
 
+  <sect1 xml:id="disks-growing">
+    <info>
+      <title>Resizing and Growing Disks</title>
+
+      <authorgroup>
+	<author>
+	  <personname>
+	    <firstname>Allan</firstname>
+	    <surname>Jude</surname>
+	  </personname>
+	  <contrib>Originally contributed by </contrib>
+	</author>
+      </authorgroup>
+    </info>
+
+    <indexterm>
+      <primary>disks</primary>
+      <secondary>resizing</secondary>
+    </indexterm>
+
+    <para>This section describes how to resize (grow) an existing disk
+      in &os;.  This procedure is most common with virtual machines,
+      but can also apply to images written to USB devices or other
+      cases where the partitions written to a disk do not match the
+      actual size of the disk.</para>
+
+    <para>Determine the device name of the disk that needs to be
+      resized by inspecting <filename>/var/run/dmesg.boot</filename>.
+      In this example, there is only one <acronym>SATA</acronym> disk
+      in the system, so the drive will appear as
+      <filename>ada0</filename>.</para>
+
+    <indexterm><primary>partitions</primary></indexterm>
+    <indexterm>
+      <primary><command>gpart</command></primary>
+    </indexterm>
+
+    <para>List the partitions on the disk to determine what needs to
+      be done to resize the desired partition:</para>
+
+    <screen>&prompt.root; <command>gpart show <replaceable>ada0</replaceable></command>
+=>      34  83886013  ada0  GPT  (48G) [CORRUPT]
+        34       128     1  freebsd-boot  (64k)
+       162  79691648     2  freebsd-ufs  (38G)
+  79691810   4194236     3  freebsd-swap  (2G)
+  83886046         1        - free -  (512B)</screen>
+
+    <note>
+      <para>If the disk was formatted with the <link
+	  xlink:href="http://en.wikipedia.org/wiki/GUID_Partition_Table">
+	<acronym>GPT</acronym></link> partitioning scheme, it may show
+	as corrupted because <acronym>GPT</acronym> stores a backup
+	of the partition table at the end of the drive, which has now
+	moved.</para>
+
+      <screen>&prompt.root; <command>gpart recover <replaceable>ada0</replaceable></command>
+ada0 recovered</screen>
+    </note>
+
+    <para>Now the additional space on the disk is available:</para>
+
+    <screen>&prompt.root; <command>gpart show <replaceable>ada0</replaceable></command>
+=>       34  102399933  ada0  GPT  (48G)
+         34        128     1  freebsd-boot  (64k)
+        162   79691648     2  freebsd-ufs  (38G)
+   79691810    4194236     3  freebsd-swap  (2G)
+   83886046   18513921        - free -  (8.8G)</screen>
+
+    <para>It is only possible to resize a partition into contiguous
+      free space, however the last partition on the disk is the swap
+      partition, rather than the partition to be resized.  Since swap
+      does not contain any non-volatile data, it can safely be deleted
+      and recreated after.</para>
+
+    <screen>&prompt.root; <command>swapoff <replaceable>/dev/ada0p3</replaceable></command>
+&prompt.root; <command>gpart delete -i <replaceable>3</replaceable> <replaceable>ada0</replaceable></command>
+ada0p3 deleted
+&prompt.root; <command>gpart show <replaceable>ada0</replaceable></command>
+=>       34  102399933  ada0  GPT  (48G)
+         34        128     1  freebsd-boot  (64k)
+        162   79691648     2  freebsd-ufs  (38G)
+   79691810   22708157        - free -  (10G)</screen>
+
+    <para>Next resize the partition, leaving room to recreate a swap
+      partition of the desired size.</para>
+
+    <note>
+      <para>There is risk involved with modifying a live file system,
+	it is best to perform the following steps while running off of
+	a live CD or USB device.  However it can be done on a live
+	system with the following work around:
+
+	<screen>&prompt.root; <command>sysctl kern.geom.debugflags=16</command></screen>
+      </para>
+    </note>
+
+    <screen>&prompt.root; <command>gpart resize -i <replaceable>2</replaceable> -s <replaceable>47G</replaceable> <replaceable>ada0</replaceable></command>
+ada0p2 resized
+&prompt.root; <command>gpart show <replaceable>ada0</replaceable></command>
+=>       34  102399933  ada0  GPT  (48G)
+         34        128     1  freebsd-boot  (64k)
+        162   98566144     2  freebsd-ufs  (47G)
+   98566306    3833661        - free -  (1.8G)</screen>
+
+    <para>Next, recreate the swap partition:</para>
+
+    <screen>&prompt.root; <command>gpart add -t freebsd-swap <replaceable>ada0</replaceable></command>
+ada0p3 added
+&prompt.root; <command>gpart show <replaceable>ada0</replaceable></command>
+=>       34  102399933  ada0  GPT  (48G)
+         34        128     1  freebsd-boot  (64k)
+        162   98566144     2  freebsd-ufs  (47G)
+   98566306    3833661     3  freebsd-swap  (1.8G)
+&prompt.root; <command>swapon <replaceable>/dev/ada0p3</replaceable></command></screen>
+
+    <para>Finally, grow the UFS file system on the resized
+      partition:</para>
+
+    <note>
+      <para>growing a live UFS file system is only possible in &os;
+	10.0-RELEASE and later, for earlier versions, the file system
+	must not be mounted.</para>
+    </note>
+
+    <screen>&prompt.root; <command>growfs <replaceable>/dev/ada0p2</replaceable></command>
+Device is mounted read-write; resizing will result in temporary write suspension for /.
+It's strongly recommended to make a backup before growing the file system.
+OK to grow filesystem on /dev/ada0p2, mounted on /, from 38GB to 47GB? [Yes/No] <userinput>Yes</userinput>
+super-block backups (for fsck -b #) at:
+ 80781312, 82063552, 83345792, 84628032, 85910272, 87192512, 88474752,
+ 89756992, 91039232, 92321472, 93603712, 94885952, 96168192, 97450432</screen>
+
+    <para>The partition has now been resized to make use of all
+      available space on the disk.</para>
+
+  </sect1>
+
   <sect1 xml:id="usb-disks">
     <info>
       <title>USB Storage Devices</title>


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-doc->wblock 
Responsible-Changed-By: wblock 
Responsible-Changed-When: Sun Feb 2 16:08:44 UTC 2014 
Responsible-Changed-Why:  
Take. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=186377 
State-Changed-From-To: open->closed 
State-Changed-By: wblock 
State-Changed-When: Thu Feb 6 04:03:45 UTC 2014 
State-Changed-Why:  
Committed modified version of patch submitted.  Thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=186377 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: docs/186377: commit references a PR
Date: Thu,  6 Feb 2014 04:03:36 +0000 (UTC)

 Author: wblock
 Date: Thu Feb  6 04:03:28 2014
 New Revision: 43798
 URL: http://svnweb.freebsd.org/changeset/doc/43798
 
 Log:
   Add a new section on growing disks.  Modified version of patch submitted
   with PR.
   
   PR:		docs/186377
   Submitted by:	Allan Jude <freebsd@allanjude.com>
 
 Modified:
   head/en_US.ISO8859-1/books/handbook/disks/chapter.xml
 
 Modified: head/en_US.ISO8859-1/books/handbook/disks/chapter.xml
 ==============================================================================
 --- head/en_US.ISO8859-1/books/handbook/disks/chapter.xml	Thu Feb  6 01:58:10 2014	(r43797)
 +++ head/en_US.ISO8859-1/books/handbook/disks/chapter.xml	Thu Feb  6 04:03:28 2014	(r43798)
 @@ -252,6 +252,154 @@
      <screen>&prompt.root; <userinput>mount /newdisk</userinput></screen>
    </sect1>
  
 +  <sect1 xml:id="disks-growing">
 +    <info>
 +      <title>Resizing and Growing Disks</title>
 +
 +      <authorgroup>
 +	<author>
 +	  <personname>
 +	    <firstname>Allan</firstname>
 +	    <surname>Jude</surname>
 +	  </personname>
 +	  <contrib>Originally contributed by </contrib>
 +	</author>
 +      </authorgroup>
 +    </info>
 +
 +    <indexterm>
 +      <primary>disks</primary>
 +      <secondary>resizing</secondary>
 +    </indexterm>
 +
 +    <para>A disk's capacity can increase without any changes to the
 +      data already present.  This happens commonly with virtual
 +      machines, when the virtual disk turns out to be too small and is
 +      enlarged.  Sometimes a disk image is written to a
 +      <acronym>USB</acronym> memory stick, but does not use the full
 +      capacity.  Here we describe how to resize or
 +      <emphasis>grow</emphasis> disk contents to take advantage of
 +      increased capacity.</para>
 +
 +    <para>Determine the device name of the disk to be resized by
 +      inspecting <filename>/var/run/dmesg.boot</filename>.  In this
 +      example, there is only one <acronym>SATA</acronym> disk in the
 +      system, so the drive will appear as
 +      <filename>ada0</filename>.</para>
 +
 +    <indexterm><primary>partitions</primary></indexterm>
 +    <indexterm>
 +      <primary><command>gpart</command></primary>
 +    </indexterm>
 +
 +    <para>List the partitions on the disk to see the current
 +      configuration:</para>
 +
 +    <screen>&prompt.root; <command>gpart show <replaceable>ada0</replaceable></command>
 +=>      34  83886013  ada0  GPT  (48G) [CORRUPT]
 +        34       128     1  freebsd-boot  (64k)
 +       162  79691648     2  freebsd-ufs  (38G)
 +  79691810   4194236     3  freebsd-swap  (2G)
 +  83886046         1        - free -  (512B)</screen>
 +
 +    <note>
 +      <para>If the disk was formatted with the <link
 +	  xlink:href="http://en.wikipedia.org/wiki/GUID_Partition_Table">
 +	<acronym>GPT</acronym></link> partitioning scheme, it may show
 +	as <quote>corrupted</quote> because the <acronym>GPT</acronym>
 +	backup partition table is no longer at the end of the
 +	drive.  Fix the backup
 +	partition table with
 +	<command>gpart</command>:</para>
 +
 +      <screen>&prompt.root; <command>gpart recover <replaceable>ada0</replaceable></command>
 +ada0 recovered</screen>
 +    </note>
 +
 +    <para>Now the additional space on the disk is available for
 +      use by a new partition, or an existing partition can be
 +      expanded:</para>
 +
 +    <screen>&prompt.root; <command>gpart show <replaceable>ada0</replaceable></command>
 +=>       34  102399933  ada0  GPT  (48G)
 +         34        128     1  freebsd-boot  (64k)
 +        162   79691648     2  freebsd-ufs  (38G)
 +   79691810    4194236     3  freebsd-swap  (2G)
 +   83886046   18513921        - free -  (8.8G)</screen>
 +
 +    <para>Partitions can only be resized into contiguous free space.
 +      Here, the last partition on the disk is the swap partition, but
 +      the second partition is the one that needs to be resized.  Swap
 +      partitions only contain temporary data, so it can safely be
 +      unmounted, deleted, and then recreated after resizing other
 +      partitions.</para>
 +
 +    <screen>&prompt.root; <command>swapoff <replaceable>/dev/ada0p3</replaceable></command>
 +&prompt.root; <command>gpart delete -i <replaceable>3</replaceable> <replaceable>ada0</replaceable></command>
 +ada0p3 deleted
 +&prompt.root; <command>gpart show <replaceable>ada0</replaceable></command>
 +=>       34  102399933  ada0  GPT  (48G)
 +         34        128     1  freebsd-boot  (64k)
 +        162   79691648     2  freebsd-ufs  (38G)
 +   79691810   22708157        - free -  (10G)</screen>
 +
 +    <warning>
 +      <para>There is risk of data loss when modifying the partition
 +	table of a mounted file system.  It is best to perform the
 +	following steps on an unmounted file system while running from
 +	a live <acronym>CD-ROM</acronym> or <acronym>USB</acronym>
 +	device.  However, if absolutely necessary, a mounted file
 +	system can be  resized after disabling GEOM safety
 +	features:</para>
 +
 +      <screen>&prompt.root; <command>sysctl kern.geom.debugflags=16</command></screen>
 +    </warning>
 +
 +    <para>Resize the partition, leaving room to recreate a swap
 +      partition of the desired size.  This only modifies the size of
 +      the partition.  The file system in the partition will be
 +      expanded in a separate step.</para>
 +
 +    <screen>&prompt.root; <command>gpart resize -i <replaceable>2</replaceable> -a 4k -s <replaceable>47G</replaceable> <replaceable>ada0</replaceable></command>
 +ada0p2 resized
 +&prompt.root; <command>gpart show <replaceable>ada0</replaceable></command>
 +=>       34  102399933  ada0  GPT  (48G)
 +         34        128     1  freebsd-boot  (64k)
 +        162   98566144     2  freebsd-ufs  (47G)
 +   98566306    3833661        - free -  (1.8G)</screen>
 +
 +    <para>Recreate the swap partition:</para>
 +
 +    <screen>&prompt.root; <command>gpart add -t freebsd-swap -a 4k <replaceable>ada0</replaceable></command>
 +ada0p3 added
 +&prompt.root; <command>gpart show <replaceable>ada0</replaceable></command>
 +=>       34  102399933  ada0  GPT  (48G)
 +         34        128     1  freebsd-boot  (64k)
 +        162   98566144     2  freebsd-ufs  (47G)
 +   98566306    3833661     3  freebsd-swap  (1.8G)
 +&prompt.root; <command>swapon <replaceable>/dev/ada0p3</replaceable></command></screen>
 +
 +    <para>Grow the <acronym>UFS</acronym> file system to use the new
 +      capacity of the resized partition:</para>
 +
 +    <note>
 +      <para>Growing a live <acronym>UFS</acronym> file system is only
 +	possible in &os; 10.0-RELEASE and later.  For earlier
 +	versions, the file system must not be mounted.</para>
 +    </note>
 +
 +    <screen>&prompt.root; <command>growfs <replaceable>/dev/ada0p2</replaceable></command>
 +Device is mounted read-write; resizing will result in temporary write suspension for /.
 +It's strongly recommended to make a backup before growing the file system.
 +OK to grow file system on /dev/ada0p2, mounted on /, from 38GB to 47GB? [Yes/No] <userinput>Yes</userinput>
 +super-block backups (for fsck -b #) at:
 + 80781312, 82063552, 83345792, 84628032, 85910272, 87192512, 88474752,
 + 89756992, 91039232, 92321472, 93603712, 94885952, 96168192, 97450432</screen>
 +
 +    <para>Both the partition and the file system on it have now been
 +      resized to use the newly-available disk space.</para>
 +  </sect1>
 +
    <sect1 xml:id="usb-disks">
      <info>
        <title>USB Storage Devices</title>
 _______________________________________________
 svn-doc-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-doc-all
 To unsubscribe, send any mail to "svn-doc-all-unsubscribe@freebsd.org"
 
>Unformatted:
