# shrink a partion to split it?



## weberjn (Apr 2, 2020)

I have got a FreeBSD system that I use as Samba server. It has only one partition. I'd like to split it into two partitions with os and data and encrypt the data partition with Geli.

As I understand, I cannot shrink the partition?

So, if I mount the disk on another system, cp -rp the disk, delete and create the partitions, copy back the data, will the system still boot, or is it better to install from scratch?

Can I somehow have the Geli partition unlocked automatically if a unix or samba user logs in, i.e. use the unix and samba passwords as Geli encryption key?


----------



## George (Apr 2, 2020)

> So, if I mount the disk on another system, cp -rp the disk, delete and create the partitions, copy back the data, will the system still boot, or is it better to install from scratch?


You would also need an /etc/fstab entry, to mount your second partition/file system.


----------



## ralphbsz (Apr 3, 2020)

Easiest and safest: Get a second disk, set up the disk the way you like it to be, then copy the data onto the second disk. Ideally, you should do a clean install on the new disk, and then copy only the user data onto it.
Harder solution: Borrow a second disk, copy everything temporarily to the temporary disk, reformat the original disk, then copy everything back, and return the borrowed disk.

I think it is theoretically possible to shrink a UFS file system using "growfs -s", adjust the partition table to match the new smaller size, and then take the free space created and create a new partition and new file system on it. I don't know whether the same in possible in ZFS; the only way I know to change the partition size in ZFS is to enlarge it, using "zpool import -e", and I don't think that would work to shrink (because you have to do the partition first, which works for growing but not for shrinking). In practice, I would NEVER try this on a live system that has not been  thoroughly backed up. To thoroughly back it up, you need a second disk ... and at that point, you are back to the original easier and safer solution.

If you really want to to try it in place, I would first set up a sacrificial system and practice on it. Given that  shrinking with "growfs -s" is not even documented in the man page or handbook, but mentioned in some folklore, I'm not sure it's trustworthy.


----------



## Emrion (Apr 3, 2020)

Concerning UFS, `growfs` doesn't allow to reduce size. I didn't find a way to shrink a UFS partition. Well, you can actually shrink it with `gpart` but the file system seems unrecoverable with `fsck` and is unable to boot anymore.


----------

