Update bsp

This commit is contained in:
orangepi-xunlong 2022-06-16 14:50:55 +08:00
parent 530ed5c15b
commit d623002594
6 changed files with 35 additions and 23 deletions

View File

@ -31,7 +31,7 @@ MACADDR=$(printf ${prefixes[$random]}':%02X:%02X:%02X:%02X:%02X\n' $[RANDOM%256]
}
# set fixed IP address from first randomly assigned one. If nothing is deteceted, generate one.
# set fixed IP address from first randomly assigned one. If nothing is detected, generate one.
set_fixed_mac ()
{
if [ -n "$(command -v nmcli)" ]; then
@ -47,10 +47,10 @@ set_fixed_mac ()
[[ -z $MACADDR ]] && get_random_mac
if [[ -n "$(command -v nmcli)" && -n $UUID ]]; then
nmcli connection modify $UUID ethernet.cloned-mac-address $MACADDR
nmcli connection modify $UUID -ethernet.mac-address ""
nmcli connection down $UUID >/dev/null 2>&1
nmcli connection up $UUID >/dev/null 2>&1
nmcli connection modify "$UUID" ethernet.cloned-mac-address "$MACADDR"
nmcli connection modify "$UUID" -ethernet.mac-address ""
nmcli connection down "$UUID" >/dev/null 2>&1
nmcli connection up "$UUID" >/dev/null 2>&1
elif [[ -f /etc/systemd/network/$DEVNAME.network ]]; then
if ! grep '^ *MACAddress=' /etc/systemd/network/$DEVNAME.network > /dev/null; then
sed -i "s/#MACAddress=/MACAddress=$MACADDR/g" /etc/systemd/network/$DEVNAME.network

View File

@ -50,6 +50,7 @@ syncToDisk () {
if [ "$USE_RSYNC" = true ]; then
${NoCache} rsync -aXWv \
--exclude "lost+found" --exclude orangepi-ramlog.log \
--delete \
--links \
${XTRA_RSYNC_TO[@]+"${XTRA_RSYNC_TO[@]}"} \
$RAM_LOG $HDD_LOG 2>&1 | $LOG_OUTPUT

View File

@ -13,6 +13,15 @@
do_expand_partition()
{
# check if growroot (from cloud-initramfs-growroot package) is installed.
# despite it's name, that package does NOT require cloud-init.
# if so, it means the partition with root filesystem was already resized during initramfs.
# in this case do nothing here, but return 0 to allow resize2fs to run (growroot does not handle that).
if [[ -f /usr/share/initramfs-tools/hooks/growroot ]] || [[ -f /usr/share/initramfs-tools/scripts/local-bottom/growroot ]]; then
echo "partition resize skipped: growroot detected."
return 0
fi
# trim any btrfs subvolume identifier given in square brackets (e.g. /dev/mapper/orangepi-root[/@])
local rootsource=$(findmnt -n -o SOURCE / | sed 's~\[.*\]~~') # i.e. /dev/mmcblk0p1 or /dev/mapper/orangepi-root
@ -162,6 +171,7 @@ do_resize_crypt()
do_expand_ext4()
{
echo -e "\n### [resize2fs] Start resizing ext4 partition $1 now\n" >> ${Log}
echo "Running 'resize2fs ${rootpart}' now..."
resize2fs ${rootpart} >> ${Log} 2>&1
}

View File

@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
#
# Copyright (c) Authors: https://www.armbian.com/authors
#
@ -29,5 +29,5 @@ if [ $logusage -ge $treshold ]; then
# remove
/usr/bin/find /var/log -name '*.[0-9]' -or -name '*.gz' | xargs -r rm -f
# vacuum systemd-journald
[ -d /var/log/journal ] && journalctl --vacuum-size=${JOURNAL_SIZE}
[ -d /var/log/journal ] && journalctl --quiet --vacuum-size=${JOURNAL_SIZE}
fi

View File

@ -37,7 +37,7 @@ activate_zram() {
cpu_cores=$(grep -c '^processor' /proc/cpuinfo | sed 's/^0$/1/')
[[ ${cpu_cores} -gt ${zram_max_devs} ]] && zram_devices=${zram_max_devs} || zram_devices=${cpu_cores}
module_args="$(modinfo zram | awk -F" " '/num_devices/ {print $2}' | cut -f1 -d:)"
[[ -n ${module_args} ]] && modprobe zram ${module_args}=$(( ${zram_devices} + 2 )) || return
[[ -n ${module_args} ]] && modprobe zram ${module_args}=$(( zram_devices + 2 )) || return
swap_algo=${SWAP_ALGORITHM:=lzo}
# Expose 50% of real memory as swap space by default
@ -45,11 +45,11 @@ activate_zram() {
mem_info=$(LC_ALL=C free -w 2>/dev/null | grep "^Mem" || LC_ALL=C free | grep "^Mem")
mem_info=$(echo $mem_info | awk '{print $2}')
memory_total=$(( mem_info * 1024 ))
mem_per_zram_device=$(( ${memory_total} / ${zram_devices} * ${zram_percent} / 100 ))
mem_per_zram_device=$(( memory_total * zram_percent / zram_devices / 100 ))
# Limit memory available to zram to 50% by default
mem_limit_percent=${MEM_LIMIT_PERCENTAGE:=50}
mem_limit_per_zram_device=$(( ${memory_total} / ${zram_devices} * ${mem_limit_percent} / 100 ))
mem_limit_per_zram_device=$(( memory_total * mem_limit_percent / zram_devices / 100 ))
}
activate_zram_swap() {
@ -67,7 +67,7 @@ activate_zram_swap() {
for (( i=1; i<=zram_devices; i++ )); do
swap_device=$(zramctl -f |sed 's/\/dev\///')
[[ ! ${swap_device} =~ ^zram ]] && echo -e "\n### No more available zram devices (${swap_device})\n" >>${Log} && exit 1;
[[ ! ${swap_device} =~ ^zram ]] && printf "\n### No more available zram devices (%s)\n" "${swap_device}" >> ${Log} && exit 1;
if [ -f /sys/block/${swap_device}/comp_algorithm ]; then
# set compression algorithm, if defined as lzo choose lzo-rle if available
# https://www.phoronix.com/scan.php?page=news_item&px=ZRAM-Linux-5.1-Better-Perform
@ -88,7 +88,7 @@ activate_zram_swap() {
# Swapping to HDDs is stupid so switch to settings made for flash memory and zram/zswap
echo 0 > /proc/sys/vm/page-cluster
echo -e "\n### Activated ${zram_devices} ${swap_algo} zram swap devices with $(( ${mem_per_zram_device} / 1048576 )) MB each\n" >>${Log}
printf "\n### Activated %s %s zram swap devices with %dMB each.\n" "${zram_devices}" "${swap_algo}" "$((mem_per_zram_device / 1048576))" >> ${Log}
} # activate_zram_swap
activate_ramlog_partition() {
@ -97,7 +97,7 @@ activate_ramlog_partition() {
ENABLED=$(awk -F"=" '/^ENABLED/ {print $2}' /etc/default/orangepi-ramlog)
[[ "$ENABLED" != "true" ]] && return
log_device=$(zramctl -f |sed 's/\/dev\///')
[[ ! ${log_device} =~ ^zram ]] && echo -e "\n### No more available zram devices (${log_device})\n" >>${Log} && exit 1;
[[ ! ${log_device} =~ ^zram ]] && printf "\n### No more available zram devices (%s)\n" "${log_device}" >> ${Log} && exit 1;
# read size also from /etc/default/orangepi-ramlog
ramlogsize=$(awk -F"=" '/^SIZE/ {print $2}' /etc/default/orangepi-ramlog)
@ -123,14 +123,14 @@ activate_ramlog_partition() {
mkfs.ext4 -O ^has_journal -s 1024 -L log2ram /dev/${log_device}
algo=$(sed 's/.*\[\([^]]*\)\].*/\1/g' </sys/block/${log_device}/comp_algorithm)
echo -e "### Activated Orange Pi ramlog partition with ${algo} compression" >>${Log}
printf "### Activated Orange Pi ramlog partition with %s compression\n" "${algo}" >> ${Log}
} # activate_ramlog_partition
activate_compressed_tmp() {
# create /tmp not as tmpfs but zram compressed if no fstab entry exists
grep -q '^tmpfs /tmp' /etc/mtab && return
tmp_device=$(zramctl -f |sed 's/\/dev\///')
[[ ! ${tmp_device} =~ ^zram ]] && echo -e "\n### No more available zram devices (${tmp_device})\n" >>${Log} && exit 1;
[[ ! ${tmp_device} =~ ^zram ]] && printf "\n### No more available zram devices (%s)\n" "${tmp_device}" >> ${Log} && exit 1;
if [[ -f /sys/block/${tmp_device}/comp_algorithm ]]; then
if [ "X${TMP_ALGORITHM}" = "X" ]; then
@ -139,12 +139,12 @@ activate_compressed_tmp() {
echo ${TMP_ALGORITHM} >/sys/block/${tmp_device}/comp_algorithm 2>/dev/null
fi
fi
[[ -z ${TMP_SIZE} ]] && echo -n $(( ${memory_total} / 2 )) > /sys/block/${tmp_device}/disksize || echo -n ${TMP_SIZE} > /sys/block/${tmp_device}/disksize
[[ -z ${TMP_SIZE} ]] && echo -n $(( memory_total / 2 )) > /sys/block/${tmp_device}/disksize || echo -n ${TMP_SIZE} > /sys/block/${tmp_device}/disksize
mkfs.ext4 -O ^has_journal -s 1024 -L tmp /dev/${tmp_device}
mount -o nosuid,discard /dev/${tmp_device} /tmp
chmod 1777 /tmp
algo=$(sed 's/.*\[\([^]]*\)\].*/\1/g' </sys/block/${tmp_device}/comp_algorithm)
echo -e "\n### Activated ${algo} compressed /tmp" >>${Log}
printf "\n### Activated %s compressed /tmp\n" "${algo}" >> ${Log}
} # activate_compressed_tmp
case $1 in

View File

@ -1,6 +1,6 @@
#!/bin/bash
#
# Copyright (c) Authors: http://www.armbian.com/authors
# Copyright (c) Authors: https://www.armbian.com/authors
#
# Tool to transfer the rootfs of an already running Orange Pi installation from SD card
# to NAND, eMMC, SATA or USB storage. In case of eMMC it's also possible to transfer
@ -10,6 +10,7 @@
# Import:
# DIR: path to u-boot directory
# write_uboot_platform: function to write u-boot to a block device
# write_uboot_platform_mtd: function to write u-boot to a mtd (eg. SPI flash) device
[[ -f /usr/lib/u-boot/platform_install.sh ]] && source /usr/lib/u-boot/platform_install.sh
@ -268,13 +269,13 @@ create_orangepi()
# fix that we can have one exlude file
cp -R /boot "${TempDir}"/bootfs
# old boot scripts
sed -e 's,root='"$root_uuid"',root='"$targetuuid"',g' -i "${TempDir}"/bootfs/boot/boot.cmd
[[ -f "${TempDir}"/bootfs/boot/boot.cmd ]] && sed -e 's,root='"$root_uuid"',root='"$targetuuid"',g' -i "${TempDir}"/bootfs/boot/boot.cmd
# new boot scripts
if [[ -f "${TempDir}"/bootfs/boot/orangepiEnv.txt ]]; then
sed -e 's,rootdev=.*,rootdev='"$targetuuid"',g' -i "${TempDir}"/bootfs/boot/orangepiEnv.txt
grep -q '^rootdev' "${TempDir}"/bootfs/boot/orangepiEnv.txt || echo "rootdev=$targetuuid" >> "${TempDir}"/bootfs/boot/orangepiEnv.txt
else
sed -e 's,setenv rootdev.*,setenv rootdev '"$targetuuid"',g' -i "${TempDir}"/bootfs/boot/boot.cmd
[[ -f "${TempDir}"/bootfs/boot/boot.cmd ]] && sed -e 's,setenv rootdev.*,setenv rootdev '"$targetuuid"',g' -i "${TempDir}"/bootfs/boot/boot.cmd
[[ -f "${TempDir}"/bootfs/boot/boot.ini ]] && sed -e 's,^setenv rootdev.*$,setenv rootdev "'"$targetuuid"'",' -i "${TempDir}"/bootfs/boot/boot.ini
[[ -f "${TempDir}"/rootfs/boot/boot.ini ]] && sed -e 's,^setenv rootdev.*$,setenv rootdev "'"$targetuuid"'",' -i "${TempDir}"/rootfs/boot/boot.ini
fi
@ -294,16 +295,16 @@ create_orangepi()
# if the rootfstype is not defined as cmdline argument on orangepiEnv.txt
if ! grep -qE '^rootfstype=.*' "${TempDir}"/bootfs/boot/orangepiEnv.txt; then
# Add the line of type of the selected rootfstype to the file orangepiEnv.txt
echo "rootfstype=$choosen_fs" >> "${TempDir}"/bootfs/boot/orangepiEnv.txt
[[ -f "${TempDir}"/bootfs/boot/orangepiEnv.txt ]] && echo "rootfstype=$choosen_fs" >> "${TempDir}"/bootfs/boot/orangepiEnv.txt
fi
if [[ $eMMCFilesystemChoosen =~ ^(btrfs|f2fs)$ ]]; then
echo "$targetuuid / $choosen_fs ${mountopts[$choosen_fs]}" >> "${TempDir}"/rootfs/etc/fstab
# swap file not supported under btrfs but we might have made a partition
[[ -n ${emmcswapuuid} ]] && sed -e 's,/var/swap.*,'$emmcswapuuid' none swap sw 0 0,g' -i "${TempDir}"/rootfs/etc/fstab
sed -e 's,rootfstype=.*,rootfstype='$eMMCFilesystemChoosen',g' -i "${TempDir}"/bootfs/boot/orangepiEnv.txt
[[ -f "${TempDir}"/bootfs/boot/orangepiEnv.txt ]] && sed -e 's,rootfstype=.*,rootfstype='$eMMCFilesystemChoosen',g' -i "${TempDir}"/bootfs/boot/orangepiEnv.txt
else
sed -e 's,rootfstype=.*,rootfstype='$choosen_fs',g' -i "${TempDir}"/bootfs/boot/orangepiEnv.txt
[[ -f "${TempDir}"/bootfs/boot/orangepiEnv.txt ]] && sed -e 's,rootfstype=.*,rootfstype='$choosen_fs',g' -i "${TempDir}"/bootfs/boot/orangepiEnv.txt
echo "$targetuuid / $choosen_fs ${mountopts[$choosen_fs]}" >> "${TempDir}"/rootfs/etc/fstab
fi