Skip to main content

Reduce Ubuntu Server

· 3 min read

0. Sizes for /boot and /boot/efi

  • /boot Partition: You could reduce the /boot partition size to around 200 MB. This should still be sufficient to hold the kernel and initramfs image. Be cautious, as going too small could lead to issues during unexpected updates or changes that might require space, such as security patches for the kernel.
  • /boot/efi Partition: The EFI System Partition (/boot/efi) typically doesn't require much space if you're only using a few boot loaders. A size of 100 MB is often recommended as a minimum by many Linux distributions and should be more than adequate for most single-boot configurations.

1. Install pre-installed ubuntu server

2. Remove Unnecessary Packages (compile envionrment)

After installation, you can remove packages that are not necessary for your server's purpose:

  • List installed packages:
dpkg-query -W --showformat='${Installed-Size}\t${Package}\n' | awk '{print $1/1024 " MB\t" $2}' | sort -n -r

在硬盘上运行虚拟机系统

· One min read

将虚拟机安装的系统完整拷贝为img文件,并做成U盘系统的方案

1. 安装 qemu-img

2. 虚拟机安装操作系统

  • NOTE: 安装时选择单个文件

3. 将vmdk文件转换为img

qemu-img convert -f vmdk -O raw image.vmdk image.img

4. 使用 WindowsDiskImager 烧写U盘

auto-expand-partition

· 2 min read

Manually expand partition scripts

find partition for /

findmnt -nosource /

/dev/sda3

split disk and partition number

growpart /dev/sda 3

resize2fs

resize2fs /dev/sda3

HOWTO-configure-network-on-ubuntu

· 2 min read

Set netplan configuration

Set Dynamic IP address

for inter in $(ls /sys/class/net); do
if [[ $inter != 'lo' ]]; then
cat << EOF > /etc/netplan/99-$inter.yaml
network:
ethernets:
$inter:
dhcp4: true
version: 2
renderer: networkd
EOF
ip link set dev $inter up
fi
done

Set docker proxy

· 2 min read
  1. create/edit user docker configuration:
sudo vim /etc/docker/daemon.json
  1. set up proxy
{
"proxies": {
"http-proxy": "http://proxy.example.com:80",
"https-proxy": "https://proxy.example.com:443",
"no-proxy": "*.test.example.com,.example.org"
}
}
  • This is a full example of the allowed configuration options on Linux:
{
"allow-nondistributable-artifacts": [],
"api-cors-header": "",
"authorization-plugins": [],
"bip": "",
"bridge": "",
"cgroup-parent": "",
"containerd": "/run/containerd/containerd.sock",
"containerd-namespace": "docker",
"containerd-plugin-namespace": "docker-plugins",
"data-root": "",
"debug": true,
"default-address-pools": [
{
"base": "172.30.0.0/16",
"size": 24
},
{
"base": "172.31.0.0/16",
"size": 24
}
],
"default-cgroupns-mode": "private",
"default-gateway": "",
"default-gateway-v6": "",
"default-network-opts": {},
"default-runtime": "runc",
"default-shm-size": "64M",
"default-ulimits": {
"nofile": {
"Hard": 64000,
"Name": "nofile",
"Soft": 64000
}
},
"dns": [],
"dns-opts": [],
"dns-search": [],
"exec-opts": [],
"exec-root": "",
"experimental": false,
"features": {},
"fixed-cidr": "",
"fixed-cidr-v6": "",
"group": "",
"hosts": [],
"proxies": {
"http-proxy": "http://proxy.example.com:80",
"https-proxy": "https://proxy.example.com:443",
"no-proxy": "*.test.example.com,.example.org"
},
"icc": false,
"init": false,
"init-path": "/usr/libexec/docker-init",
"insecure-registries": [],
"ip": "0.0.0.0",
"ip-forward": false,
"ip-masq": false,
"iptables": false,
"ip6tables": false,
"ipv6": false,
"labels": [],
"live-restore": true,
"log-driver": "json-file",
"log-level": "",
"log-opts": {
"cache-disabled": "false",
"cache-max-file": "5",
"cache-max-size": "20m",
"cache-compress": "true",
"env": "os,customer",
"labels": "somelabel",
"max-file": "5",
"max-size": "10m"
},
"max-concurrent-downloads": 3,
"max-concurrent-uploads": 5,
"max-download-attempts": 5,
"mtu": 0,
"no-new-privileges": false,
"node-generic-resources": ["NVIDIA-GPU=UUID1", "NVIDIA-GPU=UUID2"],
"oom-score-adjust": 0,
"pidfile": "",
"raw-logs": false,
"registry-mirrors": [],
"runtimes": {
"cc-runtime": {
"path": "/usr/bin/cc-runtime"
},
"custom": {
"path": "/usr/local/bin/my-runc-replacement",
"runtimeArgs": ["--debug"]
}
},
"seccomp-profile": "",
"selinux-enabled": false,
"shutdown-timeout": 15,
"storage-driver": "",
"storage-opts": [],
"swarm-default-advertise-addr": "",
"tls": true,
"tlscacert": "",
"tlscert": "",
"tlskey": "",
"tlsverify": true,
"userland-proxy": false,
"userland-proxy-path": "/usr/libexec/docker-proxy",
"userns-remap": ""
}