Skip to content

Commit

Permalink
Adjust file directory
Browse files Browse the repository at this point in the history
  • Loading branch information
ophub committed Mar 25, 2022
1 parent a66448a commit f8e1a00
Show file tree
Hide file tree
Showing 26 changed files with 1,910 additions and 4 deletions.
4 changes: 3 additions & 1 deletion build-armbian/README.cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@

## common-files

- files: 这里存放的是 Armbian 固件的个性化配置文件,将在打包脚本 `sudo ./rebuild` 执行时自动将相关文件集成到你的固件里。相关目录及文件命名均须与 Armbian 中 ROOTFS 分区 ( 即在 TTYD 终端里输入: `cd / && ls .` 你所看到的目录及各目录里面的文件名称 ) 保持完全一致。
- rootfs: 这里存放的是 Armbian 固件的个性化配置文件,将在打包脚本 `sudo ./rebuild` 执行时自动将相关文件集成到你的固件里。相关目录及文件命名均须与 Armbian 中 ROOTFS 分区 ( 即在 TTYD 终端里输入: `cd / && ls .` 你所看到的目录及各目录里面的文件名称 ) 保持完全一致。

```yaml
etc/network/interfaces
usr/sbin
```

- bootfs: 这里存放的是 Armbian 系统中 `/boot` 目录下的个性化配置文件。

- patches: 这是补丁文件存放目录,你可以将扩展文件,补丁等放置在该目录。
4 changes: 3 additions & 1 deletion build-armbian/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ These duplications are automated in the repository's packaging and install/upgra

## common-files

- files: The files in the `common-files/files` directory are custom files, which must be completely consistent with the structure and file naming and storage under the ***`ROOTFS`*** partiton in Armbian. If there are files in this directory, they will be automatically copied to the Armbian directory during `sudo ./rebuild`. E.g:
- rootfs: The files in the `common-files/files` directory are custom files, which must be completely consistent with the structure and file naming and storage under the ***`ROOTFS`*** partiton in Armbian. If there are files in this directory, they will be automatically copied to the Armbian directory during `sudo ./rebuild`. E.g:

```yaml
etc/network/interfaces
usr/sbin
```

- bootfs: This is the personalized configuration file in the `/boot` directory of the Armbian system.

- patches: This is the directory where patch files are stored. You can place extension files, patches, etc. in this directory.

