Linux

Adding a New Drive

Adding a New Drive #

In this guide, we’ll add a new disk, and format it for use. This guide makes assumptions about drive lettering and paths, ensure you’re running things where you want to.


  1. Determine drive name and logical size.
fdisk -l
  1. Partition drive using fdisk
fdisk /dev/sdc

# Common commands

n – Create partition
p – print partition table
d – delete a partition
q – exit without saving the changes
w – write the changes and exit.
  1. Create Partition using whole Block Device, defaults are fine

...

Create Swap

Create Swap #

In this guide, we’ll create a swap file on CentOS.

This guide will provide steps on the quickest way to create a swap file on CentOS, should work on both CentOS 7, 8 and Stream. Before proceeding with this tutorial, check if your CentOS installation already has swap enabled by typing:

sudo swapon --show
  1. Create file
sudo dd if=/dev/zero of=/swapfile bs=1024 count=1048576
  1. Lock to root perms
sudo chmod 600 /swapfile
  1. Make Swap and enable it
sudo mkswap /swapfile
sudo swapon /swapfile
  1. Persist on boot
sudo vi /etc/fstab

/swapfile swap swap defaults 0 0
  1. Change swappiness
vi /etc/sysctl.conf 
vm.swappiness=10

Extend a Disk

Extend a Disk #

In this guide, we’ll expand existing disks, using GParted, as well as fdisk, including partition expansions.

Extending an LVM partition with GParted #

Follow guide at own risk, resizing disks comes with risk, make sure you have backups. This guide assumes paths, make sure you’re running commands agains the correct drives/paths.

  1. Grow disk in Hypervisor
  2. Use Gparted to increase logical volume size
  3. Run vgdisplay - find the “VG Name”, in my sitation it’s d0
  4. Extend the LVM volume
lvextend -l +100%FREE /dev/d0/root
  1. expand the file system, either using resize2fs or xfx_growfs if using centOS and XFS This
xfs_growfs /dev/d0/root

Or this depending on FS type

...

Htaccess

Htaccess #

I’ve collected some useful and some not so useful modifers that go in a htaccess file. These were made specifically for LiteSpeed webserver, which shares a lot of the same code so it should be mostly compatbile.

Force HTTPS #

A generic rewrite to alwasy redirect a http request to https

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Htaccess Redirect from old domain to new domain #

A standard 301 reidrect, basepath / to a new domain

...