= FreeBSD cheat sheet :homepage: https://yurisk.info Author: Yuri Slobodyanyuk, https://www.linkedin.com/in/yurislobodyanyuk/ == Working with disks and partitions [cols=2, options="header"] |=== |Command |Description |*camcontrol devlist* |Show list of attached storage devices |*geom list* |Display detailed information for the given GEOM class `disk` - physical disk, `label` - device labels, `part` - partitions. Other classes are available, but not mentioned for irrelevance here. |*mount* |Show mounted in fact partitions and their properties (journaled or not, type). |*glabel list* |Show labels, same as `geom label list`. |*gpart show* |Show partitions, similar to `geom part list` minus labels information, so is shorter. Add `-r` to show GPT partition types, see for the complete list at https://en.wikipedia.org/wiki/GUID_Partition_Table . |*gpart recover * |Recover partition information, e.g. when increasing the size of already partitioned disk in Virtual Machine, the last sector holding the partition info is lost, so to put the needed info in the last sector of now increased disk: `gpart recover da0`. |*swapoff * |Turn off temporarily the swap file, e.g. to move its partition to the end of the increased virtual disk: `swapoff /dev/da0p3` |*gpart delete -i * |Delete partition number `n` (as shown by `gpart show`) on the device `device name`. E.g. If the swap partition was number 3 on disk /dev/da0, to delete it: `gpart delete -i 3 /dev/da0`. |*gpart create -s * |Set type of partition to be added on device `device name`. E.g. to set up device _da1_ for GPT partitioning: `gpart create -s gpt da1`. |*sysctl kern.geom.debugflags=16* |Resizing a live partition may require turning off this protection. |*gpart resize -i [ -s ] [-a ] * |Resize existing partition number `n` to `new size`, optionally setting alighnment, on device `device name`. If `-s` size is not given, use up all available _free_ space. E.g. to increase the _2nd_ partition on device _da0_ to 47 Gigabyte with 4k alignment: `gpart resize -i 2 -s 47G -a 4k da0`. |*growfs * |After resizing a partition, grow the existing file system on it to encompass the new free space. E.g.`growfs /dev/da0p2`. |*gpart add -t [-a ] [-l