I need to create an ext4 fs over a zpool. I wanted to use all (or almost all) available space, as shown below.
# zpool list
NAME SIZE ALLOC FREE CKPOINT EXPANDSZ FRAG CAP DEDUP HEALTH ALTROOT
nat2012 1,81T 124K 1,81T - - 0% 0% 1.00x ONLINE -
# zfs list
NAME USED AVAIL REFER MOUNTPOINT
nat2012 105K 1,76T 24K none
# zfs create -V 1.75T nat2012/backup
bad volume size '1.75T': invalid numeric suffix '.75T'
# zfs get avail nat2012
NAME PROPERTY VALUE SOURCE
nat2012 available 1,76T -
# zfs get -H avail nat2012
nat2012 available 1,76T -
My problem is that "1.75T" is not accepted as a volume size. (But it is displayed as a size.) Its value is rounded to 0.01T which is 10G. Next thing I tried is to get the available size in bytes, Mbytes or GBytes or blocks, or practically anything that tells me the exact size, and can be used with "zfs create -V". I was suprised when I saw that there is no "zfs get" option for that. According to the docs, the "-H" option should "display output in a form more easily parsed by scripts". It omitted the headers and used tabs to separate the fields, but the formatting is bad. Size is still displayed in TBytes and rounded with +/- 10G precision. Smaller issue but it is formatted using the current locale (in my case, the decimal point "." is replaced with ","). It would be an integer number in KBytes.
Please note that the "df" command cannot be used in this particular case, because nothing is mounted. I could do this to display free blocks in Kbytes:
# mkdir -p /nat2012
# zfs set mountpoint=/nat2012 nat2012
# df -k | grep nat2012
nat2012 1885339520 128 1885339392 1% /nat2012
But this would give a false result. As you can see, it is now mounted as zfs filesystem, and the dataset already uses 1% of the available space. This does not tell me the exact size that is available for creating a new ext4 volume. (The -V option is mandatory - if you don't specify it, then ext4.mkfs will not be able to format it.)
Of course, I can always do a trial, something like this:
# zfs create -V 1760G nat2012/backup
cannot create 'nat2012/backup': out of space
# zfs create -V 1755G nat2012/backup
cannot create 'nat2012/backup': out of space
# zfs create -V 1750G nat2012/backup
cannot create 'nat2012/backup': out of space
# zfs create -V 1740G nat2012/backup
# zfs destroy nat2012/backup
# zfs create -V 1745G nat2012/backup
cannot create 'nat2012/backup': out of space
# zfs create -V 1744G nat2012/backup
cannot create 'nat2012/backup': out of space
# zfs create -V 1743G nat2012/backup
At this point, I can be sure that there is at most 1G space left unused. This is very clumsy. I can live with this, but I have to do the same things for a number of drives in the future.
Is there a better way to "use all available space" for creating a fixed size volume?
0 Answers