Categories
GCP Technology

Shrinking GCP Drives

I use Google Cloud Platform on a daily basis. It’s great in a bunch of ways, but the hard disk space is pretty expensive.

Google gives you recommendations on if you are using too much CPU or RAM resources, but if you have too much hard disk space.

It’s super easy to expand the hard disk, but shrinking a disk, especially a boot disk is another story.

Many sites incorrectly state you can use the same method that you use to expand, to shrink, but I don’t reckon they’ve ever done it, as the documentation clearly states that you can’t.

For me, I had a 1TB drive and was only consistently using 300GB, so a 400GB drive would suffice, this a saving of approximately $200 AUD a month. Definitely worth the resize for me.

So how can it be done?

Basically, you need to add another, smaller drive then copy everything from the source drive to this new drive.

You can use DD or Rsync, but these are tricky if you are trying to shrink the boot disk.

In comes Weresync. Weresync is a tool which takes care of the copy for you and even copies the partition tables and boot loader.

The only catch I found is that it uses Python3, which isn’t default on a bunch of operating systems, but once you have Python3 handy, then it’s easy to install.

  1. Make a Snapshot of your server instance. Just in case you screw something up.
  2. Install Python3 for your platform. There are a bunch of sites on this info. You might even be lucky and have it.
  3. Create your new drive in GCP and attach it to the instance. Basically edit the instance and select the new drive option. This is done in the GCP console.
  4. Format the new drive #mkfs.ext4 -m 0 -F -E lazy_itable_init=0,lazy_journal_init=0,discard /dev/[DEVICE_ID] The new [DEVICE_ID] is most likely /dev/sdb if you only had one drive, you can use lsblk to see what drives you have.
  5. Install weresync #pip install weresync
  6. Run the weresync daemon (this has to run in the background for weresync to work).weresync-daemon & >/dev/null 2>&1
  7. Start up weresync to copy your data #weresync -C -L grub2 -g 1 /dev/sda /dev/sdb
  8. Disconnect your new drive from the instance.
  9. Either switch boot disks to the new drive on your existing instance, or create a new instance with the new drive as the boot disk, then switch the IP addresses, if all is good 🙂

Weresync documentation: https://weresync.readthedocs.io/en/master/

Categories
Personal

Why a personal blog?

I decided to create a personal blog, as often there are things I’d like to communicate which I don’t want post within the echo chamber of social media, or using my business site, as they are irrelevant to my business.

I’m a father of three of my own kids and one from a previous relationship. I’m a web developer and systems administrator of around 20 years, who has had experience working with hundreds of companies to assist them with their online needs. I’m also a certified yoga teacher and regular yoga practitioner.

I guess what you’ll get is my ramblings on any of the above. I don’t really care what people think of this, but hopefully something is helpful to someone.