您现在的位置是: 网站首页 >服务部署 服务部署

【ipxe、clonezilla】iPXE启动Clonezilla实现镜像自动恢复及硬盘健康值检测探索

admin2020年5月17日 14:27 Clonezilla | Linux | Shell 27人已围观

# ipxe参数迭代 ## Ver1.0 ```bash #!ipxe kernel {{ http_svr }}/clonezilla/live/vmlinuz initrd {{ http_svr }}/clonezilla/live/initrd.img imgargs vmlinuz boot=live union=overlay fetch={{ http_svr }}/clonezilla/live/filesystem.squashfs username=user hostname=wily config quiet components noswap edd=on nomodeset nodmraid noeject locales=en_US.UTF-8 keyboard-layouts=NONE ocs_prerun1="dhclient -v eth0" ocs_prerun2="sleep 2" ocs_prerun3="mount -t cifs -o user={{ user_name }},password={{ user_password }} {{ image_server_path }} {{ image_path }}" ocs_live_run="ocs-live-restore" ocs_live_extra_param="-g auto -scr -batch -p reboot restoredisk {{ image_name }} {{ disk_num }}" ocs_live_batch=yes vga=788 ip= net.ifnames=0 splash i915.blacklist=yes radeonhd.blacklist=yes nouveau.blacklist=yes vmwgfx.enable_fbdev=1 boot ``` ## Ver2.0 ```bash #!ipxe kernel {{ http_svr }}/clonezilla/live/vmlinuz initrd {{ http_svr }}/clonezilla/live/initrd.img imgargs vmlinuz boot=live union=overlay fetch={{ http_svr }}/clonezilla/live/filesystem.squashfs username=user hostname=wily config quiet components noswap edd=on nomodeset nodmraid noeject locales=en_US.UTF-8 keyboard-layouts=NONE ocs_prerun1="dhclient -v eth0" ocs_prerun2="sleep 2" ocs_prerun3="mount -t cifs -o user={{ user_name }},password={{ user_password }} {{ image_server_path }} {{ image_path }}" ocs_live_run="ocs-live-restore" ocs_live_extra_param="-g auto -nogui -batch -r -p reboot restoredisk {{ image_name }} {{ disk_num }}" ocs_live_batch=yes vga=788 ip= net.ifnames=0 splash i915.blacklist=yes radeonhd.blacklist=yes nouveau.blacklist=yes vmwgfx.enable_fbdev=1 boot ``` ### 探索 ```bash ocs_prerun3="mount -t cifs -o user=imagman,password=pxe-svr //192.168.96.166/images /home/partimag" ocs_live_run="ocs-live-restore" ocs_live_extra_param="-g auto -nogui -batch -r -p reboot restoredisk Vostro3900-GTX745-Win7 sda" reboot --> choose ocs_live_batch=yes 确认执行 -p 参数 poweroff reboot cmd return1 ``` ## Ver3.0 ```bash #!ipxe kernel {{ http_svr }}/clonezilla/live/vmlinuz initrd {{ http_svr }}/clonezilla/live/initrd.img imgargs vmlinuz boot=live union=overlay fetch={{ http_svr }}/clonezilla/live/filesystem.squashfs username=user hostname=wily config quiet components noswap edd=on nomodeset nodmraid noeject locales=en_US.UTF-8 keyboard-layouts=NONE ocs_prerun1="dhclient -v eth0" ocs_prerun2="sleep 2" ocs_prerun3="mount -t cifs -o user={{ user_name }},password={{ user_password }} {{ image_server_path }} {{ image_path }}" ocs_live_run="ocs-live-restore" ocs_live_extra_param="-g auto -nogui -batch -r -o0 -o1 -p reboot restoredisk {{ image_name }} {{ disk_num }}" ocs_live_batch=yes vga=788 ip= net.ifnames=0 splash i915.blacklist=yes radeonhd.blacklist=yes nouveau.blacklist=yes vmwgfx.enable_fbdev=1 boot ``` ## Ver4.0(2017.07.03) ```bash #!ipxe kernel {{ http_svr }}/clonezilla/live/vmlinuz initrd {{ http_svr }}/clonezilla/live/initrd.img imgargs vmlinuz boot=live union=overlay fetch={{ http_svr }}/clonezilla/live/lr.filesystem.squashfs username=user config components quiet noswap edd=on nomodeset noeject locales=en_US.UTF-8 keyboard-layouts=NONE ocs_prerun1="dhclient -v eth0" ocs_prerun2="sleep 2" ocs_prerun3="LC_ALL=C mount -t cifs -o user={{ user_name }},vers=2.1,password={{ user_password }} {{ image_server_path }} {{ image_path }}" ocs_live_run="ocs-sr -g auto -e1 auto -e2 -nogui -batch -r -j2 -o0 -o1 -scr -p reboot restoredisk {{ image_name }} {{ disk_num }}" ocs_live_extra_param="" ocs_live_batch="yes" vga=791 ip= net.ifnames=0 nosplash i915.blacklist=yes radeonhd.blacklist=yes nouveau.blacklist=yes vmwgfx.enable_fbdev=1 boot ``` ## Ver5.0(2017.07.13,支持UEFI+Leagcy) > 修改为支持UEFI加传统启动方式 ```bash #!ipxe kernel {{ http_svr }}/clonezilla/live/vmlinuz initrd=initrd.img boot=live union=overlay fetch={{ http_svr }}/clonezilla/live/lr.filesystem.squashfs username=user config components quiet noswap edd=on nomodeset noeject locales=en_US.UTF-8 keyboard-layouts=NONE ocs_prerun1="dhclient -v eth0" ocs_prerun2="sleep 2" ocs_prerun3="LC_ALL=C mount -t cifs -o user={{ user_name }},vers=2.1,password={{ user_password }} {{ image_server_path }} {{ image_path }}" ocs_live_run="ocs-sr -g auto -e1 auto -e2 -nogui -batch -r -j2 -o0 -o1 -scr -p reboot restoredisk {{ image_name }} {{ disk_num }}" ocs_live_extra_param="" ocs_live_batch="yes" vga=791 ip= net.ifnames=0 nosplash i915.blacklist=yes radeonhd.blacklist=yes nouveau.blacklist=yes vmwgfx.enable_fbdev=1 initrd {{ http_svr }}/clonezilla/live/initrd.img boot ``` ## Ver6.0(安装前后脚本执行) > 增加恢复前后访问服务器功能,修改 filesystem.squashfs 文件名 > 支持`-o0`、`-o1`参数,即安装前后执行脚本 ```bash #!ipxe kernel {{ http_svr }}/clonezilla/live/vmlinuz initrd=initrd.img boot=live union=overlay fetch={{ http_svr }}/clonezilla/live/v1.web.filesystem.squashfs username=user config components quiet noswap edd=on nomodeset noeject locales=en_US.UTF-8 keyboard-layouts=NONE ocs_prerun1="dhclient -v eth0" ocs_prerun2="sleep 2" ocs_prerun3="LC_ALL=C mount -t cifs -o user={{ user_name }},vers=2.1,password={{ user_password }} {{ image_server_path }} {{ image_path }}" ocs_live_run="ocs-sr -g auto -e1 auto -e2 -nogui -batch -r -j2 -o0 -o1 -scr -p reboot restoredisk {{ image_name }} {{ disk_num }}" ocs_live_extra_param="" ocs_live_batch="yes" vga=791 ip= net.ifnames=0 nosplash i915.blacklist=yes radeonhd.blacklist=yes nouveau.blacklist=yes vmwgfx.enable_fbdev=1 initrd {{ http_svr }}/clonezilla/live/initrd.img boot ``` ## Ver7.0(自动选择硬盘) > 自动选择硬盘增加,修改 filesystem.squashfs 文件名 > 使用`ep-ocs-sr`脚本代替`ocs-sr`脚本执行恢复 ```bash #!ipxe kernel {{ http_svr }}/clonezilla/live/vmlinuz initrd=initrd.img boot=live union=overlay fetch={{ http_svr }}/clonezilla/live/v2.autodisk.filesystem.squashfs username=user config components quiet noswap edd=on nomodeset noeject locales=en_US.UTF-8 keyboard-layouts=NONE ocs_prerun1="dhclient -v eth0" ocs_prerun2="sleep 2" ocs_prerun3="LC_ALL=C mount -t cifs -o user={{ user_name }},vers=2.1,password={{ user_password }} {{ image_server_path }} {{ image_path }}" ocs_live_run="ep-ocs-sr -g auto -e1 auto -e2 -nogui -batch -r -j2 -o0 -o1 -scr -p reboot restoredisk {{ image_name }}" ocs_live_extra_param="" ocs_live_batch="yes" vga=791 ip= net.ifnames=0 nosplash i915.blacklist=yes radeonhd.blacklist=yes nouveau.blacklist=yes vmwgfx.enable_fbdev=1 initrd {{ http_svr }}/clonezilla/live/initrd.img boot ``` ## Ver8.0(更新到新版Clonezilla参数) > Clonezilla版本升级到2.6.6 > 重新对 filesystem.squashfs 镜像进行修改:增加`ep-ocs-sr`、`check_disk_health.sh`脚本 > 增加`-icds`、`-ps`等参数 ```bash #!ipxe kernel {{ http_svr }}/clonezilla/live/vmlinuz initrd=initrd.img boot=live union=overlay fetch={{ http_svr }}/clonezilla/live/v2.autodisk.filesystem.squashfs username=user config components quiet noswap edd=on nomodeset noeject locales=en_US.UTF-8 keyboard-layouts=NONE ocs_prerun1="dhclient -v eth0" ocs_prerun2="sleep 2" ocs_prerun3="LC_ALL=C mount -t cifs -o user={{ samba_username }},vers=2.1,password={{ samba_password }} {{ image_path }} {{ image_load_path }}" ocs_live_run="ep-ocs-sr -g auto -e1 auto -e2 -nogui -batch -r -icds -j2 -o0 -o1 -ps -k1 -scr -p reboot restoredisk {{ image_name }}" ocs_live_extra_param="" ocs_live_batch="yes" vga=791 ip= net.ifnames=0 nosplash i915.blacklist=yes radeonhd.blacklist=yes nouveau.blacklist=yes vmwgfx.enable_fbdev=1 initrd {{ http_svr }}/clonezilla/live/initrd.img boot ``` # -o0和-o1执行脚本 \clonezilla-live-2.5.0-25-amd64\live\**filesystem.squashfs** 可以使用7z解压filesystem.squashfs 原始脚本所在目录:`\usr\sbin`,所有`osc`开头的 ## -o0参数(恢复前) 客户端复制前执行目录`$OSC_PRERUN_DIR`下的执行脚本 所在目录:`\usr\share\drbl\prerun\ocs` ### 脚本01:恢复前请求服务器 通过`wget`访问url会下载文件需要使用**rm -f \complete***删除下载的文件,脚本名称不同正是因为这个删除会删掉所有以...开头的文件 **request_start.sh** ```bash #/usr/bin/env bash NIC=eth0 MAC=`LANG=C ifconfig $NIC | awk '/HWaddr/{ print $5 }' ` IP=`LANG=C ifconfig $NIC | awk '/inet addr:/{ print $2 }' | awk -F: '{print $2 }'` MASK=`LANG=C ifconfig $NIC | awk -F: '/Mask/{print $4}'` if [ -f /etc/resolv.conf ]; then dns=`awk '/^nameserver/{print $2}' /etc/resolv.conf ` fi #---------------------------- echo "Your network information is as below:" echo $MAC echo $IP echo $dns wget -t 2 -T 2 -w 1 http://192.168.96.20/start_request?mac=$MAC\&ip=$IP wget -t 2 -T 2 -w 1 http://172.16.66.88/start_request?mac=$MAC\&ip=$IP rm -f \start* ``` **clonezilla版本** ```bash #!/bin/bash NIC=eth0 MAC=`LANG=C ifconfig $NIC | grep ether | awk '{print $2}'` IP=`LANG=C ifconfig $NIC | grep netmask | awk '{print $2 }'` echo $MAC echo $IP wget -t 2 -T 2 -w 1 http://192.168.96.20/complete_request?mac=$MAC\&ip=$IP wget -t 2 -T 2 -w 1 http://172.16.66.88/complete_request?mac=$MAC\&ip=$IP rm -f \start* ``` ### 脚本02:硬盘S.M.A.R.T.检测 #### 引言 我们在使用Clonezilla恢复系统时,系统恢复完了,才能使用自动化配置脚本完成硬盘检测,如果在这时发现硬盘有故障的,之前的工作就白费了。特别是故障硬盘就是安装系统的,如果是机器中的其他硬盘还好。 考虑在进入系统安装过程前就能对硬盘进行一次检测,正好Clonezilla系统中自带`smartctl`,可以直接拿来使用。 主要是检测05、B8、C5这三项比较重要的数值。 #### 测试 Clonezilla自带`smartctl`命令 ```bash # 查看所有硬盘 sudo fdisk -l | grep "Disk /dev/sd" | cut -d " " -f 2 | cut -d ":" -f 1 # 获取命令结果并循环 for disk in `sudo fdisk -l | grep "Disk /dev/sd" | cut -d " " -f 2 | cut -d ":" -f 1` do # 输出磁盘名称 echo -e "\033[35m$disk\033[0m" # 检测磁盘健康状态,但是这个就算是有05、C5错误也会PASSED,检测不准确 sudo smartctl -H $disk done ``` 检测SMART信息,05(5)、B8(184)、C5(197) ```bash # 首列有空格,显示以0个或以上数量" "开头的行,并打印第10列 # 显示05值异常的值 sudo smartctl -A /dev/sdb | awk /^" "*5/'{print $10}' # 显示B8值异常的值 sudo smartctl -A /dev/sdb | awk /^" "*184/'{print $10}' # 显示C5值异常的值 sudo smartctl -A /dev/sdb | awk /^" "*197/'{print $10}' # 或 function check_smart(){ # 调用方式:check_smart /dev/sda V_05=$(sudo smartctl -A $1 | awk '$2 ~ /Reallocated_Sector_Ct/ {print $10}') if [ "$V_05" -gt 0 ] then echo Error else echo Normal fi echo V_B8=$(sudo smartctl -A $1 | awk '$2 ~ /End-to-End_Error/ {print $10}') if [ "$V_B8" -gt 0 ] then echo Error else echo Normal fi echo V_C5=$(sudo smartctl -A $1 | awk '$2 ~ /Current_Pending_Sector/ {print $10}') if [ "$V_C5" -gt 0 ] then echo Error else echo Normal fi echo } ``` #### Ver1.0 ```bash #!/bin/bash #Filename: $1 #Author : StarMeow #Mail : starmeow@qq.com #Date : `date +"%F %T"` #Description: # Clonezilla在安装系统前检测硬盘健康值,好在自带smartctl,可以直接拿来使用 # 1、cd /usr/fileshare/clonezilla-live-2.6.6-15-amd64/clonezilla/live/ # 2、解包 filesystem.squashfs 文件: unsquashfs filesystem.squashfs # 3、进入目录 cd squashfs-root/usr/share/drbl/prerun/ocs/ 目录 # 4、创建一个文件 vim.tiny check_disk_health.sh 添加下面脚本内容 # 5、最后执行 chmod +x check_disk_health.sh # 6、重新进入目录: cd /usr/fileshare/clonezilla-live-2.6.6-15-amd64/clonezilla/live/ # 7、如果有 squashfs-root 目录,需要先删除 rm -r squashfs-root # 8、封包 filesystem.squashfs 文件: mksquashfs squashfs-root v2.autodisk.filesystem.squashfs function echoDanger(){ # 红底黑字 echo -e "\033[41;30m $1 \033[0m" } function echoWarning(){ # 黄底白字 echo -e "\033[43;37m $1 \033[0m" } function echoInfo(){ # 青底黑字 echo -e "\033[46;30m $1 \033[0m" } function echoSuccess(){ # 绿底黑字 echo -e "\033[42;30m $1 \033[0m" } function echoPrimary(){ # 蓝底白字 echo -e "\033[44;37m $1 \033[0m" } function get_disk_info(){ # 参数一:/dev/sda (磁盘) # 调用方式:get_disk_info /dev/sda # 获取硬盘信息 DISK=$(sudo smartctl --info $1) FAMILY=$(echo "$DISK" | grep "Model Family" | cut -d ":" -f 2 | awk '$1=$1') # | awk '$1=$1'是去掉前后空格 MODEL=$(echo "$DISK" | grep "Device Model" | cut -d ":" -f 2 | awk '$1=$1') SERIAL=$(echo "$DISK" | grep "Serial Number" | cut -d ":" -f 2 | awk '$1=$1') echoPrimary "$FAMILY-$MODEL($SERIAL)" echo echo } function check_disk_smart(){ # 参数一:/dev/sda (磁盘);参数二:05、C5(检测值);参数三:搜索关键字 # 调用方式:check_disk_smart /dev/sda C5 Current_Pending_Sector # 检查磁盘SMART值 # VALUE=$(sudo smartctl -A $1 | awk '$2 ~ /Reallocated_Sector_Ct/ {print $10}') VALUE=$(sudo smartctl -A $1 | grep $3 | awk '{print $10}') if test -z "$VALUE" then echoInfo "S.M.A.R.T. $2 does not exist!" else if [ "$VALUE" -gt 0 ] then echoDanger "S.M.A.R.T. $2 Error, Current Value: $VALUE, Shutdown and check the hard disk!" sleep 8 else echoSuccess "S.M.A.R.T. $2 check normal!" fi fi echo } clear echo -e '\n\n\n\n\n\n' echo -e "\033[34mStart detecting hard disk--->\033[0m" echo -e '\n\n' for disk in `sudo fdisk -l | grep "Disk /dev/sd" | cut -d " " -f 2 | cut -d ":" -f 1` do # 输出磁盘名称 echo -e "\033[34m$disk\033[0m" # 获取磁盘信息 get_disk_info $disk # 检测磁盘SMART值 check_disk_smart $disk 05 Reallocated_Sector_Ct check_disk_smart $disk B8 End-to-End_Error check_disk_smart $disk C5 Current_Pending_Sector echo -e '\n\n' sleep 1 done echo -e "\033[34m<---End detection of hard disk\033[0m" echo -e '\n\n' ``` 启动显示 ![BLOG_20200517_142951_68](/media/blog/images/2020/05/BLOG_20200517_142951_68.png "博客图集BLOG_20200517_142951_68.png") #### Ver2.0(支持检测nvme硬盘) ```bash #!/bin/bash #Filename: $1 #Author : StarMeow #Mail : starmeow@qq.com #Date : `date +"%F %T"` #Description: # Clonezilla在安装系统前检测硬盘健康值,好在自带smartctl,可以直接拿来使用 # 1、cd /usr/fileshare/clonezilla-live-2.6.6-15-amd64/clonezilla/live/ # 2、解包 filesystem.squashfs 文件: unsquashfs filesystem.squashfs # 3、进入目录 cd squashfs-root/usr/share/drbl/prerun/ocs/ 目录 # 4、创建一个文件 vim.tiny check_disk_health.sh 添加下面脚本内容 # 5、最后执行 chmod +x check_disk_health.sh # 6、重新进入目录: cd /usr/fileshare/clonezilla-live-2.6.6-15-amd64/clonezilla/live/ # 7、如果有 squashfs-root 目录,需要先删除 rm v2.autodisk.filesystem.squashfs # 8、封包 filesystem.squashfs 文件: mksquashfs squashfs-root v2.autodisk.filesystem.squashfs function echoDanger(){ # 红底黑字 echo -e "\033[41;30m $1 \033[0m" } function echoWarning(){ # 黄底白字 echo -e "\033[43;37m $1 \033[0m" } function echoInfo(){ # 青底黑字 echo -e "\033[46;30m $1 \033[0m" } function echoSuccess(){ # 绿底黑字 echo -e "\033[42;30m $1 \033[0m" } function echoPrimary(){ # 蓝底白字 echo -e "\033[44;37m $1 \033[0m" } function get_disk_info(){ # 参数一:/dev/sda (磁盘) # 调用方式:get_disk_info /dev/sda # 获取硬盘信息 DISK=$(sudo smartctl --info $1) FAMILY=$(echo "$DISK" | grep "Model Family" | cut -d ":" -f 2 | awk '$1=$1') # | awk '$1=$1'是去掉前后空格 MODEL=$(echo "$DISK" | grep "Device Model" | cut -d ":" -f 2 | awk '$1=$1') SERIAL=$(echo "$DISK" | grep "Serial Number" | cut -d ":" -f 2 | awk '$1=$1') echoPrimary "$FAMILY-$MODEL($SERIAL)" echo echo } function check_disk_smart(){ # 参数一:/dev/sda (磁盘);参数二:05、C5(检测值);参数三:搜索关键字 # 调用方式:check_disk_smart /dev/sda C5 Current_Pending_Sector # 检查磁盘SMART值 # VALUE=$(sudo smartctl -A $1 | awk '$2 ~ /Reallocated_Sector_Ct/ {print $10}') VALUE=$(sudo smartctl -A $1 | grep $3 | awk '{print $10}') if test -z "$VALUE" then echoInfo "S.M.A.R.T. $2 does not exist!" else if [ "$VALUE" -gt 0 ] then echoDanger "S.M.A.R.T. $2 Error, Current Value: $VALUE, Shutdown and check the hard disk!" sleep 8 else echoSuccess "S.M.A.R.T. $2 check normal!" fi fi echo } function check_disk_health(){ # 检查磁盘健康,nvme不能识别出smart,只能这样检测了 VALUE=$(sudo smartctl -H $1 | grep PASSED) if test -z "$VALUE" # 没有查到,说明有异常 then echoDanger "$(sudo smartctl -H $1 | grep result)" else echoSuccess "$(sudo smartctl -H $1 | grep result)" fi } clear echo -e '\n\n\n\n\n\n' echo -e "\033[34mStart detecting hard disk--->\033[0m" echo -e '\n\n' for disk in `sudo fdisk -l | egrep "Disk /dev/sd|Disk /dev/nvme" | cut -d " " -f 2 | cut -d ":" -f 1` do # 输出磁盘名称 echo -e "\033[34m$disk\033[0m" # 获取磁盘信息 get_disk_info $disk nvme="nvme" if [[ $disk =~ $nvme ]] then # 查看nvme硬盘的健康状态 check_disk_health $disk else # 检测磁盘SMART值 check_disk_smart $disk 05 Reallocated_Sector_Ct check_disk_smart $disk B8 End-to-End_Error check_disk_smart $disk C5 Current_Pending_Sector fi echo -e '\n\n' sleep 1 done echo -e "\033[34m<---End detection of hard disk\033[0m" echo -e '\n\n' ``` ## -o1参数(恢复后) 客户端复制后执行目录`$OSC_POSTRUN_DIR`下的执行脚本 所在目录:`\usr\share\drbl\postrun\ocs` ### 脚本01:恢复后请求服务器 **request_complete.sh** ```bash #/usr/bin/env bash NIC=eth0 MAC=`LANG=C ifconfig $NIC | awk '/HWaddr/{ print $5 }' ` IP=`LANG=C ifconfig $NIC | awk '/inet addr:/{ print $2 }' | awk -F: '{print $2 }'` MASK=`LANG=C ifconfig $NIC | awk -F: '/Mask/{print $4}'` if [ -f /etc/resolv.conf ]; then dns=`awk '/^nameserver/{print $2}' /etc/resolv.conf ` fi #---------------------------- echo "Your network information is as below:" echo $MAC echo $IP echo $dns wget http://192.168.96.96:8899/complete_request?mac=$MAC\&ip=$IP rm -f \complete* ``` ```bash **clonezilla版本** #!/bin/bash NIC=eth0 MAC=`LANG=C ifconfig $NIC | grep ether | awk '{print $2}'` IP=`LANG=C ifconfig $NIC | grep netmask | awk '{print $2 }'` echo $MAC echo $IP wget http://192.168.96.96:8899/complete_request?mac=$MAC\&ip=$IP rm -f \complete* ``` # ep-ocs-sr脚本迭代 增加自动选择硬盘 ocs-sr所在目录:/home/user/桌面/squashfs-root/usr/sbin ```bash root@userpxe-svr:~# cd /home/user/桌面/squashfs-root/usr/sbin root@userpxe-svr:/home/user/桌面/squashfs-root/usr/sbin# vim.tiny ocs-sr root@userpxe-svr:/home/user/桌面/squashfs-root/usr/sbin# ls -l ocs-sr -rwxr-xr-x 1 root root 59722 4月 29 16:08 ocs-sr ``` **新版Clonezilla恢复使用`ep-ocs-sr`替代原有的`ocs-sr`加参数执行功能。** ## 获取硬盘大小 ```bash root@PXEControlSystem# fdisk -l Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0xb1946616 Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 40136703 40134656 19.1G 83 Linux /dev/sda2 40138750 41940991 1802242 880M 5 Extended /dev/sda5 40138752 41940991 1802240 880M 82 Linux swap / Solaris ``` ## Ver1.0(2017.08.18,自动选择硬盘,nvme和sata) 自动选择硬盘恢复过程: 执行脚本路径:`桌面/squashfs-root/usr/sbin/ocs-sr` 以前是 `ocs-sr` 接收参数还行,现在使用自己创建的脚本 `ep-ocs-sr` 接收参数处理,然后传递给 `ocs-sr` 进行后续处理 ```bash root@userpxe-svr:/home/user/桌面/squashfs-root# cd usr/sbin/ root@userpxe-svr:/home/user/桌面/squashfs-root/usr/sbin# vim.tiny ep-ocs-sr # 添加下面的脚本 ``` 编辑 ```bash #!/bin/bash #Authors: StarMeow #Description:Clonezilla装机硬盘自动选择 ssd_name="" ssd_model="" ssd_cap="0" get_sth_model_has_sth(){ ts=`sudo hdparm -i /dev/$1 | grep -iEo "Model=.*," | awk -F "," '{print $1}' | sed -s "s/Model=//g" | grep -i $2` tc=`get_cap $1` if [ -n "$ts" ]&&[ $tc -ge 100 ]; then # ssd_cap=$tc echo $ts #echo $tc #ssd_cap=$tc return 0 fi return 1 } get_sth_model_name(){ ssd_model=`sudo hdparm -i /dev/$1 | grep -iEo "Model=.*," | awk -F "," '{print $1}' | sed -s "s/Model=//g"` } get_cap(){ ssd_cap="$(sudo fdisk -l | grep -iEo "Disk /dev/$1: .*GiB," | awk -F " " '{print $3}' | awk -F "." '{print $1}')" echo $ssd_cap } get_ssd(){ #1step if [ -b /dev/nvme0n1 ]; then ssd_name="nvme0n1" echo "find nvme0n1" sleep 2 return 0 else echo "no nvme0n1" fi #2step if [ -n "$(get_sth_model_has_sth sdc ssd)" ]; then ssd_name="sdc" return 0 elif [ -n "$(get_sth_model_has_sth sdb ssd)" ]; then ssd_name="sdb" return 0 elif [ -n "$(get_sth_model_has_sth sda ssd)" ]; then ssd_name="sda" return 0 else echo "no model name has ssd" fi #3step if [ -n "$(get_sth_model_has_sth sda intel)" -o -n "$(get_sth_model_has_sth sda micron)" -o -n "$(get_sth_model_has_sth sda liteon)" ]; then ssd_name="sda" return 0 elif [ -n "$(get_sth_model_has_sth sdb intel)" -o -n "$(get_sth_model_has_sth sdb micron)" -o -n "$(get_sth_model_has_sth sdb liteon)" ]; then ssd_name="sdb" return 0 elif [ -n "$(get_sth_model_has_sth sdc intel)" -o -n "$(get_sth_model_has_sth sdc micron)" -o -n "$(get_sth_model_has_sth sdc liteon)" ]; then ssd_name="sdc" return 0 else echo "no model name has intel micron liteon" fi #last if [ -b /dev/sda ]; then ssd_name="sda" return 0 elif [ -b /dev/sdb ]; then ssd_name="sdb" return 0 elif [ -b /dev/sdc ]; then ssd_name="sdc" return 0 else echo "no sda sdb sdc" fi echo "get_ssd_fail_exit" sleep 5 } get_ssd get_sth_model_name $ssd_name get_cap $ssd_name #echo $ssd_cap echo "select $ssd_name , model is $ssd_model, cap is $ssd_cap GiB" echo $* $ssd_name #echo "testdata" #get_sth_model_has_sth sdc liteon #echo "$ssd_cap" #get_cap sdc sleep 5 ocs-sr $* $ssd_name ``` 打包添加执行权限 ```bash root@userpxe-svr:/$ sudo mksquashfs /home/user/桌面/squashfs-root /home/user/桌面/v2.autodisk.filesystem.squashfs root@userpxe-svr:/home/user/桌面/squashfs-root/usr/sbin# chmod +x ep-ocs-sr ``` ## Ver2.0(2018.3.13,支持金士顿硬盘) ```bash # 进入 /usr/fileshare/clonezilla-live-2.6.6-15-amd64/clonezilla/live 解包后 # 进入目录 cd squashfs-root/usr/sbin/ # 如果有先进行备份 squashfs-root/usr/sbin# cp ep-ocs-sr ep-ocs-sr.bak.2020.5.12 squashfs-root/usr/sbin# rm ep-ocs-sr # 没有直接创建 squashfs-root/usr/sbin# vim ep-ocs-sr # 添加下面的脚本 squashfs-root/usr/sbin# chmod +x ep-ocs-sr # 进入 /usr/fileshare/clonezilla-live-2.6.6-15-amd64/clonezilla/live 目录,重新打包 ``` > 增加金士顿硬盘,优化显示 ```bash #!/bin/bash #Authors: StarMeow #Update log #2018年3月13日 增加Kingston SSD支持 #2020年5月7日 修改输出硬盘、镜像显示信息 #解包:unsquashfs filesystem.squashfs #/squashfs-root/usr/sbin# rm ep-ocs-sr #squashfs-root/usr/sbin# vim ep-ocs-sr #squashfs-root/usr/sbin# chmod +x ep-ocs-sr #封包:mksquashfs squashfs-root/ new.filesystem.squashfs disk_name="" disk_model="" disk_cap="0" get_sth_model_has_sth(){ ts=`sudo hdparm -i /dev/$1 | grep -iEo "Model=.*," | awk -F "," '{print $1}' | sed -s "s/Model=//g" | grep -i $2` tc=`get_cap $1` if [ -n "$ts" ]&&[ $tc -ge 100 ]; then # disk_cap=$tc echo $ts #echo $tc #disk_cap=$tc return 0 fi return 1 } get_sth_model_name(){ disk_model=`sudo hdparm -i /dev/$1 | grep -iEo "Model=.*," | awk -F "," '{print $1}' | sed -s "s/Model=//g"` } get_cap(){ disk_cap="$(sudo fdisk -l | grep -iEo "Disk /dev/$1: .*GiB," | awk -F " " '{print $3}' | awk -F "." '{print $1}')" echo $disk_cap } get_ssd(){ #1step if [ -b /dev/nvme0n1 ]; then disk_name="nvme0n1" echo "find nvme0n1" sleep 2 return 0 else echo "no nvme0n1" fi #2step if [ -n "$(get_sth_model_has_sth sdc ssd)" ]; then disk_name="sdc" return 0 elif [ -n "$(get_sth_model_has_sth sdb ssd)" ]; then disk_name="sdb" return 0 elif [ -n "$(get_sth_model_has_sth sda ssd)" ]; then disk_name="sda" return 0 else echo "no model name has ssd" fi #3step if [ -n "$(get_sth_model_has_sth sda intel)" -o -n "$(get_sth_model_has_sth sda micron)" -o -n "$(get_sth_model_has_sth sda liteon)" -o -n "$(get_sth_model_has_sth sda kingston)" ]; then disk_name="sda" return 0 elif [ -n "$(get_sth_model_has_sth sdb intel)" -o -n "$(get_sth_model_has_sth sdb micron)" -o -n "$(get_sth_model_has_sth sdb liteon)" -o -n "$(get_sth_model_has_sth sdb kingston)" ]; then disk_name="sdb" return 0 elif [ -n "$(get_sth_model_has_sth sdc intel)" -o -n "$(get_sth_model_has_sth sdc micron)" -o -n "$(get_sth_model_has_sth sdc liteon)" -o -n "$(get_sth_model_has_sth sdc kingston)" ]; then disk_name="sdc" return 0 else echo "no model name has intel micron liteon kingston" fi #last if [ -b /dev/sda ]; then disk_name="sda" return 0 elif [ -b /dev/sdb ]; then disk_name="sdb" return 0 elif [ -b /dev/sdc ]; then disk_name="sdc" return 0 else echo "no sda sdb sdc" fi echo "get_ssd_fail_exit" sleep 5 } get_ssd get_sth_model_name $disk_name get_cap $disk_name #echo $disk_cap clear echo -e '\n\n\n\n\n\n\n' echo -e '** Information Obtained **\n\n' echo -e "\033[35mSelect Disk Name: $disk_name\033[0m\n" echo -e "\033[35mSelect Disk Model: $disk_model\033[0m\n" echo -e "\033[35mSelect Disk Capacity: $disk_cap GiB\033[0m\n\n\n" echo -e "\033[44;30mCommand: \033[0m$* $disk_name" echo -e '\n\n\n\n\n\n\n' #echo "testdata" #get_sth_model_has_sth sdc liteon #echo "$disk_cap" #get_cap sdc sleep 8 ocs-sr $* $disk_name ``` ### 显示样式 ![BLOG_20200517_142857_48](/media/blog/images/2020/05/BLOG_20200517_142857_48.png "博客图集BLOG_20200517_142857_48.png") # Clonezilla版本升级2.5.2->2.6.6 ![BLOG_20200517_142818_89](/media/blog/images/2020/05/BLOG_20200517_142818_89.png "博客图集BLOG_20200517_142818_89.png") 新版未做修改,内容如下 ![BLOG_20200517_142811_98](/media/blog/images/2020/05/BLOG_20200517_142811_98.png "博客图集BLOG_20200517_142811_98.png") ## 升级步骤 1. 装机页面增加新版 ![BLOG_20200517_142800_98](/media/blog/images/2020/05/BLOG_20200517_142800_98.png "博客图集BLOG_20200517_142800_98.png") 2. 检查Clonezilla恢复选项,进入Clonezilla手动恢复界面选择 `ep-ocs-sr -g auto -e1 auto -e2 -nogui -batch -r -icds -j2 -o0 -o1 -ps -k1 -scr -p reboot restoredisk image_name` `-g auto`:【默认开】可多户端重新安装grub开机管理程序(找到gurb配置文件才会执行) `-e1 auto`:【默认开】如果NTFS开机分割表存在,自动调整文件系统的CHS值 `-e2`:【默认开】用客户端执行sfdisk时强迫使用EDD的硬盘CHS值(用于非grub开机管理程序) `-nogui`:【建议开】只显示文字结果,不用显示图形显示结果 `-v`:使用详细信息(尤其是uppcast的讯息) `-batch`:【建议开】使用批次模式(危险!务必先确认设定正确) `-c`:【建议关】客户端电脑在开始复制前会再次确认是否要执行 `-r`:【建议开】尝试再客户端调整文件系统负荷分区大小 `-icds`:【可以开】创建分区表之前略去检查目的磁盘空间是否够大[Clonezilla live 2.6.6-15日志](https://sourceforge.net/p/clonezilla/bugs/342/) `j2`:【默认开】复制介于MBR与第一个分割表中的隐藏资料 `-o0`:【建议开】客户端复制前执行目录$OSC_PRERUN_DIR下的执行脚本 `-o1`:【建议开】客户端复制后执行目录$OSC_POSTRUN_DIR下的执行脚本 `-ps`:【建议开】复制完成后播放声音 额外高级参数 `-k1`:照比例方法产生的硬盘分割表 `-scr`:还原前略去检查 `-p reboot`还原后重启 3. 修改网站`clonezilla-automatic-selectdisk.html`代码,查看ipxe参数Ver8.0

很赞哦! (1)

文章交流

  • emoji
0人参与,0条评论

当前用户

未登录,点击   登录

站点信息

  • 建站时间:网站已运行657天
  • 系统信息:Linux
  • 后台程序:Python: 3.6.6
  • 网站框架:Django: 2.2.12
  • 文章统计:235 篇
  • 文章评论:40 条
  • 腾讯分析网站概况-腾讯分析
  • 百度统计网站概况-百度统计
  • 公众号:微信扫描二维码,关注我们
  • QQ群:QQ加群,下载网站的学习源码
返回
顶部
标题 换行 登录
网站