Server

Ubuntu Server

Installation

Storage Configuration

RAID0

RAID1

Prerequisites

  • At least two hard drives for RAID 1 configuration.

Steps

When prompted to configure storage, select "Custom storage layout".

  1. Select the first hard drive free space and press Enter.
  2. Select Add GPT Partition
  3. Type 500M for the size and press Enter.
  4. Select ext4 for the file system and press Enter.
  5. Select /boot and press Enter.
  6. Select Create and press Enter.
  7. Go back and select the remaining free space and press Enter.
  8. Select Add GPT Partition for swap partition.
  9. Type 32G if you have 16GB memory or 64G if you have 32GB memory for the size and press Enter.
  10. Leave the Format as Leave unformatted and press Enter.
  11. Select Create and press Enter.
  12. Go back and select the remaining free space and press Enter.
  13. Select Add GPT Partition for root partition.
  14. Type the remaining max size for the size and press Enter.
  15. Leave the Format as Leave unformatted and press Enter.
  16. Select Mount with / and press Enter.
  17. Repeat step 8 to 15 for the second hard drive.
  18. When you create the root for the second hard drive, make the size same as the root of first hard drive.
  19. Select Create software RAID (md) and press Enter.
  20. Select mirrored as RAID level and press Enter.
  21. Select the two partitions you created for swap by pressing Space.
  22. Select Create Software RAID (md) again and press Enter.
  23. Select mirrored as RAID level and press Enter.
  24. Select two partitions you created for root by pressing Space.
  25. Select md0 not the free space and press Enter.
  26. Select Format and press Enter.
  27. Select swap as Format.
  28. Select Done and press Enter.
  29. Select md1 not the free space and press Enter.
  30. Select Format and press Enter.
  31. Select ext4 as Format.
  32. Select / as Mount point.
  33. Select Done and press Enter.
  34. Scroll down and select Done to finish the configuration.
  35. Select Continue to write the changes to disk.

Storage

For cloud server, we might need an additional storage for data. We can use the following steps to add additional storage.

> sudo fdisk -lu
  1. Identify the disk you want to partition. For example, /dev/sdb.
Disk /dev/vda: 40 GiB, 42949672960 bytes, 83886080 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: E7B4EB42-B9BF-48EE-B8C6-FB167DAEF600

Device      Start      End  Sectors  Size Type
/dev/vda1    2048     4095     2048    1M BIOS boot
/dev/vda2    4096   413695   409600  200M EFI System
/dev/vda3  413696 83886046 83472351 39.8G Linux filesystem


Disk /dev/vdb: 40 GiB, 42949672960 bytes, 83886080 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
  1. Partition the disk.
> fdisk /dev/vdb
  • Type n to create a new partition.
  • Type p for primary partition.
  • Type 1 for partition number.
  • Press Enter to accept the default first sector.
  • Press Enter to accept the default last sector.
  • Type w to write the changes.
  1. Format the partition.
> sudo fdisk -lu
> sudo mkfs -t ext4 /dev/vdb1
  1. Create a mount point.
> sudo mkdir /data
  1. Mount the partition.
> sudo mount /dev/vdb1 /data
  1. Update the /etc/fstab file to automatically mount the partition on boot.
> echo `blkid /dev/vdb1 | awk '{print $2}' | \
sed 's/\"//g'` /data ext4 defaults 0 0 >> /etc/fstab
  1. Verify the mount.
> df -h

Configure DHCP

  1. Identify the Network Interface:

Determine the name of your Ethernet interface by running:

> ip link
  1. Edit the Netplan Configuration:

Open the Netplan configuration file (usually located in /etc/netplan/), such as 01-netcfg.yaml or 50-cloud-init.yaml:

> sudo nano /etc/netplan/01-netcfg.yaml
  1. Update the Configuration for eth0:

Modify the file to enable DHCP for eth0:

network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      dhcp4: true
  1. Apply the Configuration:
> sudo netplan apply
  1. Verify the IP Address:

Check the IP address assigned to the eth0 interface:

> ip addr show eth0

SSH

SSH Tunnel

Set Up the SSH Tunnel

You will create a local port on your laptop that forwards traffic through the bridge server to the remote server.

ssh -L <local-port>:<remote-server>:<remote-port> <user>@<bridge-server>
  • local-port: A port on your laptop (e.g., 2222).
  • remote-server: The hostname or IP address of the remote server.
  • remote-port: The port on the remote server (usually 22 for SSH).
  • user: Your username on the bridge server.
  • bridge-server: The hostname or IP address of the bridge server.

Example:

ssh -L 2222:remote.server.com:22 user@bridge.server.com

This command:

  • Opens a tunnel on port 2222 of your laptop.
  • Forwards all traffic from localhost:2222 to remote.server.com:22 via bridge.server.com.

Connect to the Remote Server Through the Tunnel

After setting up the tunnel, open a new terminal and SSH to the remote server through the local port:

ssh -p <local-port> <user>@localhost

Example:

ssh -p 2222 user@localhost

Background the Tunnel

To keep the tunnel running in the background, use the -f (background) and -N (no commands) flags:

ssh -f -N -L <local-port>:<remote-server>:<remote-port> \
<user>@<bridge-server>

Example:

ssh -f -N -L 2222:remote.server.com:22 user@bridge.server.com

Systemd Services

List Services

> systemctl list-units --type=service --state=running

Rsync

rsync -avzP -e "ssh -p 2200" /home/user/file.txt remoteuser@192.168.1.100:/home/remoteuser/files/

apt

Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1302892 (apt)

Solution:

  1. Check if apt or dpkg is still running
ps aux | grep apt

This will list the processes related to apt. If process 1302892 (or similar) is listed and actively running, it may be completing another task. In that case, wait for it to finish.

  1. Kill the conflicting process (if stuck)

If you’re sure the process is stuck or no other package managers should be running, you can terminate it by running:

> sudo kill -9 1302892
  1. Remove the lock files

If no active process is using apt, but the lock file is still there, you can manually remove the lock files:

sudo rm /var/lib/dpkg/lock-frontend
sudo rm /var/lib/apt/lists/lock
  1. Reconfigure dpkg

Sometimes this error may corrupt the package database. To fix it, run:

sudo dpkg --configure -a
  1. Try upgrading again

Once the steps above are completed, you can safely run the upgrade command:

$ sudo apt update
$ sudo apt upgrade

Watch Command

  • watch: Runs a command repeatedly at a specified interval.
  • -10: Specifies the interval (in seconds) between each execution.
  • -h /data: Displays the disk usage of /data in a human-readable format (-h flag).
$ watch -n 10 df -h /data

If you want to log this information to a file while still viewing it, you can use:

$ watch -n 10 "df -h /data | tee -a /data/log/disk_usage.log"

Troubleshooting

Can not upgrade Snap Store while its using:

$ snap-store --quit && sudo snap refresh snap-store
Previous
SSH