• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Archives

swap

Create A Swap File

February 16, 2021

How to create a swap file.

A 2GB swap file.

dd if=/dev/zero of=/swapfile bs=1k count=2048k

dd if=/dev/zero of=/swapfile bs=1k count=2048k

Activate.

mkswap /swapfile
chmod 0600 /swapfile
systemctl daemon-reload
swapon /swapfile

mkswap /swapfile chmod 0600 /swapfile systemctl daemon-reload swapon /swapfile

To make swap permanent, add to /etc/fstab.

/swapfile  swap   swap    defaults   0 0

/swapfile swap swap defaults 0 0

Check if swap is working.

cat /proc/swaps
free -h

cat /proc/swaps free -h

Filed Under: Linux Tagged With: activate, create, file, swap

Create Swap Disk

March 28, 2020

To see which disk is available for swap disk use.

lsblk
blkid
df -Th

lsblk blkid df -Th

Format the disk.

fdisk /dev/xvda

fdisk /dev/xvda

Create a swap disk.

sudo mkswap -f /dev/xvda
sudo swapon -s /dev/xvda
# or
sudo swapon /dev/xvda

sudo mkswap -f /dev/xvda sudo swapon -s /dev/xvda # or sudo swapon /dev/xvda

Check if swap disk is available.

lsblk
free -h 
cat /proc/swaps
cat /proc/meminfo
swapon -s
top
vmstat
vmstat 1 5

lsblk free -h cat /proc/swaps cat /proc/meminfo swapon -s top vmstat vmstat 1 5

Filed Under: Linux Tagged With: create, redhat, swap, xfs

VM Stats

January 13, 2020

To check VM stats, use the following commands.

To see used and unused memory, swap space.

free

free

To see RAM details.

sudo dmidecode -t 17

sudo dmidecode -t 17

To see number of processors.

nproc

nproc

To see CPU details.

lscpu

lscpu

Filed Under: Cloud, Linux Tagged With: cpu, free, gcp, memory, processors, stats, swap

Migrate GCP VM to another network

September 10, 2019

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.

Filed Under: Cloud Tagged With: create similar, gcp, migrate, move, network, new, swap, vm

  • Home
  • About
  • Archives

Copyright © 2023