Migrate GCP VM to another network

Here are the steps how to migrate a GCP VM from one network to another. It involves recreating the instance in that network.

  1. Find the VM. Click the ‘Create Similar’ button.
  2. Select the new network. Save Network. Everything else should stay the same.
  3. Don’t click Create, but get the ‘Create Similar’ command line script only. Click Cancel after.
  4. Make sure to edit the hostname. GCP appends a ‘-1’ at the end of hostname.
  5. Edit VM to keep all disks. Delete VM. Make sure to preserve boot drive.
  6. Run the ‘Create Similar’ command line script you capture to create new VM in the new network.
  7. The new VM will be based on golden image.
  8. Stop VM. Swap new disks with old disks.
  9. Start VM.
  10. Done.

AWS Instance Type to M5 or C5

If you have changed instance type to either C5 or M5 and it no longer boots, it’s due to the following reasons.

  1. The Elastic Network Adapter (ENA) enaSupport attribute is disabled for the instance.
  2. The ENA module isn’t installed on the instance
  3. The NVMe module isn’t installed on the instance, or, if installed, the NVMe module isn’t loaded in the initramfs image of the instance.
  4. You are trying to mount the file systems at boot time in the “/etc/fstab” file using a device name.¬†Amazon Elastic Block Store (Amazon EBS) volumes are exposed as NVMe devices to these instance types, and the device names are changed. To avoid this, mount the file systems using UUID/Label. For more information, see¬†Amazon EBS and NVMe.

You will need to run a Bash script to update the current instance to be able to support a C5 or M5 instance.

AWS EC2 Enable Secondary IPs

Here’s how to enable secondary private IPs for AWS EC2 instances.

  1. Add secondary private IPs to the instance.
    • Editing the instance Networking > Manage IP Addresses.
    • Add new private IP addresses.
    • Save.
  2. Set the route configuration for each secondary IP address.
    • Config files are ifcfg-eth0:0, ifcfg-eth:0.1 and so on.
    • Test each interface or IP to see if they respond to ping.
    • /etc/sysconfig/network-scripts/

ifcfg-eth0:0

NM_CONTROLLED="no"
DEVICE="eth0:0"
ONBOOT="yes"
BOOTPROTO="static"
IPADDR="10.0.0.14"
NETMASK="255.255.255.255"

ifcfg-eth0:1

NM_CONTROLLED="no"
DEVICE="eth0:1"
ONBOOT="yes"
BOOTPROTO="static"
IPADDR="10.0.0.15"
NETMASK="255.255.255.255"

GCP Change VPC of Instance

The following are steps on how to change the network of an instance from one VPC to another. This is assuming you want to keep the same server name, but will need to make a network change. Unfortunately, changing networks will require creating a new instance. The following are the steps to make that change.

  1. Keep track of all the disks.
  2. Keep all disks including boot.
  3. Stop the instance.
  4. Create an image of the boot drive. Wait for it to complete.
  5. Create a similar instance, but do not execute.
  6. Make the network changes. Save the GCloud CLI command.
  7. Delete the instance.
  8. Run the saved command from step 4. This creates a new instance.
  9. Stop the instance.
  10. Detach the boot disk.
  11. Attach all the other disks.
  12. Boot the instance.

Resolv.conf

Resolv.conf is a computer file used by various operating systems as a DNS resolver. The file is in plain text. It’s usually generated by the system administrator or a network program. The file is located in the /etc/ directory and contains the search domain as well a list of nameservers.

Here’s an example of the /etc/resolv.conf file.

search domain.com local.lan
nameserver 1.1.1.1
nameserver 8.8.8.8
nameserver 9.9.9.9

If you have problems resolving domain names, check this file first.