5 changes: 5 additions & 0 deletions build-armbian/common-files/bootfs/extlinux/extlinux.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
label Armbian
kernel /zImage
initrd /uInitrd
fdt /dtb/amlogic/meson-g12b-gtking-pro.dtb
append root=LABEL=ROOTFS rootfstype=btrfs rootflags=compress=zstd:6 console=ttyAML0,115200n8 console=tty0 no_console_suspend consoleblank=0 fsck.fix=yes fsck.repair=yes net.ifnames=0 loglevel=1 voutmode=hdmi disablehpd=false overscan=100 sdrmode=auto
4 changes: 4 additions & 0 deletions build-armbian/common-files/bootfs/uEnv.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
LINUX=/zImage
INITRD=/uInitrd
FDT=/dtb/amlogic/meson-g12b-gtking-pro.dtb
APPEND=root=LABEL=ROOTFS console=ttyAML0,115200n8 console=tty0 no_console_suspend consoleblank=0 fsck.fix=yes fsck.repair=yes net.ifnames=0 cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory swapaccount=1
3 changes: 3 additions & 0 deletions build-armbian/common-files/rootfs/etc/fstab
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
LABEL=ROOTFS / btrfs defaults,noatime,compress=zstd:6 0 1
LABEL=BOOT /boot vfat defaults 0 2
tmpfs /tmp tmpfs defaults,nosuid 0 0
9 changes: 9 additions & 0 deletions build-armbian/common-files/rootfs/etc/network/interfaces
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
source /etc/network/interfaces.d/*
# Network is managed by Network manager
auto lo
iface lo inet loopback
auto wlan0
iface wlan0 inet dhcp
auto eth0
iface eth0 inet dhcp
hwaddress ether 12:34:56:78:9A:BC
112 changes: 112 additions & 0 deletions build-armbian/common-files/rootfs/etc/sysctl.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#
# /etc/sysctl.conf - Configuration file for setting system variables
# See /etc/sysctl.d/ for additional system variables.
# See sysctl.conf (5) for information.
#

#kernel.domainname = example.com

# Uncomment the following to stop low-level messages on console
kernel.printk = 7 4 1 7

##############################################################3
# Functions previously found in netbase
#

# Uncomment the next two lines to enable Spoof protection (reverse-path filter)
# Turn on Source Address Verification in all interfaces to
# prevent some spoofing attacks
#net.ipv4.conf.default.rp_filter=1
#net.ipv4.conf.all.rp_filter=1

# Uncomment the next line to enable TCP/IP SYN cookies
# See http://lwn.net/Articles/277146/
# Note: This may impact IPv6 TCP sessions too
#net.ipv4.tcp_syncookies=1

# Uncomment the next line to enable packet forwarding for IPv4
#net.ipv4.ip_forward=1

# Uncomment the next line to enable packet forwarding for IPv6
# Enabling this option disables Stateless Address Autoconfiguration
# based on Router Advertisements for this host
#net.ipv6.conf.all.forwarding=1


###################################################################
# Additional settings - these settings can improve the network
# security of the host and prevent against some network attacks
# including spoofing attacks and man in the middle attacks through
# redirection. Some network environments, however, require that these
# settings are disabled so review and enable them as needed.
#
# Do not accept ICMP redirects (prevent MITM attacks)
#net.ipv4.conf.all.accept_redirects = 0
#net.ipv6.conf.all.accept_redirects = 0
# _or_
# Accept ICMP redirects only for gateways listed in our default
# gateway list (enabled by default)
# net.ipv4.conf.all.secure_redirects = 1
#
# Do not send ICMP redirects (we are not a router)
#net.ipv4.conf.all.send_redirects = 0
#
# Do not accept IP source route packets (we are not a router)
#net.ipv4.conf.all.accept_source_route = 0
#net.ipv6.conf.all.accept_source_route = 0
#
# Log Martian Packets
#net.ipv4.conf.all.log_martians = 1
#

###################################################################
# Magic system request Key
# 0=disable, 1=enable all, >1 bitmask of sysrq functions
# See https://www.kernel.org/doc/html/latest/admin-guide/sysrq.html
# for what other values do
#kernel.sysrq=438

vm.swappiness = 100

vm.max_map_count = 262144
# Generated file - do not edit.
# Disable the hung task timer by default. (bnc#552820)
kernel.hung_task_timeout_secs = 0

# Increase defaults for IPC (bnc#146656)
kernel.msgmax = 65536
kernel.msgmnb = 65536

net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr
net.ipv4.ip_local_port_range = 1024 65535

net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.ip_forward = 1
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.icmp_ignore_bogus_error_responses = 1
net.ipv4.igmp_max_memberships = 100
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 120
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_timestamps = 1
net.ipv4.tcp_sack = 1
net.ipv4.tcp_dsack = 1

net.ipv6.conf.default.forwarding = 1
net.ipv6.conf.all.forwarding = 1

net.core.rmem_max = 4194304
net.core.wmem_max = 1048576

net.netfilter.nf_conntrack_acct = 1
net.netfilter.nf_conntrack_checksum = 0
net.netfilter.nf_conntrack_max = 65535
net.netfilter.nf_conntrack_tcp_timeout_established = 7440
net.netfilter.nf_conntrack_udp_timeout = 60
net.netfilter.nf_conntrack_udp_timeout_stream = 180
net.netfilter.nf_conntrack_helper = 1

# net.ipv6.conf.all.disable_ipv6 = 1
# net.ipv6.conf.all.disable_ipv6 = 1
Binary file not shown.
107 changes: 107 additions & 0 deletions build-armbian/common-files/rootfs/usr/sbin/armbian-ddbr
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#!/bin/bash
#=========================================================================
# This file is licensed under the terms of the GNU General Public
# License version 2. This program is licensed "as is" without any
# warranty of any kind, whether express or implied.
#
# This file is a part of the Armbian Rebuild and kernel Recompile script
# https://github.com/ophub/amlogic-s9xxx-armbian
#
# Description: Backup and restore the system in emmc
# Copyright (C) 2017- The function borrowed from ddbr, Author: xXx
# Copyright (C) 2021- https://github.com/unifreq/openwrt_packit
# Copyright (C) 2021- https://github.com/ophub/amlogic-s9xxx-armbian
#
# Command: armbian-ddbr
#=========================================================================

# Set font color
blue_font_prefix="\033[94m"
purple_font_prefix="\033[95m"
green_font_prefix="\033[92m"
yellow_font_prefix="\033[93m"
red_font_prefix="\033[91m"
font_color_suffix="\033[0m"
INFO="[${blue_font_prefix}INFO${font_color_suffix}]"
STEPS="[${purple_font_prefix}STEPS${font_color_suffix}]"
SUCCESS="[${green_font_prefix}SUCCESS${font_color_suffix}]"
OPT="[${yellow_font_prefix}OPT${font_color_suffix}]"
ERROR="[${red_font_prefix}ERROR${font_color_suffix}]"
# File name for backup/restore
ddbr_image="BACKUP-arm-64-emmc.img.gz"
# Need remaining space, unit: GB
need_space="2"
# Get device name
mydevice_name=$(cat /proc/device-tree/model | tr -d '\000')

# Find the EMMC drive
emmc="$(lsblk -l -o NAME | grep -oE "mmcblk[0-9]boot0" | sort | uniq | sed "s/boot0//g")"
if [[ "${emmc}" == "" ]]; then
echo "No emmc can be found to install the openwrt system!"
exit 1
fi

# Find the partition where root is located
root_devname=$(df / | tail -n1 | awk '{print $1}' | awk -F '/' '{print substr($3, 1, length($3)-2)}')
if lsblk -l | grep -E "^${root_devname}boot0" >/dev/null; then
echo "You are running in emmc mode, please boot system with TF/SD/USB!"
exit 1
fi

# Check the output path
out_path="/ddbr"
[ -d "${out_path}" ] || mkdir -p ${out_path}

# Check emmc partition size
dev_intsize="$(fdisk -s /dev/${emmc})"
[ -z "$(echo "${dev_intsize}" | sed -n "/^[0-9]\+$/p")" ] && echo -e "${ERROR} Unable to get EMMC size." && exit 1

# Check the remaining space
do_checkspace() {
remaining_space="$(df -hT ${out_path} | grep '/dev/' | awk '{print $5}' | sed 's/.$//' | awk -F "." '{print $1}')"
if [ -z "$(echo "${remaining_space}" | sed -n "/^[0-9]\+$/p")" ]; then
echo -e "${ERROR} The path is not available, the remaining space cannot be obtained."
exit 1
fi
if [[ "${remaining_space}" -lt "${need_space}" ]]; then
echo -e "${ERROR} The remaining space is [ ${remaining_space} ] GB."
echo -e "It is recommended that the remaining space should not be less than [ ${need_space} ] GB."
echo -e "Please use the [ armbian-tf ] command to extended partition first."
exit 1
fi
}

# Backup the emmc system
do_backup() {
echo -e "${STEPS} Start to backup the system in emmc."
do_checkspace
echo -e "Saving and Compressing [ /dev/${emmc} ] to [ ${out_path}/${ddbr_image} ], Please wait..."
rm -f ${out_path}/${ddbr_image} 2>/dev/null && sync
dd if=/dev/${emmc} | pv -s ${dev_intsize}"K" | gzip >${out_path}/${ddbr_image}
[ "$?" -eq "0" ] && sync && echo -e "${SUCCESS} Backup is complete."
}

# Restore the emmc system
do_restore() {
echo -e "${STEPS} Start to restore the system in emmc."
[ ! -f ${out_path}/${ddbr_image} ] && echo -e "${ERROR} The [ ${out_path}/${ddbr_image} ] File not found." && exit 1
echo -e "Restoring [ ${out_path}/${ddbr_image} ] to [ /dev/${emmc} ], Please wait..."
gunzip -c ${out_path}/${ddbr_image} | pv -s ${dev_intsize}"K" | dd of=/dev/${emmc}
[ "$?" -eq "0" ] && sync && echo -e "${SUCCESS} Restore is complete."
}

# Output device information
echo -e "${STEPS} Welcome to use the EMMC system backup/restore service."
echo -e "${INFO} The device name: [ ${mydevice_name} ]"
echo -e "${INFO} The device EMMC name: [ /dev/${emmc} ]"
echo -e "${INFO} The device EMMC size: [ $(($dev_intsize / 1024 / 1024))GB ]"
echo -e "${INFO} The ddbr file path: [ ${out_path}/${ddbr_image} ]\n"

# Prompt the user to select backup/restore
echo -ne "${OPT} Do you want to backup or restore? Backup=(b) Restore=(r): "
read br
case ${br} in
b | B | backup) do_backup ;;
r | R | restore) do_restore ;;
*) exit 0 ;;
esac
Loading

0 comments on commit f8e1a00

Please sign in to comment.