Compare commits

...

10 Commits

Author SHA1 Message Date
openeuler-ci-bot
1dfdadea11
!72 KubeOS: modify version display and fix the path for EFI boot in bootloader.sh
From: @weiy6 
Reviewed-by: @li-yuanrong 
Signed-off-by: @li-yuanrong
2024-06-18 06:33:34 +00:00
Yuhang Wei
1fdbd83569 KubeOS: modify version display and fix the path for EFI boot in bootloader.sh
Signed-off-by: Yuhang Wei <weiyuhang3@huawei.com>
2024-06-18 11:18:15 +08:00
openeuler-ci-bot
f9b7578dfd
!71 KubeOS: sync to master branch 1.0.6-1
From: @weiy6 
Reviewed-by: @li-yuanrong 
Signed-off-by: @li-yuanrong
2024-06-11 13:12:38 +00:00
Yuhang Wei
3d4aa05ed3 KubeOS: sync to master branch 1.0.6-1
Signed-off-by: Yuhang Wei <weiyuhang3@huawei.com>
2024-06-11 20:54:07 +08:00
openeuler-ci-bot
18748a2400
!41 [sync] PR-40: KubeOS:fix usage does not print when an error occurs in the upgrade image creation
From: @openeuler-sync-bot 
Reviewed-by: @duguhaotian 
Signed-off-by: @duguhaotian
2022-12-08 09:29:28 +00:00
liyuanr
a8500bf39a KubeOS:fix usage does not print when an error occurs in the upgrade image creation
Fix the bug that the usage does not print
when the upgrade image has parameter errors

Signed-off-by: liyuanr <liyuanrong1@huawei.com>
(cherry picked from commit 192d36586a4533a75f4fe63e0eba8e09d5fc5dc7)
2022-12-08 17:16:28 +08:00
openeuler-ci-bot
49a6e63884
!38 [sync] PR-37: KubeOS: remove grub2 legacy install, add error handling for opstype and add entry for unit test in Makefile
From: @openeuler-sync-bot 
Reviewed-by: @duguhaotian 
Signed-off-by: @duguhaotian
2022-11-29 14:13:25 +00:00
liyuanr
b579e10e74 KubeOS: remove grub2 legacy install, add error handling for opstype and add entry for unit test in Makefile
Remove grub2 install for legacy setup to fix failure of x86
vm images building. Add the error handling of the abnormal value
of the opstype. Add an entry for unit testing in Makefile.

Signed-off-by: liyuanr <liyuanrong1@huawei.com>
(cherry picked from commit 8e409873a9e5d1157ea012bfb09b5f20b50f1d0b)
2022-11-29 21:05:59 +08:00
openeuler-ci-bot
b7f94e4802
!35 sync from branch openEuler-22.09
From: @li-yuanrong 
Reviewed-by: @duguhaotian 
Signed-off-by: @duguhaotian
2022-10-28 06:46:34 +00:00
liyuanr
f1f028839d KubeOS:add the configuration of /etc/resolv.conf and change the VM disk to gpt.
Add the user-defined /etc/resolv.conf file and change the VM disk to gpt
to be the same as that on the physical machine.

Signed-off-by: liyuanr <liyuanrong1@huawei.com>
2022-10-28 10:47:01 +08:00
9 changed files with 220 additions and 1315 deletions

View File

