# Shrink UFS filesystem



## vertexSymphony (Nov 24, 2011)

Hi people!
the question is pretty simple, can I safely shrink a UFS2 filesystem under a GPT scheme in FreeBSD 9.x?

Thanks a lot for your time.
Regards, Alex.

P.S â†’ I don't have the requirement, but it would be awesome.


----------



## wblock@ (Nov 25, 2011)

AFAIK, there isn't any automatic way to do that.  dump(8), use gpart(8) to reduce the size of the partition, restore(8).


----------



## cederom (Sep 13, 2022)

Yea, I need to create some swap space on EC2 AWS image that comes with no swap, would be good to know how to make it the righteous way


----------



## Phishfry (Sep 13, 2022)

cederom said:


> create some swap space on EC2 AWS image


If you have physical access to the image file you can 'pad' it with zero's or truncate the file to expand size..
Then open image file as a memory disk and create swap in the padded area.. Exit and upload image to the cloud.
No good way to downsize an existing partition.


----------



## Phishfry (Sep 13, 2022)

Lets assume the worse. Your AWS image is the max size Amazon allows.

Again a memory disk can be a savior.
Create memdisk of the AWS Image.
Also create a new empty memory disk of the same size. (truncate a new image file same size.)
Create your new disk structure with partitions and desired swap in the new memdisk.
Use clone to duplicate everything from AWS image's memdisk partitions to your new custom image memdisk's partitions.






						clone(1)
					






					www.freebsd.org
				




I create several /mnt directories for exactly these type jobs.
/mnt1
/mnt2
You will need multiple mountpoints to pull off a clone of a memdisk to memdisk.

For example for the EFI/ESP partition:
`mount -t msdosfs /dev/md0s1 /mnt1`
Notice md0 is my memdisk.
Make sure you properly shutdown your memdisk or disk corruption of your image file could occur.






						mdconfig(8)
					






					www.freebsd.org


----------



## cederom (Sep 13, 2022)

Thanks Phishfry, the problem is 1GB of RAM that limits compilation.. and the memdisk.. it was impossible to shrink with growfs or gpart.. so I have created a new EC2 instance with smaller disk, started the instance, shut down the inctance, increased disk size by 2GB, then in working instance I have added this additional 2GB as freebsd-swap with gpart, and this is it


----------



## Phishfry (Sep 13, 2022)

I don't see the Amazon AWS images on FreeBSD download website.


			Index of /releases/VM-IMAGES/13.1-RELEASE/amd64/Latest/
		


So I assume these are Amazon hosted images?
See if you can download it and alter or mimick.
Do they have a backend console via the web control panel?


----------



## Phishfry (Sep 13, 2022)

Sounds like you found a workaround.


----------



## Alain De Vos (Sep 13, 2022)

Is not the solution copy everything over and copy everything back ?


----------

