swap partition

Polytropon freebsd at edvax.de
Thu Dec 29 13:37:49 UTC 2016


On Thu, 29 Dec 2016 07:49:15 -0500, Stari Karp wrote:
> On Thu, 2016-12-29 at 13:08 +0100, Polytropon wrote:
> > On Thu, 29 Dec 2016 06:53:40 -0500, Stari Karp wrote:
> > > 
> > > I like to increase swap partition but I am scary to screw up my
> > > system.
> > > FreeBSD is installed on iMac (Mountain Lion).
> > > 
> > > gpart show
> > > =>        34  1953525101  ada0  GPT  (932G)
> > >           34           6        - free -  (3.0K)
> > >           40      409600     1  efi  (200M)
> > >       409640  1216587112     2  apple-hfs  (580G)
> > >   1216996752     1269536     3  apple-boot  (620M)
> > >   1218266288        1024     4  freebsd-boot  (512K)
> > >   1218267312   727710720     5  freebsd-ufs  (347G)
> > >   1945978032     7547102     6  freebsd-swap  (3.6G)
> > >   1953525134           1        - free -  (512B)
> > > 
> > > What I planning to do:
> > > Boot to OS X and than decrease apple-hfs partition for 64 GB.
> > > Than boot to FreeBSD (single user) and:
> > > swapoff -a
> > > gpart resize -i6 ada0
> > > swapon -a
> > > 
> > > Do I need to use gpart resize -i6 -s 64G ada0 or gpart will find
> > > empty
> > > space and use it, please?
> > I don't think this is possible. Partitions have to be coherent
> > disk space. If I read your current layout correctly, shrinking
> > ada0p2 (apple-hfs) would leave a "hole" before ada0p3 (apple-boot),
> > but your swap space is ada0p6.
> > 
> > However, you can add a second swap space (and maybe even ignore
> > your existing one), so the final layout could be this:
> > 
> > 	ada0p1  efi  (200M)
> > 	ada0p2  apple-hfs  (580G - 64G)	<--- shrink
> > 	ada0p3  freebsd-swap  (64G)	<--- create in "hole"
> > 	ada0p4  apple-boot  (620M)
> > 	ada0p5  freebsd-boot  (512K)
> > 	ada0p6  freebsd-ufs  (347G)
> > 	ada0p7  freebsd-swap  (3.6G)	<--- maybe ignore
> > 
> > However, I don't have experience regarding partitioning on
> > Mac OS X systems, but from a "logic point of view", this sounds
> > reasonable. I'm also not sure if repartitioning will cause
> > partition numbers to change, or if the offset and size will
> > be assigned accordingly (so the new partition would become
> > ada0p7).
> > 
> > 
> > 
> > > 
> > > Should I format on OS X empty space to FAT?
> > No, leave it untouched, "empty space", unallocated. A swap
> > partition doesn't need a file system, in fact, is _has to be_
> > void of a file system.
> > 
> Resizing apple-hfs is not a problem, what I am scary more is changes of
> partition numbers.

Use labels, and you don't have to worry. Labels will keep
consistent across partition number changes (or even device
filename changes), they are a very convenient way to describe
partitions.



> It will be nice if I could add empty space to the
> end.

But according to your gpart output, there is not sufficient
space left at the end. Partitions usually don't "shift down"
after beging resized; instead, a "hole" is left.



> I didn't ose OS X years and I need to check what can I do. I just
> know that was easy when I shrink hfs for Installed FreeBSD.

As Bernt Hansson suggested, you can use a file-based swap
from within the FreeBSD partition: Allocate a 64 GB file
and use it as swap file.

So if you want additional 64 GB of swap file:

	# dd if=/dev/zero of=/usr/swap0 bs=1024m count=64
	# chmod 0600 /usr/swap0

In /etc/fstab, add:

	md99	none	swap	sw,file=/usr/swap0,late	0	0

And finally activate it:

	# swapon -aL

Source (ch. 11.12.2, ex 11.2):

https://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/adding-swap-space.html

Note that FreeBSD can utilize more than one swap partition or
swap file, so if you keep your existing swap partition, it
will not interefere with an additional swap file on the UFS
partition. See "man swapctl" for details.

I'm doing something similar on SSDs using /etc/rc.local to
allocate via a dummy file (no disk space is being used until
there is actually anything written to swap):

	SWAP="/ssdswap"
	/bin/rm -f $SWAP
	/bin/dd if=/dev/zero of=$SWAP bs=16m seek=500 count=0
	/sbin/mdconfig -a -t vnode -u 0 -f $SWAP || /bin/sh
	/bin/chflags nodump $SWAP
	/bin/rm $SWAP
	/sbin/swapctl -a /dev/md0

Note the "count=0" in the dd call, and finally the "rm" call.
The swap access will be performed using the memory disk virtual
device, /dev/md0.

And at shutdown time, cleaning up, via /etc/rc.shutdown.local:

	/sbin/swapctl -d /dev/md0
	/sbin/mdconfig -d -u 0

But I'm not sure if it will work as good with HDDs in the same
was as it does on SSDs. :-)


-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...


More information about the freebsd-questions mailing list