@ -0,0 +1,134 @@
From dbabd83278e84e21a4e3493150add216012ba230 Mon Sep 17 00:00:00 2001
From: Yuhang Wei <weiyuhang3@huawei.com>
Date: Mon, 17 Jun 2024 10:30:52 +0800
Subject: [PATCH 1/2] Bump kubeos version to 1.0.6
Signed-off-by: Yuhang Wei <weiyuhang3@huawei.com>
---
KubeOS-Rust/Cargo.lock | 8 ++++----
KubeOS-Rust/agent/Cargo.toml | 2 +-
KubeOS-Rust/cli/Cargo.toml | 2 +-
KubeOS-Rust/manager/Cargo.toml | 2 +-
KubeOS-Rust/proxy/Cargo.toml | 6 +++---
VERSION | 2 +-
6 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/KubeOS-Rust/Cargo.lock b/KubeOS-Rust/Cargo.lock
index 4e1619aa..93e3d07d 100644
--- a/KubeOS-Rust/Cargo.lock
+++ b/KubeOS-Rust/Cargo.lock
@@ -189,7 +189,7 @@ dependencies = [
[[package]]
name = "cli"
-version = "1.0.5"
+version = "1.0.6"
dependencies = [
"anyhow",
"jsonrpc",
@@ -1226,7 +1226,7 @@ dependencies = [
[[package]]
name = "manager"
-version = "1.0.5"
+version = "1.0.6"
dependencies = [
"anyhow",
"env_logger",
@@ -1438,7 +1438,7 @@ dependencies = [
[[package]]
name = "os-agent"
-version = "1.0.5"
+version = "1.0.6"
dependencies = [
"anyhow",
"env_logger",
@@ -1601,7 +1601,7 @@ dependencies = [
[[package]]
name = "proxy"
-version = "1.0.5"
+version = "1.0.6"
dependencies = [
"anyhow",
"assert-json-diff",
diff --git a/KubeOS-Rust/agent/Cargo.toml b/KubeOS-Rust/agent/Cargo.toml
index 739bbbc7..83e1b7c0 100644
--- a/KubeOS-Rust/agent/Cargo.toml
+++ b/KubeOS-Rust/agent/Cargo.toml
@@ -3,7 +3,7 @@ description = "KubeOS os-agent"
edition = "2021"
license = "MulanPSL-2.0"
name = "os-agent"
-version = "1.0.5"
+version = "1.0.6"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
diff --git a/KubeOS-Rust/cli/Cargo.toml b/KubeOS-Rust/cli/Cargo.toml
index c3c14c6f..78d5fd51 100644
--- a/KubeOS-Rust/cli/Cargo.toml
+++ b/KubeOS-Rust/cli/Cargo.toml
@@ -3,7 +3,7 @@ description = "KubeOS os-agent client"
edition = "2021"
license = "MulanPSL-2.0"
name = "cli"
-version = "1.0.5"
+version = "1.0.6"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
diff --git a/KubeOS-Rust/manager/Cargo.toml b/KubeOS-Rust/manager/Cargo.toml
index e694090c..f60a7c08 100644
--- a/KubeOS-Rust/manager/Cargo.toml
+++ b/KubeOS-Rust/manager/Cargo.toml
@@ -3,7 +3,7 @@ description = "KubeOS os-agent manager"
edition = "2021"
license = "MulanPSL-2.0"
name = "manager"
-version = "1.0.5"
+version = "1.0.6"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dev-dependencies]
diff --git a/KubeOS-Rust/proxy/Cargo.toml b/KubeOS-Rust/proxy/Cargo.toml
index 3b5d96d1..d804ac77 100644
--- a/KubeOS-Rust/proxy/Cargo.toml
+++ b/KubeOS-Rust/proxy/Cargo.toml
@@ -3,7 +3,7 @@ description = "KubeOS os-proxy"
edition = "2021"
license = "MulanPSL-2.0"
name = "proxy"
-version = "1.0.5"
+version = "1.0.6"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
@@ -17,14 +17,14 @@ path = "src/main.rs"
[dependencies]
anyhow = "1.0.44"
async-trait = "0.1"
-cli = { version = "1.0.5", path = "../cli" }
+cli = { version = "1.0.6", path = "../cli" }
env_logger = "0.9.0"
futures = "0.3.17"
h2 = "=0.3.16"
k8s-openapi = { version = "0.13.1", features = ["v1_22"] }
kube = { version = "0.66.0", features = ["derive", "runtime"] }
log = "=0.4.15"
-manager = { version = "1.0.5", path = "../manager" }
+manager = { version = "1.0.6", path = "../manager" }
regex = "=1.7.3"
reqwest = { version = "=0.12.2", default-features = false, features = [
"json",
diff --git a/VERSION b/VERSION
index 90a27f9c..af0b7ddb 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-1.0.5
+1.0.6
--
2.39.3 (Apple Git-146)

View File

@ -1,479 +0,0 @@
From 236b8ddeb3bc7f35eb817769f117ecd68a59335c Mon Sep 17 00:00:00 2001
From: stedylan <836671668@qq.com>
Date: Sun, 7 Aug 2022 01:47:14 +0800
Subject: [PATCH] Write a tool to support KubeOS deployment on physical
machines.
This tool uses dracut module to make partitions and formatting, set network infomation, get rootfs and set boot options in initramfs before switch to the real root.
Signed-off-by: stedylan <836671668@qq.com>
---
scripts/00bootup/Global.cfg | 12 ++
scripts/00bootup/module-setup.sh | 28 +++
scripts/00bootup/mount.sh | 332 +++++++++++++++++++++++++++++++
scripts/create/imageCreate.sh | 4 +-
scripts/create/rootfsCreate.sh | 1 +
scripts/rpmlist | 10 +-
scripts/set_in_chroot.sh | 3 +
7 files changed, 387 insertions(+), 3 deletions(-)
create mode 100644 scripts/00bootup/Global.cfg
create mode 100644 scripts/00bootup/module-setup.sh
create mode 100644 scripts/00bootup/mount.sh
diff --git a/scripts/00bootup/Global.cfg b/scripts/00bootup/Global.cfg
new file mode 100644
index 0000000..cad4e33
--- /dev/null
+++ b/scripts/00bootup/Global.cfg
@@ -0,0 +1,12 @@
+# rootfs file name
+rootfs_name=kubeos.tar
+
+# select the target disk to install kubeOS
+disk=/dev/sda
+
+# address where stores the rootfs on the http server
+server_ip=192.168.1.50
+
+local_ip=192.168.1.100
+
+route_ip=192.168.1.1
\ No newline at end of file
diff --git a/scripts/00bootup/module-setup.sh b/scripts/00bootup/module-setup.sh
new file mode 100644
index 0000000..5460b2b
--- /dev/null
+++ b/scripts/00bootup/module-setup.sh
@@ -0,0 +1,28 @@
+#!/bin/bash
+
+check() {
+ return 0
+}
+
+depends() {
+ echo systemd
+}
+
+install() {
+ inst_multiple -o grub2-mkimage mkfs.ext4 mkfs.vfat lsblk tar cpio gunzip lspci parted dhclient ifconfig curl hwinfo head tee arch df awk route
+ inst_hook mount 00 "$moddir/mount.sh"
+ inst_simple "$moddir/mount.sh" "/mount.sh"
+ inst_simple "$moddir/Global.cfg" "/Global.cfg"
+}
+
+installkernel() {
+ hostonly='' \
+ instmods \
+ =drivers/ata \
+ =drivers/nvme \
+ =drivers/scsi \
+ =drivers/net \
+ =fs/fat \
+ =fs/nls
+}
+
diff --git a/scripts/00bootup/mount.sh b/scripts/00bootup/mount.sh
new file mode 100644
index 0000000..a04a364
--- /dev/null
+++ b/scripts/00bootup/mount.sh
@@ -0,0 +1,332 @@
+#!/bin/bash
+arch=$(arch)
+min_size=8
+log=/install.log
+
+source /Global.cfg
+
+function CheckSpace() {
+ local disk_ava="$(parted -l | grep ${disk} | awk '{print $3}')"
+ if echo "${disk_ava}" | grep [GT]B$; then
+ if echo "${disk_ava}" | grep GB$; then
+ disk_ava="$(echo ${disk_ava} | awk -F G '{print $1}' | awk -F . '{print $1}')"
+ if [ "${disk_ava}" -lt ${min_size} ]; then
+ echo "The available disk space is not enough, at least ${min_size}GB." | tee -a ${log}
+ return 1
+ fi
+ fi
+ else
+ echo "The available disk space is not enough, at least ${min_size}G." | tee -a ${log}
+ return 1
+ fi
+
+ return 0
+}
+
+function GetDisk() {
+ disks=$(hwinfo --disk --short | grep -vi "^disk" | awk '{print $1}')
+ if [ ! -z ${disks} ]; then
+ if [ ! -z ${disk} ] && echo "${disks[@]}" | grep -wq "${disk}" ; then
+ echo "${disk} exists, start partition" | tee -a ${log}
+ else
+ echo "disk not exist, choose default disk" | tee -a ${log}
+ disk=$(echo ${disks[0]})
+ fi
+ else
+ echo "no disk found" | tee -a ${log}
+ return 1
+ fi
+
+
+ CheckSpace
+ if [ $? -ne 0 ]; then
+ echo "no enough space on ${disk}" | tee -a ${log}
+ return 1
+ fi
+
+ return 0
+}
+
+function PartitionAndFormatting() {
+ echo "Partitioning and formatting disk $disk..."
+ # partition and format
+ parted ${disk} -s mklabel gpt >> ${log} 2>&1
+ if [ $? -ne 0 ]; then
+ echo "partition failed" | tee -a ${log}
+ return 1
+ fi
+
+ parted ${disk} -s mkpart primary fat16 1M 100M >> ${log} 2>&1
+ if [ $? -ne 0 ]; then
+ echo "partition failed" | tee -a ${log}
+ return 1
+ fi
+
+ parted ${disk} -s mkpart primary ext4 100M 2600M >> ${log} 2>&1
+ if [ $? -ne 0 ]; then
+ echo "partition failed" | tee -a ${log}
+ return 1
+ fi
+
+ parted ${disk} -s mkpart primary ext4 2600M 5100M >> ${log} 2>&1
+ if [ $? -ne 0 ]; then
+ echo "partition failed" | tee -a ${log}
+ return 1
+ fi
+
+ parted ${disk} -s mkpart primary ext4 5100M 100% >> ${log} 2>&1
+ if [ $? -ne 0 ]; then
+ echo "partition failed" | tee -a ${log}
+ return 1
+ fi
+
+ parted ${disk} -s set 1 boot on >> ${log} 2>&1
+ if [ $? -ne 0 ]; then
+ echo "partition failed" | tee -a ${log}
+ return 1
+ fi
+
+ mkfs.vfat -n "BOOT" ${disk}1 >> ${log} 2>&1
+ if [ $? -ne 0 ]; then
+ echo "format failed" | tee -a ${log}
+ return 1
+ fi
+
+ mkfs.ext4 -L "ROOT-A" ${disk}2 >> ${log} 2>&1
+ if [ $? -ne 0 ]; then
+ echo "format failed" | tee -a ${log}
+ return 1
+ fi
+
+ mkfs.ext4 -L "ROOT-B" ${disk}3 >> ${log} 2>&1
+ if [ $? -ne 0 ]; then
+ echo "format failed" | tee -a ${log}
+ return 1
+ fi
+
+ mkfs.ext4 -L "PERSIST" ${disk}4 >> ${log} 2>&1
+ if [ $? -ne 0 ]; then
+ echo "format failed" | tee -a ${log}
+ return 1
+ fi
+
+ return 0
+}
+
+function InitNetwork() {
+ echo "Initializing network..."
+ # 获取网卡信息,默认只有一个网卡
+ net_name=`ifconfig -a | awk '{print $1}' | grep : | grep '^e' | awk -F: '{print $1}'`
+ # dhclient --timeout 60 >> ${log} 2>&1
+
+ ifconfig ${net_name} up
+ if [ $? -ne 0 ]; then
+ echo "load net card failed" | tee -a ${log}
+ return 1
+ fi
+ sleep 3
+
+ ifconfig ${net_name} ${local_ip} netmask 255.255.255.0 >> ${log} 2>&1
+ if [ $? -ne 0 ]; then
+ echo "ip set failed" | tee -a ${log}
+ return 1
+ fi
+ sleep 3
+
+ route add default gw ${route_ip} >> ${log} 2>&1
+ if [ $? -ne 0 ]; then
+ echo "add route failed" | tee -a ${log}
+ return 1
+ fi
+ sleep 3
+
+
+
+ return 0
+}
+
+function MountRoot() {
+ echo "Mounting rootfs..."
+ # mount rootfs
+ mount ${disk}2 /sysroot >> ${log} 2>&1
+ if [ $? -ne 0 ]; then
+ echo "mount rootfs failed" | tee -a ${log}
+ return 1
+ fi
+
+ return 0
+}
+
+function MountPersist() {
+ echo "Mounting persist"
+ mkdir /persist
+ mount ${disk}4 /persist >> ${log} 2>&1
+ if [ $? -ne 0 ]; then
+ echo "mount persist failed" | tee -a ${log}
+ return 1
+ fi
+ mkdir /persist/{var,etc,etcwork}
+ mkdir -p /persist/etc/KubeOS/certs
+ return 0
+}
+
+function MountBoot() {
+ echo "Mounting boot"
+ mkdir -p /sysroot/boot/efi
+ mount ${disk}1 /sysroot/boot/efi >> ${log} 2>&1
+ if [ $? -ne 0 ]; then
+ echo "mount boot failed" | tee -a ${log}
+ return 1
+ fi
+ return 0
+}
+
+function GetRootfs() {
+ echo "Downloading rootfs..."
+
+ curl -o /persist/${rootfs_name} http://${server_ip}/${rootfs_name}
+ if [ ! -e "/persist/${rootfs_name}" ]; then
+ echo "download rootfs failed" | tee -a ${log}
+ return 1
+ fi
+
+ tar -xvf /persist/${rootfs_name} -C /sysroot
+ if [ $? -ne 0 ]; then
+ echo "decompose rootfs failed" | tee -a ${log}
+ return 1
+ fi
+
+ rm -rf /persist/${rootfs_name}
+
+ return 0
+}
+
+function Inst_Grub2_x86() {
+ # copy the files that boot need
+ cp -r /sysroot/usr/lib/grub/x86_64-efi /sysroot/boot/efi/EFI/openEuler
+ eval "grub2-mkimage -d /sysroot/usr/lib/grub/x86_64-efi -O x86_64-efi --output=/sysroot/boot/efi/EFI/openEuler/grubx64.efi '--prefix=(,gpt1)/EFI/openEuler' fat part_gpt part_msdos linux" >> ${log} 2>&1
+ if [ $? -ne 0 ]; then
+ echo "grub2-mkimage on x86 failed" | tee -a ${log}
+ return 1
+ fi
+
+ mkdir -p /sysroot/boot/efi/EFI/BOOT/
+ cp -f /sysroot/boot/efi/EFI/openEuler/grubx64.efi /sysroot/boot/efi/EFI/BOOT/BOOTX64.EFI
+
+ return 0
+}
+
+function Inst_Grub2_aarch64() {
+ cp -r /sysroot/usr/lib/grub/arm64-efi /sysroot/boot/efi/EFI/openEuler/
+ eval "grub2-mkimage -d /sysroot/usr/lib/grub/arm64-efi -O arm64-efi --output=/sysroot/boot/efi/EFI/openEuler/grubaa64.efi '--prefix=(,gpt1)/EFI/openEuler' fat part_gpt part_msdos linux" >> ${log} 2>&1
+ if [ $? -ne 0 ]; then
+ echo "grub2-mkimage on aarch64 failed" | tee -a ${log}
+ return 1
+ fi
+
+ mkdir -p /sysroot/boot/efi/EFI/BOOT/
+ cp -f /sysroot/boot/efi/EFI/openEuler/grubaa64.efi /sysroot/boot/efi/EFI/BOOT/BOOTAA64.EFI
+
+ return 0
+}
+
+function SetBoot() {
+ # mount boot
+ echo "Setting boot"
+
+ if [ $arch == "x86_64" ]; then
+ Inst_Grub2_x86
+ if [ $? -ne 0 ]; then
+ echo "install grub on x86 failed" | tee -a ${log}
+ return 1
+ fi
+ fi
+
+ if [ $arch == "aarch64" ]; then
+ Inst_Grub2_aarch64
+ if [ $? -ne 0 ]; then
+ echo "install grub on aarch64 failed" | tee -a ${log}
+ return 1
+ fi
+ fi
+
+ return 0
+}
+
+function Bootup_Main() {
+ # get disk
+ echo "Checking disk info..." | tee -a ${log}
+ GetDisk
+ if [ $? -ne 0 ]; then
+ echo "Checking disk info failed" | tee -a ${log}
+ return 1
+ fi
+
+ # partition and format disk
+ echo "Partion and formatting..." | tee -a ${log}
+ PartitionAndFormatting
+ if [ $? -ne 0 ]; then
+ echo "Partition and formatting disk failed" | tee -a ${log}
+ return 1
+ fi
+
+ # init network
+ echo "Initializing network..." | tee -a ${log}
+ InitNetwork
+ if [ $? -ne 0 ]; then
+ echo "Initializing network failed" | tee -a ${log}
+ return 1
+ fi
+
+ # mount partitions
+ echo "Mounting root..." | tee -a ${log}
+ MountRoot
+ if [ $? -ne 0 ]; then
+ echo "Mounting root failed" | tee -a ${log}
+ return 1
+ fi
+
+ # mount persist
+ echo "Mounting persisst..." | tee -a ${log}
+ MountPersist
+ if [ $? -ne 0 ]; then
+ echo "Mounting persist failed" | tee -a ${log}
+ return 1
+ fi
+
+ # mount boot
+ echo "Mounting boot..." | tee -a ${log}
+ MountBoot
+ if [ $? -ne 0 ]; then
+ echo "Mounting boot failed" | tee -a ${log}
+ return 1
+ fi
+
+ # download rootfs
+ echo "Downloading rootfs..." | tee -a ${log}
+ GetRootfs
+ if [ $? -ne 0 ]; then
+ echo "Downloading rootfs failed" | tee -a ${log}
+ return 1
+ fi
+
+ # set boot
+ echo "Setting boot..." | tee -a ${log}
+ SetBoot
+ if [ $? -ne 0 ]; then
+ echo "Setting boot failed" | tee -a ${log}
+ return 1
+ fi
+
+ return 0
+}
+
+Bootup_Main
+ret=$?
+if [ ${ret} -eq 0 ]; then
+ echo "kubeOS install success! switch to root" | tee -a ${log}
+ cp ${log} /persist
+else
+ echo "kubeOS install failed, see install.log" | tee -a ${log}
+fi
+
diff --git a/scripts/create/imageCreate.sh b/scripts/create/imageCreate.sh
index f8dafbe..95ebcde 100644
--- a/scripts/create/imageCreate.sh
+++ b/scripts/create/imageCreate.sh
@@ -62,12 +62,12 @@ function create_pxe_img() {
case $opt in
"repo")
create_os_tar_from_repo "$@"
- tar -xvf os.tar ./boot/initramfs.img
+ tar -xvf os.tar ./initramfs.img
tar -xvf os.tar ./boot/vmlinuz
;;
"docker")
create_os_tar_from_docker "$@"
- tar -xvf os.tar boot/initramfs.img
+ tar -xvf os.tar initramfs.img
tar -xvf os.tar boot/vmlinuz
;;
esac
diff --git a/scripts/create/rootfsCreate.sh b/scripts/create/rootfsCreate.sh
index 8049f09..e5c53d5 100644
--- a/scripts/create/rootfsCreate.sh
+++ b/scripts/create/rootfsCreate.sh
@@ -61,6 +61,7 @@ EOF
mv "${RPM_ROOT}"/boot/initramfs* "${RPM_ROOT}/boot/initramfs.img"
cp grub.cfg "${RPM_ROOT}"/boot/grub2
cp grub.cfg "${RPM_ROOT}"/boot/efi/EFI/openEuler
+ cp -r ./00bootup ${RPM_ROOT}/usr/lib/dracut/modules.d/
cp set_in_chroot.sh "${RPM_ROOT}"
ROOT_PWD="${PASSWD}" chroot "${RPM_ROOT}" bash /set_in_chroot.sh
rm "${RPM_ROOT}/set_in_chroot.sh"
diff --git a/scripts/rpmlist b/scripts/rpmlist
index 7a9adfa..077a164 100644
--- a/scripts/rpmlist
+++ b/scripts/rpmlist
@@ -13,4 +13,12 @@ socat
conntrack-tools
ebtables
ethtool
-rsyslog
\ No newline at end of file
+rsyslog
+vi
+net-tools
+hwinfo
+dracut
+coreutils
+gawk
+parted
+dosfstools
\ No newline at end of file
diff --git a/scripts/set_in_chroot.sh b/scripts/set_in_chroot.sh
index bacef78..4b061df 100644
--- a/scripts/set_in_chroot.sh
+++ b/scripts/set_in_chroot.sh
@@ -11,3 +11,6 @@ sed -i '/^root:/d' /etc/shadow_bak
echo "root:"${ROOT_PWD}${str:1} > /etc/shadow
cat /etc/shadow_bak >> /etc/shadow
rm -rf /etc/shadow_bak
+
+dracut -f -v --add bootup /initramfs.img --kver `ls /lib/modules`
+rm -rf /usr/lib/dracut/modules.d/00bootup
\ No newline at end of file
--
2.33.0.windows.2

View File

@ -1,341 +0,0 @@
From f64c9587a20cc44036b0f622105501ff142729d7 Mon Sep 17 00:00:00 2001
From: liyuanr <liyuanrong1@huawei.com>
Date: Tue, 23 Aug 2022 15:32:36 +0800
Subject: [PATCH] KubeOS:fix the kbimg.sh exception and pxe installation
problem.
Fixed the issue of abnormal usage printing of the kbimg.sh parameter,
no verification of the -b parameter, and environment clearance in
the concurrent scenario.
Fix the problem that disks and network adapters cannot be found
due to disk and network adapter verification during PXE installation.
Fix the problem that os-proxy does not transfer imagetype and dockerimage
to the os-agent.
Signed-off-by: liyuanr <liyuanrong1@huawei.com>
---
cmd/proxy/controllers/os_controller.go | 16 ++++++------
scripts/00bootup/Global.cfg | 12 ++++++---
scripts/00bootup/mount.sh | 35 ++++++++++++++------------
scripts/common/utils.sh | 7 ++++++
scripts/create/imageCreate.sh | 4 +--
scripts/kbimg.sh | 30 +++++++++++++---------
6 files changed, 62 insertions(+), 42 deletions(-)
diff --git a/cmd/proxy/controllers/os_controller.go b/cmd/proxy/controllers/os_controller.go
index f73c750..09e58f9 100644
--- a/cmd/proxy/controllers/os_controller.go
+++ b/cmd/proxy/controllers/os_controller.go
@@ -106,13 +106,15 @@ func (r *OSReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Re
case "upgrade":
version := osVersionSpec
downloadInfo := &agentclient.DownloadInfo{
- ImageURL: osInstance.Spec.ImageURL,
- FlagSafe: osInstance.Spec.FlagSafe,
- CheckSum: osInstance.Spec.CheckSum,
- CaCert: osInstance.Spec.CaCert,
- ClientCert: osInstance.Spec.ClientCert,
- ClientKey: osInstance.Spec.ClientKey,
- MTLS: osInstance.Spec.MTLS,
+ ImageURL: osInstance.Spec.ImageURL,
+ FlagSafe: osInstance.Spec.FlagSafe,
+ CheckSum: osInstance.Spec.CheckSum,
+ CaCert: osInstance.Spec.CaCert,
+ ClientCert: osInstance.Spec.ClientCert,
+ ClientKey: osInstance.Spec.ClientKey,
+ MTLS: osInstance.Spec.MTLS,
+ ImageType: osInstance.Spec.ImageType,
+ DockerImage: osInstance.Spec.DockerImage,
}
if err := r.Connection.UpdateSpec(version, downloadInfo); err != nil {
return values.RequeueNow, err
diff --git a/scripts/00bootup/Global.cfg b/scripts/00bootup/Global.cfg
index cad4e33..dd78617 100644
--- a/scripts/00bootup/Global.cfg
+++ b/scripts/00bootup/Global.cfg
@@ -4,9 +4,13 @@ rootfs_name=kubeos.tar
# select the target disk to install kubeOS
disk=/dev/sda
-# address where stores the rootfs on the http server
+# pxe server ip address where stores the rootfs on the http server
server_ip=192.168.1.50
-
+# target machine ip
local_ip=192.168.1.100
-
-route_ip=192.168.1.1
\ No newline at end of file
+# target machine route
+route_ip=192.168.1.1
+# target machine netmask
+netmask=255.255.255.0
+# target machine netDevice name
+net_name=eth0
diff --git a/scripts/00bootup/mount.sh b/scripts/00bootup/mount.sh
index a04a364..1bc83ff 100644
--- a/scripts/00bootup/mount.sh
+++ b/scripts/00bootup/mount.sh
@@ -24,20 +24,17 @@ function CheckSpace() {
}
function GetDisk() {
- disks=$(hwinfo --disk --short | grep -vi "^disk" | awk '{print $1}')
- if [ ! -z ${disks} ]; then
- if [ ! -z ${disk} ] && echo "${disks[@]}" | grep -wq "${disk}" ; then
+ disks=(`hwinfo --disk --short 2>&1 | grep -vi "^disk" | awk '{print $1}'`)
+ if [ ${#disks[*]} -gt 0 ]; then
+ if [ -n "${disk}" ] && echo "${disks[@]}" | grep -wq "${disk}" ; then
echo "${disk} exists, start partition" | tee -a ${log}
else
- echo "disk not exist, choose default disk" | tee -a ${log}
- disk=$(echo ${disks[0]})
+ echo "disk not exist, please choose correct disk" | tee -a ${log}
fi
else
echo "no disk found" | tee -a ${log}
return 1
fi
-
-
CheckSpace
if [ $? -ne 0 ]; then
echo "no enough space on ${disk}" | tee -a ${log}
@@ -115,9 +112,18 @@ function PartitionAndFormatting() {
function InitNetwork() {
echo "Initializing network..."
- # 获取网卡信息,默认只有一个网卡
- net_name=`ifconfig -a | awk '{print $1}' | grep : | grep '^e' | awk -F: '{print $1}'`
- # dhclient --timeout 60 >> ${log} 2>&1
+ netNames=(`ifconfig -a | awk '{print $1}' | grep : | grep '^e' | awk -F: '{print $1}'`)
+ if [ ${#netNames[*]} -gt 0 ]; then
+ if [ -n "${net_name}" ] && echo "${netNames[@]}" | grep -wq "${net_name}" ; then
+ echo "${net_name} exists, start set ip" | tee -a ${log}
+ else
+ echo "net_name not exist, choose default net" | tee -a ${log}
+ net_name=${netNames[0]}
+ fi
+ else
+ echo "no net Device found" | tee -a ${log}
+ return 1
+ fi
ifconfig ${net_name} up
if [ $? -ne 0 ]; then
@@ -126,7 +132,7 @@ function InitNetwork() {
fi
sleep 3
- ifconfig ${net_name} ${local_ip} netmask 255.255.255.0 >> ${log} 2>&1
+ ifconfig ${net_name} ${local_ip} netmask ${netmask} >> ${log} 2>&1
if [ $? -ne 0 ]; then
echo "ip set failed" | tee -a ${log}
return 1
@@ -139,9 +145,6 @@ function InitNetwork() {
return 1
fi
sleep 3
-
-
-
return 0
}
@@ -249,6 +252,7 @@ function SetBoot() {
return 1
fi
fi
+ sed -i 's#/dev/sda#'${disk}'#g' /sysroot/boot/efi/EFI/openEuler/grub.cfg
return 0
}
@@ -328,5 +332,4 @@ if [ ${ret} -eq 0 ]; then
cp ${log} /persist
else
echo "kubeOS install failed, see install.log" | tee -a ${log}
-fi
-
+fi
\ No newline at end of file
diff --git a/scripts/common/utils.sh b/scripts/common/utils.sh
index 902a6ae..3546c8c 100644
--- a/scripts/common/utils.sh
+++ b/scripts/common/utils.sh
@@ -87,6 +87,13 @@ function delete_file() {
return 0
}
+function check_binary_exist() {
+ if [ ! -f "$1" ];then
+ log_error_print "binary path is invalid."
+ exit 3
+ fi
+}
+
function check_repo_path() {
if [ ! -f "$1" ];then
log_error_print "REPO path is invalid."
diff --git a/scripts/create/imageCreate.sh b/scripts/create/imageCreate.sh
index 95ebcde..564c740 100644
--- a/scripts/create/imageCreate.sh
+++ b/scripts/create/imageCreate.sh
@@ -56,19 +56,17 @@ function create_img() {
}
function create_pxe_img() {
- rm -rf boot/ kubeos.tar
+ rm -rf initramfs.img kubeos.tar
local opt=$1
shift
case $opt in
"repo")
create_os_tar_from_repo "$@"
tar -xvf os.tar ./initramfs.img
- tar -xvf os.tar ./boot/vmlinuz
;;
"docker")
create_os_tar_from_docker "$@"
tar -xvf os.tar initramfs.img
- tar -xvf os.tar boot/vmlinuz
;;
esac
mv os.tar kubeos.tar
diff --git a/scripts/kbimg.sh b/scripts/kbimg.sh
index 1268700..a77d62e 100644
--- a/scripts/kbimg.sh
+++ b/scripts/kbimg.sh
@@ -72,12 +72,12 @@ options:
EOF
}
-function show_vm_image_usage() {
+function show_vm_pxe_image_usage() {
cat << EOF
-Usage : kbimg create vm-image -p iso-path -v os-version -b os-agent-dir -e os-password
+Usage : kbimg create [vm-image|pxe-image] -p iso-path -v os-version -b os-agent-dir -e os-password
or
- kbimg create vm-image -d repository/name:tag
+ kbimg create [vm-image|pxe-image] -d repository/name:tag
options:
-p repo path
@@ -130,7 +130,7 @@ function clean_space() {
function clean_img() {
delete_file system.img
delete_file update.img
- delete_dir boot
+ delete_file initramfs.img
delete_file kubeos.tar
}
@@ -170,6 +170,7 @@ function verify_upgrade_image_input() {
;;
*)
log_error_print "option $opt not found"
+ show_upgrade_image_usage
exit 3
;;
esac
@@ -183,6 +184,7 @@ function verify_repo_input() {
echo "$@" | grep -q "\-$i "
if [ "$?" -ne 0 ];then
log_error_print "option -$i is mandatory, please check input"
+ show_vm_pxe_image_usage
exit 3
fi
done
@@ -208,6 +210,7 @@ function verify_repo_input() {
;;
*)
log_error_print "option $opt not found"
+ show_vm_pxe_image_usage
exit 3
;;
esac
@@ -215,7 +218,8 @@ function verify_repo_input() {
}
function verify_docker_input() {
if [ $1 != "-d" ]; then
- log_error_print "option $opt not found"
+ log_error_print "option $1 not found"
+ show_vm_pxe_image_usage
exit 3
fi
check_param $2
@@ -242,13 +246,14 @@ function verify_create_input() {
check_disk_space "docker"
verify_upgrade_image_input "$@"
check_repo_path "${REPO}"
+ check_binary_exist "${AGENT_PATH}"
create_docker_image "${REPO}" "${VERSION}" "${AGENT_PATH}" "${PASSWD}" "${DOCKER_IMG}"
;;
"vm-image")
shift
if [ $# -eq 1 ]; then
if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
- show_vm_image_usage
+ show_vm_pxe_image_usage
exit 0
fi
fi
@@ -256,6 +261,7 @@ function verify_create_input() {
if [ $# -eq 8 ]; then
verify_repo_input "$@"
check_repo_path "${REPO}"
+ check_binary_exist "${AGENT_PATH}"
create_vm_img "repo" "${REPO}" "${VERSION}" "${AGENT_PATH}" "${PASSWD}"
elif [ $# -eq 2 ]; then
verify_docker_input "$@"
@@ -263,7 +269,7 @@ function verify_create_input() {
create_vm_img "docker" "${DOCKER_IMG}"
else
log_error_print "the number of parameters is incorrect, please check it."
- show_vm_image_usage
+ show_vm_pxe_image_usage
exit 3
fi
;;
@@ -271,7 +277,7 @@ function verify_create_input() {
shift
if [ $# -eq 1 ]; then
if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
- show_pxe_image_usage
+ show_vm_pxe_image_usage
exit 0
fi
fi
@@ -279,6 +285,7 @@ function verify_create_input() {
if [ $# -eq 8 ]; then
verify_repo_input "$@"
check_repo_path "${REPO}"
+ check_binary_exist "${AGENT_PATH}"
create_pxe_img "repo" "${REPO}" "${VERSION}" "${AGENT_PATH}" "${PASSWD}"
elif [ $# -eq 2 ]; then
verify_docker_input "$@"
@@ -286,7 +293,7 @@ function verify_create_input() {
create_pxe_img "docker" "${DOCKER_IMG}"
else
log_error_print "the number of parameters is incorrect, please check it."
- show_pxe_image_usage
+ show_vm_pxe_image_usage
exit 3
fi
;;
@@ -327,9 +334,8 @@ function kubeos_image_main() {
esac
}
+test_lock
trap clean_space EXIT
trap clean_img ERR
-test_lock
-kubeos_image_main "$@"
-
+kubeos_image_main "$@"
\ No newline at end of file
--
2.33.0.windows.2

View File

@ -0,0 +1,35 @@
From e77d86d37c9320547b98b5639dfa328f1b0542fb Mon Sep 17 00:00:00 2001
From: Yuhang Wei <weiyuhang3@huawei.com>
Date: Mon, 17 Jun 2024 10:34:37 +0800
Subject: [PATCH 2/2] fix: update bootloader.sh paths for EFI boot
Signed-off-by: Yuhang Wei <weiyuhang3@huawei.com>
---
scripts/bootloader.sh | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/scripts/bootloader.sh b/scripts/bootloader.sh
index 75096a38..df4be329 100644
--- a/scripts/bootloader.sh
+++ b/scripts/bootloader.sh
@@ -19,7 +19,7 @@ function install_grub2_x86 ()
cp -r /usr/lib/grub/x86_64-efi boot/efi/EFI/openEuler
eval "grub2-mkimage -d /usr/lib/grub/x86_64-efi -O x86_64-efi --output=/boot/efi/EFI/openEuler/grubx64.efi '--prefix=(,gpt1)/EFI/openEuler' fat part_gpt part_msdos linux"
- mkdir -p /boot/EFI/BOOT/
+ mkdir -p /boot/efi/EFI/BOOT/
cp -f /boot/efi/EFI/openEuler/grubx64.efi /boot/efi/EFI/BOOT/BOOTX64.EFI
fi
}
@@ -29,7 +29,7 @@ function install_grub2_efi ()
cp -r /usr/lib/grub/arm64-efi /boot/efi/EFI/openEuler/
eval "grub2-mkimage -d /usr/lib/grub/arm64-efi -O arm64-efi --output=/boot/efi/EFI/openEuler/grubaa64.efi '--prefix=(,gpt1)/EFI/openEuler' fat part_gpt part_msdos linux"
- mkdir -p /boot/EFI/BOOT/
+ mkdir -p /boot/efi/EFI/BOOT/
cp -f /boot/efi/EFI/openEuler/grubaa64.efi /boot/efi/EFI/BOOT/BOOTAA64.EFI
}
--
2.39.3 (Apple Git-146)

View File

@ -1,300 +0,0 @@
From fd5b3f24446c8c5dfc2fb271431ed296618eccc1 Mon Sep 17 00:00:00 2001
From: liyuanr <liyuanrong1@huawei.com>
Date: Sat, 27 Aug 2022 16:22:56 +0800
Subject: [PATCH] KubeOS: fixed the issue of VMs images and add check of
Global.cfg.
Modify the docker image creation method to fix the problem that /etc/hosts is
empty in the VM created using the docker image and that the /sys directory is
mounted abnormally.
Add checks whether configuration in the Global.cfg file are empty and whether
the IP address is valid.
Signed-off-by: liyuanr <liyuanrong1@huawei.com>
---
api/v1alpha1/os_types.go | 15 +++---
cmd/agent/server/docker_image.go | 27 +++++++----
.../config/crd/upgrade.openeuler.org_os.yaml | 1 -
scripts/Dockerfile | 2 +-
scripts/common/utils.sh | 48 ++++++++++++++++---
scripts/create/imageCreate.sh | 3 +-
scripts/create/rootfsCreate.sh | 12 ++---
scripts/kbimg.sh | 19 +-------
8 files changed, 74 insertions(+), 53 deletions(-)
diff --git a/api/v1alpha1/os_types.go b/api/v1alpha1/os_types.go
index 5acb97a..862d408 100644
--- a/api/v1alpha1/os_types.go
+++ b/api/v1alpha1/os_types.go
@@ -23,14 +23,13 @@ type OSSpec struct {
MaxUnavailable int `json:"maxunavailable"`
CheckSum string `json:"checksum"`
FlagSafe bool `json:"flagSafe"`
- // +kubebuilder:default=true
- MTLS bool `json:"mtls"`
- ImageType string `json:"imagetype"`
- DockerImage string `json:"dockerimage"`
- OpsType string `json:"opstype"`
- CaCert string `json:"cacert"`
- ClientCert string `json:"clientcert"`
- ClientKey string `json:"clientkey"`
+ MTLS bool `json:"mtls"`
+ ImageType string `json:"imagetype"`
+ DockerImage string `json:"dockerimage"`
+ OpsType string `json:"opstype"`
+ CaCert string `json:"cacert"`
+ ClientCert string `json:"clientcert"`
+ ClientKey string `json:"clientkey"`
}
// +kubebuilder:subresource:status
diff --git a/cmd/agent/server/docker_image.go b/cmd/agent/server/docker_image.go
index c5ed640..11b21aa 100644
--- a/cmd/agent/server/docker_image.go
+++ b/cmd/agent/server/docker_image.go
@@ -54,7 +54,7 @@ func pullOSImage(req *pb.UpdateRequest) (string, error) {
return "", err
}
defer cli.ContainerRemove(ctx, info.ID, types.ContainerRemoveOptions{})
- tarStream, stat, err := cli.CopyFromContainer(ctx, info.ID, "/")
+ tarStream, stat, err := cli.CopyFromContainer(ctx, info.ID, "/os.tar")
if err != nil {
return "", err
}
@@ -71,6 +71,15 @@ func pullOSImage(req *pb.UpdateRequest) (string, error) {
return "", fmt.Errorf("space is not enough for downloaing")
}
+ srcInfo := archive.CopyInfo{
+ Path: "/",
+ Exists: true,
+ IsDir: stat.Mode.IsDir(),
+ }
+ if err = archive.CopyTo(tarStream, srcInfo, PersistDir); err != nil {
+ return "", err
+ }
+
tmpMountPath := filepath.Join(PersistDir, "/kubeos-update")
if err = os.Mkdir(tmpMountPath, imgPermission); err != nil {
return "", err
@@ -80,25 +89,23 @@ func pullOSImage(req *pb.UpdateRequest) (string, error) {
if err = runCommand("dd", "if=/dev/zero", "of="+imagePath, "bs=2M", "count=1024"); err != nil {
return "", err
}
- if err = runCommand("mkfs.ext4", imagePath); err != nil {
+ _, next, err := getNextPart(partA, partB)
+ if err = runCommand("mkfs.ext4", "-L", "ROOT-"+next, imagePath); err != nil {
return "", err
}
if err = runCommand("mount", "-o", "loop", imagePath, tmpMountPath); err != nil {
return "", err
}
defer func() {
- runCommand("losetup", "-D")
syscall.Unmount(tmpMountPath, 0)
-
+ runCommand("losetup", "-D")
}()
- srcInfo := archive.CopyInfo{
- Path: "/",
- Exists: true,
- IsDir: stat.Mode.IsDir(),
- }
+
logrus.Infoln("downloading to file " + imagePath)
- if err = archive.CopyTo(tarStream, srcInfo, tmpMountPath); err != nil {
+ tmpTarPath := filepath.Join(PersistDir, "/os.tar")
+ if err = runCommand("tar", "-xvf", tmpTarPath, "-C", tmpMountPath); err != nil {
return "", err
}
+ defer os.Remove(tmpTarPath)
return imagePath, nil
}
diff --git a/docs/example/config/crd/upgrade.openeuler.org_os.yaml b/docs/example/config/crd/upgrade.openeuler.org_os.yaml
index 465e803..f240b8d 100644
--- a/docs/example/config/crd/upgrade.openeuler.org_os.yaml
+++ b/docs/example/config/crd/upgrade.openeuler.org_os.yaml
@@ -51,7 +51,6 @@ spec:
maxunavailable:
type: integer
mtls:
- default: true
type: boolean
opstype:
type: string
diff --git a/scripts/Dockerfile b/scripts/Dockerfile
index 6a616f5..3da4708 100644
--- a/scripts/Dockerfile
+++ b/scripts/Dockerfile
@@ -1,3 +1,3 @@
FROM scratch
-ADD os.tar /
+COPY os.tar /
CMD ["/bin/sh"]
diff --git a/scripts/common/utils.sh b/scripts/common/utils.sh
index 3546c8c..cf9441b 100644
--- a/scripts/common/utils.sh
+++ b/scripts/common/utils.sh
@@ -87,19 +87,53 @@ function delete_file() {
return 0
}
-function check_binary_exist() {
- if [ ! -f "$1" ];then
- log_error_print "binary path is invalid."
+function check_file_valid() {
+ local file="$1"
+ local mesg="$2"
+ if [ ! -e "${file}" ]; then
+ log_error_print "${mesg} is not exist."
+ exit 3
+ fi
+ if [ ! -f "${file}" ];then
+ log_error_print "${mesg} is not a file."
exit 3
fi
}
-function check_repo_path() {
- if [ ! -f "$1" ];then
- log_error_print "REPO path is invalid."
+function check_conf_valid() {
+ local conf_path="${PWD}/00bootup/Global.cfg"
+ check_file_valid ${conf_path} "Globab.cfg"
+ if [ $# != 7 ];then
+ log_error_print "configure configured in Global.cfg is empty."
exit 3
fi
+ for addr in ${server_ip} ${local_ip} ${route_ip} ${netmask}; do
+ check_ip_valid $addr
+ done
+}
+function check_ip_valid() {
+ local ipaddr="$1";
+ if [[ ! $ipaddr =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]] ; then
+ log_error_print "ip address configured in Global.cfg is not valid."
+ exit 3;
+ fi
+ for quad in $(echo "${ipaddr//./ }"); do
+ if [ $quad -ge 0 ] && [ $quad -le 255 ];then
+ continue
+ fi
+ log_error_print "ip address configured in Global.cfg is not valid."
+ exit 3;
+ done
+
+}
+
+function check_binary_exist() {
+ check_file_valid "$1" "os-agent binary"
+}
+
+function check_repo_path() {
+ check_file_valid $1 "REPO file"
if [ -d "${RPM_ROOT}" ]; then
log_error_print "there is a rootfs folder. please confirm if rootfs is being used, if not, please remove ${RPM_ROOT} first."
exit 5
@@ -117,7 +151,7 @@ function check_disk_space() {
fi
;;
vm)
- local maxsize=$((5*1024*1024))
+ local maxsize=$((25*1024*1024))
if [ "${disk_ava}" -lt "${maxsize}" ]; then
log_error_print "The available disk space is not enough, at least 25GiB."
exit 6
diff --git a/scripts/create/imageCreate.sh b/scripts/create/imageCreate.sh
index 564c740..9689f62 100644
--- a/scripts/create/imageCreate.sh
+++ b/scripts/create/imageCreate.sh
@@ -62,13 +62,12 @@ function create_pxe_img() {
case $opt in
"repo")
create_os_tar_from_repo "$@"
- tar -xvf os.tar ./initramfs.img
;;
"docker")
create_os_tar_from_docker "$@"
- tar -xvf os.tar initramfs.img
;;
esac
+ tar -xvf os.tar ./initramfs.img
mv os.tar kubeos.tar
}
function create_docker_image() {
diff --git a/scripts/create/rootfsCreate.sh b/scripts/create/rootfsCreate.sh
index e5c53d5..4c02c35 100644
--- a/scripts/create/rootfsCreate.sh
+++ b/scripts/create/rootfsCreate.sh
@@ -65,8 +65,6 @@ EOF
cp set_in_chroot.sh "${RPM_ROOT}"
ROOT_PWD="${PASSWD}" chroot "${RPM_ROOT}" bash /set_in_chroot.sh
rm "${RPM_ROOT}/set_in_chroot.sh"
-
- #todo:chroot create initramfs.img to include install-scripts for PXE install
}
function create_os_tar_from_repo() {
@@ -80,9 +78,9 @@ function create_os_tar_from_repo() {
tar -C "$RPM_ROOT" -cf ./os.tar .
}
function create_os_tar_from_docker() {
- local DOCKER_IMG=$1
- container_id=$(docker create ${DOCKER_IMG})
- echo "$container_id"
- docker export $container_id > os.tar
- docker rm $container_id
+ local DOCKER_IMG=$1
+ container_id=$(docker create ${DOCKER_IMG})
+ echo "$container_id"
+ docker cp $container_id:/os.tar ./
+ docker rm $container_id
}
diff --git a/scripts/kbimg.sh b/scripts/kbimg.sh
index a77d62e..a623e3d 100644
--- a/scripts/kbimg.sh
+++ b/scripts/kbimg.sh
@@ -24,6 +24,7 @@ source common/log.sh &>/dev/null
source common/utils.sh &>/dev/null
source create/rootfsCreate.sh &>/dev/null
source create/imageCreate.sh &>/dev/null
+source 00bootup/Global.cfg &>/dev/null
function show_options() {
cat << EOF
@@ -89,23 +90,6 @@ options:
EOF
}
-function show_pxe_image_usage() {
- cat << EOF
-
-Usage : kbimg create pxe-image -p iso-path -v os-version -b os-agent-dir -e os-password
- or
- kbimg create pxe-image -d repository/name:tag
-
-options:
- -p repo path
- -v KubeOS version
- -b directory of os-agent binary
- -e os encrypted password
- -d docker image like repository/name:tag
- -h,--help show help information
-EOF
-}
-
function file_lock() {
local lock_file=$1
exec {lock_fd}>"${lock_file}"
@@ -282,6 +266,7 @@ function verify_create_input() {
fi
fi
check_disk_space "pxe"
+ check_conf_valid ${rootfs_name} ${disk} ${server_ip} ${local_ip} ${route_ip} ${netmask} ${net_name}
if [ $# -eq 8 ]; then
verify_repo_input "$@"
check_repo_path "${REPO}"
--
2.33.0.windows.2

View File

@ -1,183 +0,0 @@
From 54d0a0304a0f76a0e619a8adac370eb3866f52b1 Mon Sep 17 00:00:00 2001
From: liyuanr <liyuanrong1@huawei.com>
Date: Wed, 31 Aug 2022 18:06:28 +0800
Subject: [PATCH] KubeOS:add the clearing of space before the upgrade and
rectifying the rollback failure.
The pre-upgrade space clearance function is added to resolve the problem that the upgrade
fails due to residual resources when the upgrade is performed again after a power failure.
Fix the rollback failure when the upgrade fails due to the upgrade using different architectures.
Signed-off-by: liyuanr <liyuanrong1@huawei.com>
---
cmd/agent/server/docker_image.go | 91 ++++++++++++++++++++++++++++----
scripts/grub.cfg | 10 ----
2 files changed, 81 insertions(+), 20 deletions(-)
diff --git a/cmd/agent/server/docker_image.go b/cmd/agent/server/docker_image.go
index 11b21aa..4f9edc1 100644
--- a/cmd/agent/server/docker_image.go
+++ b/cmd/agent/server/docker_image.go
@@ -15,6 +15,7 @@ package server
import (
"context"
+ "errors"
"fmt"
"io/ioutil"
"os"
@@ -47,9 +48,18 @@ func pullOSImage(req *pb.UpdateRequest) (string, error) {
return "", err
}
+ containerName := "kubeos-temp"
+ containers, err := cli.ContainerList(ctx, types.ContainerListOptions{All: true})
+ for _, container := range containers {
+ if container.Names[0] == "/"+containerName {
+ if err = cli.ContainerRemove(ctx, container.ID, types.ContainerRemoveOptions{}); err != nil {
+ return "", err
+ }
+ }
+ }
info, err := cli.ContainerCreate(ctx, &container.Config{
Image: imageName,
- }, nil, nil, "kubeos-temp")
+ }, nil, nil, containerName)
if err != nil {
return "", err
}
@@ -71,22 +81,31 @@ func pullOSImage(req *pb.UpdateRequest) (string, error) {
return "", fmt.Errorf("space is not enough for downloaing")
}
+ tmpUpdatePath := filepath.Join(PersistDir, "/KubeOS-Update")
+ tmpMountPath := filepath.Join(tmpUpdatePath, "/kubeos-update")
+ tmpTarPath := filepath.Join(tmpUpdatePath, "/os.tar")
+ imagePath := filepath.Join(PersistDir, "/update.img")
+
+ if err = cleanSpace(tmpUpdatePath, tmpMountPath, imagePath); err != nil {
+ return "", err
+ }
+ if err = os.MkdirAll(tmpMountPath, imgPermission); err != nil {
+ return "", err
+ }
+ defer os.RemoveAll(tmpUpdatePath)
+
srcInfo := archive.CopyInfo{
Path: "/",
Exists: true,
IsDir: stat.Mode.IsDir(),
}
- if err = archive.CopyTo(tarStream, srcInfo, PersistDir); err != nil {
+ if err = archive.CopyTo(tarStream, srcInfo, tmpUpdatePath); err != nil {
return "", err
}
-
- tmpMountPath := filepath.Join(PersistDir, "/kubeos-update")
- if err = os.Mkdir(tmpMountPath, imgPermission); err != nil {
+ if err = runCommand("dd", "if=/dev/zero", "of="+imagePath, "bs=2M", "count=1024"); err != nil {
return "", err
}
- defer os.Remove(tmpMountPath)
- imagePath := filepath.Join(PersistDir, "/update.img")
- if err = runCommand("dd", "if=/dev/zero", "of="+imagePath, "bs=2M", "count=1024"); err != nil {
+ if err = os.Chmod(imagePath, imgPermission); err != nil {
return "", err
}
_, next, err := getNextPart(partA, partB)
@@ -102,10 +121,62 @@ func pullOSImage(req *pb.UpdateRequest) (string, error) {
}()
logrus.Infoln("downloading to file " + imagePath)
- tmpTarPath := filepath.Join(PersistDir, "/os.tar")
if err = runCommand("tar", "-xvf", tmpTarPath, "-C", tmpMountPath); err != nil {
return "", err
}
- defer os.Remove(tmpTarPath)
return imagePath, nil
}
+
+func cleanSpace(updatePath, mountPath, imagePath string) error {
+ isFileExist, err := checkFileExist(mountPath)
+ if err != nil {
+ return err
+ }
+ if isFileExist {
+ var st syscall.Stat_t
+ if err := syscall.Lstat(mountPath, &st); err != nil {
+ return err
+ }
+ dev := st.Dev
+ parent := filepath.Dir(mountPath)
+ if err := syscall.Lstat(parent, &st); err != nil {
+ return err
+ }
+ if dev != st.Dev {
+ if err := syscall.Unmount(mountPath, 0); err != nil {
+ return err
+ }
+ }
+ }
+
+ if err = deleteFile(updatePath); err != nil {
+ return err
+ }
+
+ if err = deleteFile(imagePath); err != nil {
+ return err
+ }
+ return nil
+}
+
+func deleteFile(path string) error {
+ isFileExist, err := checkFileExist(path)
+ if err != nil {
+ return err
+ }
+ if isFileExist {
+ if err = os.RemoveAll(path); err != nil {
+ return err
+ }
+ }
+ return nil
+}
+func checkFileExist(path string) (bool, error) {
+ if _, err := os.Stat(path); err == nil {
+ return true, nil
+ } else if errors.Is(err, os.ErrNotExist) {
+ return false, nil
+ } else {
+ return false, err
+ }
+}
diff --git a/scripts/grub.cfg b/scripts/grub.cfg
index d10e4cf..c1a2641 100644
--- a/scripts/grub.cfg
+++ b/scripts/grub.cfg
@@ -91,11 +91,6 @@ menuentry 'A' --class KubeOS --class gnu-linux --class gnu --class os --unrestri
insmod part_msdos
insmod ext2
set root='hd0,msdos2'
- if [ x$feature_platform_search_hint = xy ]; then
- search --no-floppy --file --set=root --hint-bios=hd0,msdos2 --hint-efi=hd0,msdos2 --hint-baremetal=ahci0,msdos2 /boot/vmlinuz
- else
- search --no-floppy --file --set=root /boot/vmlinuz
- fi
linux /boot/vmlinuz root=/dev/sda2 ro rootfstype=ext4 nomodeset quiet oops=panic softlockup_panic=1 nmi_watchdog=1 rd.shell=0 selinux=0 crashkernel=256M panic=3
initrd /boot/initramfs.img
}
@@ -107,11 +102,6 @@ menuentry 'B' --class KubeOS --class gnu-linux --class gnu --class os --unrestri
insmod part_msdos
insmod ext2
set root='hd0,msdos3'
- if [ x$feature_platform_search_hint = xy ]; then
- search --no-floppy --file --set=root --hint-bios=hd0,msdos3 --hint-efi=hd0,msdos3 --hint-baremetal=ahci0,msdos3 /boot/vmlinuz
- else
- search --no-floppy --file --set=root /boot/vmlinuz
- fi
linux /boot/vmlinuz root=/dev/sda3 ro rootfstype=ext4 nomodeset quiet oops=panic softlockup_panic=1 nmi_watchdog=1 rd.shell=0 selinux=0 crashkernel=256M panic=3
initrd /boot/initramfs.img
}
--
2.33.0.windows.2

View File

@ -1,18 +1,18 @@
# Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
Name: KubeOS
Version: 1.0.2
Release: 5
Version: 1.0.6
Release: 2
Summary: O&M platform used to update the whole OS as an entirety
License: Mulan PSL v2
Source0: https://gitee.com/openeuler/KubeOS/repository/archive/v%{version}.tar.gz
Patch1: 0001-Write-a-tool-to-support-KubeOS-deployment-on-physica.patch
Patch2: 0002-KubeOS-fix-the-kbimg.sh-exception-and-pxe-installati.patch
Patch3: 0003-KubeOS-fixed-the-issue-of-VMs-images-and-add-check-o.patch
Patch4: 0004-KubeOS-add-the-clearing-of-space-before-the-upgrade-.patch
Patch1: 0001-Bump-kubeos-version-to-1.0.6.patch
Patch2: 0002-fix-update-bootloader.sh-paths-for-EFI-boot.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-build
BuildRequires: make
BuildRequires: make rust cargo openssl-devel
BuildRequires: golang >= 1.13
%description
This is an O&M platform used to update the whole OS as an entirety,
it should be running in kubernetes environment.
@ -32,14 +32,24 @@ The scripts package includes scripts which could build the os image and binaries
%{nil}
%build
mkdir ./KubeOS-Rust/.cargo
cat << EOF >> ./KubeOS-Rust/.cargo/config
[source.crates-io]
replace-with = "vendored-sources"
[source.vendored-sources]
directory = "vendor"
EOF
make
%install
install -d %{buildroot}%{_bindir}
#install binary
install -d -m 0740 %{buildroot}/opt/kubeOS/bin
install -p -m 0500 ./bin/os-agent %{buildroot}/opt/kubeOS/bin
install -p -m 0500 ./bin/proxy %{buildroot}/opt/kubeOS/bin
install -p -m 0500 ./bin/rust/release/os-agent %{buildroot}/opt/kubeOS/bin
install -p -m 0500 ./bin/rust/release/proxy %{buildroot}/opt/kubeOS/bin
install -p -m 0500 ./bin/operator %{buildroot}/opt/kubeOS/bin
#install artifacts
@ -74,8 +84,8 @@ install -p -m 0600 ./files/os-agent.service %{buildroot}/opt/kubeOS/files
install -p -m 0600 ./files/os-release %{buildroot}/opt/kubeOS/files
%files
%attr(0500,root,root) /opt/kubeOS/bin/os-agent
%defattr(-,root,root,0500)
%attr(0500,root,root) /opt/kubeOS/bin/os-agent
%attr(0600,root,root) /opt/kubeOS/files/boot-efi.mount
%attr(0600,root,root) /opt/kubeOS/files/etc.mount
%attr(0600,root,root) /opt/kubeOS/files/persist.mount
@ -105,11 +115,40 @@ install -p -m 0600 ./files/os-release %{buildroot}/opt/kubeOS/files
%attr(0500,root,root) /opt/kubeOS/scripts/00bootup/module-setup.sh
%attr(0500,root,root) /opt/kubeOS/scripts/00bootup/mount.sh
%clean
rm -rfv %{buildroot}
%changelog
* Tue Jun 18 2024 Yuhang Wei<weiyuhang3@huawei.com> - 1.0.6-2
- Type:requirement
- CVE:NA
- SUG:restart
- DESC:modify version display and fix the path for EFI boot in bootloader.sh
* Tue Jun 11 2024 Yuhang Wei<weiyuhang3@huawei.com> - 1.0.6-1
- Type:requirement
- CVE:NA
- SUG:restart
- DESC:update version to 1.0.6-1
* Thu Dec 08 2022 liyuanrong<liyuanrong1@huawei.com> - 1.0.2-8
- Type:requirement
- CVE:NA
- SUG:restart
- DESC:fix usage does not print when an error occurs in the upgrade image creation
* Tue Nov 29 2022 liyuanrong<liyuanrong1@huawei.com> - 1.0.2-7
- Type:requirement
- CVE:NA
- SUG:restart
- DESC:remove grub2 legacy install, add error handling for opstype and add entry for unit test in Makefile
* Sat Sep 03 2022 liyuanrong<liyuanrong1@huawei.com> - 1.0.2-6
- Type:requirement
- CVE:NA
- SUG:restart
- DESC:add the configuration of /etc/resolv.conf and change the VM disk to gpt.
* Wed Aug 31 2022 liyuanrong<liyuanrong1@huawei.com> - 1.0.2-5
- Type:requirement
- CVE:NA
@ -158,7 +197,7 @@ rm -rfv %{buildroot}
- SUG:restart
- DESC:fix bugs of checks in generate.sh and change module path
* Fri Oct 30 2021 liyuanrong<liyuanrong1@huawei.com> - 1.0.1-2
* Sat Oct 30 2021 liyuanrong<liyuanrong1@huawei.com> - 1.0.1-2
- Type:requirement
- CVE:NA
- SUG:restart

Binary file not shown.

BIN
v1.0.6.tar.gz Normal file

Binary file not shown.