# gpart and leave some free space at the end



## CyberCr33p (Jan 19, 2018)

I have a shell script which contains these lines:


```
gpart create -s gpt ada0
gpart add -a 4k -t freebsd-boot -s 512k ada0
gpart add -a 4k -s 4G -t freebsd-ufs ada0
gpart add -a 4k -s 16G -t freebsd-swap ada0
gpart add -a 4k -s 16G -t freebsd-ufs ada0
gpart add -a 4k -s 64G -t freebsd-ufs ada0
gpart add -a 4k -s 32G -t freebsd-ufs ada0
gpart add -a 4k -s 768G -t freebsd-ufs ada0
gpart add -a 4k -t freebsd-ufs ada0
```

I want to leave some unallocated space in the end. Any idea how to do it with an automated way?


----------



## Handsome Jack (Jan 19, 2018)

modify --->
for example, _if there is - for that last partition left - let' say_ 30GB, then, _IF You wana leave_ 10GB empty space on the end, put something like this:

```
gpart create -s gpt ada0
gpart add -a 4k -t freebsd-boot -s 512k ada0
gpart add -a 4k -s 4G -t freebsd-ufs ada0
gpart add -a 4k -s 16G -t freebsd-swap ada0
gpart add -a 4k -s 16G -t freebsd-ufs ada0
gpart add -a 4k -s 64G -t freebsd-ufs ada0
gpart add -a 4k -s 32G -t freebsd-ufs ada0
gpart add -a 4k -s 768G -t freebsd-ufs ada0
gpart add -a 4k -s 20G -t freebsd-ufs ada0
```

I did that few days ago when (although I didn't have script, but manually entered commands from shell) installed system on some other computer, and it was succesful - I got my free space for some other partitions.
- I am a newbie so recheck my words, anyway that disk is empty You can try ..


----------



## CyberCr33p (Jan 19, 2018)

The problem is I don't know how to get the free space after the creation of 768GB partition.

One idea is to use "gpart show ada1"


```
40  7814037088  ada1  GPT  (3.6T)
          40        1024     1  freebsd-boot  (512K)
        1064     8388608     2  freebsd-ufs  (4.0G)
     8389672    33554432     3  freebsd-swap  (16G)
    41944104    33554432     4  freebsd-ufs  (16G)
    75498536   134217728     5  freebsd-ufs  (64G)
   209716264    67108864     6  freebsd-ufs  (32G)
   276825128  1610612736     7  freebsd-ufs  (768G)
  1887437864  5926599264        - free -  (2.8T)
```

and parse the 2.8T and then to run:


```
gpart add -a 4k -s 2700G -t freebsd-ufs ada0
```

But this way I will waste a lot of disk space.

I try to find another way to waste only few MB.


----------



## Handsome Jack (Jan 19, 2018)

I don't know if I understand this correctly.

```
gpart add -a 4k -s 2700G -t freebsd-ufs ada0
"But this way I will waste a lot of disk space."
```
How much?
Can You adjust 2700G to 2867G, according to --> see here


----------



## CyberCr33p (Jan 19, 2018)

I am not sure how the "gpart show" 2.8TB is calculated. For example maybe it's 2.75TB. I try to find a way to see the unallocated space in KB.


----------

