I've searched about resizing partitions and only found about increasing size.
Sincesysutils/gpart gpart(8) is the default tool on FreeBSD, I would like to know how to do it with
I tried to experiment shrinking of freebsd-zfs and ntfs partitions on VirtualBox and found that there are two thing I don't like aboutsysutils/gpart gpart(8) ; (correct me if I'm wrong)
sysutils/gpart gpart(8) can't do that, which tool in FreeBSD can be used for that purpose?
These are the commands and outputs. (
Since
gpart resize
.I tried to experiment shrinking of freebsd-zfs and ntfs partitions on VirtualBox and found that there are two thing I don't like about
- Shrinking cause corrupted disk. There is no warning or nothing. Expanding back to original size can fix the disk.
- Allowing shrink / resize even though there is no enough free space. And there is no warning or nothing about it too.
These are the commands and outputs. (
ntfsfix
can't fix the error)
Code:
root@FBSD:~ # gpart show -p
=> 40 20971440 ada0 GPT (10G)
40 532480 ada0p1 efi (260M)
532520 2008 - free - (1.0M)
534528 4194304 ada0p2 freebsd-swap (2.0G)
4728832 7854040 ada0p3 freebsd-zfs (3.7G)
12582872 8388608 - free - (4.0G)
root@FBSD:~ # gart add -s 2g -t ms-basic-data ada0
ada0p4 added
root@FBSD:~ # mkntfs --quick /dev/ada0p4
The partition start sector was not specified for /dev/ada0p4 and it could not be obtained automatically. It has been set to 0.
The number of sectors per track was not specified for /dev/ada0p4 and it could not be obtained automatically. It has been set to 0.
The number of heads was not specified for /dev/ada0p4 and it could not be obtained automatically. It has been set to 0.
Cluster size has been automatically set to 4096 bytes.
To boot from a device, Windows needs the 'partition start sector', the 'sectors per track' and the 'number of heads' to be set.
Windows will not be able to boot from this device.
Creating NTFS volume structures.
mkntfs completed successfully. Have a nice day.
root@FBSD:~ # ntfs-3g /dev/ada0p4 /mnt/
root@FBSD:~ # touch /mnt/test.txt
root@FBSD:~ # ls /mnt/test.txt
/mnt/test.txt
root@FBSD:~ # umount /mnt/
root@FBSD:~ # gpart resize -i 4 -s 1g ada0
ada0p4 resize
root@FBSD:~ # gpart show -p
=> 40 20971440 ada0 GPT (10G)
40 532480 ada0p1 efi (260M)
532520 2008 - free - (1.0M)
534528 4194304 ada0p2 freebsd-swap (2.0G)
4728832 7854040 ada0p3 freebsd-zfs (3.7G)
12582872 2097152 ada0p4 ms-basic-data (1.0G)
14680024 6291456 - free - (3.0G)
root@FBSD:~ # ntfs-3g /dev/ada0p4 /mnt/
Failed to read last sector (4194302): Invalid argument
HINTS: Either the volume is a RAID/LDM but it wasn't setup yet,
or it was not setup correctly (e.g. by not using mdadm --build ...),
or a wrong device is tried to be mounted,
or the partition table is corrupt (partition is smaller than NTFS),
or the NTFS boot sector is corrupt (NTFS size is not valid).
Failed to mount '/dev/ada0p4': Invalid argument
The device '/dev/ada0p4' doesn't seem to have a valid NTFS.
Maybe the wrong device is used? Or the whole disk instead of a
partition (e.g. /dev/sda, not /dev/sda1)? Or the other way around?