SOLVED Deleting swap partition (Is it safe to do this )

NASbox

Guru
Joined
May 8, 2012
Messages
650
I am used to working with partitions in Linux/EXT4 where this would be no problem, but I know under FreeBSD/ZFS things can be a bit different so I wanted to check. Hopefully one of the FreeBSD gurus here let me know if this is OK or not.

I want to remove the swap partitions from a pool, but I don't want to lose the data and/or have to recreate the pool.
(In another thread not having a swap partition was recommended as the best way to permanently control swap.)

Is the following procedure OK, and will I be able to re-import the pool into FreeNAS afterwards?

Procedure:
  1. Export the pool from the GUI (pool was created using the GUI and currently in use)
  2. gpart delete -i 1 ada0
  3. gpart delete -i 1 ada1
  4. Import the pool using the GUI (Free space at beginning of drives is now just over 2G)
Disk geometry shown below:
(This pool is very old and was created under v8.x and has been upgraded over the years which is why it looks a bit different than pools created today, but the sway is still the first partition and 2.0G)
Code:
#>zpool status SCRATCH

#>gpart show -l  ada0
=>        34  7814037101  ada0  GPT  (3.6T)
          34          94        - free -  (47K)
         128     4194304     1  (null)  (2.0G)
     4194432  7809842696     2  (null)  (3.6T)
  7814037128           7        - free -  (3.5K)

#>gpart show -l  ada1
=>        34  7814037101  ada1  GPT  (3.6T)
          34          94        - free -  (47K)
         128     4194304     1  (null)  (2.0G)
     4194432  7809842696     2  (null)  (3.6T)
  7814037128           7        - free -  (3.5K)

  pool: SCRATCH
state: ONLINE
  scan: scrub repaired 0 in 0 days 15:54:54 with 0 errors on Thu Jan  3 22:14:11 2019
config:

        NAME                                            STATE     READ WRITE CKSUM
        SCRATCH                                         ONLINE       0     0     0
          mirror-0                                      ONLINE       0     0     0
            gptid/eb2ee48c-a398-11e2-bc5c-c860006d863b  ONLINE       0     0     0
            gptid/ec0615be-a398-11e2-bc5c-c860006d863b  ONLINE       0     0     0
 

toadman

Guru
Joined
Jun 4, 2013
Messages
619
Pretty sure the pool will import as it's attached to the p2 partitions. I recently was switching disks around in mirrors and had to blow away the active p1 partitions that were part of swap. I suffered no ill effects. (Swap runs in a file if needed. I run a post init script to set the swap space to that file.)
 

NASbox

Guru
Joined
May 8, 2012
Messages
650
Pretty sure the pool will import as it's attached to the p2 partitions. I recently was switching disks around in mirrors and had to blow away the active p1 partitions that were part of swap. I suffered no ill effects. (Swap runs in a file if needed. I run a post init script to set the swap space to that file.)

Thanks @toadman for the reply. Just wanted to confirm that I was able to successfully delete the swap partitions on the pool without damaging the data, and then successfully reimport the pool (under FreeNAS 11.1-U6).

For the benefit of anyone else who cares:
As recommended in https://forums.freenas.org/index.php?threads/limiting-the-scope-of-swap-pool.73117/ the best way to prevent a device from being used as a swap device is to make sure that it doesn't have a swap partition on it. Here are the steps to follow:

Code:
#>gmirror status

        Name    Status  Components
mirror/swap0  COMPLETE  ada1p1 (ACTIVE)
                        ada0p1 (ACTIVE)
mirror/swap1  COMPLETE  da7p1 (ACTIVE)
                        da6p1 (ACTIVE)
mirror/swap2  COMPLETE  da5p1 (ACTIVE)
                        da4p1 (ACTIVE)
mirror/swap3  COMPLETE  da3p1 (ACTIVE)
                        da2p1 (ACTIVE)
mirror/swap4  COMPLETE  da1p1 (ACTIVE)
                        da0p1 (ACTIVE)

#>gmirror stop -fv swap0
Done.

#>gmirror status

        Name    Status  Components
mirror/swap1  COMPLETE  da7p1 (ACTIVE)
                        da6p1 (ACTIVE)
mirror/swap2  COMPLETE  da5p1 (ACTIVE)
                        da4p1 (ACTIVE)
mirror/swap3  COMPLETE  da3p1 (ACTIVE)
                        da2p1 (ACTIVE)
mirror/swap4  COMPLETE  da1p1 (ACTIVE)
                        da0p1 (ACTIVE)

#>gpart show -l ada0

=>        34  7814037101  ada0  GPT  (3.6T)
          34          94        - free -  (47K)
         128     4194304     1  (null)  (2.0G)
     4194432  7809842696     2  (null)  (3.6T)
  7814037128           7        - free -  (3.5K)

#>gpart delete -i 1 ada0
ada0p1 deleted

#>gpart delete -i 1 ada1
ada1p1 deleted

#>gpart show -l ada0
=>        34  7814037101  ada0  GPT  (3.6T)
          34     4194398        - free -  (2.0G)
     4194432  7809842696     2  (null)  (3.6T)
  7814037128           7        - free -  (3.5K)

#>gpart show -l ada1
=>        34  7814037101  ada1  GPT  (3.6T)
          34     4194398        - free -  (2.0G)
     4194432  7809842696     2  (null)  (3.6T)
  7814037128           7        - free -  (3.5K)
 

toadman

Guru
Joined
Jun 4, 2013
Messages
619
Glad you got it working.

For those not comfortable with the command line, there is another way one can get rid of swap on a device. Set the swap size to 0 in the System > Advanced, then offline the drive and replace it with itself.
 

NASbox

Guru
Joined
May 8, 2012
Messages
650
Glad you got it working.

For those not comfortable with the command line, there is another way one can get rid of swap on a device. Set the swap size to 0 in the System > Advanced, then offline the drive and replace it with itself.

Hi @toadman - Follow up question for the benefit of others - is this destructive or non-destructive?
(Does that destroy the drive and resliver? If so that's fairly risky and will take a lot of time for a large/full drive.)
As long as it is executed correctly the command line method doesn't touch the data on the drive.
gpart only edits the partition table, so as long as there isn't a typo or a glitch there is no appreciable risk.
(Obviously backups are a good idea under any circumstance.)
On a multi-drive pool a bit of free space (likely 100MB should be more than enough) is a good idea to take care of differences in drives (a 6TB drive by different manufacturers can vary). If you need to replace a drive it makes sure that if the new drive is a bit smaller than the old drive it doesn't matter.
 
Top