Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mount persistent disk to /home in Google Cloud Platform

Is there a way to mount a persistent disk to /home directory?

I've followed instructions from GCP (https://cloud.google.com/compute/docs/disks/add-persistent-disk) that allows me to mount the disk to /home directory initially. Then after I copied all the files from original home directory to the mounted /home, restart instance, I can no longer access the server using browser ssh tool anymore. I've tried: 1. Mount the disk directly to /home 2. Mount the disk else where and create a soft link link to it

I can create files and folders and everything works just fine in the newly mounted /home before I power off the instance. Once the instance is off and back online, I wont be able to ssh to it anymore with the message - "Unable to Connect, Retrying (2/3)..."

Has anyone with luck to mount a disk to /home successfully? Any help is appreciated.

like image 993
ridea.com.tw Avatar asked Nov 08 '22 16:11

ridea.com.tw


1 Answers

Try first mounting the disk to /mnt, then copy your files from /home to /mnt:

sudo mount /dev/sdb1 /mnt
sudo rsync -avHAX /home/ /mnt/

If everything got copied correctly, then you can delete the folders in /home:

sudo rm -rf /home/*

Then, unmount the disk from /mnt and mount it to /home:

sudo umount /mnt
sudo mount /dev/sdb1 /home

(assuming /dev/sdb1 is the partition you're trying to mount)

Configure /etc/fstab so that the /home partition will mount properly on boot. See for example https://www.tecmint.com/move-home-directory-to-new-partition-disk-in-linux/

like image 110
axiomatic Avatar answered Nov 15 '22 07:11

axiomatic