diff --git a/ReadMe.md b/ReadMe.md index cce72e4..5e80380 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -1,9 +1,14 @@ # Ubuntu Server Essentials -A collection of scripts intended to simplify setting up and maintianing an Ubuntu server +A collection of scripts and tutorials intended to simplify setting up and maintianing an Ubuntu server ## Scripts [All In One](Scripts/USE-AIO.sh) - All USE scripts combined together with a menu for selecting which one to run [Docker](Scripts/Docker.sh) - Install Docker -[Portainer](Scripts/Portainer.sh) - Install Docker and Portainer Server +[Portainer Server](Scripts/Portainer-Server.sh) - Install Docker and Portainer Server +[Portainer Agent](Scripts/Portainer-Agent.sh) - Install Docker and Portianer Agent [Update](Scripts/Update.sh) - Update and clean up unused packages -[Change Hostname](Scripts/change_hostname.sh) - Change the hostname for the system \ No newline at end of file +[Change Hostname](Scripts/change_hostname.sh) - Change the hostname for the system + +## Tutorials +[Expand Drive Space](Tutorials/expand_drive_space.md) +[Mount Drive At Boot](Tutorials/automount_drive_at_boot.md) \ No newline at end of file diff --git a/Scripts/Portainer-Agent.sh b/Scripts/Portainer-Agent.sh new file mode 100644 index 0000000..78db965 --- /dev/null +++ b/Scripts/Portainer-Agent.sh @@ -0,0 +1,25 @@ +#! /bin/bash + +echo "Installing Docker..." + # Add Docker's official GPG key: + sudo apt-get update 1>/dev/null + sudo apt-get install ca-certificates curl -y 1>/dev/null + sudo install -m 0755 -d /etc/apt/keyrings 1>/dev/null + sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc 1>/dev/null + sudo chmod a+r /etc/apt/keyrings/docker.asc 1>/dev/null + + # Add the repository to Apt sources: + echo \ + "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \ + $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \ + sudo tee /etc/apt/sources.list.d/docker.list > /dev/null + sudo apt-get update 1>/dev/null + + # Install Docker + sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y 1>/dev/null + echo "Done" + + #install Portianer agent + echo "Installing Portainer agent..." + sudo docker run -d -p 9001:9001 --name portainer_agent --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/docker/volumes:/var/lib/docker/volumes -v /:/host portainer/agent:lts 1>/dev/null + echo "Done" ;; \ No newline at end of file diff --git a/Scripts/Portainer.sh b/Scripts/Portainer-Server.sh similarity index 100% rename from Scripts/Portainer.sh rename to Scripts/Portainer-Server.sh diff --git a/Scripts/USE-AIO.sh b/Scripts/USE-AIO.sh index ad68219..6b49b46 100644 --- a/Scripts/USE-AIO.sh +++ b/Scripts/USE-AIO.sh @@ -4,11 +4,12 @@ clear echo "What do you want to do?" echo "1. Install Docker" echo "2. Install Docker + Portainer Server" -echo "3. Update System" -echo "4. Change Hostname" -echo "5. Exit" +echo "3. Install Docker + Portianer Agent" +echo "4. Update System" +echo "5. Change Hostname" +echo "00. Exit" echo "" -echo -n "enter your selection(1-4)(5 to exit): " +echo -n "enter your selection(1-5)(00 to exit): " while : do @@ -60,7 +61,31 @@ case $choice in sudo docker run -d -p 8000:8000 -p 9443:9443 --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:lts 1>/dev/null echo "Done" ;; -3) echo "Updating repository..." +3) echo "Installing Docker..." + # Add Docker's official GPG key: + sudo apt-get update 1>/dev/null + sudo apt-get install ca-certificates curl -y 1>/dev/null + sudo install -m 0755 -d /etc/apt/keyrings 1>/dev/null + sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc 1>/dev/null + sudo chmod a+r /etc/apt/keyrings/docker.asc 1>/dev/null + + # Add the repository to Apt sources: + echo \ + "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \ + $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \ + sudo tee /etc/apt/sources.list.d/docker.list > /dev/null + sudo apt-get update 1>/dev/null + + # Install Docker + sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y 1>/dev/null + echo "Done" + + #install Portianer agent + echo "Installing Portainer agent..." + sudo docker run -d -p 9001:9001 --name portainer_agent --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/docker/volumes:/var/lib/docker/volumes -v /:/host portainer/agent:lts 1>/dev/null + echo "Done" ;; + +4) echo "Updating repository..." sudo apt-get update 1>/dev/null echo "Done" echo "Installing updates..." @@ -70,7 +95,7 @@ case $choice in sudo apt-get autoremove -y 1>/dev/null echo "Done" ;; -4) echo "" +5) echo "" #get current hostname and set it as value of old_host old_host=$(hostname) @@ -95,7 +120,7 @@ case $choice in printf "%s\n" "Hostname changed from [$old_host] to [$new_host]" printf "%s\n" "Reboot your system for the change to take effect" ;; -5) echo "Exiting..." +00) echo "Exiting..." exit ;; *) echo "Invalid option" ;; @@ -104,6 +129,6 @@ esac echo "" echo "" -echo -n "enter your selection(1-4)(5 to exit): " +echo -n "enter your selection(1-5)(00 to exit): " done \ No newline at end of file diff --git a/Tutorials/automount_drive_at_boot.md b/Tutorials/automount_drive_at_boot.md new file mode 100644 index 0000000..2164396 --- /dev/null +++ b/Tutorials/automount_drive_at_boot.md @@ -0,0 +1,34 @@ +## 1. Find the location of the drive using `lsblk` +- ex. `/dev/sdb` + +## 2. Make a new partition on the disk +1. `fdisk /dev/[location of hdd]` + - ex. `fdisk /dev/sdb` +2. `n` to make a new partiton +3. `w` to save changes + +## 3. Confirm that the new partition was created +- `lsblk` + - ex. `/dev/sdb1` + +## 4. Make a file system on the new partiton +- `mkfs -t ext4 /dev/[location of partition]` + - ex. `mkfs -t ext4 /dev/sdb1` + +## 5. Make a directory to mount HDD to + - `sudo mkdir /mnt/hdd` + +## 6. Get the UUID for the drive to be mounted +- `lsblk -fs` + +## 7. Make a backup of /etc/fstab +- `sudo cp /etc/fstab /etc/fstab.bk` +- In case anything goes wrong you can restore this backup version + - `sudo cp /etc/fstab.bk /etc/fstab` + +## 8. Add the new harddrive to /etc/fstab so that it is automatically mounted when the system boots +1. `sudo nano /etc/fstab` +2. add the line `UUID=[drive UUID] [mount location] ext4 defaults,auto,rw 0 0` + - ex. `UUID=4579acc6-e00d-433b-8087-0a75506e7a9c /mnt/hdd ext4 defaults,auto,rw 0 0` + +## 9. Restart the system to confirm that drive mounts at boot diff --git a/Tutorials/expand_drive_space.md b/Tutorials/expand_drive_space.md new file mode 100644 index 0000000..ae7881d --- /dev/null +++ b/Tutorials/expand_drive_space.md @@ -0,0 +1,42 @@ +# Add new partion and add partion to existing LVM +## 1. Add new partion using fdisk +- `sudo fdisk /dev/[drive containing partition you want to expand]` + - ex. if you want to expand partion sda3 you would use `sudo fdisk /dev/sda` +- use `p` to list partiton talble +use `F` to list free space on drive +use `n` to create a new partion +use `w` to save changes + +## 2. Add new partion to existing LVM +- use `lsblk` to list all drives, partitions, and LVMs +### 2.1 Create a new physical volume (pv) +- `sudo pvcreate /dev/[partiton you want to use]` + - ex. `sudo pvcreate /dev/sda4` +### 2.2 Identify the volume group (vg) you want to use +- you can use `sudo vgs` to list all available volume groups +### 2.3 Extend volume group +- `sudo vgextend [volume group] /dev/[partition]` + - ex. `sudo vgextend ubuntu-vg /dev/sda4` +### 2.4 Identify the logical volume (lv) you want to use +- you can use `sudo lvs` to list all available logical volumes +### 2.5 Extend logical volume +- `sudo lvextend -l +100%FREE /dev/[volume group]/[logical volume]` + - ex. `sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv` + +## 3. Resize filesystem so system sees changes +- `sudo resize2fs /dev/[volume group]/[logical volume]` + - ex. `sudo resize2fs/dev/ubuntu-vg/ubuntu-lv` + + + + +# Expand existing partion +1. `sudo growpart /dev/[disk] [partition number]` + - ex. `sudo growpart /dev/sda 3` + - ***note the space between disk and partion number*** +2. `sudo resize2fs /dev/[partition]` + - ex. `sudo resize2fs /dev/sda3` + +# Expand existing LVM to use whole partition +- `sudo lvextend -l +100%FREE /dev/[volume group]/[logical volume]` + - ex. `sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv` \ No newline at end of file