View Single Post
  #1   (View Single Post)  
Old 19th June 2022
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 4,128
Default Partition size calculator

For easy replication the OpenBSD disklabel program and the OpenBSD installer can use a file that specifies the size of the partitions or labels.
From disklabel(8):
Code:
     A template for the automatic allocation can be passed to disklabel using
     the -T option.  The template consists of one line per partition, with
     each line giving mount point, min-max size range, and percentage of disk,
     space-separated.  Max can be unlimited by specifying '*'.  If only mount
     point and min size are given, the partition is created with that exact
     size.

           /               250M
           swap            80M-256M 10%
           /tmp            120M-4G 8%
           /var            80M-4G  13%
           /usr            1.5G-3G 5%
           /usr/X11R6      512M-1G 3%
           /usr/local      2G-10G  10%
           /usr/src        1G-2G   2%
           /usr/obj        1.3G-2G 4%
           /home           1G-*    45%
I always use the second simpler variant by specifying only the minimum size.
Please note that for using the template for OpenBSD you need to specify the last entry with something like '1G-*'.
Using only '*' will not work!

To pre-calculate or optimize the partition sizes I wrote a Perl script that reads this format and shows you the cumulative and remaining free space and what it left over for the last partition.

Example of a partition size template and then running the script:

Code:
$ cat cloud20gb.txt
/               256M
swap            256M
/tmp            512M
/usr            3G
/usr/local      4G
/var            1G
/home           1M-*

$ ./partition_calc 20G cloud20gb.txt

Disk size: 20480
File system              Size      Cumulative       Remaining
=============================================================
 /                       256M           256 M         20224 M
 swap                    256M           512 M         19968 M
 /tmp                    512M          1024 M         19456 M
 /usr                      3G          4096 M         16384 M
 /usr/local                4G          8192 M         12288 M
 /var                      1G          9216 M         11264 M
 /home                 11264M         20480 M             0 M
For a cloud webserver with more partitions at Hetzner :
Code:
$ cat template2.txt
/               256M
swap            256M
/tmp            512M
/usr            3G
/usr/local      3G
/home           2G
/var            64M
/var/mail       128M
/var/log        64M
/var/mysql      3G
/var/www/logs   64M
/var/www        1M-*

$ ./partition_calc 19532M template2.txt

Disk size: 19532
File system              Size      Cumulative       Remaining
=============================================================
 /                       256M           256 M         19276 M
 swap                    256M           512 M         19020 M
 /tmp                    512M          1024 M         18508 M
 /usr                      3G          4096 M         15436 M
 /usr/local                3G          7168 M         12364 M
 /home                     2G          9216 M         10316 M
 /var                     64M          9280 M         10252 M
 /var/mail               128M          9408 M         10124 M
 /var/log                 64M          9472 M         10060 M
 /var/mysql                3G         12544 M          6988 M
 /var/www/logs            64M         12608 M          6924 M
 /var/www               6924M         19532 M             0 M
You will get a short help message if you don't specify two parameters:
Code:
i$ ./partition_calc

./partition_calc - Please specify disk size in megabyte or gigabyte
followed by the file name

For example for a 16 GB disk and a template 'disk-layout'
     ./partition_calc 16G disk-layout

For a disk of 20536 MB  and the template 'cloud-disklabel.txt
     ./partition_calc 20536M  cloud-disklabel.txt
When the sum of your partition sizes exceeds the disk size you will get this:
Code:
$ ./partition_calc 10G template2.txt

Disk size: 10240
File system              Size      Cumulative       Remaining
=============================================================
 /                       256M           256 M          9984 M
 swap                    256M           512 M          9728 M
 /tmp                    512M          1024 M          9216 M
 /usr                      3G          4096 M          6144 M
 /usr/local                3G          7168 M          3072 M
 /home                     2G          9216 M          1024 M
 /var                     64M          9280 M           960 M
 /var/mail               128M          9408 M           832 M
 /var/log                 64M          9472 M           768 M
 /var/mysql                3G         12544 M         -2304 M
 /var/www/logs            64M         12608 M         -2368 M
 /var/www              -2368M         10240 M             0 M
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump
Reply With Quote