diff options
Diffstat (limited to 'draft/other-tools/clonezilla')
-rw-r--r-- | draft/other-tools/clonezilla/drbl-ocs.conf | 414 | ||||
-rwxr-xr-x | draft/other-tools/clonezilla/ocs-expand-gpt-pt | 386 | ||||
-rwxr-xr-x | draft/other-tools/clonezilla/ocs-expand-mbr-pt | 369 | ||||
-rwxr-xr-x | draft/other-tools/clonezilla/ocs-restore-ebr | 119 | ||||
-rwxr-xr-x | draft/other-tools/clonezilla/ocs-restore-mbr | 131 | ||||
-rwxr-xr-x | draft/other-tools/clonezilla/ocs-sr | 1465 |
6 files changed, 2884 insertions, 0 deletions
diff --git a/draft/other-tools/clonezilla/drbl-ocs.conf b/draft/other-tools/clonezilla/drbl-ocs.conf new file mode 100644 index 0000000..f204029 --- /dev/null +++ b/draft/other-tools/clonezilla/drbl-ocs.conf @@ -0,0 +1,414 @@ +# drbl-ocs (Clonezilla) setting +# Do NOT modify if you are not sure what you are doing! +OCSMGRD_PORT="6461" + +# Create image volumes with a size of X, +# Annoying... +# in the past, its unit is KB (for partimage 0.6.2). +# MB (for partimage 0.6.4) +# Since we use partimage 0.6.4 now, it's MB. +# NOTE: +# If you are using partimage 0.6.5 beta 3, the maximum is 2000 MB, you can not set it larger than 2000. Otherwise it will fails to get the correct set. +# For other version of partimage, no such problem. +# Ref:http://www.partimage.org/forums/viewtopic.php?t=481 +# http://sourceforge.net/forum/message.php?msg_id=3761573 +# "0" is also "no split" for clonezilla. Before clonezilla 2.1, if split, the image name will like: hda1.000, hda1.000... which is done by partimage. +# Without split, the image is like: hda1 (not hda1.000, i.e. without ".000") +# From clonezilla 2.1 or later, we do not let partimage built function to split it, we use program split to do that. +# Unit for clonezilla split: MB, by default we set it as 100 GB, no more use unlimite (0) because the reason: +# 2009/11/05, on Ubuntu 9.10 with upstart 0.6.3 or later, the "/sbin/init" won't accept the boot parameters as an option, it will always read /proc/cmdline, therefore if we use "0", the option will be shown in /proc/cmdline as "ocs_opt=... -i 0" and in /tftpboot/node_root/sbin/init we can not make it by removing "ocs_opt=... -i 0" anymore. +# The volume limit to split an partition image file. +# This is for those file systems could support large file, like ext4 a single file size limit is 16 TiB. Here we set it as 1TB +# Unit: MB (1000*1000) +VOL_LIMIT_DEFAULT="1000000" +# Assign VOL_LIMIT_IN_INTERACTIVE as 4096 MB, since some cases when +# using ocs-sr -x, it's in FAT16B/FAT32, the limitation is +# 4,294,967,295 bytes (4 GiB - 1) +# Unit: MB (1000*1000) +# Ref: http://en.wikipedia.org/wiki/File_Allocation_Table +# http://en.wikipedia.org/wiki/Megabyte +VOL_LIMIT_IN_INTERACTIVE="4096" + +# Specify the suffix length for spliting the image file of a partition or LV. By default it's 2, i.e. aa, ab, ac... +# Integer must >= 2. +split_suf_len="2" + +# multicast setting +# From udpcast menu: +# --mcast-all-addr address +# Uses a non-standard multicast address for the control +# connection (which is used by the sender and receivers to +# "find" each other). This is not the address that is used to +# transfer the data. +# By default mcast-all-addr is the Ethernet broadcast address +# if ttl is 1, and 224.0.0.1 otherwise. This setting should not +# be used except in very special situations, such as when +# 224.0.0.1 cannot be used for policy reasons. +# Note! It's better to keep 224.0.0.1, For example, if $eth_for_multicast is eth1. In Debian sarge, for different clients in eth2 or eth3, will not be able to connect eth1 to get the multicast packets +MULTICAST_ALL_ADDR="224.0.0.1" +MULTICAST_PORT="2232" +TIME_TO_LIVE_OPT="--ttl 1" + +# You can assign extra option for udp-sender, e.g. +# (1) "--max-bitrate 150m" (150 megabits/sec). See "man udp-sender" for more info. +# Thanks to Mike Taylor for this idea. Ref: https://sourceforge.net/forum/message.php?msg_id=5281039 +# (2) "--fec 8x16/64" +# Thanks to Pretzel for this idea. Ref: https://sourceforge.net/p/clonezilla/discussion/Clonezilla_server_edition/thread/6e1e87d4/ +# (3) "--retries-until-drop 50", for example, if you want to reduce the waiting time if some clients fail to continue then udp-sender drops them. By default it will take about 3 to 4 mins, with "--retries-until-drop 50", the time is reduced to about 40 secs. Thanks to Yitzon Belandria <yitzon _at_ gmail com> for sharing this result. Ref: https://sourceforge.net/p/drbl/discussion/250176/thread/70d6fd5e/?limit=25#4496 +udp_sender_extra_opt_default="" + +# You can assign extra option for udp-receiver here (very seldom) +udp_receiver_extra_opt_default="" + +# The time to wait when multicast restoring more then 2 partitions. +# For the first partition, we will ask user. This PART_PREPARE_TIME is for the wait time before next partition (2nd, 3rd... to start) +# Not! It can not be too short!!! 30 secs is a good number. +PART_PREPARE_TIME="30" +# Time to prepare the next partition, like hda1 -> hda2 +SLEEP_TIME_AFTER_PART_CLONED="15" + +# time to wait default: sec +TIME_TO_WAIT_DEFAULT="120" +MAX_TIME_TO_WAIT_DEFAULT="300" +# +# ignore the MBR by using -M, we will ignore the error caused by devfs style +# in /proc/partitions +# now use -z0 and --volume=0 in DEFAULT_PARTIMAGE_SAVE_OPT, we will use partimage stdout and pipe it to use gzip/bzip2/lzop to compress it, not the compression function in partimge. --volume=0 is a must for stdout. +DEFAULT_PARTIMAGE_SAVE_OPT="-M -f3 -o -d -b -c -z0 --volume=0" +DEFAULT_PARTIMAGE_RESTORE_OPT="-M -f3 -b" + +# Extra gzip/lzma/xz option. This is used when using gzip/lzma/xz/lzip/lrzip (non-parallel) to save an image. +# Adding "--rsyncable" to be friendly to rsync (https://sourceforge.net/p/clonezilla/discussion/Open_discussion/thread/8d5f80a6) +# //NOTE// Option "--rsyncable" is not an official option for gzip, it's patched by some distributions. (https://sourceforge.net/p/clonezilla/discussion/Open_discussion/thread/8d5f80a6/?limit=25#89e2) +rsyncable_opt_gzip="" +if [ -n "$(LC_ALL=C gzip --help 2>&1 | grep -Ew -- "--rsyncable")" ]; then + rsyncable_opt_gzip="--rsyncable" +fi +extra_gzip_opt="--fast $rsyncable_opt_gzip" +# -1 (fatest), -2, ... -9 (best compression) +extra_bzip2_opt="-3" +extra_lzop_opt="-3" +extra_lzma_opt="-3" +extra_xz_opt="-3" +extra_lzip_opt="-3" +extra_lrzip_opt="-L 3" + +# Use parallel gzip/pbzip2 when restoring +use_parallel_decompression="yes" + +# Available programs for parallel bzip2: pbzip2, lbzip2 +# Default to use lbzip2 since pbzip2 1.0.5 has an issue about memory usage +# https://sourceforge.net/projects/clonezilla/forums/forum/663168/topic/3517181 +parallel_bzip2_prog="lbzip2" + +# Extra pigz option. This is used when using pigz to save an image. For pigz, normally "-b 1024" (1024=1024K) is enough, although you can assign more like "-p 16" (16 threads). +# Adding "-R" (--rsyncable) to be friendly to rsync (https://sourceforge.net/p/clonezilla/discussion/Open_discussion/thread/8d5f80a6) +# //NOTE// Option "--rsyncable" is only for newer pigz, it's patched by some distributions. (https://sourceforge.net/p/clonezilla/discussion/Open_discussion/thread/8d5f80a6/?limit=25#89e2) +rsyncable_opt_pigz="" +if [ -n "$(LC_ALL=C pigz --help 2>&1 | grep -Ew -- "--rsyncable")" ]; then + rsyncable_opt_pigz="--rsyncable" +fi +extra_pigz_opt="--fast -b 1024 -p 16 $rsyncable_opt_pigz" +# Extra pbzip2 option. This is used when using pbzip2 to save an image. For pbzip2, normally "-b9" (9=900K, the default value. It's different from pigz) is enough, although you can assign more like "-p16" (16 processors). Ref: https://sourceforge.net/tracker/?func=detail&atid=671650&aid=3324096&group_id=115473 +extra_pbzip2_opt="-3" +extra_lbzip2_opt="-3" +# +extra_pixz_opt="-3" +extra_plzip_opt="-3" + +# ntfsclone options, for saving and restoring, respectively. These variables will be appended when running ntfsclone. +ntfsclone_save_extra_opt_def="" +ntfsclone_restore_extra_opt_def="" + +# supported filesystem in partimage +# ///NOTE/// FAT12 is not supported by partimage. +partimage_support_fs="ext2 ext3 reiserfs xfs jfs fat16 fat32 vfat hpfs ufs hfs ntfs" + +# Supported filesystems in partclone +# Although now partclone has the following programs: +# clone.extfs clone.reiser4 clone.xfs clone.hfsp clone.reiserfs +# This file system name is the same as we get from "parted -s /dev/[hsv]dx? print" +# 2009/07/15 Since there is an issue when restoring vfat, remove fat*/vfat in the following list +# partclone_support_fs="hfs+ hfsplus reiser4 xfs reiserfs ext2 ext3 ext4 ext4dev ntfs" +# partclone 0.1.1-16 has fixed the issue about FAT. Turn it on: +#partclone_support_fs="hfs+ hfsplus reiser4 xfs reiserfs ext2 ext3 ext4 ext4dev fat12 fat16 fat32 vfat ntfs" +# 2009/09/12 partclone.xfs v0.1.1 (Rev:304M) is buggy. remove xfs in the following list. +# 2009/09/18 partclone.xfs v0.1.9 was fixed. No more xfs problem. Add xfs in the following. +# 2012/01/18 partclone.fstype from version 0.2.45 will tell vmfs3 and vmfs5. Therefore no more VMFS_volume_member and vmfs, we use vmfs3 and vmfs5. Since vmfs5 support in partclone 0.2.45 is still buggy due to libvmfs not supported well yet, we won't enable it until it's fully supported. +# 2012/04/05 Enable vmfs5 since partclone 0.2.46 now works for vmfs5. +# 2013/03/01 Enable minix since partclone 0.2.59 now works for minix. +# 2014/12/01 Temporarily disabled vmfs3 and vmfs5 due to this issue: +# https://github.com/glandium/vmfs-tools/issues/12 +# 2015/07/06 Enabled vmfs3 and vmfs5 since partclone >= 0.2.79 fixed this issue. +partclone_support_fs="hfs+ hfsplus reiser4 reiserfs xfs jfs ext2 ext3 ext4 ext4dev fat12 fat16 fat32 vfat ntfs ufs btrfs exfat minix vmfs3 vmfs5 f2fs nilfs2" +# Options to be appended in the partclone command, for save and restore. +# For example, for restoring, if you want to ignore device size checking, "-C" can be put, like: +# PARTCLONE_RESTORE_OPT_INIT="-C" +# From Partclone 0.2.61, we switch to use "-z" instead of "-m": +PARTCLONE_SAVE_OPT_INIT="-z 10485760" +PARTCLONE_RESTORE_OPT_INIT="-z 10485760" +PARTCLONE_RESTORE_ONTHEFLY_OPT_INIT="-z 10485760" + +# The debug_level for partimage +# it's better we turn off the debug mode by default, this will reduce the server's loading. +# It seems in partiamge 0.6.5-beta2, when using --debug=0 to save NTFS partition +# partimage will crash. However, 0.6.5-beta1 works without this problem. +# To avoid this, we set debug_level=1 as default value. +debug_level="1" +# +MAX_DIALOG_HEIGHT="10" +# dialog width for showing images +RESTORE_DIA_WIDTH="70" +# +POSTACTION_DEF="reboot" +# The poweroff/reboot options, which are used when clone finishes. +# If you are impatient, you can set it as "-f -n" so it will force halt or reboot, don't call shutdown sequence, and do not sync. i.e. poweroff/reboot immediately. Note! This might fail your wake-on-LAN since it's not a normal soft-shutdown. +# In some case (clonezilla live), we might overwrite this option to let it do normal poweroff/reboot. +HALT_REBOOT_OPT="" +# To avoid all the clients notify at almost same time, we use random sleep before send info. This is the maximun time limit (in secs). +NOTIFY_OCS_SERVER_TIME_LIMIT="20" + +# OCS_PRERUN_DIR & OCS_POSTRUN_DIR +# Run the script in the direcoty $OCS_POSTRUN_DIR before clone starts and finishes. The command will be run before that assigned in -p or --postaction." +OCS_PRERUN_DIR="$DRBL_SCRIPT_PATH/prerun/ocs/" +OCS_POSTRUN_DIR="$DRBL_SCRIPT_PATH/postrun/ocs/" + +# PREFIX for M$ windows hostname +WIN_HOSTNAME_PREFIX="PC" + +# The way to trigger clonezilla client to start ocs-sr, 3 options: +# (1) ocs-run.param: the ocs_opt is put in client's /etc/ocs/ocs-run.param +# (2) proc-cmdline: the ocs_opt is put in client's /proc/cmdline, which is actually from server's pxelinux config /tftpboot/nbi_img/pxelinux.cfg/default or others. +# (3) both: ocs_opt will be put both in /etc/ocs/ocs-run.param and server's pxelinux config /tftpboot/nbi_img/pxelinux.cfg/default or others. However, when ocs-run is run in client, it will use the ocs_opt from /tftpboot/nbi_img/pxelinux.cfg/default (i.e. /proc/cmdline) +# We choose to use ocs_opt from proc-cmdline if it's both so that we can always put "ocs_client_trig_type=both" in this file. If we want to interactively debug clonezilla in client, just use "/etc/init.d/ocs-run -p start". +# Note: SET IT AS "both" ONLY, other modes are only for backward compatibility testing. +ocs_client_trig_type="both" + +# modify client's /etc/inittab when start clonezilla service. +# If yes, both client's inittab and pxelinux config will be modified. +# If no, just put "1" in pxelinux config so it will show in client's /proc/cmdline. +# Available value: yes/no +# Note: Do NOT set it as "yes", it's only for backward compatibility testing. +modify_client_etc_inittab="no" + +# When use use drbl-ocs stop to stop clonezilla, do we want to clean the ocs related services (ssh, arm-wol...). +# Available value: yes/no +# Note: Do NOT set it as "yes", it's only for backward compatibility testing. +clean_client_all_ocs_related_srv="no" + +# clean dhcpd lease in the server when it's clonezilla box mode. +# Note: Do NOT set it as "yes", it's only for backward compatibility testing. +clean_dhcpd_lease_in_clone_box_mode="no" + +# flag to regenerate the DRBL SSI template tarball +# Note: Do NOT set it as "yes", it's only for backward compatibility testing. +regen_drbl_ssi_template_tarball="no" + +# flag to re-put ocs related files in client's rc1.d (ocs-functions) +# Note: Do NOT set it as "yes", it's only for backward compatibility testing. +re_put_ocs_related_srv_in_client_rc1d="no" + +# flag to re-put S19ocs-run and all other services from template node's +# client's rc1.d to /tftpboot/node_root/etc/drbl_ssi/rc1.d/ (drbl-ocs) +# Note: Do NOT set it as "yes", it's only for backward compatibility testing. +copy_rc1d_for_drbl_ssi_clone_box="no" + +# Flag to use dd or partclone in ocs (not ocs-onthefly) +# Sector to sector copy program in ocs (not ocs-onthefly). Available progs are: dd, partclone +S2S_IMAGE_PROG_IN_OCS="partclone" + +# Since dd does not report status with any option, we have to send SIGUSR1 to tell dd to report every some secs when using dd to save or restore an image. This will only take effect when S2S_IMAGE_PROG_IN_OCS = dd +# dd report interval (secs) +dd_report_interval="20" + +# Flag to use ntfsclone, dd, or partclone in ocs-onthefly +# ///NOTE/// 2008/May/11 by Steven Shiau: local part to remote part still has a problem with partclone: e.g. local hda1 to remote hda3, due to the filesystem of source partition can not be informed to target machine in the current mechanism, it will fail if the filesystem is not the same with the list on $src_pt_info. +# Something like: partclone.reiserfs can't restore from the image which filesystem is XFS not REISERFS +USE_NTFSCLONE_IN_OCS_ONTHEFLY="no" +USE_PARTCLONE_IN_OCS_ONTHEFLY="yes" +# Sector to sector copy program. Available progs are: dd, partclone +S2S_CLONE_PROG_IN_OCS_ONTHEFLY="partclone" + +# Hidden data space size limit. This is the max hidden data space size limit, if it's larger than +# this, we won't create the file (e.g. sda-hidden-data-after-mbr). +# Unit: MB +hidden_data_after_mbr_limit="1024" + +# some presettings about clonezilla when running dcs +# The prompt for user to input the disk when saving +savedisk_preset="sda" +# The prompt for user to input the partitions when saving +saveparts_preset="sda1 sda2" + +# Options for encryption of image dir. We use ecryptfs to mount that. Therefore the options are from ecryptfs. +# Run "man ecryptfs" for more details. +ocs_ecryptfs_cipher="aes" +ocs_ecryptfs_key_bytes="16" + +# checksum algorithm for files in the partition. +# This is used to create the checksum for all the regular files in a partition or LV. +# Available command: md5sum, sha1sum, sha256sum, sha512sum +chksum_cmd_for_files_in_dev="md5sum" + +# Option for mounting file system for image repository ($ocsroot) +# Ref: https://sourceforge.net/tracker/?func=detail&atid=671653&aid=2949613&group_id=115473 +# For cifs, noatime and nodiratime won't be honored, but cifs won't exit with error. It just ignores nodiratime. +# For sshfs, nodiratime is not honored, and sshfs will exit with error. +# For nfs, both noatime and nodiratime are honored. +# Therefore we put noatime only, and add "nodiratime" for nfs, hfsplus and other fs. +ocsroot_def_mnt_opt="noatime" + +# For davfs2 config. Do not modify unless you know what you are doing. +davfs2_buf_size="10240" #KiByte maybe more +davfs2_use_locks="0" +davfs2_use_expect100="1" +davfs2_use_compression="1" +davfs2_cache_size_def="64" # MiByte. This is default value if appropriate free memory size can not be decided. +davfs2_delay_upload="0" +# The ratio for the cache size to free disk space (RAM disk actually) in Clonezilla live env. +# Value must between 0 and 1. Default:0.2. Better not to be larger than 0.5 +# ///NOTE/// The cache mechanism of davfs2 is a problem (ref: https://sourceforge.net/forum/forum.php?thread_id=2248597&forum_id=82589). Although we use ratio_davfs2_cache_2_free_disk and free ramdisk space to set the cache size of davfs2, according to "man davfs2.conf": +# cache_size: The amount of disk space in MiByte that may be used. mount.davfs will always take enough space to cache open files, ignoring this value if necessary. +# Therefore the cache_size get in ocs-tune-conf-for-webdav is actually applied to VOL_LIMIT_DEFAULT and VOL_LIMIT_IN_INTERACTIVE, too, so that single file won't be over size. +ratio_davfs2_cache_2_free_disk="0.2" +# When webdav is the image repository, we need longer suffix length for "split" command, i.e. the option "-a" of split. +# When "3" is used, Clonezilla live in a machine with 1 GB RAM could have 0.8 GB ramdisk size, so: +# 26*26*26*0.8/5=2812 GB +davfs2_split_suf_len_def="3" + +# This part is for DRBL/Clonezilla/GParted live +# Settings +# Debian Repository when creating debian live. It's better to use http://httpredir.debian.org/debian. However, some mirror site seems to be not so stable, and we might encounter the error like: +# W: Failed to fetch http://httpredir.debian.org/debian/dists/sid/main/binary-i386/Packages Hash Sum mismatch +# Therefore we use http://free.nchc.org.tw which can be fixed by Clonezilla team if something goes wrong. +debian_mirror_url_def="http://free.nchc.org.tw/debian" +debian_mirror_security_url_def="http://security.debian.org/debian-security" +# Ubuntu repository when creating ubuntu live +ubuntu_mirror_url_def="http://free.nchc.org.tw/ubuntu" +ubuntu_mirror_security_url_def="http://free.nchc.org.tw/ubuntu" +# DRBL repository +DRBL_REPOSITORY_URL_def="http://free.nchc.org.tw/drbl-core" +# URL to the repository key +DRBL_GPG_KEY_URL="http://drbl.org/GPG-KEY-DRBL" + +# Clonezilla live iso template file name. By default we use debian-live-for-ocs.iso as the template file name in ocs-iso and ocs-live-dev. +DEBIAN_ISO_DEF="debian-live-for-ocs.iso" +# http://free.nchc.org.tw/drbl-core/iso/MD5SUMS +md5_file="MD5SUMS" +uni_font_file="unifont.bgf" +syslinux_exe_file="syslinux.exe" +makeboot_exe_file="MakeBoot.exe" +wget_opt="-r -l1 --no-parent --passive-ftp -e robots=off -q -nd --retr-symlinks" +CD_FILE_LIMIT="650" # unit: MB +FILE_LIMIT="4500" # unit: MB +# The kernel and initrd files are used just in case, normally ocs-iso or ocs-live-dev will search them. +kernel_file="vmlinuz1" +initrd_file="initrd1.img" +# Client framebuffer mode +VGA_MODE_DEF="788" +BG_MODE_DEF="graphic" +# Default console columns for adjust font and its size in live cd. This only will affect KMS mode, not other framebuffer mode. +console_prefer_font="TerminusBold" +# We want to show 100 characters in the screen (width) +console_prefer_cols="100" +# //NOTE// Generally this variable BOOT_PARAM_DEFAULT will be overwritten by the function get_live_boot_param in ocs-functions. +BOOT_PARAM_DEFAULT="boot=live union=overlay" +# Common boot parameters that Clonezilla live (iso/zip) need. +# //NOTE// "nomodeset" is required for framebuffer mode (vga=788... or video=uvesafb:....). If no "nomodeset", it will enter kernel mode setting (KMS) mode. Then framebuffer mode will only take effect in the early booting. It won't work when we use Clonezilla. Therefore here we keep "nomodeset" +supp_boot_param_ocs_live_iso="noswap edd=on nomodeset" +# For Clonezilla live USB, we add "noeject" so by default we do not ask user to remove the USB flash drive when rebooting/halting. +supp_boot_param_ocs_live_dev="$supp_boot_param_ocs_live_iso noeject" +# Possible live media path (when live CD/USB-disk boots, the reall live media is mounted as...) +# casper 1.77+debian-7 uses /live_media, 1.110 uses /cdrom +# live-initramfs uses /live/image. +# For Debian Live 3.x, rootfs is in /lib/live/mount/medium/live/filesystem.squashfs +live_media_path_chklist="/lib/live/mount/medium /lib/live/image /live/image /live_media /cdrom" +# Possible kernel/initrd paths in live CD/USB-disk are /casper (created by casper), /live (created by live-initramfs) or /isolinux (created by live pacakge with casper), or "/" (when using toram="filesystem.squashfs", filesystem.squashfs will be copied to / in the ram disk). +live_sys_files_dir_list="live / isolinux casper" +# For live-package, it's "/usr/share/make-live/hooks", for live-helper... +live_pkg_hook_dir="/usr/share/make-live/hooks" +# Some locales (especially CJK) need bterm to show +locale_need_bterm="zh_TW zh_CN zh_HK zh_SG ja_JP ko_KR" +# unifont.bgf path is required by bterm in clonezilla live. +uni_font="$DRBL_SCRIPT_PATH/lib/unifont.bgf" +# fb_term is either bterm or jfbterm. If not assigned, clonezilla live will try to use jfbterm first, then bterm. However, due to a bug of jfbterm in Ubuntu intrepid, bterm will be used in intrepid anyway. +fb_term="" +# Live build and debootstrap minimal version to create debian/gparted/drbl live, i.e. >= this +lh_ver_required="3.0.5-1" +debootstrap_ver_required="1.0.52" + +# Use RawCHS from EDD (sysfs interface to BIOS EDD information) for partclone.ntfsfixboot +use_RawCHS_from_EDD_for_ntfsreloc="yes" + +# Use RawCHS from sfdisk for partclone.ntfsfixboot +use_RawCHS_from_sfdisk_for_ntfsreloc="yes" + +# The run_grub2_from_restored_os_mode is for us to decide to run grub2 from the restored OS. Possible values are "yes", "no" or "". If "yes", Clonezilla will chroot and run grub-install. If "no", use the grub in the running system to run grub-install --root-directory=.... If "", then we will test in ocs-functions to use "yes" mode first, if fails, then "no" mode. +# //NOTE// The OS arch in the running environment must be the same as that in the restored OS, otherwise, e.g. running OS is i386, and restored OS is x86-64, if this option is "yes", you will get error messages when run grub2 install: +# "cannot run command" "Exec format error" +run_grub2_from_restored_os_mode="" + +# A mounting point for temporary (middle) use. +pre_ocsroot_path="/tmp/ocsroot_bind_root" + +# Log files for the output of clonezilla and related files. +OCS_LOGFILE="/var/log/clonezilla.log" ; export OCS_LOGFILE +OCS_NETCFG_LOG="/var/log/ocs-netcfg.log" ; export OCS_NETCFG_LOG +OCS_MOUNT_LOG="/var/log/ocs-mount.log" ; export OCS_MOUNT_LOG + + +################################################### +### Settings about Clonezilla-live based client ### +################################################### +# The flag to use NFSRoot-based or Clonezilla-live-based system in the client +# Available name: nfsroot, clonezilla-live +diskless_client_os="nfsroot" + +# If diskless_client_os is clonezilla-live, the URL to download the clonezilla live. e.g. +# http://downloads.sourceforge.net/clonezilla/clonezilla-live-1.2.5-6-i486.iso +# http://sourceforge.net/projects/clonezilla/files/clonezilla_live_testing/clonezilla-live-1.2.5-6-i486.iso +# Or +# http://free.nchc.org.tw/clonezilla-live/testing/clonezilla-live-1.2.5-6-i486.iso +# If you want to use a local copy, you can make it like: +# iso_url_for_pxe_ocs_live_default="file://tmp/clonezilla-live-20130902-saucy-amd64.iso" +iso_url_for_pxe_ocs_live_default="" + +# Flags when running drbl-ocs, shall we remove some boot parameters from pxelinux config file for Clonezilla live. (only takes effect when diskless_client_os="clonezilla-live" +# Available flag for remove_some_boot_param_for_pxe_ocs_live: yes, no +remove_some_boot_param_for_pxe_ocs_live="yes" + +# If remove_some_boot_param_for_pxe_ocs_live is yes, what shall we remove: +# By default we remove quiet, splash, vga and video, we want it to be more verbose when booting clients +boot_param_2_be_removed_in_pxe_ocs_live="quiet splash vga video" + +# Boot parameters to preseed: ocs_live_keymap, ocs_lang, ocs_daemonon, ocs_prerun, +# Available keymaps: "NONE" (won't change the default layout), "/usr/share/keymaps/i386/azerty/fr-latin9.kmap.gz" (French keyboard)... +ocs_live_keymap_for_pxe_ocs_live="NONE" + +# Available languages: en_US.UTF-8 es_ES.UTF-8 fr_FR.UTF-8 it_IT.UTF-8 ja_JP.UTF-8 zh_CN.UTF-8 zh_TW.UTF-8 +# However, the CJK might have problem to be shown on the screen because in the PXE client we do not always enter jfbterm unless it's Clonezilla live mode. Therefore it's better to keep it as "en_US.UTF-8" +ocs_lang_for_pxe_ocs_live="en_US.UTF-8" + +# The daemon to be started, e.g. ssh (the file name in /etc/init.d/) +ocs_daemonon_for_pxe_ocs_live="ssh" + +# The account and password for the Clonezilla live clients of Clonezilla SE. +# //NOTE// These variables are not used to assign the default username and password of Clonezilla live when creating it by create-debian-live or create-ubuntu-live. They are only used for ssh login by drbl-doit. Therefore if someday Debian live changes its default username and password, we have to change here, too. +ocs_live_username="user" +ocs_live_passwd="live" + +# Prompt messages preference. Could be "tui" or "cmd". If not assigned, cmd is the default. +# //NOTE// Not all the messages are supported to be shown in dialog/whiptail +ocs_prompt_mode="" + +# The command to run before ocs_live_run command is executed. E.g. "mount -t nfs 192.168.120.254:/home/partimag/ /home/partimag". If not assigned, by default we will use: +# mount -t nfs $IP:/home/partimag/ /home/partimag +# where $IP is the 1st IP address on DRBL server. +ocs_prerun_for_pxe_ocs_live="" + +### EFI network booting on Clonezilla SE ### +# The option to decide if the EFI network booting is set as 1st priority +# in the boot order in EFI NVRAM after the image is restored by Clonezilla SE +# Values: yes, no +efi_netboot_1st_in_nvram="yes" +################################################### diff --git a/draft/other-tools/clonezilla/ocs-expand-gpt-pt b/draft/other-tools/clonezilla/ocs-expand-gpt-pt new file mode 100755 index 0000000..191bc06 --- /dev/null +++ b/draft/other-tools/clonezilla/ocs-expand-gpt-pt @@ -0,0 +1,386 @@ +#!/bin/bash +# Author: Steven Shiau <steven _at_ nchc org tw> +# License: GPL +# A script to expand the GPT partition table by disk size ratio. +# ///NOTE/// This program only works for GPT partition table, not for MBR. + +# Load DRBL setting and functions +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 + +# Settings +# Flag to check target disk size before creating partition table +chk_tgt_disk_size_bf_mk_pt="yes" + +# +cmd_name="$(basename $0)" +# +USAGE() { + echo "$cmd_name: To create a proportional MBR partition table (not GPT) in a disk based on a existing partition table (sfdisk format)" + echo "Usage:" + echo " $cmd_name [OPTION] PARTITION_TABLE_FILE TARGET_DEVICE" + echo + echo "OPTION:" + echo " -b, --batch Run $cmd_name in batch mode, i.e. without any prompt or wait to press enter. VERY DANGEROUS!" + echo "$cmd_name will honor experimental variable EXTRA_SFDISK_OPT and use it as the option for sfdisk." + echo " -icds, --ignore-chk-dsk-size-pt Skip checking destination disk size before creating the partition table on it. By default it will be checked and if the size is smaller than the source disk, quit." + echo "Example:" + echo " To create a proportional partition table on disk /dev/sda based on /home/partimag/IMAGE/sda-pt.sf, use:" + echo "$cmd_name /home/partimag/IMAGE/sda-pt.sf /dev/sda" +} + +# Parse command-line options +while [ $# -gt 0 ]; do + case "$1" in + -b|--batch) + batch_mode="yes" + shift;; + -icds|--ignore-chk-dsk-size-pt) + chk_tgt_disk_size_bf_mk_pt="no" + shift;; + -*) echo "${0}: ${1}: invalid option" >&2 + USAGE >& 2 + exit 2 ;; + *) break ;; + esac +done + +# Original sfdisk format file +orig_sf=$1 # orig_sf is like: /home/partimag/IMAGE/sda-pt.sf +target_disk=$2 # target_disk is like: /dev/sda + +# +ask_and_load_lang_set $specified_lang + +# +if [ -z "$orig_sf" ]; then + [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE + echo "No source partition table file was assigned!" + [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL + USAGE + echo "$msg_program_stop!" + exit 1 +fi +if [ ! -f "$orig_sf" ]; then + [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE + echo "Source partition table file \"$orig_sf\" was _NOT_ found" + [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL + echo "$msg_program_stop!" + exit 1 +fi + +if [ -z "$target_disk" ]; then + [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE + echo "No target disk was assigned!" + [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL + echo "$msg_program_stop!" + USAGE + exit 1 +fi + +# +if [ "$batch_mode" != "yes" ]; then + [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING + echo "This program will create a partition table in $target_disk" + echo "ALL THE DATA IN THE TARGET DEVICE WILL BE ERASED!!!" + [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL + echo -n "$msg_are_u_sure_u_want_to_continue ? (y/N) " + read continue_confirm_ans + case "$continue_confirm_ans" in + y|Y|[yY][eE][sS]) + echo "$msg_ok_let_do_it!" + ;; + *) + echo "$msg_program_stop!" + exit 1 + esac +fi + +# Check if GPT disk, if yes, exit +if `is_mbr_partitition_table_disk $target_disk`; then + [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE + echo "Disk $target_disk is MBR format. This program only works for GPT format." + [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL + echo "$msg_program_stop!" + exit 1 +fi + +# Check if the format of sfdisk is created by sfdisk >= 2.26 +if [ -z "$(LC_ALL=C grep -E "^label: gpt" $orig_sf)" ]; then + [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE + echo "Partition table file \"$orig_sf\" does not contain GPT info." + echo "Make sure it's GPT format and outputted by sfdisk >= 2.26." + [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL + echo "$msg_program_stop!" + exit 1 +fi + +# No size info in sda-pt.sf, we have to use sda-pt.parted. +orig_parted_tab="${orig_sf/.sf/.parted}" +orig_parted_dir="$(dirname $orig_sf)" +if [ ! -e "$orig_parted_tab" ]; then + [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE + echo "$orig_parted_tab was not found! It is required so that we know the original disk size! Maybe your Clonezilla image is too old ? You can try to create such an file in your source machine by: \"parted -s /dev/$SOURCE_DEV unit s print > $orig_parted_tab\" (Replace $SOURCE_DEV with your device name)" + [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL + echo "$msg_program_stop!" + exit 1 +fi + +# parted output format example: +# Disk /dev/sda: 16777215s +# Sector size (logical/physical): 512B/512B +# Partition Table: msdos +# +# Number Start End Size Type File system Flags +# 1 63s 586844s 586782s primary boot +# 2 586845s 978074s 391230s primary +# 3 978075s 1955204s 977130s primary +# 4 1955205s 16776584s 14821380s extended +# 5 1955268s 2151764s 196497s logical +# 6 2151828s 2542994s 391167s logical +# 7 2543058s 16776584s 14233527s logical + +ori_disk_size="$(LC_ALL=C grep -E "^Disk /dev" $orig_parted_tab | awk -F":" '{print $2}' | sed -e "s/s$//g")" +# If nothing in target disk, parted will show like this: +# sudo parted -s /dev/sda unit s print +# Error: Unable to open /dev/sda - unrecognised disk label. + +if ! LC_ALL=C parted -s $target_disk unit s print &>/dev/null; then + # Try to create a partition table so that we can read the size via parted -s $dev unit s print + echo "No initial GPT table on disk $target_disk. Create one now by:" | tee --append $OCS_LOGFILE + echo "parted -s $target_disk mklabel gpt" | tee --append $OCS_LOGFILE + LC_ALL=C parted -s $target_disk mklabel gpt | tee --append $OCS_LOGFILE +fi +tgt_disk_size="$(LC_ALL=C parted -s $target_disk unit s print | grep -E "^Disk /dev" | awk -F":" '{print $2}' | sed -e "s/s$//g")" + +# +ratio=$(echo "scale=10; $tgt_disk_size / $ori_disk_size" | bc -l) || exit 1 +echo "The ratio for target disk size to original disk size is $ratio." +if [ "$chk_tgt_disk_size_bf_mk_pt" = "yes" ]; then + if [ "$(LC_ALL=C echo "$ratio < 1" | bc -l)" = "1" ]; then + [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE + echo "The target disk (size=$tgt_disk_size sectors) is smaller than the source disk (size=$ori_disk_size sectors)!" + echo "Clonezilla won't be able to restore a partition image to smaller partition!" + [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL + echo "Program terminated!" + exit 1 + fi +fi + +new_sf="$(mktemp /tmp/new_sf.XXXXXX)" || exit 1 +new_sf_tmp="$(mktemp /tmp/new_sf_tmp.XXXXXX)" || exit 1 +# Increase. Example for sfdisk format: +# ===================================== +# label: gpt +# label-id: ADC40CC4-77D7-4858-8F0E-8BC2447052AE +# device: /dev/sda +# unit: sectors +# first-lba: 34 +# last-lba: 125829086 +# +# /dev/sda1 : start= 2048, size= 409600, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, uuid=E8D785ED-A65F-4EA1-ADF0-CC61E75677EB +# /dev/sda2 : start= 411648, size= 1024000, type=EBD0A0A2-B9E5-4433-87C0-68B6B72699C7, uuid=AB72A495-4141-4500-AE48-B7AC492160B4 +# /dev/sda3 : start= 1435648, size= 40505344, type=E6D6D379-F507-44C2-A23C-238F2A3DF928, uuid=C7A87C41-72FD-41DB-9B10-DF3568A4089D +# ===================================== +# label: gpt +# label-id: D4165706-2FAD-491E-82CA-7866982D196B +# device: /dev/sda +# unit: sectors +# first-lba: 34 +# last-lba: 125829086 +# +# /dev/sda1 : start= 2048, size= 614400, type=DE94BBA4-06D1-4D40-A16A-BFD50179D6AC, uuid=0802BFF4-2549-4CD4-A1CA-93D54AEE26F0, name="Basic data partition", attrs="RequiredPartiton GUID:63" +# /dev/sda2 : start= 616448, size= 202752, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, uuid=C9C164D5-5E0F-476D-B2EA-A4D818A266CF, name="EFI system partition", attrs="GUID:63" +# /dev/sda3 : start= 819200, size= 262144, type=E3C9E316-0B5C-4DB8-817D-F92DF00215AE, uuid=15D5A869-5C6E-4F2C-B234-7D6B91B58555, name="Microsoft reserved partition", attrs="GUID:63" +# /dev/sda4 : start= 1081344, size= 124745728, type=EBD0A0A2-B9E5-4433-87C0-68B6B72699C7, uuid=E53DEA7E-2639-4AE9-9DFD-DDD2406C3EC0, name="Basic data partition" +# ===================================== + +# We only need those required info +grep -E "^/dev" $orig_sf > $new_sf_tmp +# start=291579750 or size=291563622 is not a good format for us to parse, we need a space between "=" and "number" +# i.e. +# No good: +# /dev/sda1 : start= 63, size=291563622, Id= 7, bootable +# /dev/sda2 : start=291579750, size= 20980890, Id= 7 +# /dev/sda3 : start= 0, size= 0, Id= 0 +# /dev/sda4 : start= 0, size= 0, Id= 0 +# +# Good: +# /dev/sda1 : start= 63, size= 291563622, Id= 7, bootable +# /dev/sda2 : start= 291579750, size= 20980890, Id= 7 +# /dev/sda3 : start= 0, size= 0, Id= 0 +# /dev/sda4 : start= 0, size= 0, Id= 0 + +# //NOTE// For partitions number >=10, it looks like: +# label: gpt +# label-id: 56C0DC13-942C-493F-B141-F9903658453B +# device: /dev/sda +# unit: sectors +# first-lba: 34 +# last-lba: 125829086 +# +# /dev/sda1 : start= 2048, size= 2097152, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=4F5FF221-D350-4CE7-BADA-20022DA453CC, name="Linux filesystem" +# /dev/sda2 : start= 2099200, size= 2097152, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=975A9722-E2ED-46CC-B0E1-995095A6BB66, name="Linux filesystem" +# /dev/sda3 : start= 4196352, size= 2097152, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=A27C9E16-70B1-48D0-9A3F-915AFBA8FCC7, name="Linux filesystem" +# /dev/sda4 : start= 6293504, size= 2097152, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=3E134963-5B14-49C1-9F83-9BAF9C5F61C9, name="Linux filesystem" +# /dev/sda5 : start= 8390656, size= 2097152, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=FB1FB744-E6DC-48FA-9891-256AD0F3CF7C, name="Linux filesystem" +# /dev/sda6 : start= 10487808, size= 2097152, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=BB764A64-35BF-4415-A8D6-84642339FB3F, name="Linux filesystem" +# /dev/sda7 : start= 12584960, size= 2097152, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=B0D77252-85AB-4AFB-8866-38C21605DB7B, name="Linux filesystem" +# /dev/sda8 : start= 14682112, size= 2097152, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=79E8897A-B821-4C5D-A481-5F8628C57D2E, name="Linux filesystem" +# /dev/sda9 : start= 16779264, size= 2097152, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=2CA8A44E-9A2B-475A-BFC8-1E6295847F6A, name="Linux filesystem" +# /dev/sda10 : start= 18876416, size= 2097152, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=B454EC36-562F-4844-B8D9-28C5C1C111C9, name="Linux filesystem" +# /dev/sda11 : start= 20973568, size= 104855519, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=FA55D210-62EE-4948-A853-FDD4360CDCB5, name="Linux filesystem" + +# Therefore we force to put a space no matter there is already space or not +perl -pi -e "s/start=/start= /g" $new_sf_tmp +perl -pi -e "s/size=/size= /g" $new_sf_tmp +# Remove ":" in the temp file, since it's only for parsing, won't be used for sfdisk /dev/... < $new_sf_tmp ... +perl -pi -e "s/://g" $new_sf_tmp + +# Get the line number of "last-lba:" +header_line="$(LC_ALL=C grep -E -n "^last-lba:" $orig_sf | awk -F":" '{print $1}')" +if [ -z "$header_line" ]; then + [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE + echo "Failed to find the line \"last-lba:\" in $orig_sf!" + [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL + echo "$msg_program_stop!" + exit 1 +fi +# We do not output the line "last-lba:" in the generated line. Otherwise we have to calculate the last-lba number. +LC_ALL=C head -n "$((header_line -1))" $orig_sf > $new_sf +echo "" >> $new_sf +start_no_keep="" +size_no_keep="" +append_to_next="0" +# Initial gap for the 1st partition. After this, it should be 0. +logical_part_gap="2" +while read dev start start_no size size_no type uuid name attrs; do + pt_no="$(LC_ALL=C get_part_number $dev | sed -r -e "s|^[^[:digit:]]*||g")" + if `is_partition $dev` ; then + [ -z "$start_no_keep" ] && start_no_keep=${start_no/,/} # The 1st one + [ -z "$size_no_keep" ] && size_no_keep=0 + if [ "${size_no/,/}" -eq 0 ]; then + start_no=0 + size_no=0 + else + # If we found the partition is EFI System partition, keep the size. + # EFI System partition: C12A7328-F81F-11D2-BA4B-00A0C93EC93B, + # Ref: https://en.wikipedia.org/wiki/GUID_Partition_Table + expand="true" + if [ -n "$(echo $type | grep -iE "type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B")" ]; then + expand="false" + [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING + echo "\"EFI System partition\" found. Not to expand this partition." + [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL + fi + # If we found the partition is MS Windows "system reserved partition", keep the size. + # Microsoft Reserved Partition (MSR): E3C9E316-0B5C-4DB8-817D-F92DF00215AE + # Ref: https://en.wikipedia.org/wiki/GUID_Partition_Table + if [ -n "$(echo $type | grep -iE "type=E3C9E316-0B5C-4DB8-817D-F92DF00215AE")" ]; then + expand="false" + [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING + echo "\"Microsoft Reserved Partition (MSR)\" found. Not to expand this partition." + [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL + fi + # If we found the partition is MS Windows "system reserved partition", keep the size. + # Windows Recovery Environment DE94BBA4-06D1-4D40-A16A-BFD50179D6AC + # Ref: https://en.wikipedia.org/wiki/GUID_Partition_Table + if [ -n "$(echo $type | grep -iE "type=DE94BBA4-06D1-4D40-A16A-BFD50179D6AC")" ]; then + expand="false" + [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING + echo "\"Windows Recovery Environment\" found. Not to expand this partition." + [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL + fi + # For newer Clonezilla (>=2.4.36-1drbl), a tag file (sda1.info) might exist + if [ -e "$orig_parted_dir/$(to_filename ${dev}).info" ]; then + . $orig_parted_dir/$(to_filename ${dev}).info + if [ "$PARTITION_TYPE" = "Win_boot_reserved" ]; then + expand="false" + fi + fi + # For Linux Swap partition + if [ -n "$(echo $type | grep -iE "type=0657FD6D-A4AB-43C4-84E5-0933C84B4F4F")" ]; then + [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING + echo "Linux swap partition \"$type\" found. Not to expand this partition." + [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL + expand="false" + fi + + if [ "$expand" = "true" ]; then + start_no="$(LC_ALL=C printf "%.0f" "$(echo "($start_no_keep + $size_no_keep)" | bc -l)")" + size_no="$(LC_ALL=C printf "%.0f" "$(echo "${size_no/,/}*$ratio + $append_to_next" | bc -l)")" + # Reset the space append_to_next. + append_to_next="0" + else + start_no="$(LC_ALL=C printf "%.0f" "$(echo "($start_no_keep + $size_no_keep)" | bc -l)")" + size_no="${size_no/,/}" + # Since we do not expand this "system reserved partition" or "swap partition", + # we append the space to the next partition. + # It's possible that there are more than one partition which will be + # kept as original size, e.g. + # Number Start End Size File system Name Flags + # 1 1049kB 106MB 105MB EFI system partition boot, esp + # 2 106MB 240MB 134MB Microsoft reserved partition msftres + # 3 240MB 128GB 128GB Basic data partition msftdata + # In the above, partition 1 and 2 will not be expanded. Therefore we + # might need to add the previous $append_to_next + append_to_next="$(LC_ALL=C printf "%.0f" "$(echo "$append_to_next + ${size_no}*$ratio - ${size_no}" | bc -l)")" + fi + fi + if [ "$size_no" -lt 0 ]; then + # append_to_next might be nagtive when "-icds" is enabled and ration is < 1, therefore + # we have to check the size_no. + [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE + echo "The calculated size of $dev is < 0!" + echo "Unable to create a smaller partitions layout." + [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL + echo "$msg_program_stop!" + exit 1 + fi + echo $dev : $start $start_no, $size $size_no, $type $uuid $name $attrs >> $new_sf + [ "$start_no" -ne 0 ] && start_no_keep="${start_no/,/}" + [ "$size_no" -ne 0 ] && size_no_keep="${size_no/,/}" + fi +done < $new_sf_tmp + +echo "The partition table to write in $target_disk:" +echo "*****************************************" +cat $new_sf +echo "*****************************************" + +# EXTRA_SFDISK_OPT is environment variable +# If not --force, we force to append it since by default if sfdisk find some CHS it does not like, it won't do it without --force +if [ -z "$(echo $EXTRA_SFDISK_OPT | grep -Ew -- "--force")" ]; then + EXTRA_SFDISK_OPT="$EXTRA_SFDISK_OPT --force" +fi +echo "Running: sfdisk $EXTRA_SFDISK_OPT $target_disk < $new_sf" +LC_ALL=C sfdisk $EXTRA_SFDISK_OPT $target_disk < $new_sf +echo "Partition table was created by: sfdisk $EXTRA_SFDISK_OPT $target_disk < $new_sf" + +# Use parted to fill the last partitition to the end of disk because +# there might be some resudial in the calculation. +# Thanks to Conan for this suggestion. +# Ref: https://sourceforge.net/p/clonezilla/discussion/ +# Clonezilla_live/thread/c5e92d87/?limit=25#080c +if [ -n "$(LC_ALL=C parted -h | grep -w resizepart)" ]; then + # Find the last partition number. + # Firstly we get the line number for "Number Start End Size + # File system Name Flags" + line_after="$(LC_ALL=C parted -s $target_disk print | \ + grep -n -Ew "^Number[[:space:]]+Start[[:space:]]+End.*" | \ + awk -F":" '{print $1}')" + line_after="$((line_after +1))" + last_part_no="$(LC_ALL=C parted -s $target_disk print | \ + tail -n +${line_after} | awk -F" " '{print $1}' | sort -V | tail -n 1)" + if [ -n "$last_part_no" ]; then + echo "Trying to extend the last partition to the end of disk by:" + echo "parted -s $target_disk resizepart $last_part_no 100%" + LC_ALL=C parted -s $target_disk resizepart $last_part_no 100% + fi +fi + +[ -e "$new_sf" ] && rm -f $new_sf +[ -e "$new_sf_tmp" ] && rm -f $new_sf_tmp diff --git a/draft/other-tools/clonezilla/ocs-expand-mbr-pt b/draft/other-tools/clonezilla/ocs-expand-mbr-pt new file mode 100755 index 0000000..eeb9759 --- /dev/null +++ b/draft/other-tools/clonezilla/ocs-expand-mbr-pt @@ -0,0 +1,369 @@ +#!/bin/bash +# Author: Steven Shiau <steven _at_ nchc org tw> +# License: GPL +# A script to expand the partition table by disk size ratio. +# ///NOTE/// This program only works for MBR partition table, not for GPT. + +# Load DRBL setting and functions +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 + +# Settings +# Flag to check target disk size before creating partition table +chk_tgt_disk_size_bf_mk_pt="yes" + +# +cmd_name="$(basename $0)" +# +USAGE() { + echo "$cmd_name: To create a proportional MBR partition table (not GPT) in a disk based on a existing partition table (sfdisk format)" + echo "Usage:" + echo " $cmd_name [OPTION] PARTITION_TABLE_FILE TARGET_DEVICE" + echo + echo "OPTION:" + echo " -b, --batch Run $cmd_name in batch mode, i.e. without any prompt or wait to press enter. VERY DANGEROUS!" + echo "$cmd_name will honor experimental variable EXTRA_SFDISK_OPT and use it as the option for sfdisk." + echo " -icds, --ignore-chk-dsk-size-pt Skip checking destination disk size before creating the partition table on it. By default it will be checked and if the size is smaller than the source disk, quit." + echo "Example:" + echo " To create a proportional partition table on disk /dev/sda based on /home/partimag/IMAGE/sda-pt.sf, use:" + echo "$cmd_name /home/partimag/IMAGE/sda-pt.sf /dev/sda" +} + +# Parse command-line options +while [ $# -gt 0 ]; do + case "$1" in + -b|--batch) + batch_mode="yes" + shift;; + -icds|--ignore-chk-dsk-size-pt) + chk_tgt_disk_size_bf_mk_pt="no" + shift;; + -*) echo "${0}: ${1}: invalid option" >&2 + USAGE >& 2 + exit 2 ;; + *) break ;; + esac +done + +# Original sfdisk format file +orig_sf=$1 # orig_sf is like: /home/partimag/IMAGE/sda-pt.sf +target_disk=$2 # target_disk is like: /dev/sda + +# +ask_and_load_lang_set $specified_lang + +# +if [ -z "$orig_sf" ]; then + [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE + echo "No source partition table file was assigned!" + [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL + USAGE + echo "$msg_program_stop!" + exit 1 +fi +if [ ! -f "$orig_sf" ]; then + [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE + echo "Source partition table file \"$orig_sf\" was _NOT_ found" + [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL + echo "$msg_program_stop!" + exit 1 +fi + +if [ -z "$target_disk" ]; then + [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE + echo "No target disk was assigned!" + [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL + echo "$msg_program_stop!" + USAGE + exit 1 +fi + +# +if [ "$batch_mode" != "yes" ]; then + [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING + echo "This program will create a partition table in $target_disk" + echo "ALL THE DATA IN THE TARGET DEVICE WILL BE ERASED!!!" + [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL + echo -n "$msg_are_u_sure_u_want_to_continue ? (y/N) " + read continue_confirm_ans + case "$continue_confirm_ans" in + y|Y|[yY][eE][sS]) + echo "$msg_ok_let_do_it!" + ;; + *) + echo "$msg_program_stop!" + exit 1 + esac +fi + +# Check if GPT disk, if yes, exit +if `is_gpt_partitition_table_disk $target_disk`; then + [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE + echo "Disk $target_disk is GPT format. This program only works for MBR format." + [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL + echo "$msg_program_stop!" + exit 1 +fi + +# No size info in sda-pt.sf, we have to use sda-pt.parted. +orig_parted_tab="${orig_sf/.sf/.parted}" +orig_parted_dir="$(dirname $orig_sf)" +if [ ! -e "$orig_parted_tab" ]; then + [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE + echo "$orig_parted_tab was not found! It is required so that we know the original disk size! Maybe your Clonezilla image is too old ? You can try to create such an file in your source machine by: \"parted -s /dev/$SOURCE_DEV unit s print > $orig_parted_tab\" (Replace $SOURCE_DEV with your device name)" + [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL + echo "$msg_program_stop!" + exit 1 +fi + +# parted output format example: +# Disk /dev/sda: 16777215s +# Sector size (logical/physical): 512B/512B +# Partition Table: msdos +# +# Number Start End Size Type File system Flags +# 1 63s 586844s 586782s primary boot +# 2 586845s 978074s 391230s primary +# 3 978075s 1955204s 977130s primary +# 4 1955205s 16776584s 14821380s extended +# 5 1955268s 2151764s 196497s logical +# 6 2151828s 2542994s 391167s logical +# 7 2543058s 16776584s 14233527s logical + +ori_disk_size="$(LC_ALL=C grep -E "^Disk /dev" $orig_parted_tab | awk -F":" '{print $2}' | sed -e "s/s$//g")" +# If nothing in target disk, parted will show like this: +# sudo parted -s /dev/sda unit s print +# Error: Unable to open /dev/sda - unrecognised disk label. + +if ! LC_ALL=C parted -s $target_disk unit s print &>/dev/null; then + # Try to create a partition table so that we can read the size via parted -s $dev unit s print + echo -n "No partition table exists in target disk $target_disk, try to initialize one so that we can get the disk size by sfdisk... " + echo 1,,83 | sfdisk -f $target_disk &>/dev/null + echo "done!" +fi +tgt_disk_size="$(LC_ALL=C parted -s $target_disk unit s print | grep -E "^Disk /dev" | awk -F":" '{print $2}' | sed -e "s/s$//g")" + +# If target_disk size is larger than 2 TiB (~2.2 TB = 2,199,023,255,040 bytes), exit. It's over the MBR's limitation. +check_mbr_disk_size_gt_2TiB $target_disk exit + +# +ratio=$(echo "scale=10; $tgt_disk_size / $ori_disk_size" | bc -l) || exit 1 +echo "The ratio for target disk size to original disk size is $ratio." +if [ "$chk_tgt_disk_size_bf_mk_pt" = "yes" ]; then + if [ "$(LC_ALL=C echo "$ratio < 1" | bc -l)" = "1" ]; then + [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE + echo "The target disk (size=$tgt_disk_size sectors) is smaller than the source disk (size=$ori_disk_size sectors)!" + echo "Clonezilla won't be able to restore a partition image to smaller partition!" + [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL + echo "Program terminated!" + exit 1 + fi +fi + +new_sf="$(mktemp /tmp/new_sf.XXXXXX)" || exit 1 +new_sf_tmp="$(mktemp /tmp/new_sf_tmp.XXXXXX)" || exit 1 +# Increase. Example for sfdisk format: +# # partition table of /dev/sda +# unit: sectors +# +# /dev/sda1 : start= 63, size= 586782, Id=83, bootable +# /dev/sda2 : start= 586845, size= 391230, Id=82 +# /dev/sda3 : start= 978075, size= 977130, Id=83 +# /dev/sda4 : start= 1955205, size= 14821380, Id= 5 +# /dev/sda5 : start= 1955268, size= 196497, Id=83 +# /dev/sda6 : start= 2151828, size= 391167, Id=83 +# /dev/sda7 : start= 2543058, size= 14233527, Id=83 +# +# Or +# /dev/sda1 : start= 63, size= 196497, Id=83 +# /dev/sda2 : start= 196560, size= 16580025, Id= 5 +# /dev/sda3 : start= 0, size= 0, Id= 0 +# /dev/sda4 : start= 0, size= 0, Id= 0 +# /dev/sda5 : start= 196623, size= 16579962, Id=83 + +# We only need those required info +grep -E "^/dev" $orig_sf > $new_sf_tmp +# Format the output, since something like "Id= 5" is not a good idea for us to parse +perl -pi -e "s/Id=[[:space:]]+/Id=/g" $new_sf_tmp +# start=291579750 or size=291563622 is not a good format for us to parse, we need a space between "=" and "number" +# i.e. +# No good: +# /dev/sda1 : start= 63, size=291563622, Id= 7, bootable +# /dev/sda2 : start=291579750, size= 20980890, Id= 7 +# /dev/sda3 : start= 0, size= 0, Id= 0 +# /dev/sda4 : start= 0, size= 0, Id= 0 +# +# Good: +# /dev/sda1 : start= 63, size= 291563622, Id= 7, bootable +# /dev/sda2 : start= 291579750, size= 20980890, Id= 7 +# /dev/sda3 : start= 0, size= 0, Id= 0 +# /dev/sda4 : start= 0, size= 0, Id= 0 + +# //NOTE// For partitions number >=10, it looks like: +## partition table of /dev/sda +#unit: sectors +# +#/dev/sda1 : start= 63, size= 976562, Id=83 +#/dev/sda2 : start= 976625, size= 1171875, Id=83 +#/dev/sda3 : start= 2148500, size= 1367187, Id=83 +#/dev/sda4 : start= 3515687, size= 13256173, Id= f +#/dev/sda5 : start= 3515750, size= 195312, Id=83 +#/dev/sda6 : start= 3711063, size= 390624, Id=83 +#/dev/sda7 : start= 4101688, size= 585936, Id=83 +#/dev/sda8 : start= 4687625, size= 781249, Id=83 +#/dev/sda9 : start= 5468875, size= 976561, Id=83 +#/dev/sda10: start= 6445437, size= 976561, Id=83 <-- No space before ":" +#/dev/sda11: start= 7421999, size= 976561, Id=83 + +# Therefore we force to put a space no matter there is already space or not +perl -pi -e "s/start=/start= /g" $new_sf_tmp +perl -pi -e "s/size=/size= /g" $new_sf_tmp +# Remove ":" in the temp file, since it's only for parsing, won't be used for sfdisk /dev/... < $new_sf_tmp ... +perl -pi -e "s/://g" $new_sf_tmp + +# +echo "unit: sectors" > $new_sf +echo "" >> $new_sf +start_no_keep="" +size_no_keep="" +extended_part="" +flag_1st_logic_drv="off" +append_to_next="0" +# Initial gap for the 1st partition. After this, it should be 0. +logical_part_gap="2" +while read dev start start_no size size_no id flag; do + pt_no="$(LC_ALL=C get_part_number $dev | sed -r -e "s|^[^[:digit:]]*||g")" + if `is_partition $dev` && [ "$pt_no" -le 4 ]; then + # primary/extended partitions + [ -z "$start_no_keep" ] && start_no_keep=${start_no/,/} # The 1st one + [ -z "$size_no_keep" ] && size_no_keep=0 + if [ "${size_no/,/}" -eq 0 ]; then + start_no=0 + size_no=0 + else + # If we found the partition is MS Windows (Vista, 7) "system reserved partition", i.e. size is about 100 MB (204800) or 200 MB (409600 sectors), and Id=7, and flag is bootable, not to expand it. i.e.: + # /dev/sda1 : start= 2048, size= 204800, Id= 7, bootable + # The files and dirs in MS Windows (Vista, 7) "system reserved partition" + # drwxrwxrwx 1 root root 4.0K 2011-07-20 06:22 Boot/ + # -rwxrwxrwx 1 root root 375K 2009-07-14 01:38 bootmgr* + # -rwxrwxrwx 1 root root 8.0K 2011-07-20 06:22 BOOTSECT.BAK* + # drwxrwxrwx 1 root root 0 2011-07-20 06:31 System Volume Information/ + # //NOTE// The above files and dirs will be shown after restoring, not the time when creating partition table. Therefore we can not mount the partition and parse them. + # Ref: http://windows7forums.com/windows-7-discussion/15629-hack-remove-100-mb-system-reserved-partition-when-installing-windows-7-a.html + expand="true" + if [ "${size_no/,/}" -eq "409600" -o "${size_no/,/}" -eq "204800" ]; then + if [ -n "$(echo $id | grep -iE "(id|type)=7")" -a \ + -n "$(echo $flag | grep -iE "bootable")" ]; then + expand="false" + [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING + echo "MS Windows (Vista or 7) \"system reserved partition\" found. Not to expand this partition." + [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL + fi + fi + # For newer Clonezilla (>=2.4.36-1drbl), a tag file (sda1.info) might exist + if [ -e "$orig_parted_dir/$(to_filename ${dev}).info" ]; then + . $orig_parted_dir/$(to_filename ${dev}).info + if [ "$PARTITION_TYPE" = "Win_boot_reserved" ]; then + expand="false" + fi + fi + # For Linux Swap partition + if [ -n "$(echo $id | grep -iE "(id|type)=82")" ]; then + [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING + echo "Linux swap partition \"$id\" found. Not to expand this partition." + [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL + expand="false" + fi + + if [ "$expand" = "true" ]; then + start_no="$(LC_ALL=C printf "%.0f" "$(echo "($start_no_keep + $size_no_keep)" | bc -l)")" + size_no="$(LC_ALL=C printf "%.0f" "$(echo "${size_no/,/}*$ratio + $append_to_next" | bc -l)")" + # Reset the space append_to_next. + append_to_next="0" + else + start_no="$(LC_ALL=C printf "%.0f" "$(echo "($start_no_keep + $size_no_keep)" | bc -l)")" + size_no="${size_no/,/}" + # Since we do not expand this "system reserved partition" or "swap partition", + # we append the space to the next partition. + append_to_next="$(LC_ALL=C printf "%.0f" "$(echo "${size_no}*$ratio - ${size_no}" | bc -l)")" + fi + fi + if [ "$size_no" -lt 0 ]; then + # append_to_next might be nagtive when "-icds" is enabled and ration is < 1, therefore + # we have to check the size_no. + [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE + echo "The calculated size of $dev is < 0!" + echo "Unable to create a smaller partitions layout." + [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL + echo "$msg_program_stop!" + exit 1 + fi + if [ -n "$(echo $id | grep -iE "((id|type)=5|(id|type)=f)")" ]; then + # keep the extended partition, we need it for logical partitions. + extended_part="$dev" + extended_start_no="$start_no" + extended_size_no="$size_no" + fi + echo $dev : $start $start_no, $size $size_no, $id $flag >> $new_sf + [ "$start_no" -ne 0 ] && start_no_keep="${start_no/,/}" + [ "$size_no" -ne 0 ] && size_no_keep="${size_no/,/}" + else + # logical partitions + if [ "$flag_1st_logic_drv" = "off" ]; then + start_no_keep="$((extended_start_no))" + size_no_keep="0" + flag_1st_logic_drv="on" + fi + if [ "${size_no/,/}" -eq 0 ]; then + start_no=0 + size_no=0 + else + expand="true" + # For Linux Swap partition + if [ -n "$(echo $id | grep -iE "(id|type)=82")" ]; then + [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING + echo "Linux swap partition \"$id\" found. Not to expand this partition." + [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL + expand="false" + fi + + if [ "$expand" = "true" ]; then + start_no="$(LC_ALL=C printf "%.0f" "$(echo "($start_no_keep+$size_no_keep+$logical_part_gap)" | bc -l)")" + size_no="$(LC_ALL=C printf "%.0f" "$(echo "${size_no/,/}*$ratio + $append_to_next" | bc -l)")" + logical_part_gap="0" + # Reset the space append_to_next. + append_to_next="0" + else + start_no="$(LC_ALL=C printf "%.0f" "$(echo "($start_no_keep+$size_no_keep+$logical_part_gap)" | bc -l)")" + size_no="${size_no/,/}" + # Since we do not expand the "swap partition", we append the space to the next partition. + append_to_next="$(LC_ALL=C printf "%.0f" "$(echo "${size_no}*$ratio - ${size_no}" | bc -l)")" + fi + fi + echo $dev : $start $start_no, $size $size_no, $id $flag >> $new_sf + [ "$start_no" -ne 0 ] && start_no_keep="${start_no/,/}" + [ "$size_no" -ne 0 ] && size_no_keep="${size_no/,/}" + fi +done < $new_sf_tmp +# For sfdisk <= 0.25, only "Id=" is accepted, not "type=". +perl -pi -e "s/type=/Id=/g" $new_sf + +echo "The partition table to write in $target_disk:" +echo "*****************************************" +cat $new_sf +echo "*****************************************" + +# EXTRA_SFDISK_OPT is environment variable +# If not --force, we force to append it since by default if sfdisk find some CHS it does not like, it won't do it without --force +if [ -z "$(echo $EXTRA_SFDISK_OPT | grep -Ew -- "--force")" ]; then + EXTRA_SFDISK_OPT="$EXTRA_SFDISK_OPT --force" +fi +echo "Running: sfdisk $EXTRA_SFDISK_OPT $target_disk < $new_sf" +LC_ALL=C sfdisk $EXTRA_SFDISK_OPT $target_disk < $new_sf +echo "Partition table was created by: sfdisk $EXTRA_SFDISK_OPT $target_disk < $new_sf" + +[ -e "$new_sf" ] && rm -f $new_sf +[ -e "$new_sf_tmp" ] && rm -f $new_sf_tmp diff --git a/draft/other-tools/clonezilla/ocs-restore-ebr b/draft/other-tools/clonezilla/ocs-restore-ebr new file mode 100755 index 0000000..6912c9a --- /dev/null +++ b/draft/other-tools/clonezilla/ocs-restore-ebr @@ -0,0 +1,119 @@ +#!/bin/bash +#!/bin/bash +# License: GPL +# Author: Steven Shiau <steven _at_ clonezilla org> +# Reinstall executable code area (first 446 bytes in EBR) +# Ref: https://en.wikipedia.org/wiki/Extended_boot_record +# Extended boot record (EBR) is the 512-byte boot sector: +# 446 bytes (executable code area) + 64 bytes (table of primary partitions) + 2 bytes (EBR signature; # 0xAA55) = 512 bytes. +# EBRs have essentially the same structure as the MBR. +# +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 + +# +USAGE() { + echo "$ocs - To restore the EBR (Extended boot record) from an image to device" + echo "Usage:" + echo "To run $ocs:" + echo "$ocs [OPTION] IMAGE_NAME DEVICE" + echo "Options:" + 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 "Ex:" + echo "To restore the the EBR saved in the image \"my-image\" to device sda4, run:" + echo " $ocs my-image sda4" + echo +} # end of USAGE + + +#################### +### Main program ### +#################### + +ocs_file="$0" +ocs=`basename $ocs_file` +# +# +while [ $# -gt 0 ]; do + case "$1" in + -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 + ;; + -*) echo "${0}: ${1}: invalid option" >&2 + USAGE >& 2 + exit 2 ;; + *) break ;; + esac +done + +target_dir="$1" +shift +target_part="$*" + +# 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 + +if [ -z "$target_dir" ]; then + [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE + echo "No image was assigned!" + [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL + USAGE + echo "$msg_program_stop!" + exit 1 +fi +if [ -z "$target_part" ]; then + [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE + echo "No destination partition was assigned!" + [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL + USAGE + echo "$msg_program_stop!" + exit 1 +fi + +# +target_dir_fullpath="$ocsroot/$target_dir" + +for ipart in $target_part; do + # 1st, check if this partition on a MBR disk, not GPT one. + dsk_pt="$target_dir_fullpath/$(to_filename $(get_diskname ${ipart}))-pt.parted" + if ! `is_mbr_partitition_table_file $dsk_pt`; then + echo "Partition $ipart is not on MBR disk. Maybe it's on GPT one. No need to restore the EBR data." + continue + fi + # 2nd, check if $ipart is extended partition + # For cciss partition, e.g. /dev/cciss/c0d0p2 will be "p2" which is got from $(get_part_number /dev/cciss/c0d0p2)", here the part_index we want is only number, hence we need to trip the leading characters. + index="$(LC_ALL=C get_part_number $ipart | sed -r -e "s|^[^[:digit:]]*||g")" # index is like 2 + part_type="$(LC_ALL=C grep -Ew "^[[:space:]]*$index" ${dsk_pt} | grep -iw "extended")" + if [ -z "$part_type" ]; then + # Not extended partition + echo "Partition $ipart is not extended partition. No need to restore the EBR data." + continue + fi + + # + echo -n "Restoring the first 446 bytes of EBR data for extended partition $ipart... " + dd if=$target_dir_fullpath/$(to_filename ${ipart})-ebr of=/dev/$ipart bs=446 count=1 &>/dev/null + echo "done." + echo $msg_delimiter_star_line +done diff --git a/draft/other-tools/clonezilla/ocs-restore-mbr b/draft/other-tools/clonezilla/ocs-restore-mbr new file mode 100755 index 0000000..08fc697 --- /dev/null +++ b/draft/other-tools/clonezilla/ocs-restore-mbr @@ -0,0 +1,131 @@ +#!/bin/bash + +# Reinstall executable code area (first 446 bytes in MBR) + +# 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. +# +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 + +# Setings +# By default we do not restore the prebuild mbr from syslinux. +restore_prebuild_mbr="no" + +# +USAGE() { + echo "$ocs - To restore the MBR from an image to device" + echo "Usage:" + echo "To run $ocs:" + echo "$ocs [OPTION] IMAGE_NAME DEVICE" + echo "Options:" + echo "-p, --prebuild_mbr Use the prebuild bootloader from syslinux (For Windows only), not from the saved image" + 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. sda, sda..." + echo "Ex:" + echo "To restore the the mbr saved in the image \"my-image\" to device sda, run:" + echo " $ocs my-image sda" + echo +} # end of USAGE + + +#################### +### Main program ### +#################### + +ocs_file="$0" +ocs=`basename $ocs_file` +# +# +while [ $# -gt 0 ]; do + case "$1" in + -p|--prebuild_mbr) + restore_prebuild_mbr="yes" + 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 + ;; + -*) echo "${0}: ${1}: invalid option" >&2 + USAGE >& 2 + exit 2 ;; + *) break ;; + esac +done + +target_dir="$1" +shift +target_hd="$*" + +# 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 + +if [ -z "$target_dir" ]; then + [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE + echo "No image was assigned!" + [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL + USAGE + echo "$msg_program_stop!" + exit 1 +fi +if [ -z "$target_hd" ]; then + [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE + echo "No destination disk was assigned!" + [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL + USAGE + echo "$msg_program_stop!" + exit 1 +fi + +# +target_dir_fullpath="$ocsroot/$target_dir" + +for ihd in $target_hd; do + # No matter it's msdos partition table or GPT one, here we restore the MBR. + # If it's GPT format, this could make GPT one as "valid GPT with protective MBR", + # and it's still GPT format. + # Some OS (e.g. VMware ESXi 5.5.0) need protective MBR even it's GPT partition table. + # Ref: + # https://sourceforge.net/p/clonezilla/discussion/Clonezilla_live/thread/30662778/ + # https://sourceforge.net/p/clonezilla/discussion/Clonezilla_live/thread/ca825570/ + + # Install MBR which displays a failure message on boot. This is for fault tolerance. If all the partitions are cloned successfully, the correcting MBR will be restored later. For more info, please check https://sourceforge.net/tracker/?func=detail&atid=671653&aid=2793248&group_id=115473 + cat /usr/share/partclone/fail-mbr.bin > /dev/$ihd + if [ "$restore_prebuild_mbr" = "yes" ]; then + # For M$ Windows system, sometimes it will fail if we restore the mbr from the one we saved (Ex. hda-mbr). Another option is to use mbr.bin from syslinux + cat_cmd="cat $pxelinux_binsrc_dir/bios/mbr.bin > /dev/$ihd" + echo "Restoring the mbr.bin from syslinux to /dev/$ihd by:" + echo "$cmd_cmd" + eval $cat_cmd + echo "done." + else + dd_cmd="dd if=$target_dir_fullpath/$(to_filename ${ihd})-mbr of=/dev/$ihd bs=446 count=1 &>/dev/null" + echo "Restoring the first 446 bytes of MBR data (executable code area) for $ihd by:" + echo "$dd_cmd" + eval $dd_cmd + echo "done." + fi + echo $msg_delimiter_star_line +done diff --git a/draft/other-tools/clonezilla/ocs-sr b/draft/other-tools/clonezilla/ocs-sr new file mode 100755 index 0000000..7ea1d9f --- /dev/null +++ b/draft/other-tools/clonezilla/ocs-sr @@ -0,0 +1,1465 @@ +#!/bin/bash +# +# License: GPL +# Original author: Blake, Kuo-Lien Huang +# Description: +# 2003/04/11 the first version, only work on /dev/hda1 & PXE +# 2003/06/01 disk to disk mode & etherboot support +# (the etherboot lzdsk images are located in +# /tftpboot/etherboot-5.0.7 after DRBLCD installed) +# 2003/07/18 `checkInodeForDevice` +# +# Author: Steven Shiau <steven _at_ nchc org tw> +# 2003/07/21 the first version for Redhat, modified from Blake's version, +# only work on /dev/hda1 & PXE +# 2004/02/04 add the multicast function +# 2005/01/21 add code to save/restore some partitions (not entire disk). +# 2005/11/06 Many thanks to Christian Treczoks for providing "dd skip=1" method +# 2006/05/06 Remove save & restore hda1, since we can use save & restore partitions. +# 2006/12/07 Rewrite drbl-ocs to drbl-ocs + ocs-sr + ocs-functions. + +# input parameters: +# save/savedisk/saveparts/restore/restoredisk/restoreparts/multicast_restore/multicast_restoredisk IMAGE-NAME DEVICES + +# Notes: +# task_restorexxx/savexxx function will always use $ocsroot (/home/partimag) as mount point to do the save/restore, so it might overwrite the /home/partimag by mounting $ocsroot from server:/home2 (for example). +# The mount action is done in function task_preprocessing + +ocs_file="$0" +ocs=`basename $ocs_file` +ocs_myself_id="$$" +# we need ocs_ppid for ocs-functions +ocs_ppid="$PPID" +# log file for sfdisk when restoring +# RESTORE_SFDISK_LOG is loaded from drbl.conf + +# Some initial setting +confirm_before_clone="no" +ocs_sr_mode="" +gen_md5sum="no" +gen_sha1sum="no" +check_md5sum="no" +check_sha1sum="no" +gen_chksum_for_files_in_dev="no" +chk_chksum_for_files_in_dev="no" +chk_img_restoreable_mod_save_def="yes" +chk_img_restoreable_mod_restore_def="yes" +# Flag to save restoring error log +save_restore_error_log="no" +# Flag to check target disk size before creating partition table +chk_tgt_disk_size_bf_mk_pt="yes" +# Flag to update EFI NVRAM after restoring a disk +update_efi_nvram="" + +# Load DRBL setting and functions +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 + +# 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 + +# +USAGE() { + echo "Usage:" + echo "To save or restore image" + echo "$ocs [OPTION] {savedisk|saveparts|restoredisk|restoreparts} IMAGE_NAME DEVICE" + echo + echo " Options for saving:" + USAGE_common_save + echo " -i, --image-size SIZE Set the split image file volume size SIZE (MB). When $ocs is run with -x, the default SIZE is set as $VOL_LIMIT_IN_INTERACTIVE, if without -x, we will not split it." + USAGE_reserved_word_for_save + echo + echo " Options for restoring:" + USAGE_common_restore + echo " --mcast-port NO Assign the udp port number for multicast restore. This is used by clonezilla server. Normally it's not necessary to manually assign this option." + USAGE_reserved_word_for_restore + echo + echo " General options:" + USAGE_common_general + dialog_like_prog_help_prompt + echo " -x, --interactive Interactive mode to save or restore." + echo + echo "Example:" + echo " To save or restore image in client (Only that DRBL client will join, and its local partitions is NOT mounted). NOTE!!! You should run the command in DRBL client or you have to make sure the target device is NOT busy!." + echo " To save all the data in local first IDE harddrive 'hda' as image 'IMAGE1', use ntfsclone instead of partimage, and lzop compression (NOTE!!! You should run the command in DRBL client or make sure hda is NOT busy/mounted!):" + echo " $ocs --use-ntfsclone -z3 savedisk IMAGE1 hda" + echo + echo " To save the data in first and second partitions in local first IDE harddrive 'hda' as image 'IMAGE2', use ntfsclone instead of partimage, and lzop compression (NOTE!!! You should run the command in DRBL client, or make sure hda is NOT busy/mounted!):" + echo " $ocs" '--use-ntfsclone -z3 saveparts IMAGE2 "hda1 hda2"' + echo + echo " To restore image "IMAGE1" to local hda. grub-install will be run after cloning (image IMAGE1 is already in DRBL server. NOTE!!! You should run the command in DRBL client or make sure hda is NOT busy/mounted!):" + echo " $ocs -g auto restoredisk IMAGE1 hda" + echo + echo " To restore image first and second partitions from "IMAGE2" to local hda1 and hda2. grub-install will be run after cloning (image IMAGE2 is already in DRBL server. NOTE!!! You should run the command in DRBL client or make sure hda is NOT busy/mounted!):" + echo " $ocs" '-g auto restoreparts IMAGE2 "hda1 hda2"' + echo + echo " To save disk(s)/partitition(s) as an image or restore an image to disk(s)/partitition(s) interactively, use:" + echo " $ocs -x" +} +# +parse_ocs_sr_cmd_options_with_dash() { + # Parse command-line options + # It's UGLY to use "shift; n_shift=$((n_shift+1))" + # However, we want to reuse the parse_ocs_sr_cmd_options_with_dash, + # a problem here: + # The parameters (-b -g auto --nogui --max-time-to-wait 300 --language 0 multicast_restoreparts sarge-base "hda1 hda3" 2232), when put it as $*, it will + # become (-b -g auto --nogui --max-time-to-wait 300 --language 0 multicast_restoreparts sarge-base hda1 hda3 2232), you see, "hda1 hda3" -> hda1 hda3 + # Then everyting is in a mess... so now the best solution I can find is to + # calculate the n_shift, then parse it to original shell, not in the function. + + n_shift=0 + while [ $# -gt 0 ]; do + case "$1" in + -l|--language) + shift; n_shift=$((n_shift+1)) + if [ -z "$(echo $1 |grep ^-.)" ]; then + # skip the -xx option, in case + specified_lang="$1" + shift; n_shift=$((n_shift+1)) + fi + [ -z "$specified_lang" ] && USAGE && exit 1 + ;; + -g|--grub-install) + install_grub="on" + shift; n_shift=$((n_shift+1)) + # skip the -xx option, in case + if [ -z "$(echo $1 |grep ^-.)" ]; then + grub_partition=$1 + shift; n_shift=$((n_shift+1)) + fi + [ -z "$grub_partition" ] && USAGE && exit 1 + ;; + -f|--from-part-in-img) + shift; n_shift=$((n_shift+1)) + # skip the -xx option, in case + if [ -z "$(echo $1 |grep ^-.)" ]; then + source_part=$1 + shift; n_shift=$((n_shift+1)) + fi + [ -z "$source_part" ] && USAGE && exit 1 + ;; + -a|--no-force-dma-on) + force_dma_on="no" + shift; n_shift=$((n_shift+1));; + -k|--no-fdisk|--no-create-partition) + create_part="no" + shift; n_shift=$((n_shift+1));; + -k1|--fdisk-proportion) + create_part="yes" + create_part_type="proportion" + shift; n_shift=$((n_shift+1));; + -k2|--fdisk-manual) + create_part="yes" + create_part_type="manual" + shift; n_shift=$((n_shift+1));; + -t|--no-restore-mbr) + restore_mbr="no" + shift; n_shift=$((n_shift+1));; + -t1|--restore-raw-mbr) + # The flag to restore syslinux mbr.bin to M$ windows system. + restore_prebuild_mbr="yes" + shift; n_shift=$((n_shift+1));; + -t2|--no-restore-ebr) + restore_ebr="no" + shift; n_shift=$((n_shift+1));; + -u|--select-img-in-client) + select_img_in_client="yes" + shift; n_shift=$((n_shift+1));; + -e|--load-geometry) + load_HD_CHS_from_img="yes" + shift; n_shift=$((n_shift+1));; + -e1|--change-geometry) + change_ntfs_boot_chs="on" + shift; n_shift=$((n_shift+1)) + # skip the -xx option, in case + if [ -z "$(echo $1 |grep ^-.)" ]; then + ntfs_boot_partition=$1 + shift; n_shift=$((n_shift+1)) + fi + [ -z "$ntfs_boot_partition" ] && USAGE && exit 1 + ;; + -e2|--load-geometry-from-edd) + use_HD_CHS_from_EDD_pref="yes" + shift; n_shift=$((n_shift+1));; + -y|-y0|--always-restore|--always-restore-default-local) + always_restore="yes" + pxe_menu_default_mode="local" + shift; n_shift=$((n_shift+1));; + -y1|--always-restore-default-clone) + always_restore="yes" + pxe_menu_default_mode="clone" + shift; n_shift=$((n_shift+1));; + -y2|--always-restore-default-drbl) + always_restore="yes" + pxe_menu_default_mode="drbl" + shift; n_shift=$((n_shift+1));; + -c|--confirm) + confirm_before_clone="yes" + shift; n_shift=$((n_shift+1));; + -sc|-scs|--skip-check-restorable|--skip-check-restorable-s) + # Flag to check if the image is restorable + chk_img_restoreable_mod_save="no" + shift; n_shift=$((n_shift+1));; + -scr|--skip-check-restorable-r) + # Flag to check if the image is restorable + chk_img_restoreable_mod_restore="no" + shift; n_shift=$((n_shift+1));; + -srel|--save-restore-error-log) + # Flag to save restoring log + save_restore_error_log="yes" + shift; n_shift=$((n_shift+1));; + -w|--wait-time) + shift; n_shift=$((n_shift+1)) + if [ -z "$(echo $1 |grep ^-.)" ]; then + # skip the -xx option, in case + TIME_to_wait="$1" + shift; n_shift=$((n_shift+1)) + fi + ;; + --debug=?*) + debug_level=${1#--debug=} + shift; n_shift=$((n_shift+1));; + -b|-batch|--batch) + ocs_batch_mode="on" + shift; n_shift=$((n_shift+1));; + -d|--debug-mode) + debug_mode="on" + shift; n_shift=$((n_shift+1));; + -d0|--dialog) + DIA="dialog" + shift;; + -d1|--Xdialog) + DIA="Xdialog" + shift;; + -d2|--whiptail) + DIA="whiptail" + shift;; + -d3|--gdialog) + DIA="gdialog" + shift;; + -d4|--kdialog) + DIA="kdialog" + shift;; + -enc|--enc-ocs-img) + encrypt_ocs_img="yes" + shift; n_shift=$((n_shift+1));; + -senc|--skip-enc-ocs-img) + encrypt_ocs_img="no" + shift; n_shift=$((n_shift+1));; + -m|--module) + shift; n_shift=$((n_shift+1)) + if [ -z "$(echo $1 |grep ^-.)" ]; then + # skip the -xx option, in case + module_to_load=$1 + shift; n_shift=$((n_shift+1)) + fi + [ -z "$module_to_load" ] && USAGE && exit 1 + ;; + -r|--resize-partition) + resize_partition="on" + shift; n_shift=$((n_shift+1));; + -v|--verbose) + verbose="on" + shift; n_shift=$((n_shift+1));; + -z0|--no-compress) + IMG_CLONE_CMP="cat" + shift; n_shift=$((n_shift+1));; + -z1|--gzip-compress) + IMG_CLONE_CMP="gzip -c $extra_gzip_opt" + shift; n_shift=$((n_shift+1));; + -z1p|--smp-gzip-compress) + IMG_CLONE_CMP="pigz -c $extra_pigz_opt" + shift; n_shift=$((n_shift+1));; + -z2|--bz2-compress) + IMG_CLONE_CMP="bzip2 -c $extra_bzip2_opt" + shift; n_shift=$((n_shift+1));; + -z2p|--smp-bzip2-compress) + if [ "$parallel_bzip2_prog" = "pbzip2" ]; then + IMG_CLONE_CMP="pbzip2 -c $extra_pbzip2_opt" + elif [ "$parallel_bzip2_prog" = "lbzip2" ]; then + IMG_CLONE_CMP="lbzip2 -c $extra_lbzip2_opt" + fi + shift; n_shift=$((n_shift+1));; + -z3|--lzo-compress) + # Now only for ntfsclone, partimage not yet. + IMG_CLONE_CMP="lzop -c $extra_lzop_opt" + shift; n_shift=$((n_shift+1));; + -z4|--lzma-compress) + IMG_CLONE_CMP="lzma -c $extra_lzma_opt" + shift; n_shift=$((n_shift+1));; + -z5|--xz-compress) + IMG_CLONE_CMP="xz -c $extra_xz_opt" + shift; n_shift=$((n_shift+1));; + -z5p|--smp-xz-compress) + IMG_CLONE_CMP="pixz $extra_pixz_opt" + shift; n_shift=$((n_shift+1));; + -z6|--lzip-compress) + IMG_CLONE_CMP="lzip -c $extra_lzip_opt" + shift; n_shift=$((n_shift+1));; + -z6p|--smp-lzip-compress) + IMG_CLONE_CMP="plzip -c $extra_plzip_opt" + shift; n_shift=$((n_shift+1));; + -z7|--lrzip-compress) + # The option for lrzip is different from that of gzip (not -c) + # Although lrzip uses "-p value Set processor count to override number of threads" to assign the CPU number, however, from the manual of lrzip: + # -p value + # Set the number of processor count to determine the number of + # threads to run. Normally lrzip will scale according to the num‐ + # ber of CPUs it detects. Using this will override the value in + # case you wish to use less CPUs to either decrease the load on + # your machine, or to improve compression. Setting it to 1 will + # maximise compression but will not attempt to use more than one + # CPU. + # Therefore there is no need to assign a parallel version of lrzip. + IMG_CLONE_CMP="lrzip -q - $extra_lrzip_opt" + shift; n_shift=$((n_shift+1));; + -nogui|--nogui) + # -nogui is for backward compatable, better to use --nogui + nogui="on" + shift; n_shift=$((n_shift+1));; + -ntfs-ok|--ntfs-ok) + # if ntfs integrity is assumed OK, do not check + ntfs_integrity_check="no" + shift; n_shift=$((n_shift+1));; + -rm-win-swap-hib|--rm-win-swap-hib) + # Remove page and hibernation files in M$ windows + rm_win_swap_hib="yes" + shift; n_shift=$((n_shift+1));; + -rescue|--rescue) + rescue_mode="on" + shift; n_shift=$((n_shift+1));; + -sfsck|--skip-fsck-src-part) + fsck_src_part_intr="no" + fsck_src_part_auto="no" + shift; n_shift=$((n_shift+1));; + -fsck-src-part|--fsck-src-part|-fsck) + fsck_src_part_intr="yes" + shift; n_shift=$((n_shift+1));; + -fsck-src-part-y|--fsck-src-part-y|-fsck-y) + fsck_src_part_auto="yes" + shift; n_shift=$((n_shift+1));; + -mp|--mount-point) + shift; n_shift=$((n_shift+1)); + if [ -z "$(echo $1 |grep ^-.)" ]; then + # skip the -xx option, in case + mount_point=$1 + shift; n_shift=$((n_shift+1)) + fi + [ -z "$mount_point" ] && USAGE && exit 1 + ;; + -or|--ocsroot) + # overwrite the ocsroot in drbl.conf + shift; n_shift=$((n_shift+1)); + if [ -z "$(echo $1 |grep ^-.)" ]; then + # skip the -xx option, in case + ocsroot="$1" + shift; n_shift=$((n_shift+1)) + fi + [ -z "$ocsroot" ] && USAGE && exit 1 + ;; + -i|--image-size) + shift; n_shift=$((n_shift+1)) + if [ -z "$(echo $1 |grep ^-.)" ]; then + # skip the -xx option, in case + VOL_LIMIT=$1 + shift; n_shift=$((n_shift+1)) + fi + [ -z "$VOL_LIMIT" ] && USAGE && exit 1 + ;; + --max-time-to-wait) + # ocs-sr need to know the --max-time-to-wait so that when sleeping + # between partitions restoring clone won't timeout. + shift; n_shift=$((n_shift+1)) + if [ -z "$(echo $1 |grep ^-.)" ]; then + # skip the -xx option, in case + mcast_max_wait_time="$1" + shift; n_shift=$((n_shift+1)) + fi + [ -z "$mcast_max_wait_time" ] && USAGE && exit 1 + ;; + -q|--use-ntfsclone) + USE_NTFSCLONE="yes" + shift; n_shift=$((n_shift+1));; + -q1|--force-to-use-dd) + FORCE_TO_USE_DD="yes" + shift; n_shift=$((n_shift+1));; + -q2|--use-partclone) + USE_PARTCLONE="yes" + shift; n_shift=$((n_shift+1));; + -j|--create-part-by-sfdisk) + # We leave this option for backward compatability. + create_part_by_sfdisk="yes" + shift; n_shift=$((n_shift+1));; + -j0|--create-part-by-dd) + create_part_by_sfdisk="no" + shift; n_shift=$((n_shift+1));; + -j1|--dump-mbr-in-the-end) + dump_mbr_in_the_end="yes" + shift; n_shift=$((n_shift+1));; + -j2|--clone-hidden-data) + clone_hidden_data="yes" + shift; n_shift=$((n_shift+1));; + -icrc|--icrc) + do_partclone_crc_check="no" + shift; n_shift=$((n_shift+1));; + -irvd|--irvd) + rm_ntfs_vol_dirty_flag="no" + shift; n_shift=$((n_shift+1));; + -irhr|--irhr) + do_rm_hardware_record="no" + shift; n_shift=$((n_shift+1));; + -ius|--ius) + do_update_syslinux="no" + shift; n_shift=$((n_shift+1));; + -hn0) + shift; n_shift=$((n_shift+1)) + change_win_hostname="By_IP" + if [ -z "$(echo $1 |grep ^-.)" ]; then + # skip the -xx option, in case + win_hostname_prefix="$1" + shift; n_shift=$((n_shift+1)) + fi + [ -z "$win_hostname_prefix" ] && USAGE && exit 1 + ;; + -hn1) + shift; n_shift=$((n_shift+1)) + change_win_hostname="By_MAC" + if [ -z "$(echo $1 |grep ^-.)" ]; then + # skip the -xx option, in case + win_hostname_prefix="$1" + shift; n_shift=$((n_shift+1)) + fi + [ -z "$win_hostname_prefix" ] && USAGE && exit 1 + ;; + -o|-o1|--run-postrun-dir) + # -o is for backward compatability + run_postrun_dir="yes" + shift; n_shift=$((n_shift+1));; + -o0|--run-prerun-dir) + run_prerun_dir="yes" + shift; n_shift=$((n_shift+1));; + -ns|--ntfs-progress-in-image-dir) + ntfsclone_progress="image_dir" + shift; n_shift=$((n_shift+1));; + -gm|--gen-md5sum) + gen_md5sum="yes" + shift; n_shift=$((n_shift+1));; + -gs|--gen-sha1sum) + gen_sha1sum="yes" + shift; n_shift=$((n_shift+1));; + -cm|--check-md5sum) + check_md5sum="yes" + shift; n_shift=$((n_shift+1));; + -cs|--check-sha1sum) + check_sha1sum="yes" + shift; n_shift=$((n_shift+1));; + -gmf|--gen-chksum-for-files-in-dev) + gen_chksum_for_files_in_dev="yes" + shift; n_shift=$((n_shift+1));; + -cmf|--chk-chksum-for-files-in-dev) + chk_chksum_for_files_in_dev="yes" + shift; n_shift=$((n_shift+1));; + -x|--interactive) + ocs_sr_mode="interactive" + shift; n_shift=$((n_shift+1));; + --mcast-port) + shift; n_shift=$((n_shift+1)); + if [ -z "$(echo $1 |grep ^-.)" ]; then + # skip the -xx option, in case + ocs_sr_mcast_port="$1" + shift; n_shift=$((n_shift+1)) + fi + [ -z "$ocs_sr_mcast_port" ] && USAGE && exit 1 + ;; + -p|--postaction) + shift; n_shift=$((n_shift+1)); + if [ -z "$(echo $1 |grep ^-.)" ]; then + # skip the -xx option, in case + postaction="$1" + shift; n_shift=$((n_shift+1)) + fi + [ -z "$postaction" ] && USAGE && exit 1 + ;; + --restore-only) + ocs_x_mode="restore_only" + shift; n_shift=$((n_shift+1));; + --save-only) + ocs_x_mode="save_only" + shift; n_shift=$((n_shift+1));; + -um|--user-mode) + shift; n_shift=$((n_shift+1)); + # skip the -xx option, in case + if [ -z "$(echo $1 |grep ^-.)" ]; then + ocs_user_mode="$1" + shift; n_shift=$((n_shift+1)); + fi + [ -z "$ocs_user_mode" ] && USAGE && exit 1 + ;; + -icds|--ignore-chk-dsk-size-pt) + chk_tgt_disk_size_bf_mk_pt="no" + shift; n_shift=$((n_shift+1));; + -iefi|--ignore-update-efi-nvram) + update_efi_nvram="no" + shift; n_shift=$((n_shift+1));; + -*) echo "${0}: ${1}: invalid option" >&2 + USAGE >& 2 + exit 2 ;; + *) break ;; + esac + done +} # end of parse_ocs_sr_cmd_options_with_dash +# +save_only_dia_des() { + savedisk_msg_1="savedisk" + savedisk_msg_2="$(rep_whspc_w_udrsc "$msg_clonezilla_save_local_disk")" + saveparts_msg_1="saveparts" + saveparts_msg_2="$(rep_whspc_w_udrsc "$msg_clonezilla_save_local_parts")" +} +# +restore_only_dia_des() { + restoredisk_msg_1="restoredisk" + restoredisk_msg_2="$(rep_whspc_w_udrsc "$msg_clonezilla_restore_local_disk")" + restoreparts_msg_1="restoreparts" + restoreparts_msg_2="$(rep_whspc_w_udrsc "$msg_clonezilla_restore_local_parts")" +} +recovery_clonezilla_live_dia_des() { + recovery_clonezilla_live_msg_1="recovery-iso-zip" + recovery_clonezilla_live_msg_2="$(rep_whspc_w_udrsc "$msg_recovery_clonezilla_live")" +} +chk_img_restorable_dia_des() { + chk_img_restorable_msg_1="chk-img-restorable" + chk_img_restorable_msg_2="$(rep_whspc_w_udrsc "$msg_check_if_image_restorable")" +} +convert_img_compression_dia_des() { + convert_img_compression_msg_1="cvt-img-compression" + convert_img_compression_msg_2="$(rep_whspc_w_udrsc "$msg_convert_img_compression")" +} +encrypt_img_dia_des() { + encrypt_img_msg_1="encrypt-img" + encrypt_img_msg_2="$(rep_whspc_w_udrsc "$msg_encrypt_existing_img")" +} +decrypt_img_dia_des() { + decrypt_img_msg_1="decrypt-img" + decrypt_img_msg_2="$(rep_whspc_w_udrsc "$msg_decrypt_existing_img")" +} +p2v_img_dia_des() { + p2v_img_msg_1="p2v-img" + p2v_img_msg_2="$(rep_whspc_w_udrsc "$msg_p2v_existing_img")" +} +one_image_to_multiple_disks_dia_des() { + one_2_m_disks_msg_1="1-2-mdisks" + one_2_m_disks_msg_2="$(rep_whspc_w_udrsc "$msg_restore_1_image_to_multiple_local_disks")" +} +# functions to process options. +wrap_up_opt() { + [ -z "$VOL_LIMIT" ] && VOL_LIMIT=$VOL_LIMIT_DEFAULT + + # change to other mount point for extra harddisk + # Note: functions get_existing_disk_image, get_existing_parts_image and get_existing_partitions_from_img will use $imagedir + if [ -n "$mount_point" ]; then + echo "Option -mp|--mount-point is assigned." + echo "Using the image root directory $mount_point instead of $ocsroot." + imagedir="$mount_point" + else + imagedir="$ocsroot" + fi + + check_ocs_input_params + + # Set/Reset init values + PARTIMAGE_SAVE_OPT="$PARTIMAGE_SAVE_OPT_INIT --debug=$debug_level" + PARTIMAGE_RESTORE_OPT="$PARTIMAGE_RESTORE_OPT_INIT --debug=$debug_level" + PARTCLONE_SAVE_OPT="$PARTCLONE_SAVE_OPT_INIT" + PARTCLONE_RESTORE_OPT="$PARTCLONE_RESTORE_OPT_INIT" + if [ "$nogui" = "on" ]; then + # Partimage default uses TUI, if noguid, we have to run it with -B gui=no + PARTIMAGE_SAVE_OPT="$PARTIMAGE_SAVE_OPT -B gui=no" + PARTIMAGE_RESTORE_OPT="$PARTIMAGE_RESTORE_OPT -B gui=no" + fi + if [ "$nogui" = "off" ]; then + # TUI is on. + # Use the TUI mode for partclone (i.e. run with -N, otherwise by default partclone runs only text output) + # //NOTE// From Partclone 0.2.52, if -N is set for partclone in save mode, the ncurse interface is able to be shown in stderr. + PARTCLONE_SAVE_OPT="$PARTCLONE_SAVE_OPT -N" + PARTCLONE_RESTORE_OPT="$PARTCLONE_RESTORE_OPT_INIT -N" + fi + if [ "$rescue_mode" = "on" ]; then + PARTCLONE_SAVE_OPT="$PARTCLONE_SAVE_OPT --rescue" + fi + if [ "$do_partclone_crc_check" = "no" ]; then + PARTCLONE_RESTORE_OPT="$PARTCLONE_RESTORE_OPT --ignore_crc" + fi + + echo $msg_delimiter_star_line + [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING + [ "$create_part" = "no" ] && echo "$msg_do_not_create_part" + [ "$restore_mbr" = "no" ] && echo "$msg_do_not_restore_mbr" + [ "$select_img_in_client" = "yes" ] && echo "$msg_you_have_to_input_image_names_in_client" + [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL + + # Append postaction, since we did not ask that in set_ocs_sr_extra_param and we might already set that. + if [ -n "$postaction" -a \ + -z "$(echo $OCS_OPTS | grep -Ewo -- "-p")" ] + then + OCS_OPTS="$OCS_OPTS -p $postaction" + fi + if [ "$verbose" = "on" ]; then + PARTCLONE_SAVE_OPT="$PARTCLONE_SAVE_OPT -d" + PARTCLONE_RESTORE_OPT="$PARTCLONE_RESTORE_OPT -d" + echo "OCS_OPTS: $OCS_OPTS" + echo "PARTIMAGE_SAVE_OPT: $PARTIMAGE_SAVE_OPT" + echo "PARTIMAGE_RESTORE_OPT: $PARTIMAGE_RESTORE_OPT" + echo "PARTCLONE_SAVE_OPT: $PARTCLONE_SAVE_OPT" + echo "PARTCLONE_RESTORE_OPT: $PARTCLONE_RESTORE_OPT" + # The default output for udpcast stderr is surpressed, now turn it on + udpcast_stderr="/dev/stderr" + fi + # If VOL_LIMIT is too large, split won't work. Check and fix it if required. + check_and_fix_vol_limit_if_required +} # end of wrap_up_opt +# +wrap_up_opt_after_interactive_selection() { + wrap_up_opt + # For case when interactive mode the option "-scr" or "-scs" is used. + # i.e. command like: "ocs-sr -x -scr" or "ocs-sr -x "-scs" + if [ -z "$chk_img_restoreable_mod_save" ]; then + chk_img_restoreable_mod_save="$chk_img_restoreable_mod_save_def" + fi + if [ -z "$chk_img_restoreable_mod_restore" ]; then + chk_img_restoreable_mod_restore="$chk_img_restoreable_mod_restore_def" + fi + # Shall we set default postaction if empty here? + #[ -z "$postaction" ] && postaction="$POSTACTION_DEF" + +} # end of wrap_up_opt_after_interactive_selection +# +run_ocs_sr_again_prompt() { + local img dev + # OCS_OPTS is a global variable + img="$1" + dev="$2" + if [ "$ocs_sr_mode" = "interactive" ]; then + run_again_fname="/tmp/ocs-$img-`date +%F-%H-%M`" + [ "$BOOTUP" = "color" ] && $SETCOLOR_SUCCESS + echo PS. $msg_run_drbl_ocs_again_cmd | tee --append ${OCS_LOGFILE} + echo $0 $OCS_OPTS $ocs_sr_type $img $dev >> ${OCS_LOGFILE} + echo $0 $OCS_OPTS $ocs_sr_type $img $dev | tee $run_again_fname + echo "$msg_ocs_sr_again_command_saved_filename: $run_again_fname" + [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL + [ -e "$run_again_fname" ] && chmod 755 $run_again_fname + echo $msg_delimiter_star_line | tee --append ${OCS_LOGFILE} + if [ "$ocs_batch_mode" != "on" ]; then + echo -n "$msg_press_enter_to_continue " + read + fi + fi +} # end of run_ocs_sr_again_prompt +# +save_ocs_sr_related_vars() { + # Function to save ocs-related variables so that some customized program can use. + # The old one will be overwritten + mkdir -p /var/lib/clonezilla/ + echo "ocs_cmd=\"$ocs\"" > /var/lib/clonezilla/ocs-vars + echo "target_dir=\"$target_dir\"" >> /var/lib/clonezilla/ocs-vars + echo "target_hd=\"$target_hd\"" >> /var/lib/clonezilla/ocs-vars + echo "postaction=\"$postaction\"" >> /var/lib/clonezilla/ocs-vars + echo "ocs_sr_mode=\"$ocs_sr_mode\"" >> /var/lib/clonezilla/ocs-vars +} # end of save_ocs_related_var +# +create_clonezilla_live_recovery_iso_zip() { + # Target command Ex: + # ocs-iso -g en -t -k NONE -e "-b -c restoredisk sarge-r5 hda" sarge-r5 + # ocs-live-dev -c -g en -t -k NONE -e "-b -c restoredisk sarge-r5 hda" sarge-r5 + local REC_TMP ans_ + REC_TMP=`mktemp /tmp/ocs_recovery_tmp.XXXXXX` + trap "[ -f "$REC_TMP" ] && rm -f $REC_TMP" HUP INT QUIT TERM EXIT + + # Ask image name first (disk or parts image) + if [ "$ocs_sr_img_name" = "ask_user" ]; then + # Since get_target_dir_name_when_restoring_parts can search disk and parts image, we use this function instead of get_target_dir_name_when_restoring_disk + get_target_dir_name_when_restoring_parts # get $target_dir + else + target_dir="$ocs_sr_img_name" + fi + check_input_target_image "$ocsroot/$target_dir" + # Check if the image is disk or parts + if [ -e "$ocsroot/$target_dir/disk" ]; then + rec_dev_action=restoredisk + else + rec_dev_action=restoreparts + fi + + # ask target disk/parts + case "$rec_dev_action" in + "restoredisk") + dev_prompt_and_example="$msg_input_device_name_for_recovery_iso_zip ($msg_ex: 'hda' $msg_or 'sda' $msg_or 'hda hdb' $msg_or 'sda sdb') \n$msg_linux_disk_MS_mapping\n$msg_prompt_to_use_ask_user_for_later_choose" + # savedisk_preset is borrowed from drbl-ocs.conf + dev_preset="$(get_disk_list_from_img $ocsroot/$target_dir)" + ;; + "restoreparts") + dev_prompt_and_example="$msg_input_device_name_for_recovery_iso_zip ($msg_ex: 'hda1 hda2' $msg_or 'sda1 sda2') \n$msg_linux_parts_MS_mapping\n$msg_prompt_to_use_ask_user_for_later_choose" + # saveparts_preset is borrowed from drbl-ocs.conf + dev_preset="$(get_parts_list_from_img $ocsroot/$target_dir)" + ;; + esac + ASK_DEV_NAME=1 + while [ "$ASK_DEV_NAME" -ne 0 ]; do + $DIA --backtitle "$msg_nchc_free_software_labs" --title "$msg_nchc_clonezilla | $msg_mode: $ocs_mode_prompt" \ + --inputbox "$dev_prompt_and_example" 0 0 "$dev_preset" 2> $REC_TMP + rec_dev_name="$(cat $REC_TMP)" + if [ -z "$rec_dev_name" ]; then + $DIA --backtitle "$msg_nchc_free_software_labs" --title "$msg_nchc_clonezilla" \ + --yesno "$msg_you_must_input_device_name_to_be_restored! $msg_do_u_want_to_do_it_again" 0 0 + ans_="$?" + case "$ans_" in + 0) # yes is chosen + ASK_DEV_NAME=1;; + 1) # no is chosen + echo "$msg_program_stop!" + [ -f "$REC_TMP" ] && rm -f $REC_TMP + exit 1;; + esac + else + ASK_DEV_NAME=0 + fi + done + echo > $REC_TMP # clean REC_TMP + + # ask if want to set ocs extra param for recovery iso/zip + set_ocs_sr_extra_param restore $REC_TMP $ocs_sr_type + OCS_OPTS="$(cat $REC_TMP)" + parse_ocs_sr_cmd_options_with_dash $OCS_OPTS + OCS_OPTS="$(echo $OCS_OPTS)" # make it in a line + echo > $REC_TMP # clean REC_TMP + + # Ask language to be used in live iso/zip + # $DRBL_SCRIPT_PATH/lang/bash/$lang + get_existing_language $REC_TMP + rec_lang="$(cat $REC_TMP)" + + # Ask keymap + ASK_KEYMAP_FILE=1 + while [ "$ASK_KEYMAP_FILE" -ne 0 ]; do + $DIA --backtitle "$msg_nchc_free_software_labs" --title "$msg_nchc_clonezilla | $msg_mode: $ocs_mode_prompt" \ + --inputbox "$keymap_file_prompt_and_example" 0 0 "NONE" 2> $REC_TMP + rec_keymap_file="$(cat $REC_TMP)" + if [ -z "$rec_keymap_file" ]; then + $DIA --backtitle "$msg_nchc_free_software_labs" --title "$msg_nchc_clonezilla | $msg_mode: $ocs_mode_prompt" \ + --yesno "$msg_you_must_input_keymap_file! $msg_do_u_want_to_do_it_again" 0 0 + ans_="$?" + case "$ans_" in + 0) # yes is chosen + ASK_KEYMAP_FILE=1;; + 1) # no is chosen + echo "$msg_program_stop!" + [ -f "$REC_TMP" ] && rm -f $REC_TMP + exit 1;; + esac + else + ASK_KEYMAP_FILE=0 + fi + done + echo > $REC_TMP # clean REC_TMP + + # Generage iso, zip or both ? + $DIA --backtitle "$msg_nchc_free_software_labs" --title "$msg_nchc_clonezilla | $msg_mode: $ocs_mode_prompt" \ + --menu "$msg_recovery_clonezilla_file_type $msg_choose_file_type" \ + 0 0 0 \ + "iso" "$msg_create_recovery_clonezilla_live_iso" \ + "zip" "$msg_create_recovery_clonezilla_live_zip" \ + "both" "$msg_create_recovery_clonezilla_live_iso_and_zip" \ + 2> $REC_TMP + rec_file_type="$(cat $REC_TMP)" + + [ -f "$REC_TMP" ] && rm -f $REC_TMP + + # Run ocs-iso/ocs-live-dev + # Ex:ocs-iso -g en -t -k NONE -e "-b -c restoredisk sarge-r5 hda" sarge-r5 + # ocs-live-dev -c -g en -t -k NONE -e "-b -c restoredisk sarge-r5 hda" sarge-r5 + (cd $ocsroot + case "$rec_file_type" in + iso) + run_again_fname="/tmp/ocs-iso-zip-`date +%F-%H-%M`" + [ "$BOOTUP" = "color" ] && $SETCOLOR_SUCCESS + echo PS. $msg_run_drbl_ocs_again_cmd | tee --append ${OCS_LOGFILE} + echo ocs-iso -g $rec_lang -t -k $rec_keymap_file -e \"$OCS_OPTS $rec_dev_action $target_dir $rec_dev_name\" $target_dir >> ${OCS_LOGFILE} + echo ocs-iso -g $rec_lang -t -k $rec_keymap_file -e \"$OCS_OPTS $rec_dev_action $target_dir $rec_dev_name\" $target_dir | tee $run_again_fname + [ -e "$run_again_fname" ] && chmod 755 $run_again_fname + echo "$msg_ocs_sr_again_command_saved_filename: $run_again_fname" + echo "$msg_the_output_file_is_in_dir: $ocsroot" + [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL + echo -n "$msg_press_enter_to_continue" + read + ocs-iso -g $rec_lang -t -k $rec_keymap_file -e "$OCS_OPTS $rec_dev_action $target_dir $rec_dev_name" $target_dir + ;; + zip) + run_again_fname="/tmp/ocs-iso-zip-`date +%F-%H-%M`" + [ "$BOOTUP" = "color" ] && $SETCOLOR_SUCCESS + echo PS. $msg_run_drbl_ocs_again_cmd | tee --append ${OCS_LOGFILE} + echo ocs-live-dev -c -g $rec_lang -t -k $rec_keymap_file -e \"$OCS_OPTS $rec_dev_action $target_dir $rec_dev_name\" $target_dir >> ${OCS_LOGFILE} + echo ocs-live-dev -c -g $rec_lang -t -k $rec_keymap_file -e \"$OCS_OPTS $rec_dev_action $target_dir $rec_dev_name\" $target_dir | tee $run_again_fname + [ -e "$run_again_fname" ] && chmod 755 $run_again_fname + echo "$msg_ocs_sr_again_command_saved_filename: $run_again_fname" + echo "$msg_the_output_file_is_in_dir: $ocsroot" + [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL + echo -n "$msg_press_enter_to_continue" + read + ocs-live-dev -c -g $rec_lang -t -k $rec_keymap_file -e "$OCS_OPTS $rec_dev_action $target_dir $rec_dev_name" $target_dir + ;; + both) + run_again_fname="/tmp/ocs-iso-zip-`date +%F-%H-%M`" + [ "$BOOTUP" = "color" ] && $SETCOLOR_SUCCESS + echo PS. $msg_run_drbl_ocs_again_cmd | tee --append ${OCS_LOGFILE} + echo ocs-iso -g $rec_lang -t -k $rec_keymap_file -e \"$OCS_OPTS $rec_dev_action $target_dir $rec_dev_name\" $target_dir >> ${OCS_LOGFILE} + echo ocs-iso -g $rec_lang -t -k $rec_keymap_file -e \"$OCS_OPTS $rec_dev_action $target_dir $rec_dev_name\" $target_dir | tee $run_again_fname + echo ocs-live-dev -c -g $rec_lang -t -k $rec_keymap_file -e \"$OCS_OPTS $rec_dev_action $target_dir $rec_dev_name\" $target_dir >> ${OCS_LOGFILE} + echo ocs-live-dev -c -g $rec_lang -t -k $rec_keymap_file -e \"$OCS_OPTS $rec_dev_action $target_dir $rec_dev_name\" $target_dir | tee -a $run_again_fname + [ -e "$run_again_fname" ] && chmod 755 $run_again_fname + echo "$msg_ocs_sr_again_command_saved_filename: $run_again_fname" + echo "$msg_the_output_file_is_in_dir: $ocsroot" + [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL + echo -n "$msg_press_enter_to_continue" + read + ocs-iso -g $rec_lang -t -k $rec_keymap_file -e "$OCS_OPTS $rec_dev_action $target_dir $rec_dev_name" $target_dir + ocs-live-dev -c -g $rec_lang -t -k $rec_keymap_file -e "$OCS_OPTS $rec_dev_action $target_dir $rec_dev_name" $target_dir + ;; + esac + ) +} # end of create_clonezilla_live_recovery_iso_zip +# +get_extra_param_when_type_is_ask_user_and_interactive_mode() { + if [ "$ocs_sr_type_assign" = "ask_user" -o \ + "$ocs_sr_mode" = "interactive" ]; then + # since this ocs-sr asks for ocs_sr type, this means the option maybe not parsed. + case "$ocs_sr_type" in + save*) + # ask if want to set ocs extra param + OCS_PARAM_TMP=`mktemp /tmp/ocs_sr_param_tmp.XXXXXX` + trap "[ -f "$OCS_PARAM_TMP" ] && rm -f $OCS_PARAM_TMP" HUP INT QUIT TERM EXIT + set_ocs_sr_extra_param save $OCS_PARAM_TMP $ocs_sr_type + # In interactive mode, we reset OCS_OPTS instead of appending it. Later wrap_up_opt will process more. + OCS_OPTS="$(cat $OCS_PARAM_TMP)" + [ -f "$OCS_PARAM_TMP" ] && rm -f $OCS_PARAM_TMP + ;; + restore*) + # Skip the multicast_restore*, since it's spawned by drbl-ocs, not from ocs-sr + # ask if want to set ocs extra param + OCS_PARAM_TMP=`mktemp /tmp/ocs_sr_param_tmp.XXXXXX` + trap "[ -f "$OCS_PARAM_TMP" ] && rm -f $OCS_PARAM_TMP" HUP INT QUIT TERM EXIT + set_ocs_sr_extra_param restore $OCS_PARAM_TMP $ocs_sr_type + # In interactive mode, we reset OCS_OPTS instead of appending it. Later wrap_up_opt will process more. + OCS_OPTS="$(cat $OCS_PARAM_TMP)" + [ -f "$OCS_PARAM_TMP" ] && rm -f $OCS_PARAM_TMP + ;; + exit) + echo "To use it again, run \"$ocs -x\"." + exit 2 + ;; + esac + # Some options might be assigned in in /etc/ocs/ocs-live.conf. Here we have to add that. + if [ -n "$ocs_sr_save_extra_opt" -o -n "$ocs_sr_restore_extra_opt" ]; then + case "$ocs_sr_type" in + *save*) OCS_OPTS="$OCS_OPTS $ocs_sr_save_extra_opt" ;; + *restore*) OCS_OPTS="$OCS_OPTS $ocs_sr_restore_extra_opt" ;; + esac + fi + parse_ocs_sr_cmd_options_with_dash $OCS_OPTS + fi +} # end of get_extra_param_when_type_is_ask_user_and_interactive_mode + +# OCS_OPT is for drbl-ocs using, will not put into the partimage command options +# PARTIMAGE_RESTORE_OPT & PARTIMAGE_SAVE_OPT will put into partimage command options +PARTIMAGE_SAVE_OPT_INIT="" +PARTIMAGE_RESTORE_OPT_INIT="" +OCS_OPT="" +report_msg="" +# Set some default values, +nfs_restart="no" +always_restore="no" +pxe_menu_default_mode="" +mcast_loop="1" +USE_NTFSCLONE="no" +nogui="off" # Default to turn on TUI +FORCE_TO_USE_DD="no" +force_dma_on="yes" +create_part="yes" +restore_mbr="yes" +restore_ebr="yes" +restore_prebuild_mbr="no" +rm_win_swap_hib="no" +rescue_mode="off" +select_img_in_client="no" +# If create_part_by_sfdisk=no, then we will use "dd if=$tgt_dir/mbr of=$sfdisk_target_hd skip=446 seek=446 bs=1 count=66" to dump the partition table. +create_part_by_sfdisk="yes" +# we want to make sfdisk --force if sfdisk is used. +sfdisk_opt="--force" +# Normally we do not dump MBR again when everything is done. However, This is an insurance for some hard drive has different numbers of cylinder, head and sector between image was saved and restored.". If the option is "yes", we will use dd to dump the MBR (total 512 Bytes, i.e. 446 bytes (executable code area) + 64 bytes (table of primary partitions) + 2 bytes (MBR signature; # 0xAA55) = 512 bytes) after disk was restored. +dump_mbr_in_the_end="no" +# The flag to save or restore the hidden data between MBR and 1st partition. +clone_hidden_data="no" +# default output for udpcast stderr is surpressed. +# NOTE! Do not redirect it to standard output (stdin), otherwise partimage/ntfsclone pipe will get wrong image! +udpcast_stderr="/dev/null" +# default not to run those scripts in $OCS_PRERUN_DIR $OCS_POSTRUN_DIR +run_prerun_dir="no" +run_postrun_dir="no" +# default to put the ntfsclone progress in local /tmp/ (tmpfs) +ntfsclone_progress="local_tmp" +# Default to do CRC checking of partclone when restoring +do_partclone_crc_check="yes" +# Default to remove the Linux udev MAC address records on the restored GNU/Linux +do_rm_hardware_record="yes" +# Default to run ocs-update-syslinux to update the syslinux files (ldlinux.sys, *.c32 and *.bin) +do_update_syslinux="yes" +# Default not to put yes or no for encrypting the image dir +encrypt_ocs_img="" +# Default to remove the ntfs volume dirty flag after it's restored. +rm_ntfs_vol_dirty_flag="yes" + +# The parameters, example: +# (-b -g auto --nogui --max-time-to-wait 300 --language 0 multicast_restoreparts sarge-base "hda1 hda3" 2232) -> +# (multicast_restoreparts sarge-base "hda1 hda3" 2232) +parse_ocs_sr_cmd_options_with_dash $* +shift ${n_shift} +ocs_sr_type_assign="$1" +ocs_sr_img_name="$2" +shift 2 +ocs_sr_dev="$*" +# If the inputted dev is: "hda hdb", convert it to hda hdb (so it won't be ""hda hdb"") +ocs_sr_dev="$(echo $ocs_sr_dev | tr -d \")" + +# Rotate the log file +ocs_log_rotate $OCS_LOGFILE +ocs_log_rotate /var/log/partclone.log + +# +echo "Starting $0 at "$(LC_ALL=C date +%F' '%T' '%Z)"..." | tee --append ${OCS_LOGFILE} + +# +ask_and_load_lang_set $specified_lang + +# check DIA +check_DIA_set_ESC $DIA + +############## +#### MAIN #### +############## + +# ocs root +if [ ! -d "$ocsroot" ]; then + echo "Please make sure your $ocsroot is a directory!!!" + # The common error is user try to create a ocsroot as /home/partimage, the default is /home/partimag (without e) + if [ "$ocsroot" = "/home/partimag" -a -d "/home/partimage" ]; then + [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING + echo "$msg_home_partimag_not_home_partimage" + [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL + fi + echo "We can NOT go on! Press \"c\" to enter command prompt or any other key to quit the program..." + read fail_answer + case "$fail_answer" in + [cC]) sulogin ;; + *) exit 1 ;; + esac +fi + +# +if [ "$ocs_sr_type_assign" = "ask_user" -o \ + "$ocs_sr_mode" = "interactive" ]; then + ASK_OCS_SR_TYPE=1 + case "$ocs_x_mode" in + "save_only") + save_only_dia_des + ;; + "restore_only") + restore_only_dia_des + ;; + *) # Both when image exists, or only save menu + save_only_dia_des + if check_if_any_image_exists; then + restore_only_dia_des + fi + ;; + esac + if [ "$ocs_sr_extra_restore_mode" != "no" ]; then + # If there is any image in $ocsroot, we can create recovery clonezilla live iso/zip and check the image. + if check_if_any_image_exists; then + recovery_clonezilla_live_dia_des + chk_img_restorable_dia_des + one_image_to_multiple_disks_dia_des + convert_img_compression_dia_des + encrypt_img_dia_des + decrypt_img_dia_des + if type qemu-img &>/dev/null && type kvm &>/dev/null; then + p2v_img_dia_des + fi + fi + fi + + # + [ -z "$ocs_user_mode" ] && ask_if_beginner_or_expert_mode + + # Clean the previous saved env so if ocs-onthefly is cancelled, won't read the previous env and reboot/poweroff. + rm -f /var/lib/clonezilla/ocs-vars + + # + echo "Choose the mode for ocs-sr" + TMP="$(mktemp /tmp/menu-ocs.XXXXXX)" + trap "[ -f "$TMP" ] && rm -f $TMP" HUP INT QUIT TERM EXIT + while [ "$ASK_OCS_SR_TYPE" -ne 0 ]; do + $DIA --backtitle "$msg_nchc_free_software_labs" \ + --title "$msg_nchc_clonezilla: $msg_choose_mode" \ + --menu "$msg_clonezilla_is_free_and_no_warranty\n$msg_overwrite_data_on_disk_when_restoring\n$msg_hint_multiple_choice_select_by_space\n$msg_choose_mode_ocs_sr" \ + 0 0 0 \ + $savedisk_msg_1 $savedisk_msg_2 \ + $saveparts_msg_1 $saveparts_msg_2 \ + $restoredisk_msg_1 $restoredisk_msg_2 \ + $restoreparts_msg_1 $restoreparts_msg_2 \ + $one_2_m_disks_msg_1 $one_2_m_disks_msg_2 \ + $recovery_clonezilla_live_msg_1 $recovery_clonezilla_live_msg_2 \ + $chk_img_restorable_msg_1 $chk_img_restorable_msg_2 \ + $convert_img_compression_msg_1 $convert_img_compression_msg_2 \ + $encrypt_img_msg_1 $encrypt_img_msg_2 \ + $decrypt_img_msg_1 $decrypt_img_msg_2 \ + $p2v_img_msg_1 $p2v_img_msg_2 \ + "exit" "$msg_exit. $msg_enter_cml" \ + 2> $TMP + ocs_sr_type="$(cat $TMP)" + if [ -z "$ocs_sr_type" ]; then + ASK_OCS_SR_TYPE=1 + else + ASK_OCS_SR_TYPE=0 + fi + done + [ -e "$TMP" ] && rm -f $TMP + [ "$ocs_sr_type" = "exit" ] && exit 0 + [ -z "$ocs_sr_type" ] && echo "You must specify the action! Program terminated!!!" && exit 1 + # If ocs_sr_type from ask_user, then we should let ocs_sr_img_name & ocs_sr_dev as ask_user, too + ocs_sr_img_name="ask_user" + ocs_sr_dev="ask_user" + # Overwrite the default HALT_REBOOT_OPT (-f -n) so that if user choose to halt/reboot, it will use normal halt/reboot sequence, then mounted device will be unmounted. + HALT_REBOOT_OPT="" + VOL_LIMIT="$VOL_LIMIT_IN_INTERACTIVE" +else + ocs_sr_type="$ocs_sr_type_assign" +fi + +# ocs_mode_prompt is to be shown in the title of dialog menu later +ocs_mode_prompt="$ocs_sr_type" + +echo $msg_delimiter_star_line | tee --append $OCS_LOGFILE +# Clonezilla image home +[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING +echo "Clonezilla image dir: $ocsroot" | tee --append $OCS_LOGFILE +[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL +[ ! -d "$ocsroot" ] && mkdir -p $ocsroot + +# Some options might be assigned in in /etc/ocs/ocs-live.conf. Here we have to add that. +if [ -n "$ocs_sr_save_extra_opt" -o -n "$ocs_sr_restore_extra_opt" ]; then + case "$ocs_sr_type" in + *save*) OCS_OPTS="$OCS_OPTS $ocs_sr_save_extra_opt" ;; + *restore*) OCS_OPTS="$OCS_OPTS $ocs_sr_restore_extra_opt" ;; + esac + parse_ocs_sr_cmd_options_with_dash $OCS_OPTS +fi + +# Decide the mode for update_efi_nvram if it's not assigned. The EFI NVRAM is only updated when the mode is restoredisk or multicast_restoredisk +if [ -z "$update_efi_nvram" ]; then + case "$ocs_sr_type" in + *restoredisk) update_efi_nvram="yes";; + *) update_efi_nvram="no";; + esac +fi + +# Process options. //NOTE// There might be twice of wrap_up_opt, one is for the command options assigned, the other one is the command options got from interactive mode. +wrap_up_opt + +# Before starting, we turn off swap and LVM2, unlock the busy partitions. +turn_off_swap_and_LVM2 + +# Boot parameter ocs_overwrite_postaction has higher priority than the action assigned by option "-p". +overwrite_postaction_if_assigned $ocs_sr_type + +# +case "$ocs_sr_type" in + "savedisk") + task_preprocessing "$ocs_sr_type" + MULTIPATH_INFODIR="$(mktemp -d /tmp/multipath_info.XXXXXX)" + + if [ "$ocs_sr_img_name" = "ask_user" ]; then + get_target_dir_name_when_saving # get $target_dir + elif [ "$ocs_sr_img_name" = "autoname" ]; then + # Ref: https://sourceforge.net/projects/clonezilla/forums/forum/799287/topic/4815557 + # We need something unique, so MAC address is a good choice + for i in `LC_ALL=C get-nic-devs`; do + prefix_mac="$(LC_ALL=C drbl-get-macadd $i)" + if [ -n "$prefix_mac" ]; then + prefix_mac="$(LC_ALL=C echo $prefix_mac | sed -e 's/://g')" + break + fi + done + # If not found, use UUID from MB manufacture + [ -z "$prefix_mac" ] && prefix_mac="$(LC_ALL=C dmidecode | grep -io "UUID: .*$" | head -n 1 | sed -e "s/^UUID: //g")" + target_dir="${prefix_mac}-$(LC_ALL=C date '+%Y-%m-%d-%H%M')-img" + elif [ "$ocs_sr_img_name" = "autohostname" ]; then + # Ref: https://sourceforge.net/projects/clonezilla/forums/forum/663168/topic/5103006 + ip="" + for i in `LC_ALL=C get-nic-devs`; do + ip="$(drbl-get-ipadd $i)" + if [ -n "$ip" ]; then + break + fi + done + # If not found, give it a default name based on time. + if [ -z "ip" ]; then + prefix_host="autohostname-$(LC_ALL=C date '+%Y-%m-%d-%H%M')" + else + if LC_ALL=C host $ip &>/dev/null; then + # FQDN found + prefix_host="$(LC_ALL=C host $ip | sed -r -e "s/^.*name pointer//g" -e "s/^[[:space:]]*//g" -e "s|\.$||g")" + prefix_host="${prefix_host}-$(LC_ALL=C date '+%Y-%m-%d-%H%M')" + else + # FQDN not found. Give it a default name based on IP address and time. + prefix_host="autohostname-${ip}-$(LC_ALL=C date '+%Y-%m-%d-%H%M')" + fi + fi + target_dir="${prefix_host}-img" + elif [ "$ocs_sr_img_name" = "autoproductname" ]; then + # Ref: https://sourceforge.net/projects/clonezilla/forums/forum/663168/topic/5103006 + target_dir="$(get_vendor_product_name)-img" + else + target_dir="$ocs_sr_img_name" + fi + + if [ "$ocs_sr_dev" = "ask_user" ]; then + # To get $target_hd + get_target_hd_name_from_local_machine "$msg_local_source_disk \n$msg_linux_disk_naming $msg_press_space_to_mark_selection" + target_hd="$(select_VG "$target_hd")" + elif [ "$ocs_sr_dev" = "all" ]; then + get_not_busy_disks_or_parts harddisk "" "" # we will get dev_list + target_hd="$dev_list" + else + target_hd="$ocs_sr_dev" + fi + # check if the device exists + ANS_TMP=`mktemp /tmp/ocs_chkdev.XXXXXX` + trap "[ -f "$ANS_TMP" ] && rm -f $ANS_TMP" HUP INT QUIT TERM EXIT + check_if_input_device_exist $ANS_TMP $target_hd + target_hd="$(cat $ANS_TMP | tr -d \")" + [ -f "$ANS_TMP" ] && rm -f $ANS_TMP + get_extra_param_when_type_is_ask_user_and_interactive_mode + wrap_up_opt_after_interactive_selection # Since extra param inputed again, wrap up again + + task_processing_after_parameters_checked + + save_ocs_sr_related_vars + run_ocs_sr_again_prompt "$target_dir" "$target_hd" + + # //NOTE// If encrypt_ocs_img="yes", after this step, ocsroot and target_dir will be changed + # The original ones will be kept as ocsroot_orig and target_dir_orig. + prepare_ecryptfs_mount_point_if_necessary + + ocs-run-boot-param ocs_savedisk_prerun + task_savedisk "$target_dir" "$target_hd" + rc_savedisk="$?" + ocs-run-boot-param ocs_savedisk_postrun + + # + if [ -d "$MULTIPATH_INFODIR" -a \ + -n "$(echo $MULTIPATH_INFODIR | grep -w "multipath_info")" ]; then + rm -rf "$MULTIPATH_INFODIR" + fi + + if [ "$rc_savedisk" -eq 0 -a "$chk_img_restoreable_mod_save" = "yes" ]; then + check_image_if_restorable "$ocsroot" + rc_chkimg="$?" + if [ "$rc_chkimg" -ne 0 ]; then + echo "$msg_program_stop!" + my_ocs_exit 1 + fi + fi + echo $0 $OCS_OPTS $ocs_sr_type "$target_dir" "$target_hd" > $ocsroot/$target_dir/Info-saved-by-cmd.txt + + task_postprocessing "$ocs_sr_type" "$target_dir" + ;; + "restoredisk") + task_preprocessing "$ocs_sr_type" + MULTIPATH_INFODIR="$(mktemp -d /tmp/multipath_info.XXXXXX)" + + if [ "$ocs_sr_img_name" = "ask_user" ]; then + get_target_dir_name_when_restoring_disk # get $target_dir + elif [ "$ocs_sr_img_name" = "autoproductname" ]; then + # Ref: https://sourceforge.net/projects/clonezilla/forums/forum/663168/topic/5103006 + target_dir="$(get_vendor_product_name)-img" + else + target_dir="$ocs_sr_img_name" + fi + + check_input_target_image "$ocsroot/$target_dir" + source_dsk_no="$(get_disk_list_from_img $ocsroot/$target_dir | sed -e "s/ *$//g" | wc -w | awk '{print $1}')" + + if [ "$ocs_sr_dev" = "ask_user" ]; then + if [ "$source_dsk_no" -eq 1 ]; then + dia_sel_opt="menu" + else + dia_sel_opt="checklist" + fi + # To get $target_hd + get_target_hd_name_from_local_machine "$msg_choose_the_disks_to_restore \n$msg_linux_disk_naming $msg_press_space_to_mark_selection" $dia_sel_opt + elif [ "$ocs_sr_dev" = "all" ]; then + target_hd="$(get_disk_list_from_img $ocsroot/$target_dir)" + else + target_hd="$ocs_sr_dev" + fi + get_extra_param_when_type_is_ask_user_and_interactive_mode + wrap_up_opt_after_interactive_selection # Since extra param inputed again, wrap up again + + task_processing_after_parameters_checked + + save_ocs_sr_related_vars + run_ocs_sr_again_prompt "$target_dir" "$target_hd" + + # //NOTE// If encrypt_ocs_img="yes", after this step, ocsroot and target_dir will be changed + # The original ones will be kept as ocsroot_orig and target_dir_orig. + prepare_ecryptfs_mount_point_if_necessary + + if [ -d "$ocsroot/$target_dir" -a "$chk_img_restoreable_mod_restore" = "yes" ]; then + check_image_if_restorable "$ocsroot" + rc_chkimg="$?" + if [ "$rc_chkimg" -ne 0 ]; then + echo "$msg_program_stop!" + my_ocs_exit 1 + fi + fi + + ocs-run-boot-param ocs_restoredisk_prerun + task_restoredisk "$target_dir" "$target_hd" + ocs-run-boot-param ocs_restoredisk_postrun + + # + if [ -d "$MULTIPATH_INFODIR" -a \ + -n "$(echo $MULTIPATH_INFODIR | grep -w "multipath_info")" ]; then + rm -rf "$MULTIPATH_INFODIR" + fi + + task_postprocessing "$ocs_sr_type" "$target_dir" + ;; + "saveparts") + task_preprocessing "$ocs_sr_type" + + if [ "$ocs_sr_img_name" = "ask_user" ]; then + get_target_dir_name_when_saving # get $target_dir + elif [ "$ocs_sr_img_name" = "autoname" ]; then + # Ref: https://sourceforge.net/projects/clonezilla/forums/forum/799287/topic/4815557 + # We need something unique, so MAC address is a good choice + for i in `LC_ALL=C get-nic-devs`; do + prefix_mac="$(LC_ALL=C drbl-get-macadd $i)" + if [ -n "$prefix_mac" ]; then + prefix_mac="$(LC_ALL=C echo $prefix_mac | sed -e 's/://g')" + break + fi + done + # If not found, use UUID from MB manufacture + [ -z "$prefix_mac" ] && prefix_mac="$(LC_ALL=C dmidecode | grep -io "UUID: .*$" | head -n 1 | sed -e "s/^UUID: //g")" + target_dir="${prefix_mac}-$(LC_ALL=C date '+%Y-%m-%d-%H%M')-img" + elif [ "$ocs_sr_img_name" = "autohostname" ]; then + # Ref: https://sourceforge.net/projects/clonezilla/forums/forum/663168/topic/5103006 + ip="" + for i in `LC_ALL=C get-nic-devs`; do + ip="$(drbl-get-ipadd $i)" + if [ -n "$ip" ]; then + break + fi + done + # If not found, give it a default name based on time. + if [ -z "ip" ]; then + prefix_host="autohostname-$(LC_ALL=C date '+%Y-%m-%d-%H%M')" + else + if LC_ALL=C host $ip &>/dev/null; then + # FQDN found + prefix_host="$(LC_ALL=C host $ip | sed -r -e "s/^.*name pointer//g" -e "s/^[[:space:]]*//g" -e "s|\.$||g")" + else + # FQDN not found. Give it a default name based on IP address and time. + prefix_host="autohostname-${ip}-$(LC_ALL=C date '+%Y-%m-%d-%H%M')" + fi + fi + target_dir="${prefix_host}-img" + elif [ "$ocs_sr_img_name" = "autoproductname" ]; then + # Ref: https://sourceforge.net/projects/clonezilla/forums/forum/663168/topic/5103006 + target_dir="$(get_vendor_product_name)-img" + else + target_dir="$ocs_sr_img_name" + fi + + if [ "$ocs_sr_dev" = "ask_user" ]; then + get_target_parts_name_from_local_machine # get $target_parts + elif [ "$ocs_sr_dev" = "all" ]; then + get_not_busy_disks_or_parts partition "" "" # we will get dev_list + target_parts="$dev_list" + else + target_parts="$ocs_sr_dev" + fi + + # check if the device exists + ANS_TMP=`mktemp /tmp/ocs_chkdev.XXXXXX` + trap "[ -f "$ANS_TMP" ] && rm -f $ANS_TMP" HUP INT QUIT TERM EXIT + check_if_input_device_exist $ANS_TMP $target_parts + # 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 + get_extra_param_when_type_is_ask_user_and_interactive_mode + wrap_up_opt_after_interactive_selection # Since extra param inputed again, wrap up again + + task_processing_after_parameters_checked + + save_ocs_sr_related_vars + run_ocs_sr_again_prompt "$target_dir" "$target_parts" + + # //NOTE// If encrypt_ocs_img="yes", after this step, ocsroot and target_dir will be changed + # The original ones will be kept as ocsroot_orig and target_dir_orig. + prepare_ecryptfs_mount_point_if_necessary + + ocs-run-boot-param ocs_saveparts_prerun + task_saveparts "$target_dir" "$target_parts" + rc_saveparts="$?" + ocs-run-boot-param ocs_saveparts_postrun + + # + if [ -d "$MULTIPATH_INFODIR" -a \ + -n "$(echo $MULTIPATH_INFODIR | grep -w "multipath_info")" ]; then + rm -rf "$MULTIPATH_INFODIR" + fi + + if [ "$rc_saveparts" -eq 0 -a "$chk_img_restoreable_mod_save" = "yes" ]; then + check_image_if_restorable "$ocsroot" + rc_chkimg="$?" + if [ "$rc_chkimg" -ne 0 ]; then + echo "$msg_program_stop!" + my_ocs_exit 1 + fi + fi + echo $0 $OCS_OPTS $ocs_sr_type "$target_dir" "$target_parts" > $ocsroot/$target_dir/Info-saved-by-cmd.txt + + task_postprocessing "$ocs_sr_type" "$target_dir" + ;; + "restoreparts") + task_preprocessing "$ocs_sr_type" + + if [ "$ocs_sr_img_name" = "ask_user" ]; then + get_target_dir_name_when_restoring_parts # get $target_dir + elif [ "$ocs_sr_img_name" = "autoproductname" ]; then + # Ref: https://sourceforge.net/projects/clonezilla/forums/forum/663168/topic/5103006 + target_dir="$(get_vendor_product_name)-img" + else + target_dir="$ocs_sr_img_name" + fi + check_input_target_image "$ocsroot/$target_dir" + + if [ "$ocs_sr_dev" = "ask_user" ]; then + if [ -z "$source_part" ]; 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 select_from_img + # we have to remove " (comes with checklist in dialog) + # so that for loop will work (Specially for FC3/4...) + source_part="$(cat $ANS_TMP | tr -d \")" + [ -f "$ANS_TMP" ] && rm -f $ANS_TMP + fi + # target name exists, but file "parts" is empty ? + check_target_parts $ocsroot/$target_dir/parts "$source_part" + src_parts_no="$(LC_ALL=C echo $source_part | wc -w)" + if [ "$src_parts_no" -eq 1 ]; then + dia_sel_opt="menu" + get_target_parts_name_from_local_machine "$msg_choose_the_parts_to_restore \n$msg_linux_parts_MS_mapping" $dia_sel_opt # Obtain target_parts + else + # In this case, it's too complicated to restore partitions to different partitions on destination disk. + # Therefore we only allow original partitions to partitions, i.e. e.g., sda1, sda2 from image -> sda1, sda2 on destination disk. Therefore "source_part" is reset to none. + target_parts="$source_part" + source_part="" + if [ "$ocs_batch_mode" != "on" ]; then + [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING + echo "$msg_2_or_more_parts_only_same_parts_on_dest" + [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL + echo -n "$msg_press_enter_to_continue" + read + fi + fi + elif [ "$ocs_sr_dev" = "all" -o \ + "$ocs_sr_dev" = "unmounted_disk" ]; then + target_parts="$(get_parts_list_from_img $ocsroot/$target_dir)" + else + target_parts="$ocs_sr_dev" + fi + # + get_extra_param_when_type_is_ask_user_and_interactive_mode + wrap_up_opt_after_interactive_selection # Since extra param inputed again, wrap up again + # Append the option if restoring to different partition on the destination disk. + if [ -n "$source_part" ]; then + OCS_OPTS="$OCS_OPTS -f $source_part" + fi + + save_ocs_sr_related_vars + run_ocs_sr_again_prompt "$target_dir" "$target_parts" + + # //NOTE// If encrypt_ocs_img="yes", after this step, ocsroot and target_dir will be changed + # The original ones will be kept as ocsroot_orig and target_dir_orig. + prepare_ecryptfs_mount_point_if_necessary + + task_processing_after_parameters_checked + + if [ -d "$ocsroot/$target_dir" -a "$chk_img_restoreable_mod_restore" = "yes" ]; then + check_image_if_restorable "$ocsroot" + rc_chkimg="$?" + if [ "$rc_chkimg" -ne 0 ]; then + echo "$msg_program_stop!" + my_ocs_exit 1 + fi + fi + + ocs-run-boot-param ocs_restoreparts_prerun + task_restoreparts "$target_dir" "$target_parts" + ocs-run-boot-param ocs_restoreparts_postrun + + task_postprocessing "$ocs_sr_type" "$target_dir" + ;; + "recovery-iso-zip") create_clonezilla_live_recovery_iso_zip ;; + "chk-img-restorable") ocs-chkimg ;; + "cvt-img-compression") ocs-cvtimg-comp ;; + "encrypt-img") ocs-encrypt-img ;; + "decrypt-img") ocs-decrypt-img ;; + "p2v-img") ocs-img-2-vdk ;; + "1-2-mdisks") ocs-restore-mdisks -um $ocs_user_mode ;; + "multicast_restoredisk") + task_preprocessing "$ocs_sr_type" + task_processing_after_parameters_checked + + task_multicast_restoredisk "$ocs_sr_img_name" "$ocs_sr_dev" "$ocs_sr_mcast_port" + task_postprocessing "$ocs_sr_type" "" + ;; + "multicast_restoreparts") + task_preprocessing "$ocs_sr_type" + task_processing_after_parameters_checked + + task_multicast_restoreparts "$ocs_sr_img_name" "$ocs_sr_dev" "$ocs_sr_mcast_port" + task_postprocessing "$ocs_sr_type" "" + ;; + *) + USAGE + exit 2 + ;; +esac + +echo "Ending $0 at $(LC_ALL=C date +%F' '%T' '%Z)..." | tee --append ${OCS_LOGFILE} +exit 0 |