/usr/sbin/ocs-chkimg is in clonezilla 3.5.2-2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 | #!/bin/bash
# License: GPL
# Author: Steven Shiau <steven _at_ nchc org tw>
# Description: Program to check the Clonezilla image integrity
# (1) Check the partition table files (GPT included)
# (2) Check the MBR/EFI boot loader
# (3) Check the partition image using partclone.chkimg
#
DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}"
. $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions
. /etc/drbl/drbl-ocs.conf
. $DRBL_SCRIPT_PATH/sbin/ocs-functions
# Load the config in ocs-live.conf. This is specially for Clonezilla live. It will overwrite some settings of /etc/drbl/drbl-ocs.conf, such as $DIA...
[ -e "/etc/ocs/ocs-live.conf" ] && . /etc/ocs/ocs-live.conf
# Settings
# By default we do not check the image saved by dd.
dd_checking_method="no-check"
nogui="off" # Default to turn on TUI
#
USAGE() {
echo "$ocs - To check the image of Clonezilla"
echo "Usage:"
echo "To run $ocs:"
echo "$ocs [OPTION] IMAGE_NAME DEVICE"
echo "Options:"
echo "-b, --batch-mode Run image checking in batch mode"
echo "-nogui, --nogui Do not show GUI (TUI) of Partclone or Partimage, use text only"
echo "-or, --ocsroot DIR Specify DIR (absolute path) as directory ocsroot (i.e. overwrite the ocsroot assigned in drbl.conf)"
echo "IMAGE_NAME is the image dir name, not absolute path"
echo "DEVICE is the device name, e.g. sda1, sda2..."
echo "If \"ask_user\" is used as IMAGE_NAME or DEVICE, a dialog menu will be shown to allow selection."
echo "If no IMAGE_NAME is specified, a dialog menu will be shown."
echo "Ex:"
echo "To check the image \"my-image\", which is located in $ocsroot/my-image, run"
echo " $ocs my-image"
echo
} # end of USAGE
#
img_check_by_partclone() {
local file_ fs_ partclone_img_info_tmp file_basename rc
# First, we find the filesystem
file_="$(unalias ls &>/dev/null; ls $target_d/$img_file.*-img* 2>/dev/null | sort | head -n 1)"
file_basename="$(basename ${file_})"
if [ -n "${file_}" ]; then
if [ -n "$(echo $file_basename | grep -Eo -- "-ptcl-img")" ]; then
# new format, image file is like: sda1.ext4-ptcl-img.gz, sda1.ext4-ptcl-img.gz.aa
fs_="$(echo $file_basename | sed -e "s/^$img_file\.//g" -e "s/-ptcl-img.*//g")"
else
# old format, image file is like: sda2.hfsp-img.aa sda2.hfsp-img.ab sda2.hfsp-img.ac
fs_="$(echo $file_basename | sed -e "s/^$img_file\.//g" -e "s/-img.*//g")"
fi
fi
if [ -z "${fs_}" ]; then
[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
echo "The file system can not be decided in function img_check_by_partclone!!!"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
echo "$msg_program_stop!"
exit 1
fi
if [ -n "$(echo "$file_basename" | grep -Eo -- "-ptcl-img")" ]; then
# New format
if [ -n "$(echo "$file_basename" | grep -Eo -- "-ptcl-img.*.aa")" ]; then
# New format with image split, e.g. sda1.ext4-ptcl-img.gz.aa
get_image_cat_zip_cmd ${file_basename}
# e.g. sda1.ext4-ptcl-img.gz.aa -> sda1.ext4-ptcl-img.gz.*
img_file_prefix="$(echo ${file_basename} | sed -e "s/\.aa$//").*"
else
# New format with image not split, e.g. sda1.ext4-ptcl-img.gz
get_image_cat_zip_cmd ${file_basename}
# The file is NOT split, so the file name is just like "sda1.ext4-ptcl-img.gz" only, no "."
img_file_prefix="${file_basename}"
fi
else
# Old format
if [ -f "$target_d/$img_file.${fs_}-img.aa" ]; then
# Old format with image split
get_image_cat_zip_cmd $target_d/$img_file.${fs_}-img.aa
# The files are split, like hda1.00, hda1.01, so we have to add "."
img_file_prefix="$img_file.${fs_}-img.*"
else
# Old format with image not split
get_image_cat_zip_cmd $target_d/$img_file.${fs_}-img
# The file is NOT split, so the file name is just like "hda1" only, no "."
img_file_prefix="$img_file.${fs_}-img"
fi
fi
echo $msg_delimiter_star_line
# //NOTE// Here we force to use LC_ALL=C for partclone since we need to use get_partclone_image_info to parse the log file to get the rate. Only the keyword in English is supported in get_partclone_image_info.
( for img in $target_d/$img_file_prefix; do
cat $img
done
) | \
$unzip_stdin_cmd | LC_ALL=C partclone.chkimg $PARTCLONE_CHKIMG_OPT -s -
rc="$?"
return $rc
} # end of img_check_by_partclone
#
do_partition_or_lv_img_check() {
# part is like: /dev/hda1
local target_d="$1"
local img_file="$(to_filename $2)"
local rc hdtmp partition
image_name_="$(basename $target_d)"
# get the cat program: cat, zcat or bzcat
if [ -f "$target_d/$img_file.000" -o \
-f "$target_d/$img_file.aa" -o \
-f "$target_d/$img_file" ]; then
# The saved image is from partimage
[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
echo "This partition image was saved by partimage." | tee --append ${OCS_LOGFILE}
echo "$msg_img_check_not_supported" | tee --append ${OCS_LOGFILE}
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
rc=1
if [ "$ocs_batch_mode" != "on" ]; then
echo -n "$msg_press_enter_to_continue..."
read
fi
elif [ -f "$target_d/$img_file.ntfs-img" -o -f "$target_d/$img_file.ntfs-img.aa" ]; then
# The saved image is from ntfsclone
[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
echo "This partition image was saved by ntfsclone." | tee --append ${OCS_LOGFILE}
echo "$msg_img_check_not_supported" | tee --append ${OCS_LOGFILE}
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
rc=1
if [ "$ocs_batch_mode" != "on" ]; then
echo -n "$msg_press_enter_to_continue..."
read
fi
elif is_partclone_image $target_d $img_file; then
# The saved image is from partclone
img_check_by_partclone
rc=$?
if [ "$rc" -gt 0 -a "$ocs_batch_mode" != "on" ]; then
[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
echo "$msg_this_part_in_the_img_is_broken: $img_file" | tee --append ${OCS_LOGFILE}
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
echo -n "$msg_press_enter_to_continue..."
read
else
[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
echo "$msg_this_part_in_the_img_is_ok: $img_file" | tee --append ${OCS_LOGFILE}
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
fi
elif [ -f "$target_d/$img_file.dd-img" -o -f "$target_d/$img_file.dd-img.aa" ]; then
if [ "$dd_checking_method" = "no-check" ]; then
[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
echo "Image was saved by dd. No need to check the file system integrity: $img_file" | tee --append ${OCS_LOGFILE}
sleep 1
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
rc=0
else
# For some of the special partition, even it's dd, we do not need to check that. E.g. VMware vmkcore partition. It only need partition ID=fc, we do not care the content of the file system. Ref: http://communities.vmware.com/thread/85788
# The saved image is from dd
if [ -e "$target_d/$img_file.dd-img.info" ]; then
# Get the paritition info, we will get "$partition"
. $target_d/$img_file.dd-img.info
fi
if [ "$partition" = "VMware_vmkcore_partition" ]; then
echo "VMware vmkcore partition found. No ndeed to check the file system." | tee --append ${OCS_LOGFILE}
rc=0
elif [ "$partition" = "BSD_slice" ]; then
echo "BSD slice found. No ndeed to check the file system." | tee --append ${OCS_LOGFILE}
rc=0
elif [ "$partition" = "BSD_swap_partition" ]; then
echo "BSD swap partition found. No ndeed to check the file system." | tee --append ${OCS_LOGFILE}
rc=0
else
[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
echo "This partition image was saved by dd." | tee --append ${OCS_LOGFILE}
echo "$msg_img_check_not_supported"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
rc=1
if [ "$ocs_batch_mode" != "on" ]; then
echo -n "$msg_press_enter_to_continue..."
read
fi
fi
fi
fi
echo $msg_delimiter_star_line
return $rc
} # end of do_partition_or_lv_img_check
#
task_logv_check() {
# mode is unicast or multicast
local tgt_parts="$1" # tgt_parts is like: hda1 hda2 hda5
local volg is_in_chosen_partition lvm_tmp rc rctlv
PV_PARSE_CONF="$target_dir_fullpath/lvm_vg_dev.list"
LOGV_PARSE_CONF="$target_dir_fullpath/lvm_logv.list"
if [ ! -f "$PV_PARSE_CONF" ]; then
[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
echo "This LVM PV file NOT found: $PV_PARSE_CONF"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
echo -n "$msg_press_enter_to_continue..."
read
fi
if [ ! -f "$LOGV_PARSE_CONF" ]; then
[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
echo "This LVM LV file NOT found: $LOGV_PARSE_CONF"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
echo -n "$msg_press_enter_to_continue..."
read
fi
#
while read lv fs; do
# Then we process the real data partition, only those in the chosen partitions
# Ex:
# /dev/vg3/lvol0 Linux rev 1.0 ext3 filesystem data (large files)
# Then lvol0 is belong to VG vg3
volg="$(echo "$lv" | awk -F"/" '{print $3}')"
# Find if the LV is in the chosen partition (via VG, we can determine that)
# EX: tgt_parts: hda1, hda3, hda5...
# vg3 /dev/hda3 nPMQQ0-D2yN-YRHL-9fBM-0cUm-vgcw-DCUTri
is_in_chosen_partition="no"
for ipt in $tgt_parts; do
if [ -n "$(grep -E "[[:space:]]+/dev/$ipt[[:space:]]+" $PV_PARSE_CONF | grep -E "\<$volg\>")" ]; then
# Found the chosen partitions is in the VG
is_in_chosen_partition="yes"
break
fi
done
# If not in the chosen partition, skip this, continue with the next.
[ "$is_in_chosen_partition" = "no" ] && continue
fn="$(echo $lv | sed -e "s|^/dev/||" -e "s|/|-|g")"
# create the swap if it's swap partition
case "$fs" in
*[Ss][Ww][Aa][Pp]*)
echo $msg_delimiter_star_line
echo "Found the swap partition $lv info:"
# read LABEL, UUID info for $partition if swappt-$(to_filename ${fn}).info exists
uuid_opt=""
label_opt=""
if [ -e "$target_dir_fullpath/swappt-$(to_filename ${fn}).info" ]; then
cat "$target_dir_fullpath/swappt-$(to_filename ${fn}).info"
echo "Swap partition info file found!"
else
[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
echo "$msg_this_swap_part_info_not_found: ${fn}"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
echo -n "$msg_press_enter_to_continue..."
read
fi
echo $msg_delimiter_star_line
# then skip the rest.
continue;;
esac
[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
echo "Checking the device LV $fn in the image \"$(basename $target_dir_fullpath)\"..."
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
do_partition_or_lv_img_check $target_dir_fullpath $fn $lv
rc=$?
rctlv="$(($rctlv + $rc))"
done < $LOGV_PARSE_CONF
return $rctlv
} # end of task_logv_check
#
task_checkimage() {
local target_dir="$1"
local target_parts="$2"
local parts_included target_dir_fullpath
local ptype rc rct
if [ "$target_dir" = "ask_user" ]; then
get_target_dir_name_when_checking_img_restorable
fi
[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
echo "$msg_the_image_to_be_cheked: $target_dir"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
#
source_parts_no="$(cat $ocsroot/$target_dir/parts | sed -e "s/ *$//g" | wc -w | awk '{print $1}')"
#
if [ "$target_parts" = "ask_user" ]; then
ANS_TMP=`mktemp /tmp/ocs_ans.XXXXXX`
trap "[ -f "$ANS_TMP" ] && rm -f $ANS_TMP" HUP INT QUIT TERM EXIT
get_existing_partitions_from_img $ANS_TMP $ocsroot/$target_dir no check
# we have to remove " (comes with checklist in dialog)
# so that for loop will work (Specially for FC3/4...)
target_parts="$(cat $ANS_TMP | tr -d \")"
[ -f "$ANS_TMP" ] && rm -f $ANS_TMP
# target name exists, but file "parts" is empty ?
check_target_parts $ocsroot/$target_dir/parts "$target_parts"
elif [ -z "$target_parts" ]; then
target_parts="$(LC_ALL=C cat $ocsroot/$target_dir/parts)"
else
echo "$msg_the_requested_partition_to_be_checked: $target_parts"
fi
# target_hd will be extract from $target_parts, maybe we will have one more
# find the target hd
# maybe we will have one more hd (like hda1, hda2, hdb1, hdb3 -> hda, hdb)
for ipart in $target_parts; do
thd_tmp="$(get_diskname $ipart)"
if [ -z "$target_hd" ]; then
target_hd="$thd_tmp"
elif [ -z "$(echo $target_hd | grep -Ew "$thd_tmp" 2>/dev/null)" ]; then
target_hd="$target_hd $thd_tmp"
fi
done
#
if [ -e "$ocsroot/$target_dir/disk" ]; then
image_type="disk"
[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
echo "$msg_a_disk_image_saved_from_hd: $(cat $ocsroot/$target_dir/disk)"
echo "$msg_the_part_image_to_be_cheked: $target_parts"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
elif [ -e "$ocsroot/$target_dir/parts" ]; then
image_type="partition"
[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
echo "$msg_a_part_image_saved_from_partitions: $(cat $ocsroot/$target_dir/parts)"
echo "$msg_the_part_image_to_be_cheked: $target_parts"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
else
[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
echo "$msg_broken_image_dir"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
fi
# Use $target_dir_fullpath as the absolute path, i.e. put leading $ocsroot, since from now on we need the full path dir to access them.
target_dir_fullpath="$ocsroot/$target_dir"
check_input_target_image "$target_dir_fullpath"
screen_not_blank
# if $create_part (global variable) is no, only some preparations
# in create_partition, it won't run sfdisk in fact.
# strip the leading spaces
target_parts="$(echo $target_parts | sed -e "s/^[[:space:]]*//g")"
echo $msg_delimiter_star_line
# Start checking partition table.
echo "Checking the partition table in the image \"$target_dir\"..."
for ihd in $target_hd; do
# Get the partition type from parted output
if `is_gpt_partitition_table_file $target_dir_fullpath/$(to_filename ${ihd})-pt.parted`; then
ptype="gpt"
elif `is_mbr_partitition_table_file $target_dir_fullpath/$(to_filename ${ihd})-pt.parted`; then
ptype="mbr"
else
[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
echo "Unknown partition table format from the file $target_dir_fullpath/$(to_filename ${ihd})-pt.parted!" | tee --append ${OCS_LOGFILE}
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
echo "$msg_program_stop!" | tee --append ${OCS_LOGFILE}
exit 1
fi
case "$ptype" in
mbr)
if [ ! -e "$target_dir_fullpath/$(to_filename ${ihd})-pt.sf" ]; then
[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
echo "$msg_this_partition_table_file_not_found: $(to_filename ${ihd})-pt.sf" | tee --append ${OCS_LOGFILE}
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
echo -n "$msg_press_enter_to_continue..."
read
else
echo "Partition table file for disk was found: ${ihd}" | tee --append ${OCS_LOGFILE}
fi
;;
gpt)
if [ ! -e "$target_dir_fullpath/$(to_filename ${ihd})-gpt-1st" ]; then
[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
echo "$msg_this_partition_table_file_not_found: $(to_filename ${ihd})-gpt-1st" | tee --append ${OCS_LOGFILE}
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
echo -n "$msg_press_enter_to_continue..."
read
else
echo "GPT 1st partition table file found!" | tee --append ${OCS_LOGFILE}
fi
if [ ! -e "$target_dir_fullpath/$(to_filename ${ihd})-gpt-2nd" ]; then
[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
echo "$msg_this_partition_table_file_not_found: $(to_filename ${ihd})-gpt-2nd" | tee --append ${OCS_LOGFILE}
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
echo -n "$msg_press_enter_to_continue..."
read
else
echo "GPT 2nd partition table file found!" | tee --append ${OCS_LOGFILE}
fi
if [ ! -e "$target_dir_fullpath/$(to_filename ${ihd})-gpt.gdisk" ]; then
[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
echo "$msg_this_partition_table_file_not_found: $(to_filename ${ihd})-gpt.gdisk" | tee --append ${OCS_LOGFILE}
echo "Was this image saved by older version of Clonezilla? If so, we still can use this old image. However, it's recommended to save the image with the latest Clonezilla. " | tee --append ${OCS_LOGFILE}
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
echo -n "$msg_press_enter_to_continue..."
read
else
echo "GPT partition table file for this disk saved by gdisk was found: ${ihd}" | tee --append ${OCS_LOGFILE}
fi
;;
esac
done
# When Clonezilla does not save a whole disk image (i.e. use the mode saveparts), the swap partition will be skipped. Therefore only check if swap info files exist when it is savedisk.
if [ "$image_type" = "disk" ]; then
echo $msg_delimiter_star_line
echo "Checking the swap partition info in the image \"$target_dir\"..."
# Check swap partition
for ihd in $target_hd; do
# Get the partition type from parted output
if `is_gpt_partitition_table_file $target_dir_fullpath/$(to_filename ${ihd})-pt.parted`; then
ptype="gpt"
elif `is_mbr_partitition_table_file $target_dir_fullpath/$(to_filename ${ihd})-pt.parted`; then
ptype="mbr"
else
[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
echo "Unknown partition table format from the file $target_dir_fullpath/$(to_filename ${ihd})-pt.parted!" | tee --append ${OCS_LOGFILE}
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
echo "$msg_program_stop!" | tee --append ${OCS_LOGFILE}
exit 1
fi
case "$ptype" in
mbr)
echo "Finding swap partition(s) in MBR table $target_dir_fullpath/$(to_filename ${ihd})-pt.sf..."
for partition in `get_swap_partition_sf_format $target_dir_fullpath/$(to_filename ${ihd})-pt.sf`; do
echo "Checking swap partition $partition..."
# read LABEL, UUID info for $partition if swappt-$(to_filename $partition).info exists
uuid_opt=""
label_opt=""
if [ -e "$target_dir_fullpath/swappt-$(to_filename $partition).info" ]; then
cat "$target_dir_fullpath/swappt-$(to_filename $partition).info"
echo "Swap partition info file found!"
else
[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
echo "$msg_this_swap_part_info_not_found: $partition"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
echo -n "$msg_press_enter_to_continue..."
read
fi
done
;;
gpt)
echo "Finding swap partition(s) in GPT table $target_dir_fullpath/$(to_filename ${ihd})-pt.parted..."
for partition in `get_swap_partition_parted_format $target_dir_fullpath/$(to_filename ${ihd})-pt.parted`; do
echo "Checking swap partition $partition..."
# read LABEL, UUID info for $partition if swappt-$(to_filename $partition).info exists
uuid_opt=""
label_opt=""
if [ -e "$target_dir_fullpath/swappt-$(to_filename $partition).info" ]; then
cat "$target_dir_fullpath/swappt-$(to_filename $partition).info"
echo "Swap partition info file found!"
else
[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
echo "$msg_this_swap_part_info_not_found: $partition"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
echo -n "$msg_press_enter_to_continue..."
read
fi
done
;;
esac
done
else
echo "This is not an image for whole disk. Skip checking swap partition info..." | tee --append ${OCS_LOGFILE}
fi
echo $msg_delimiter_star_line
# Check MBR
echo "Checking the MBR in the image \"$target_dir\"..."
# Reinstall executable code area (first 446 bytes in MBR)
for ihd in $target_hd; do
# Ref: http://en.wikipedia.org/wiki/Master_boot_record
# Master Boot Record (MBR) is the 512-byte boot sector:
# 446 bytes (executable code area) + 64 bytes (table of primary partitions) + 2 bytes (MBR signature; # 0xAA55) = 512 bytes.
# However, some people also call executable code area (first 446 bytes in MBR) as MBR.
if [ ! -e "$target_dir_fullpath/$(to_filename ${ihd})-mbr" ]; then
[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
echo "$msg_mbr_img_of_this_hd_not_found: ${ihd}"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
echo -n "$msg_press_enter_to_continue..."
read
else
echo "MBR file for this disk was found: ${ihd}" | tee --append ${OCS_LOGFILE}
fi
done
echo $msg_delimiter_star_line
PV_PARSE_CONF="$target_dir_fullpath/lvm_vg_dev.list"
do_LVM_restore="no"
rct=0
for partition in $target_parts; do
# hda1 -> hda
hd_tmp="$(get_diskname $partition)"
# If we partition is listed in lvm_vg_dev.list, process LVM later. //NOTE// LVM might use Id=83 instead of 8e, so we can not parse it based on Id.
if [ -e $PV_PARSE_CONF ]; then
for i in $(sed -e 's!^.*/dev/\([^[:space:]]\{3,\}\)[[:space:]]*.*$!\1!g' $PV_PARSE_CONF); do
if [ "$partition" = "$(get_master_dev_of_multipath $i)" ]; then
do_LVM_restore="yes"
continue
fi
done
elif check_LVM_partition /dev/$partition; then
do_LVM_restore="yes"
continue
fi
[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
echo "Checking the partition $partition in the image \"$target_dir\"..."
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
do_partition_or_lv_img_check $target_dir_fullpath $partition
rc=$?
rct="$(($rct + $rc))"
done
# Check LVM
if [ "$do_LVM_restore" = "yes" ]; then
# LVM exists, check PV/VG/LV.
task_logv_check "$target_parts"
rc=$?
rct="$(($rct + $rc))"
echo $msg_delimiter_star_line
fi
if [ "$rct" -gt 0 -a "$ocs_batch_mode" != "on" ]; then
[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
echo "$msg_broken_partition_img_found: $target_dir" | tee --append ${OCS_LOGFILE}
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
echo -n "$msg_press_enter_to_continue..."
read
else
[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
echo "$msg_all_the_part_lv_are_ok: $target_dir" | tee --append ${OCS_LOGFILE}
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
fi
} # end of task_checkimage
####################
### Main program ###
####################
ocs_file="$0"
ocs=`basename $ocs_file`
#
while [ $# -gt 0 ]; do
case "$1" in
-b|--batch) ocs_batch_mode="on"; shift;;
-or|--ocsroot)
# overwrite the ocsroot in drbl.conf
shift;
if [ -z "$(echo $1 |grep ^-.)" ]; then
# skip the -xx option, in case
ocsroot="$1"
shift;
fi
[ -z "$ocsroot" ] && USAGE && exit 1
;;
-nogui|--nogui)
shift;
# -nogui is for backward compatable, better to use --nogui
nogui="on"
;;
-*) echo "${0}: ${1}: invalid option" >&2
USAGE >& 2
exit 2 ;;
*) break ;;
esac
done
ocs_chk_img_name="$1"
shift
ocs_chk_dev="$*"
# Fedora Core 1 seems to use dumb for rc1, we have to force it use linux.
# otherwise setterm will complain.
[ -z "$TERM" -o "$TERM" = "dumb" ] && TERM="linux"
echo "Setting the TERM as $TERM"
export TERM="$TERM"
#
check_if_root
ask_and_load_lang_set
# imagedir is a variable which ask_user related function need
imagedir="$ocsroot"
[ -z "$ocs_chk_img_name" ] && ocs_chk_img_name="ask_user"
# if "$ocs_chk_dev" is nothing, we check all the partitions.
#
if [ "$nogui" = "off" ]; then
# TUI is on.
PARTCLONE_CHKIMG_OPT="$PARTCLONE_CHKIMG_OPT -N"
fi
log_line_start="$(LC_ALL=C wc -l $OCS_LOGFILE | cut -d" " -f1)"
task_checkimage "$ocs_chk_img_name" "$ocs_chk_dev"
log_line_start="$((log_line_start + 1))"
# Output the log summary.
echo "Summary of image checking:"
echo "=========================="
tail -n +$log_line_start $OCS_LOGFILE
echo "=========================="
|