DaemonForums  

Go Back   DaemonForums > Miscellaneous > Guides

Guides All Guides and HOWTO's.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 19th June 2022
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 3,975
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
  #2   (View Single Post)  
Old 19th June 2022
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 3,975
Default

The script:
Code:
#!/usr/bin/perl -w
# J65nko - daemonforums.org
# ISC license

use strict;

my $nr_of_param = $#ARGV + 1;
if ($nr_of_param != 2) {
    print <<"END"; 
$0 - 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' 
     $0 16G disk-layout

For a disk of 20536 MB  and the template 'cloud-disklabel.txt
     $0 20536M  cloud-disklabel.txt
END
    exit;
}

#my $disk_size = shift; 
my $disk_size = shift @ARGV; 

my $fs;
my $size;
my $running_total = 0;
my $remain_size;

$disk_size = ($1 * 1024) if $disk_size  =~ /(\d+)G/ ;
$disk_size =  $1         if $disk_size  =~ /(\d+)M/ ;

# print header line
# Disk size: 16384
# File system              Size      Cumulative       Remaining
# =============================================================
#
print "\nDisk size: $disk_size";
printf "\n%-20s","File system";
printf " %8s", "Size";
printf " %15s", 'Cumulative';
printf " %16s", "Remaining\n";
print "=" x 61;

while (<ARGV>) {
   chomp;               # remove newline
   /^(\S+)\s+(\S+)/;    # retrieve non-whitespace columns in $1 and $2
   $fs=$1;
   $size=$2;

   $running_total += $1 if $size =~ /(\d+)M(?!-\*)/ ; 
   $running_total += ($1 * 1024) if $size =~ /(\d+)G(?!-\*)/ ; 

   if ($size =~ /-\*/) {        # last entry 1M-*
       $running_total += $remain_size;
       $size = $remain_size . "M";
   }  

   $remain_size = ($disk_size - $running_total);

   printf "\n %-20s", $fs;
   printf "%8s", $size;
   printf "  %12s M" ,$running_total;  
   printf "  %12s M",$remain_size;
}  

print "\n";
# --- end of program
__________________
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
  #3   (View Single Post)  
Old 19th June 2022
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 3,975
Default

Attached is a tarball containing the script as well as the two example templates:
Code:
$ tar tvzf PartitionCalc.tgz             
-rw-r--r--  1 adriaan  adriaan        141 Jun 19 03:55 cloud20gb.txt
-rw-r--r--  1 adriaan  adriaan        235 Jun 19 01:57 template2.txt
-rwxr--r--  1 adriaan  adriaan       1589 Jun 19 04:30 partition_calc
To extract:
Code:
$ tar xvzf PartitionCalc.tgz
Attached Files
File Type: tgz PartitionCalc.tgz (1.0 KB, 3 views)
__________________
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
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
More QEMU ram and cpu size PapaParrot OpenBSD Packages and Ports 6 7th August 2018 04:05 AM
Simple human front-end for 'bc(1)', the unlimited precision calculator J65nko Guides 1 2nd February 2013 06:50 PM
Negative partition size? giga FreeBSD General 1 2nd January 2009 09:02 PM
freebsd 7 installation partition size for 250gb harddrive ijk FreeBSD Installation and Upgrading 17 20th October 2008 07:50 PM
RPN Calculator?? DrJ FreeBSD General 7 30th May 2008 01:16 AM


All times are GMT. The time now is 04:15 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2022, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick