Skip to main content

Disadvantages of strlen() in Embedded Domain

· One min read

To read from a "TCP Communication" you are probably using read. The prototype for read is

ssize_t read(int fildes, void *buf, size_t nbyte);

and the return value is the number of bytes read (even if they are 0). So, let's say you're about to read 10 bytes, all of which are 0. You have an array with more than enough to hold all the data

int fildes;
char data[1000];
// fildes = TCPConnection
nbytes = read(fildes, data, 1000);

Now, by inspecting nbytes you know you have read 10 bytes. If you check data[0] through data[9] you will find they have 0;

Reference:

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盘

Set netplan configuration

· 2 min read

Set Dynamic IP address[^1][^2]

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

Remove snapd on ubuntu

· One min read
sudo rm -rf /var/cache/snapd/

sudo apt autoremove --purge snapd gnome-software-plugin-snap

rm -fr ~/snap

sudo apt-mark hold snapd