最後更新: 2024-09-10
目錄
- Ask "IMAGENAME" and "DEVICENAME"
- ocs-live-general (GUI)
- User Password
- 設定 Network(ocs-live-netcfg)
- SSH Server
- ocs-sr (save restore)
- ocs-onthefly
- remote-X
- ocs-iso & ocs-live-dev
- Custome Clonezilla live iso
- Boot Options
運作
Clonezilla 可以說是 partclone / partimage 的 frontend.
它會利用 nc 作網絡傳輸及會用 pigz 作多 thread 的 gzip 壓縮
在 backup 或 restore 時, 將(usb/hdd) mount 到 /home/partimag
之後在裡面建立 folder backup (e.g. 2024-09-10).
Ask "IMAGENAME" and "DEVICENAME"
In order to make Clonezilla more automatic,
clonezilla have reserved some words for "IMAGENAME" and "DEVICENAME".
* reserved names have special meanings
For image name:
- "ask_user"
- "autoname"
- "autohostname"
- "autoproductname"
For device name:
- "all"
- "ask_user"
all:
ocs-sr will automatically find the non-busy (unmounted) device as the device name,
e.g. sda, sdb... (for "savedisk"/"restoredisk" mode), and sda1, sdb1... (for "saveparts"/"restoreparts" mode).
ask_user:
In the restoring mode, when "ask_user" is used in the "DEVICENAME"
ocs-live-general (GUI)
它是 clonezilla 預設的 CLI 介面 # VGA Console(tty1)
它會載入 config(/etc/ocs/ocs-live.conf) 後執行 /usr/sbin/clonezilla
boot parameters 預設發動它
ocs_live_run="ocs-live-general"
/etc/ocs/ocs-live.conf
ocs_live_batch="no" ocs_lang="en_US.UTF-8" extra_pigz_opt="--fast -b 1024 --rsyncable"
User Password
(1) 建立 password
echo YOUR_PASSWORD | mkpasswd -s
OR
echo YOUR_PASSWD | mkpasswd -m sha-256 -s
(2) 在 boot parameter 設定它
append initrd=/live/initrd.img ... username=user usercrypted=XXXX
設定 Network(ocs-live-netcfg)
ocs-live-netcfg
SSH Server
By CLI
"Enter_shell"
sudo -i
ocs-live-netcfg # 設定 IP
service ssh start
* Default login as "user" with the password "live" # 建議改了它
By boot parameters(ocs_daemonon)
ocs_daemonon="ssh"
ssh service will be turned on when booting.
Run Clonezilla main menu
sudo /usr/sbin/clonezilla
ocs-sr (save restore)
sr = save restore # 用它建立/還原 Image 檔
它是 bash script 來
Usage:
ocs-sr [OPTION] {savedisk|saveparts|restoredisk|restoreparts} IMAGE_NAME DEVICE
Save 與 Restore 的 共用設定
--nogui # Do not show GUI (TUI) of Partclone or Partimage, use text only
-x, --interactive # Interactive mode to save or restore.
-c, --confirm # Wait for confirmation before saving or restoring
-l, --language INDEX Set the language to be shown by index number:
- [0|en_US.UTF-8]: English
- [2|zh_TW.UTF-8]: Traditional Chinese (UTF-8, Unicode) - Taiwan
- [a|ask]: Prompt to ask the language index
-scs, --skip-check-restorable
By default Clonezilla will check the image if restorable after it is created / before restoring.
The image of this partition is restorable: sda1 The image of this partition is restorable: sda2 The image of this partition is restorable: sda3
* 由 partclone 建立的 image 才能 check
pigz -d -c /home/partimag/win10b-20240910/sda2.ntfs-ptcl-img.gz |
LC_ALL=C partclone.chkimg -L /var/log/sda2-img-chk.log -s -
-p, --postaction [choose|poweroff|reboot(default)|command|CMD]
# When save/restoration finishes, choose action
Backup(savedisk)
lsblk
mount /dev/sdb1 /home/partimag;
e.g. backup 到 /home/partimag/win10b-20240910
ocs-sr savedisk win10b-20240910 sda
v3.1:
- partimage -M -f3 -o -d -b -c -z0 --volume=0 --debug=1 -B gui=no save /dev/sda1 stdout
- gzip -c --fast --rsyncable
e.g. 要 confirm 後才開發以 partclone 及 "pigz -c --fast -b 1024 --rsyncable" 去 backup
ocs-sr -c --nogui -q2 -z1p -j2 savedisk win10b-20240910 sda
* 使用 "-q2" 因為它支援 verify restorable
* 加上 "-z1p" 因為會 backup 快行多
* 加上 -j2 建立 hidden-data 的 backup
* Default 係不用 confirm 及有 gui 的
* 一般情況係可以以上 --skip-check-restorable (-scs)
Opts
-q2, --use-partclone
Use partclone to save partition(s) (效能: partclone > partimage > dd)
Notes
- -q, --use-ntfsclone
- -q1, --force-to-use-dd
-j2, --clone-hidden-data
Use dd to clone the image of the data between MBR (1st sector, i.e. 512 bytes) and 1st partition.
-sfsck, --skip-fsck-src-part
Skip running fsck on the source file system before saving it.
-z1p, --smp-gzip-compress
using parallel gzip (pigz) when saving
Other Backup Opts
-i, --image-size SIZE
Set the size in MB to split the partition image file into multiple volumes files.
-gm, --gen-md5sum
Generate the MD5 checksum for the image.
use -cm|--check-md5sum option to check the image when restoring the image
* It might take a lot of time.
-rm-win-swap-hib, --rm-win-swap-hib
Try to remove the MS windows swap file in the source partition.
Compress
-z0, --no-compress
-z1, --gzip-compress (default) # 另有 bz2, lzo, xz, lzip, lrzip, lz4, lz4mt, zstd, zstdmt
--smp # parallel X good for multi-core or multi-CPU machine
-z1p, --smp-gzip-compress # using parallel gzip (pigz) when saving
-z2p, --smp-bzip2-compress # using parallel bzip2 (lbzip2) when saving
# 另有 xz, lzip
Encrypting
-senc, --skip-enc-ocs-img (Default)
Skip encrypting the image with passphrase
-enc, --enc-ocs-img
To encrypt the image with passphrase
Restore Opts
e.g. 將 r8-20200727 restore 到 sda
ocs-sr -c --nogui -scr -j2 restoredisk c8-20200727 sda
* 建議加上 -j2, default 係沒有還原 hidden-data 的
Other Backup Opts
-g, --grub-install GRUB_PARTITION
Install grub in the MBR of the disk containing partition GRUB_PARTITION
with root grub directory in the same GRUB_PARTITION when restoration finishes
GRUB_PARTITION can be one of "/dev/sda1", "/dev/sda2"... or "auto"
("auto" will let clonezilla detect the grub root partition automatically)
If "auto" is assigned, it will work if grub partition and root partition are not in the same partition.
-r, --resize-partition
Resize the partition when restoration finishes, this will resize the file system size to fit
the partition size. It is normally used when when a small partition image is restored to a larger partition.
-t, --no-restore-mbr
Do NOT restore the MBR (Mater Boot Record) when restoring image.
-k, --no-fdisk, --no-create-partition
Do NOT create partition in target harddisk. Default is to create the partition table.
If this option is set, you must make sure there is an existing partition table in the current restored harddisk.
-cm, --check-md5sum
Check the MD5 checksum for the image.
To use this option, you must enable "-gm|--gen-md5sum" option when the image is saved.
Note! It might take a lot of time to check if the image size is large.
-iui
Skip updating initramfs file(s) on the restored GNU/Linux.
-e1, --change-geometry NTFS-BOOT-PARTITION
Force to change the CHS (cylinders, heads, sectors) value of NTFS boot partitoin after image is restored.
-e2, --load-geometry-from-edd
Force to use the CHS (cylinders, heads, sectors) from EDD (Enhanced Disk Device) when creating partition table by sfdisk.
-kN
0 (default)
Create partition table based on the partition table from the image.
1
Create partition table in the target disk proportionally.
2
Enter command line prompt to create partition table manually before restoring image.
-j, --create-part-by-sfdisk
Use sfdisk to create partition table instead of using dd to dump the partition table from saved image (This is default)
-j1, --dump-mbr-in-the-end
Use dd to dump the MBR
Notes
Cleaning RAID metadata in device
mdadm --zero-superblock /dev/sda
清空碟尾的 1024 個 sector
# Disk /dev/sda: 104857600s Running: dd if=/dev/zero of=/dev/X bs=512 seek=104856576 count=1024
建立 partition table
parted -s /dev/sda mklabel msdos LC_ALL=C sfdisk --force /dev/sda < /home/partimag/NAME/sda-pt.sf 2>&1 | tee -a /var/log/clonezilla.log
Restore partition
pigz -d -c /home/partimag/NAME/sda1.ntfs-ptcl-img.gz 2> /tmp/unzip_cmd_error.CZGHMl | LC_ALL=C partclone.ntfs -z 10485760 -L /var/log/partclone.log -s - -r -o /dev/sda1
Restore MBR
dd if=/home/partimag/NAME/sda-mbr of=/dev/sda bs=446 count=1
clear the NTFS volume dirty flag
ntfsfix -d /dev/sda1
ocs-onthefly
To run clonezilla on-the-fly (disk to disk)
Opts
-b, -batch, --batch, --batch-mode # Run program in batch mode (DANGEROUS!)
# i.e. without any prompt or wait for pressing enter key.
-r, --resize-partition # Resize the file system size to fit the partition size in the destination disk.
-nogui, --nogui
-rescue, --rescue # Turn on rescue mode, i.e. try to skip bad sectors.
-t, --no-restore-mbr # Do NOT restore the MBR. Default is to restore.
Example
1. To clone local sda to sdb, run
# -f, --source DEV Specify the source device as DEV (sda, sda1...)
# -t, --target DEV Specify the target device as DEV (sda, sda1...)
ocs-onthefly -f sda -t sdb
2. To clone sda in machine A(88.51) to machine B(88.52) 's sda via network
UI
- remote-source # 自己係 Source
- remote-dest # 自己係 Destination
CLI - In machine A
# -a, --server Specify the running machine is in network clone server.
ocs-onthefly -a -f sda
CLI - Then in machine B
# -s, --source-IP IP Specify the source IP address (used in target client machine)
ocs-onthefly -s 192.168.100.1 -t sda
* Default Setting: partclone, netcat, gzip
More Setting
-q1, --force-to-use-dd
Force to use sector-by-sector copy (supports all filesystem, but inefficient).
By default we will use partclone to clone a partition.
-u, --use-nuttcp
Use nuttcp instead of netcat as the network pipe program.
-i, --filter PROGRAM
Use the PROGRAM (gzip/lzop/bzip2/xz/lz4/zstd/cat) before sending partition data to netcat (only in network clone mode).
The default action is gzip. Use "cat" if you do not want to compress (Good for fast internode network).
Useful Opts
-k1, Create partition table in the target disk proportionally.
-rescue, --rescue Turn on rescue mode, i.e. try to skip bad sectors.
-irhr, --irhr Skip removing the Linux udev hardware records on the restored GNU/Linux.
-ius, --ius Skip updating syslinux-related files on the restored GNU/Linux.
-iui, --iui Skip updating initramfs file(s) on the restored GNU/Linux.
remote-X
source vs dest
- remote-source # 本地是 source
- remote-dest # 本地是 dest
remote-source
* 別用 GUI 版, 因為會多了其他設定
快速 CLI: /usr/sbin/ocs-onthefly -g auto -e1 auto -e2 -r -j2 -sfsck -k0 -p true -a -f sda
過程
它是利用 nc 的 listen mode 進行
# 內容: "source_type=disk"
Running: cat /tmp/ocs_onthefly_src.iFyRGC/target_type.ocs_onthefly | nc -l -q 0 -p 9003 &
# 內容: sda-mbr, sda-pt.parted, sda-hidden-data-after-mbr ...
Running: cat /tmp/ocs_onthefly_src.iFyRGC/d2d-pseudo.tgz | nc -l -q 0 -p 9009 &
# Feeding partition /dev/sda1 in listen mode with port 9015...
Running: partclone.ntfs -z 10485760 -L /var/log/partclone.log -c -s /dev/sda1 -o - 2>/dev/null |
zstdmt -c -3 | nc -l -q 0 -p 9015 &
remote-dest
快速 CLI: ocs-onthefly -s 192.168.123.61 -d sdc
ocs-iso & ocs-live-dev
Create Recovery CD(ocs-iso) / USB flash drive(ocs-live-dev)
Help
- ocs-iso -h
- ocs-live-dev -h
ocs-iso
1) 用 clonezilla 開機, 進入它的 CLI Console 後選 "Enter_shell"
sudo -s # 轉成 root 身份
2) Mount a working space(會在那裡 build ISO)
lsblk
mount /dev/sdb1 /home/partimag
mkdir /home/partimag/iso; cd /home/partimag/iso
# First
cd /home/partimag
# create clonezilla-live-c8-20200727.iso
ocs-iso c8-20200727
# create an ISO file with built-in pre-settings
ocs-iso -g en_US.UTF-8 -t -k NONE c8-20200727
-g, --ocs-live-language LANGUAGE
Assign the language when using clonezilla live, available languages are en_US.UTF-8, zh_TW.UTF-8
-t, --ocs-live-batch
Set clonezilla live to run in batch mode, usually it's for restoring.
If this mode is set, some dialog question will be ignored.
-k, --ocs-live-keymap KEYBOARD_LAYOUT c8-20200727
Assign the keyboard layout when using clonezilla live.
"-k NONE"
means won't change the keyboard layout (default is US keyboard).
Custom Program
ocs-iso -g en_US.UTF-8 -k NONE -s -m ./custom-ocs
-m, --custom-ocs PATH/custom-ocs Use the customized ocs program 'custom-ocs' instead of the default one.
A sample script file /usr/share/drbl/samples/custom-ocs
Custom Pure ISO
-s, --skip-image
Do not include any clonezilla image. The is used to created a live CD with DRBL/Clonezilla programs only.
"-e" will be run by ocs-sr when cloning
With ocs-sr
ocs-iso -g en_US.UTF-8 -t -k NONE -e "..." c8-20200727
ocs-live-dev
...
Custome Clonezilla live iso
mkdir /home/partimag/zip2iso
cd /home/partimag/zip2iso/
# 拿出 ISO 內的 File
# boot on clonezilla
cp -a /run/live/medium/* ./
OR
# On anther OS
unzip clonezilla-live-2.5.5-38-amd6.iso -d ./
# Rebuild ISO (Full CLI)
xorriso -as mkisofs -R -r -J -joliet-long -l -iso-level 3 \
-no-emul-boot -boot-load-size 4 -boot-info-table -partition_offset 16\
-A 'Clonezilla live CD' \
-b syslinux/isolinux.bin -c syslinux/boot.cat \
-eltorito-alt-boot --efi-boot boot/grub/efi.img \
-isohybrid-mbr /usr/lib/ISOLINUX/isohdpfx.bin -isohybrid-gpt-basdat -isohybrid-apm-hfsplus ./ \
> /home/partimag/clonezilla-live.iso
# 簡化 CLI
xorriso -as mkisofs -R -r -J -joliet-long -l -iso-level 3 \
-no-emul-boot -boot-load-size 4 -boot-info-table -partition_offset 16 \
-A 'Clonezilla live CD' -b syslinux/isolinux.bin -c syslinux/boot.cat \
./ > /home/partimag/clonezilla-live.iso
Boot Options
Boot parameters in syslinux/syslinux.cfg (for live USB) or syslinux/isolinux.cfg (for CD)
Clonezilla live is based on Debian live with clonezilla installed.
Therefore there are 2 kinds of boot parameters:
1. Boot parameters from Debian live-boot and live-config.
2. Boot parameters specially for Clonezilla. ("ocs_*")
live-boot parameters
locales=en_US.UTF-8
keyboard-layouts=NONE
ip=
# In Clonezilla live a patched live-initramfs is used, which is different from the original live-initramfs so that you can assign DNS server, too.
ip=eth0:10.0.100.1:255.255.255.0:10.0.100.254:8.8.8.8
live-config parameters
It contains the components that configure a live system during the boot process
live-config is only activated if 'boot=live' is used as a boot parameter.
Additionally, live-config needs to be told which components to run through the 'live-config.components' parameter or
which components to not run through the 'live-config.nocomponents' parameter.
----------------
ocs_live_*
ocs_live_run="ocs-live-general"
It is the main program to be run in Clonezilla live.
ocs_live_batch="no"
If no, will run interactively
ocs_live_extra_param=""
It will be used only when "ocs_live_run=ocs-live-restore", then it will be passed to ocs-sr
(not for ocs-live-general or any other)
"ocs_fontsize"
ocs_fontsize="24x12"
Check file /etc/default/console-setup and the console-setup(5) manual page on Debian
"ocs_preload*"
To fetch tarall/zip/sh files from http(s), ftp, tftp, and local URL then extract to /opt/ in the Clonezilla live environment
ocs_preload=http://192.168.200.254/my-custom.tar.xz
ocs_preload="mount -t cifs //192.168.120.2/images/ /tmp/cifs -o user=administrator,password=yourpasswd"
ocs_preload="mount -t nfs 192.168.120.254:/home/partimag/script/ /tmp/nfs -o ro"
ocs_prerun, ocs_prerun1, ocs_prerun2...
It is intended for running a command before an operation of saving/restoring an image or cloning disk/partition is started.
e.g.
ocs_prerun="df -h"
ocs_postrun, ocs_postrun1, ocs_postrun2...
It is intended for running a command after an operation of saving/restoring an image or cloning disk/partition has been completed.
E.g. ocs_postrun="/live/image/myscript.sh"
ocs_overwrite_postaction
This boot parameter has higher priority than the action assigned by option "-p" in ocs-sr, and "-pa" in ocs-onthefly.
The value for ocs_overwrite_postaction is: [choose|reboot|poweroff]-on-[restoredisk|restoreparts|savedisk|saveparts|clone]
Summary
keyboard-layouts=us locales=en_US.UTF-8 ocs_fontsize="24x12" ip=192.168.123.61 ocs_daemonon="ssh" usercrypted=XXXX