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?
Server Fault is a question and answer site for system and network administrators. It only takes a minute to sign up.
Sign up to join this communityI 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?
If the disk is not a boot disk you can do the following:
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:
fsarchiver savefs /mnt/backup/boot_disk.fsa /dev/sda
fsarchiver restfs /mnt/backup/boot_disk.fsa id=0,dest=/dev/sdb
My answer is very specific to Centos 7 instances on Google's Compute Engine platform. Some information could probably be used out of this for other OS types, but that is beyond my experience.
My use case was shrinking a 400G root device attached to a legacy Centos7 instance back down to 20G. Unfortunately, the root device had just 1 partition (no efi partition), so when I tried fsarchiver
, it failed with an error about not able to mount /dev/sdb1 as vfat
(sdb1
was the XFS
root partition of my target instance, mounted on a shrinker instance).
The process that finally worked for me is as below:
target-1
(this will have the shrunk disk)shrinker-1
(all command prompt actions happen here, running as root
).target-1
and edit it to detach it's root disk (usually named the same as the instance name, BUT lets say 'target-1-root').target-1-root
as an extra disk to shrinker-1
. This becomes /dev/sdb
.target-1-newroot
. - this becomes /dev/sdc
target-1-newroot
similar to target-1-root
(MBR or GPT, can be seen via fsdisk -l /dev/sdb
, and created using fdisk /dev/sdc
)target-1-newroot
(using fdisk) and format it to match target-1-root
(xfs for me) using mkfs.xfs /dev/sdc1
(or similar mkfs.$FSTYPE
)mkdir -p /media/old /media/new
mount /dev/sdc1 /media/old
(target-1-root
)mount /dev/sdb1 /media/new
(target-1-newroot
)rsync -a /media/old/ /media/new/
target-1-newroot
:
fdisk -l /dev/sdc
- this was 2048 for me:
Disk /dev/sdc: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: dos
Disk identifier: 0x0009c1de
Device Boot Start End Blocks Id System
/dev/sdc1 2048 41943039 20970496 83 Linux
dd if=/dev/sdb of=/dev/sdc bs=512 count=2048
- this is information taken from fdisk -l
above.fdisk /dev/sdc
(fdisk has inline help, use it)
lsblk -o name,uuid
) and update it as required:
/media/new/etc/fstab
/media/new/boot/grub2/grub.cfg
umount /media/new
target-1-newroot
from shrinker-1
target-1
and attach target-1-newroot
as root device. Also enable the serial console to troubleshoot boot failures if any.target-1
, login and check that things are as expected.Lastly but no the least, consider sending me a RasPi CM4-${ANY_MMC}-2GB-Wifi
using the savings :laugh: .