>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 r...@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: >Unformatted: _______________________________________________ freebsd-doc@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-doc To unsubscribe, send any mail to "freebsd-doc-unsubscr...@freebsd.org"