From owner-freebsd-doc@FreeBSD.ORG Sun Feb 2 15:30:02 2014 Return-Path: Delivered-To: freebsd-doc@smarthost.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id DB1B8A3B for ; Sun, 2 Feb 2014 15:30:02 +0000 (UTC) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id B5ABD14C2 for ; Sun, 2 Feb 2014 15:30:02 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.7/8.14.7) with ESMTP id s12FU2Mm034732 for ; Sun, 2 Feb 2014 15:30:02 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.7/8.14.7/Submit) id s12FU2wV034731; Sun, 2 Feb 2014 15:30:02 GMT (envelope-from gnats) Resent-Date: Sun, 2 Feb 2014 15:30:02 GMT Resent-Message-Id: <201402021530.s12FU2wV034731@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-doc@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Allan Jude 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 ; 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 ; 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 ; 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 To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Subject: docs/186377: new handbook section - growing disks X-BeenThere: freebsd-doc@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: Documentation project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 02 Feb 2014 15:30:02 -0000 >Number: 186377 >Category: docs >Synopsis: new handbook section - growing disks >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-doc >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Sun Feb 02 15:30:01 UTC 2014 >Closed-Date: >Last-Modified: >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 @@ &prompt.root; mount /newdisk + + + Resizing and Growing Disks + + + + + Allan + Jude + + Originally contributed by + + + + + + disks + resizing + + + 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. + + Determine the device name of the disk that needs to be + resized by inspecting /var/run/dmesg.boot. + In this example, there is only one SATA disk + in the system, so the drive will appear as + ada0. + + partitions + + gpart + + + List the partitions on the disk to determine what needs to + be done to resize the desired partition: + + &prompt.root; gpart show ada0 +=> 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) + + + If the disk was formatted with the + GPT partitioning scheme, it may show + as corrupted because GPT stores a backup + of the partition table at the end of the drive, which has now + moved. + + &prompt.root; gpart recover ada0 +ada0 recovered + + + Now the additional space on the disk is available: + + &prompt.root; gpart show ada0 +=> 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) + + 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. + + &prompt.root; swapoff /dev/ada0p3 +&prompt.root; gpart delete -i 3 ada0 +ada0p3 deleted +&prompt.root; gpart show ada0 +=> 34 102399933 ada0 GPT (48G) + 34 128 1 freebsd-boot (64k) + 162 79691648 2 freebsd-ufs (38G) + 79691810 22708157 - free - (10G) + + Next resize the partition, leaving room to recreate a swap + partition of the desired size. + + + 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: + + &prompt.root; sysctl kern.geom.debugflags=16 + + + + &prompt.root; gpart resize -i 2 -s 47G ada0 +ada0p2 resized +&prompt.root; gpart show ada0 +=> 34 102399933 ada0 GPT (48G) + 34 128 1 freebsd-boot (64k) + 162 98566144 2 freebsd-ufs (47G) + 98566306 3833661 - free - (1.8G) + + Next, recreate the swap partition: + + &prompt.root; gpart add -t freebsd-swap ada0 +ada0p3 added +&prompt.root; gpart show ada0 +=> 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; swapon /dev/ada0p3 + + Finally, grow the UFS file system on the resized + partition: + + + 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. + + + &prompt.root; growfs /dev/ada0p2 +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] Yes +super-block backups (for fsck -b #) at: + 80781312, 82063552, 83345792, 84628032, 85910272, 87192512, 88474752, + 89756992, 91039232, 92321472, 93603712, 94885952, 96168192, 97450432 + + The partition has now been resized to make use of all + available space on the disk. + + + USB Storage Devices >Release-Note: >Audit-Trail: >Unformatted: