Partitioning script for rescue mode (disk size calculation)

Hello!

I need to write partitioning script wich would work in rescue mode. It will prepare partitions and unpack linux on it. However I need to calculate whole size of the disk and create:

/dev/sda1 --> One big partition (minus (2size of memory) for swap)
/dev/sda2 --> Swap partition (2
size of memory)

I know how to later do this using fdisk or sfdisk but how to get for example (disk size - (2*memory size)) the best would be in megabytes

free -m can give me memory size but

sfdisk -s gives disk size in blocks :frowning:

fdisk -l give size (very nice) in GB
Disk /dev/sda: 750.1 GB, 750156374016 bytes

I'm confused how to calculate this properly. Can you help me??

Thank you in advance!

Hello!

I found some script on other forum and rebuilt it.
It works

#!/bin/bash

DSIZE=`fdisk -l /dev/sda | grep "Disk /dev/sda" | cut -f 3 -d " " | awk -F "." {'print $1'}`
SWAPSIZE=4;
DATASIZE=$[$DSIZE-$SWAPSIZE];
echo "Disk size:               $DSIZE GB";
echo "Size for data partition: $DATASIZE GB";
echo "Size for swap partition: $SWAPSIZE GB";