# Can I add a partition without adding the disk?



## freezr (Jan 16, 2022)

Hi Folks,

this is totally my fault, I designed bad by partition layout, hence I had to recover space to create a swap a partition from the where is installed Linux.

The point is I first read this:


> 12.12.1. Swap on a New Hard Drive or Existing Partition​Adding a new hard drive for swap gives better performance than using a partition on an existing drive. Setting up partitions and hard drives is explained in “Adding Disks” while “Designing the Partition Layout” discusses partition layouts and swap partition size considerations.
> Use swapon to add a swap partition to the system. For example:
> 
> ```
> ...


I check my disk:


```
$ gpart show ada0
=>       34  488397101  ada0  GPT  (233G)
         34       2014        - free -  (1.0M)
       2048    1951744     1  efi  (953M)
    1953792       2048        - free -  (1.0M)
    1955840    1953792     3  linux-data  (954M)
    3909632       2048     2  linux-data  (1.0M)
    3911680  471900160     4  linux-data  (225G)
  475811840       2048        - free -  (1.0M)
  475813888   12582912     5  ms-basic-data  (6.0G)
  488396800        335        - free -  (168K)
```

And I tried:


```
swapon ada0p5
```

But it didn't work out:


```
$ gpart show ada0
=>       34  488397101  ada0  GPT  (233G)
  475811840       2048        - free -  (1.0M)
  475813888   12582912     5  ms-basic-data  (6.0G)
  488396800        335        - free -  (168K)
```

Still get the Fat32 partition, hence I looked into:
18.2. Adding Disks​And it is described in there a method to add a disk while I actually need only `ada0p5`


```
# gpart create -s GPT ada1
# gpart add -t freebsd-ufs -a 1M ada1
```

But I need to add only the partition not the whole disk.
Always in the same paragraph is shown this:


```
# newfs -U /dev/ada0p5
```

I may use this command instead to format the partition as swap, but I am not very confident since the documentation doesn't consider a scenario with multiple filesystems and multiple OSes.

Thanks!


----------



## covacat (Jan 16, 2022)

you don't newfs a swap partition
just change it's type to freebsd-swap


----------



## mark_j (Jan 16, 2022)

Swap partitions aren't formatted.


----------



## Lamia (Jan 16, 2022)

You could also have deleted and recreate the partition with type freebsd-swap.


----------



## Logicien (Jan 19, 2022)

A swap partition performance is linked to the disk access in general. If the system is installed on one drive with a swap partition the swap access will be slower than if this swap partition is alone on an other drive. Simultanious access to one drive cannot be done synchroniously but two simultanious access to two different drives can be done synchroniously.

An interesting thing is two know the performances of a swap partition versus a swap file. I tend to put my home partition on a different drive than the system to allow synchronious access on the two drives when they are of the same quality performances. On a desktop installation the home directory have a lot of access on so, it can be on the best drive as a partition.

More Ram you have less you swap and it's good.


----------



## Erichans (Jan 19, 2022)

FreeBSD uses camcontrol(8), geom(8) and gpart(8) to control various aspects of your disks for o.a. others the type of a partition such as _freebsd-swap_. sysutils/lsblk uses these commands to present a useful overview. Alternatively you could opt to get the latest version from github-lsblk; then you do not have it under package control but, it's only one shell script file. 

More information from the developer: List Block Devices on FreeBSD lsblk(8) Style


----------



## freezr (Jan 19, 2022)

As I suspected FreeBSD was unable to recognize the fat32 partition hence I had to create the swap manually.

Deleting the Fat32 partition:

```
$ doas swapoff /dev/ada0p5
$ doas gpart delete -i 5 ada0
ada0p5 deleted
$ gpart show ada0
=>       34  488397101  ada0  GPT  (233G)
         34       2014        - free -  (1.0M)
       2048    1951744     1  efi  (953M)
    1953792       2048        - free -  (1.0M)
    1955840    1953792     3  linux-data  (954M)
    3909632       2048     2  linux-data  (1.0M)
    3911680  471900160     4  linux-data  (225G)
  475811840   12585295        - free -  (6.0G)
```

Creating the swap partition:

```
$ doas gpart add -t freebsd-swap -a 4k ada0
ada0p5 added
$ gpart show ada0
=>       34  488397101  ada0  GPT  (233G)
         34       2014        - free -  (1.0M)
       2048    1951744     1  efi  (953M)
    1953792       2048        - free -  (1.0M)
    1955840    1953792     3  linux-data  (954M)
    3909632       2048     2  linux-data  (1.0M)
    3911680  471900160     4  linux-data  (225G)
  475811840   12585288     5  freebsd-swap  (6.0G)
  488397128          7        - free -  (3.5K)
```

The swap is working:

```
$ swapinfo
Device          1K-blocks     Used    Avail Capacity
/dev/ada0p5       6292644        0  6292644     0%
```

My question now is how can I add 1M of freespace before the Swap partition?

Thanks!

tgl


----------



## covacat (Jan 19, 2022)

delete it and add it again with -b start


----------



## freezr (Jan 21, 2022)

covacat said:


> delete it and add it again with -b start



I understood that you want help me but given my knowledge this really creates more confusion in my mind...


----------



## covacat (Jan 21, 2022)

when you add a partition its created at the end of the previous one
if you want to leave some space before it you have to specify -b start (starting sector)
i did not see any way to change it's starting position once created


----------



## freezr (Jan 21, 2022)

I got it, but how could I determine which sector it should be? I don't think I am going to be able to achieve that.
The only method I can figuring out is to create a 1M partition UFS and than adding the SWAP and lastly delete the 1M partition.


----------



## covacat (Jan 22, 2022)

look at gpart show above
now it starts at 475811840
add 2048 to that


----------



## rawthey (Jan 22, 2022)

tgl said:


> The swap is working:
> 
> ```
> $ swapinfo
> ...


Just wondering why you should need 1M free space between the preceding partition and the swap partition?


----------



## mark_j (Jan 24, 2022)

Perhaps to get the partition on a boundary; so called alignment?


----------



## freezr (Jan 24, 2022)

It is also cleaner and help to separate and distinguish better the partitions.


----------



## rawthey (Jan 24, 2022)

mark_j said:


> Perhaps to get the partition on a boundary; so called alignment?


That would only move the partition down by 1MB. If it wasn't already on a 1MB boundary it still wouldn't be. But in this case the partition starts at sector 475811840 which is a multiple of 2048 and on a iMB boundary.


----------

