]> Zhao Yanbai Git Server - kernel.git/commitdiff
用 docker cp 的方式解决文件不同步的问题
authoracevest <zhaoyanbai@126.com>
Sat, 13 Apr 2024 05:53:45 +0000 (13:53 +0800)
committeracevest <zhaoyanbai@126.com>
Sat, 13 Apr 2024 05:53:45 +0000 (13:53 +0800)
mkiso.sh
scripts/backup/README.md [new file with mode: 0644]
scripts/backup/container.mkiso.sh [moved from scripts/mkiso.sh with 100% similarity]
scripts/backup/host.mkiso.sh [new file with mode: 0755]

index 8efcd86923bbaf2c4200b50bcba833f8db9404e9..ad5e640a19c329c97b34775d7bfb02c64cfd107d 100755 (executable)
--- a/mkiso.sh
+++ b/mkiso.sh
@@ -20,32 +20,37 @@ echo "container id ${CONTAINER_ID}"
 sync
 
 
+mkrootfs -name rootfs -path initrd
+
+grub2_boot_dir="/tmp/iso/boot"
+docker exec -it $CONTAINER_ID rm -rf /tmp/iso
+docker exec -it $CONTAINER_ID rm -rf /tmp/kernel.iso
+docker exec -it $CONTAINER_ID mkdir -p $grub2_boot_dir/grub/
+
 
 # 指定要拷贝的文件和目标文件路径及名字
-files[0]="KERNEL.ELF:Kernel"
-files[1]="scripts/iso.grub.cfg:grub/grub.cfg"
+files[0]="KERNEL.ELF:$grub2_boot_dir/Kernel"
+files[1]="scripts/iso.grub.cfg:$grub2_boot_dir/grub/grub.cfg"
+files[2]="rootfs:$grub2_boot_dir/rootfs"
 
-declare -a params
 
 for i in "${!files[@]}"; do
     file_line="${files[$i]}"
     
     IFS=':' read -ra parts <<< "${file_line}"
     src_file="${parts[0]}"
+    dst_file="${parts[1]}"
     src_file_md5=$($MD5 "$src_file" | awk '{ print $1 }')
 
-    s="$src_file_md5:$file_line"
-
-    params[$i]="$s"
-
-    echo "$s"
+    docker cp $src_file $CONTAINER_ID:$dst_file
+    echo "$src_file $src_file_md5"
+    docker exec -it $CONTAINER_ID md5sum $dst_file
 done
 
-#echo ${params[@]}
+#docker exec -it $CONTAINER_ID /usr/bin/grub2-mkrescue -o /tmp/kernel.iso /tmp/iso/
+docker exec -it $CONTAINER_ID bash -c "cd /tmp && grub2-mkrescue -o kernel.iso /tmp/iso/"
 
-params_line="${params[@]}"
-docker exec -it $CONTAINER_ID /bin/bash -c "cd /root/workspace/kernel && ./scripts/mkiso.sh ${params_line}"
 
-sync
+docker cp $CONTAINER_ID:/tmp/kernel.iso .
 
 $MD5 kernel.iso
diff --git a/scripts/backup/README.md b/scripts/backup/README.md
new file mode 100644 (file)
index 0000000..b44640b
--- /dev/null
@@ -0,0 +1,11 @@
+这两个脚本开始是为了解决宿主机和 docker 容器无法及时同步文件的问题.
+
+但这样写感觉不太优雅,废弃
+
+如果要再使用,注意的是要放在正确的目录
+
+host.mkiso.sh 放到 kernel/mkiso.sh
+container.mkiso.sh 放到 kernel/scripts/mkiso.sh
+
+host.mkiso.sh要在宿主机调用
+container.mkiso.sh会提交到 docker 容器执行
diff --git a/scripts/backup/host.mkiso.sh b/scripts/backup/host.mkiso.sh
new file mode 100755 (executable)
index 0000000..8efcd86
--- /dev/null
@@ -0,0 +1,51 @@
+#!/bin/bash
+
+# 兼容md5 命令
+MD5=md5sum
+if [[ `uname` == 'Darwin' ]]; then
+    MD5="md5 -q"
+fi
+
+
+# 找到容器
+if [ $# -ne 1 ]; then
+    docker ps -a
+    echo "input containerid "
+    read CONTAINER_ID
+else
+    CONTAINER_ID=$1
+fi
+
+echo "container id ${CONTAINER_ID}"
+sync
+
+
+
+# 指定要拷贝的文件和目标文件路径及名字
+files[0]="KERNEL.ELF:Kernel"
+files[1]="scripts/iso.grub.cfg:grub/grub.cfg"
+
+declare -a params
+
+for i in "${!files[@]}"; do
+    file_line="${files[$i]}"
+    
+    IFS=':' read -ra parts <<< "${file_line}"
+    src_file="${parts[0]}"
+    src_file_md5=$($MD5 "$src_file" | awk '{ print $1 }')
+
+    s="$src_file_md5:$file_line"
+
+    params[$i]="$s"
+
+    echo "$s"
+done
+
+#echo ${params[@]}
+
+params_line="${params[@]}"
+docker exec -it $CONTAINER_ID /bin/bash -c "cd /root/workspace/kernel && ./scripts/mkiso.sh ${params_line}"
+
+sync
+
+$MD5 kernel.iso