Adding more storage to Google Cloud Platform is easy!
On Google Cloud Platform, by default Linux instances do not have a swap file configured. Since these are production instances, I can’t always be worried about running out of RAM, so I like to add a little swap space.
In this example, I have added a new disk to the instance, used for swap.
fdisk -l – shows all disks in system
find your newly added disk in the list, it’s probably /dev/sdb if you added a new disk.
sudo fdisk /dev/sdb – as root, open fdisk by specifying disk.
n – add new partition to disk
p – make it primary
enter – use defaults for starting sector to use the whole disk
enter – use defaults for ending sector to use the whole disk
w – write the partition table to disk.
Once the partition table is written, we need to create the filesystem.
mkfs.xfs /dev/sdb1 – this command creates an XFS file system, on the specified partition
/dev/sdb1 and only takes a second to complete.
Once the file system is written we need to mount the disk.
I like to use disk UUID’s instead of device numbers, as they wont change between reboots. To find the UUID of the disk you are looking for, you can use
ls -l /dev/disk/by-uuid
once you find the UUID of the disk you would like to mount, edit
/etc/fstab and add a like like below:
UUID=cb7baf8f-df6d-45b3-aa5e-8f7fe1a25ba1 /mnt/storage/ xfs defaults 0 0
and try and mount it.
if successful, you should be able to access
/mnt/storage and write to it as the root user. To change permission, you need to use
chown but that is a different writeup all together.
chown -R username:groupname /mnt/storage
confirming the mount:
issue the following command to see if it’s mounted:
mount – command will show you mounted filesystems, you should see your mount in the list of mounts.
/dev/sdb1 on /mnt/storage type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
Adding swap to Centos 7 instances:
create swap file:
dd if=/dev/zero of=/path/to/swap.file bs=1M count=4096
take careful note to make sure you use the right partition number or file for this, using the incorrect system will break your system. They don’t call it disk destroyer (dd) for nothing!
make it a swap file:
fstab swap entry, to enable swap on boot.
/path/to/swap.file swap swap 0 0
swapon -a – enable swap
swapon -s – check swap space on system.
This should do it, leave a comment with any questions you might have!