Can I add a partition without adding the disk?

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:
Code:
# swapon /dev/ada1s1b
It is possible to use any partition not currently mounted, even if it already contains data. Using swapon on a partition that contains data will overwrite and destroy that data. Make sure that the partition to be added as swap is really the intended partition before running swapon.
I check my disk:

Code:
$ 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:

Code:
swapon ada0p5

But it didn't work out:

Code:
$ 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

Code:
# 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:

Code:
# 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!
 
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. 👍
 
As I suspected FreeBSD was unable to recognize the fat32 partition hence I had to create the swap manually.

Deleting the Fat32 partition:
Code:
$ 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:
Code:
$ 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:
Code:
$ 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
 
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
 
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. 🤔
 
The swap is working:
Code:
$ 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
Just wondering why you should need 1M free space between the preceding partition and the swap partition?
 
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.
 
Back
Top