Page MenuHomeMiraheze

Shrink db4's swap partition and reclaim space in root partition
Open, NormalPublic

Description

db4 is a server with a 400GB SSD. Today I realised we're using 16GB(!) for swap:

Device     Boot     Start       End   Sectors  Size Id Type
/dev/vda1  *         2048 805306367 805304320  384G 83 Linux
/dev/vda2       805308414 838858751  33550338   16G  5 Extended
/dev/vda5       805308416 838858751  33550336   16G 82 Linux swap / Solaris

With about 3GB RAM free while using zero swap, it seems clear to me 16GB of swap is excessive. However, living without swap is absolutely too risky so we actually do want some swap: 4 or 6GB is fine with me and gives us more usable space for MariaDB.

In theory, these commands should work for us:
[disable swap using swapoff -a]

root@db4:~# fdisk /dev/vda
Command (m for help): d
Partition number (1,2,5, default 5): 1

Partition 1 has been deleted.

Command (m for help): d
Partition number (2,5, default 5): 2

Partition 2 has been deleted.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-838860799, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-838860799, default 838860799): +394G

Created a new partition 1 of type 'Linux' and of size 394 GiB.
Partition #1 contains a ext4 signature.

Do you want to remove the signature? [Y]es/[N]o: n

Command (m for help): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2): 2
First sector (826279936-838860799, default 826279936):
Last sector, +sectors or +size{K,M,G,T,P} (826279936-838860799, default 838860799):

Created a new partition 2 of type 'Linux' and of size 6 GiB.

Command (m for help): t
Partition number (1,2, default 2): 2
Partition type (type L to list all types): 82

Changed type of partition 'Linux' to 'Linux swap / Solaris'.

Command (m for help): p
Disk /dev/vda: 400 GiB, 429496729600 bytes, 838860800 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x94b6b1d0

Device     Boot     Start       End   Sectors  Size Id Type
/dev/vda1            2048 826279935 826277888  394G 83 Linux
/dev/vda2       826279936 838860799  12580864    6G 82 Linux swap / Solaris

When done, write changes to the actual disk using the 'w' command, reload the partition table (partprobe) and add the swap partition.

db4 is a production server and this operation does pose a serious risk to data integrity, thus should be performed with utmost care. I'd like a second pair of eyes (ping Operations) for this one and a maintenance window seems like a great idea.

Event Timeline

Southparkfan triaged this task as Normal priority.Mar 3 2019, 22:35
Southparkfan created this task.

@John mind reviewing/commenting on this?

@John mind reviewing/commenting on this?

Could you review this @John?

John added a comment.Aug 1 2019, 18:06

Seems fine but I strongly discourage things like this.