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".
- Select the first hard drive
free spaceand pressEnter. - Select
Add GPT Partition - Type 500M for the size and press
Enter. - Select
ext4for the file system and pressEnter. - Select
/bootand pressEnter. - Select
Createand pressEnter. - Go back and select the remaining
free spaceand pressEnter. - Select
Add GPT Partitionfor swap partition. - Type 32G if you have 16GB memory or 64G if you have 32GB memory for the size and press
Enter. - Leave the Format as
Leave unformattedand pressEnter. - Select
Createand pressEnter. - Go back and select the remaining
free spaceand pressEnter. - Select
Add GPT Partitionfor root partition. - Type the remaining max size for the size and press
Enter. - Leave the Format as
Leave unformattedand pressEnter. - Select
Mountwith/and pressEnter. - Repeat step 8 to 15 for the second hard drive.
- When you create the
rootfor the second hard drive, make the size same as therootof first hard drive. - Select
Create software RAID (md)and pressEnter. - Select
mirroredas RAID level and pressEnter. - Select the two partitions you created for swap by pressing
Space. - Select
Create Software RAID (md)again and pressEnter. - Select
mirroredas RAID level and pressEnter. - Select two partitions you created for root by pressing
Space. - Select
md0not thefree spaceand pressEnter. - Select
Formatand pressEnter. - Select
swapas Format. - Select
Doneand pressEnter. - Select
md1not thefree spaceand pressEnter. - Select
Formatand pressEnter. - Select
ext4as Format. - Select
/as Mount point. - Select
Doneand pressEnter. - Scroll down and select
Doneto finish the configuration. - Select
Continueto 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
- 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
- Partition the disk.
> fdisk /dev/vdb
- Type
nto create a new partition. - Type
pfor primary partition. - Type
1for partition number. - Press
Enterto accept the default first sector. - Press
Enterto accept the default last sector. - Type
wto write the changes.
- Format the partition.
> sudo fdisk -lu
> sudo mkfs -t ext4 /dev/vdb1
- Create a mount point.
> sudo mkdir /data
- Mount the partition.
> sudo mount /dev/vdb1 /data
- Update the
/etc/fstabfile to automatically mount the partition on boot.
> echo `blkid /dev/vdb1 | awk '{print $2}' | \
sed 's/\"//g'` /data ext4 defaults 0 0 >> /etc/fstab
- Verify the mount.
> df -h
Configure DHCP
- Identify the Network Interface:
Determine the name of your Ethernet interface by running:
> ip link
- 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
- Update the Configuration for eth0:
Modify the file to enable DHCP for eth0:
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: true
- Apply the Configuration:
> sudo netplan apply
- Verify the IP Address:
Check the IP address assigned to the eth0 interface:
> ip addr show eth0
DNS
Check current DNS name servers:
$ resolvectl status
WiFi
- List available connections
> sudo nmcli connection show
- Modify the Wi-Fi password
Replace <SSID> with your Wi-Fi name and <new_password> with the new password:
> sudo nmcli connection modify "<SSID>" wifi-sec.psk "<new_password>"
- Restart the connection
Disconnect and reconnect to apply the new password:
> sudo nmcli connection down "<SSID>" && sudo nmcli connection up "<SSID>"
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:
- 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.
- 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
- 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
- Reconfigure dpkg
Sometimes this error may corrupt the package database. To fix it, run:
sudo dpkg --configure -a
- 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