5

I have a 5TB HD and I want to shrink it to 2TB.

I use Google Compute Engine PaaS.

How can I do that?

Can you suggest any tools to perform this manually if this cannot be solved by Google's tools?

Eran Betzalel
  • 347
  • 1
  • 3
  • 10
  • I have this issue as well. I resize2fs the disk to a smaller one but still if I try to clone the disk using a snapshot. I can only create a disk of the original size (or bigger). – RanP Apr 21 '16 at 10:21
  • @RanP was the File System accessible after doing the resize2fs? – George Apr 27 '16 at 19:18
  • Did you try taking a snapshot of the disk, create a disk from that snapshot, attach it to an instance as secondary disk and shrink it. Than use DD to create a new .raw disk, upload it to GCS and create an image from it. Maybe it's worth a try? keep in mind that uploading 2 TB to GCS has charges. https://cloud.google.com/storage/pricing – George May 04 '16 at 13:36
  • I tried dd, It only works if the disks are the same. – RanP May 04 '16 at 13:39

1 Answers1

6

If the disk is not a boot disk you can do the following:

  1. add a new disk with the required size and format it.
  2. mount the new disk
  3. cp -r --preserve=all /mnt/disk1/. /mnt/disk2/
  4. edit the /etc/fstab to mount the new disk instead the old one

If you have standard disk and you want to shorten the cp time. You can first create new ssd disk from snapshot and copy it to 2T ssd disk. Then make a snapshot from the 2T disk and create a new 2T standard disk.

If your disk is a boot disk, you can use a tool like fsarchiver:

  1. Create an archive from the boot disk. fsarchiver savefs /mnt/backup/boot_disk.fsa /dev/sda
  2. Restore the archive on the new disk fsarchiver restfs /mnt/backup/boot_disk.fsa id=0,dest=/dev/sdb
RanP
  • 176
  • 3
  • I spent few days trying fsarchiver tool as instructed to create smaller disk and instance template, but the instances created with this as rootdisk did not start without giving any info in console. So this does not seem to be working. – JaakL Jan 31 '17 at 19:21
  • Did you tried creating instance first (before the template) and then generate an image from the disk (after the shrinking)? – RanP Feb 01 '17 at 08:14
  • I tried instance from template and from disk, both were unbootable. – JaakL Feb 07 '17 at 09:12
  • Can you connect the new disk from the fsarchiver restfs to a working instance as a data disk, and check that the disk is not corrupted? – RanP Feb 08 '17 at 11:38
  • I gave up, the machines seemed unfortunately to be too slow in terms of postgres query response time performance (probably limited io) for my workload compared to some other cloud, even with big empheral ssds. – JaakL Feb 27 '17 at 09:27
  • In google cloud you get IOPS by the size of the disk. What is the size of disk you used, and what machine type? – RanP Feb 27 '17 at 13:26
  • One thing I noticed when going through this is that by default the boot partition on GCP is `/dev/sda1` while these instructions specify `/dev/sda` - I'm trying it out as we speak to see if `/dev/sda` works. As far as performance goes, @RanP is right, you have to use a large disk and specify SSD, then you will get good performance. – ckm Mar 02 '17 at 19:18