From owner-freebsd-doc@FreeBSD.ORG Sun Feb 2 08:16:13 2014 Return-Path: Delivered-To: freebsd-doc@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 C8CB2CC5 for ; Sun, 2 Feb 2014 08:16:13 +0000 (UTC) Received: from mx1.scaleengine.net (beauharnois2.bhs1.scaleengine.net [142.4.218.15]) by mx1.freebsd.org (Postfix) with ESMTP id 9D12A1736 for ; Sun, 2 Feb 2014 08:16:12 +0000 (UTC) Received: from [10.1.1.1] (S01060001abad1dea.hm.shawcable.net [50.70.146.73]) (Authenticated sender: allan.jude@scaleengine.com) by mx1.scaleengine.net (Postfix) with ESMTPSA id E23B2576DC for ; Sun, 2 Feb 2014 08:16:02 +0000 (UTC) Message-ID: <52EDFEBD.6010506@allanjude.com> Date: Sun, 02 Feb 2014 03:15:57 -0500 From: Allan Jude User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: freebsd-doc@FreeBSD.org Subject: New handbook section - resizing/growing disks X-Enigmail-Version: 1.6 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="OIUQbjDiv1OfudD7mrAk754nLOlvMqv2k" 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 08:16:13 -0000 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --OIUQbjDiv1OfudD7mrAk754nLOlvMqv2k Content-Type: multipart/mixed; boundary="------------000407000402060501060503" This is a multi-part message in MIME format. --------------000407000402060501060503 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable The question of how to resize a disk partition/file system has come up a number of times on IRC and elsewhere. A user writing a raspberry pi image to an SD card that is larger than the image and wanting to grow the file system to use the rest of the SSD Creating a live USB system A user who rented a VPS and then paid to grow the disk from 20GB to 80GB but the default install had the swap partition at the end. So, I wrote this section for the handbook that describes how to deal with those issues. --=20 Allan Jude --------------000407000402060501060503 Content-Type: text/plain; charset=windows-1252; name="docs.growfs.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="docs.growfs.patch" Index: disks/chapter.xml =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- disks/chapter.xml (revision 43726) +++ disks/chapter.xml (working copy) @@ -252,6 +252,143 @@ &prompt.root; mount /newdisk= =20 + + + 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 +=3D> 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 +=3D> 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 +=3D> 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=3D16 + + + + &prompt.root; gpart resize -i 2 -s 47G ada0 +ada0p2 resized +&prompt.root; gpart show ada0 +=3D> 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 +=3D> 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 su= spension for /. +It's strongly recommended to make a backup before growing the file syste= m. +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 --------------000407000402060501060503-- --OIUQbjDiv1OfudD7mrAk754nLOlvMqv2k Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.16 (MingW32) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQIcBAEBAgAGBQJS7f7BAAoJEJrBFpNRJZKfka4P/jVyZU4tXDHfRmdjOWpiSMRx gWtovqvQiQJCxrw0kQv9g9YrRrMlH/jNG4WQacHSZouXqbL599u2k+9sJwKM2Y3O h71gTs0J+/0EOljEoV+BTugQiGckSAcWmqOIaDKINNGF0p0+9GdAMTd58TYGY/K0 LeCvEaqHp1nyS0CjEuGBGJV8lkagaEmpBv0gx9F3vK88+l3K88v6nXG169cVdzOb DKTLsdYf9BevFqaEzE70ymsYA5ejFxC8Kq3FomA6olmBVHxhl+6mQV7hozP+KYYu COCjUtB08qT+scAJy3T4q1kbX1vJk0ApK55KLIA+IKrsd11+48ER7be9VcWjKHAW bH5Pm+umDDcKBNnPF08aR1LcZmzXc4D1TnKr8mpWw7ZBO/9SEvSuDlXrxcoDzNXP qiWxyzuriOO6nXCddjA3kdeCzTKMTfoQuzK5p+RelfAU3II5AfYRKKOvPbZu5Nfh 6An841aeN3WmZkOK1T42BpvKPp7OVRcoSjK4I/nfiNSiyrHLPuomvIcFd64an80e Tj7Apx3XCkel3sR9q+MwqqfqTTsmo+KfZ+fYsr48UbL7UG2NcoPEpkpnHnoyAyOD DVQw/Eknqi+jC4Ut0BF0wNxUl4VFbjFLsuUh/gwXN9EJAJx0CiCJqVln3MISPE09 +tGST72IPPH36TjoAoh7 =uKJx -----END PGP SIGNATURE----- --OIUQbjDiv1OfudD7mrAk754nLOlvMqv2k--