clonezilla 无人值守示例(非官方翻译)

0x00 linux 自动备份到另外的硬盘

准备

  • 下载最新的稳定版

  • 第二个硬盘驱动器

  • Grub Bootloader

实施

  1. 在驱动器的根目录下创建一个名为 isos 的目录:
    sudo mkdir /isos

  2. 将 Clonezilla(iso 文件)的副本放入 /isos,这样您就拥有:
    /isos/clonezilla-live-2.3.1-18-amd64.iso

  3. 我们需要弄清楚你的辅助目标硬盘是什么 /dev/sdX,运行 fdisk 来找出它。注意:您可能希望在 clonezilla cmd 提示符下运行此命令,以确保您的目标硬盘与启动到操作系统时的 /dev/sdX 相同。我们将向 grub 添加 3 个条目,一个用于启动到 clonezilla live,就像直接从 live CD 启动一样,一个用于无人值守备份,一个用于无人值守恢复。
    sudo fdisk -l

  4. 编辑 /etc/grub.d/40_custom 文件:
    sudo vi /etc/grub.d/40_custom

  5. 将以下三个菜单项添加到此文件:
    menuentry "Clonezilla Live 2.3.1-18" { set isofile="/isos/clonezilla-live-2.3.1-18-amd64.iso" loopback loop (hd0,1)$isofile linux (loop)/live/vmlinuz boot=live live-config noswap nolocales edd=on nomodeset ocs_live_run=\"ocs-live-general\" ocs_live_extra_param=\"\" keyboard-layouts=\"\" ocs_live_batch=\"no\" locales=\"\" vga=788 ip=frommedia nosplash toram=filesystem.squashfs findiso=$isofile initrd (loop)/live/initrd.img }

    menuentry "Clonezilla Live 2.3.1-18 (Unattended Backup)" { set isofile="/isos/clonezilla-live-2.3.1-18-amd64.iso" loopback loop (hd0,1)$isofile linux (loop)/live/vmlinuz boot=live live-config noswap nolocales edd=on nomodeset ocs_prerun=\"mount /dev/sdb1 /mnt\" ocs_prerun1=\"mount --bind /mnt/backup /home/partimag/\" ocs_live_run=\"ocs-sr -q2 --batch -j2 -z1p -i 2000 -sc -p reboot savedisk autoproductname sda\" ocs_live_extra_param=\"\" keyboard-layouts=\"\" ocs_live_batch=\"yes\" locales=\"\" vga=788 ip=frommedia nosplash toram=filesystem.squashfs findiso=$isofile initrd (loop)/live/initrd.img }

    menuentry "Clonezilla Live 2.3.1-18 (Unattended Restore)" { set isofile="/isos/clonezilla-live-2.3.1-18-amd64.iso" loopback loop (hd0,1)$isofile linux (loop)/live/vmlinuz boot=live live-config noswap nolocales edd=on nomodeset ocs_prerun=\"mount /dev/sdb1 /mnt\" ocs_prerun1=\"mount --bind /mnt/backup /home/partimag/\" ocs_live_run=\"ocs-sr -g auto -e1 auto -e2 -r -j2 -p reboot restoredisk autoproductname sda\" ocs_live_extra_param=\"\" keyboard-layouts=\"\" ocs_live_batch=\"yes\" locales=\"\" vga=788 ip=frommedia nosplash toram=filesystem.squashfs findiso=$isofile initrd (loop)/live/initrd.img }

  6. 运行以下命令以更新 grub:
    sudo update-grub

    在备份和恢复菜单条目中,您将看到我正在将 /dev/sdb1 挂载到 /mnt。然后我在一个名为 backup 的目录中。因此,从本质上讲,我们告诉 clonezilla 使用此备份文件夹作为备份/恢复的源/目标,在 clonezilla 中,它变成了 /home/partimag。

    对于无人值守备份,我运行以下命令:
    ocs-sr -q2 --batch -j2 -z1p -i 2000 -sc -p reboot savedisk autoproductname sda

    • -q2 = 使用 partclone 保存分区

    • –batch = 以批处理模式运行程序,即没有任何提示或等待按回车键。

    • -j2 = 使用 dd 克隆 MBR(第 1 扇区,即 512 字节)和第 1 个分区之间的数据映像,这可能对某些恢复工具有用。

    • -z1p = 保存时使用并行 gzip 程序 (pigz) 进行压缩:快速小的图像文件,适用于多核或多 CPU 机器

    • -i 2000 = 设置分割图像文件卷大小 SIZE (2000 MB)。

    • -sc = 默认情况下,Clonezilla 将在创建映像后检查映像是否可恢复。此选项允许您跳过该选项。

    • -p reboot = [选择|poweroff|reboot|command|CMD] 保存/恢复完成后,在客户端中选择操作、关机、重新启动(默认)、在命令提示符下或运行 CMD

    • savedisk = 告诉 clonezilla 我们要进行备份(而不是恢复)

    • autoproductname = 在保存和恢复模式下,当“autoproductname”用作“IMAGENAME”时,Clonezilla 将使用 dmidecode 命令获取 system-manufacturer 和 system-product-name,然后将它们与附加的 “-img” 组合在一起。就我而言,clonezilla 创建了一个名为 MSI_MS-7851-img 的备份目录。

    • sda = 这是我要备份的源硬盘驱动器

    对于无人值守还原,我正在运行以下命令:
    ocs-sr -g auto -e1 auto -e2 -r -j2 -p reboot restoredisk autoproductname sda

  • -g auto = 在包含分区GRUB_PARTITION的磁盘的 MBR 中安装 grub,其根 grub 目录在同一GRUB_PARTITION当恢复完成时,GRUB_PARTITION可以是 “/dev/hda1”、“/dev/hda2” 之一......或“auto”(“auto”将让 Clonezilla 自动检测 grub 根分区)。如果分配了“auto”,则如果 grub 分区和 root 分区不在同一分区中,它将起作用。

  • -e1 自动强制在映像恢复后更改 NTFS 引导部分的 CHS(柱面、磁头、扇区)值。NTFS-BOOT-PARTITION 可以是 “/dev/hda1”、“/dev/hda2” 之一...或“auto”(“auto”将让 clonezilla 自动检测 NTFS 启动分区)

  • -e2 = 通过 sfdisk 创建分区表时,强制使用 EDD(增强型磁盘设备)中的 CHS(柱面、磁头、扇区)

  • -r = 恢复完成后调整分区大小,这将尝试在小分区映像恢复到较大分区时解决问题。警告!!!请谨慎使用...首先备份您的数据

  • -j2 = 使用 dd 克隆 MBR(第 1 扇区,即 512 字节)和第 1 个分区之间的数据映像,这可能对某些恢复工具有用。

  • -p reboot = 完成后重启

  • restoredisk = 告诉 clonezilla 我们要进行还原(而不是备份)

  • sda = 这是我正在恢复的源硬盘驱动器

  1.  最后一步是创建一个脚本,该脚本可以手动运行,也可以通过 root 用户 crontab 运行。

 clonezilla_backup.sh

#!/bin/sh
# Set grub to boot to the unattended backup
/usr/sbin/grub-reboot "Clonezilla Live 2.3.1-18 (Unattended Backup)"
# Reboot server
/sbin/reboot

clonezilla_restore.sh

#!/bin/sh
# Set grub to boot to the unattended restore
/usr/sbin/grub-reboot "Clonezilla Live 2.3.1-18 (Unattended Restore)"
# Reboot server
/sbin/reboot

chmod +x clonezilla_*.sh

从本质上讲,这告诉计算机仅在下次重新启动时启动到指定的 grub 菜单项,然后重新启动。如果一切顺利,您的计算机应该已经重新启动,自动进入clonezilla,将启动驱动器备份到辅助硬盘驱动器,然后在完成后重新启动,回到启动驱动器,就好像什么都没发生过一样!


0x01 全自动 U 盘

场景

您要做的就是将“sda2”上的图像自动恢复为“sda1”

NTFS = sda1

NTFS = sda2

操作

custom-ocs 脚本

#!/bin/bash

# License: GPL

# 参考: http://sourceforge.net/forum/forum.php?thread_id=1759263&forum_id=394751

# 在这个例子中,它将允许你的用户使用 clonezilla live 来选择

# (1) 将 /dev/hda1(或 /dev/sda1)的镜像备份到 /dev/hda5(或 /dev/sda5)

# (2) 将 /dev/hda5(或 /dev/sda5)中的镜像恢复到 /dev/hda1(或 /dev/sda1)

# 这里我们假设文件系统是 ntfs。

# 当这个脚本准备好后,你可以运行

# /opt/drbl/sbin/ocs-iso -g en -k NONE -s -m ./custom-ocs

# 创建 CD/DVD 的 iso 配置文件

# /opt/drbl/sbin/ocs-live-dev -g en -k NONE -s -c -m ./custom-ocs

# 为 USB 闪存驱动器创建 zip 的配置文件

#

# 如果需要挂载 NTFS,请使用 “ntfs-3g” 而不是 “mount”

# 脚本的开头:

# 加载 DRBL 设置和函数

if [ ! -f "/opt/drbl/sbin/drbl-conf-functions" ]; then

echo "Unable to find /opt/drbl/sbin/drbl-conf-functions! Program terminated!"

exit 1

fi

. /opt/drbl/sbin/drbl-conf-functions

. /opt/drbl/sbin/ocs-functions

# 加载 CloneZilla Live 的设置。

[ -e /etc/ocs/ocs-live.conf ] && . /etc/ocs/ocs-live.conf

# 加载语言文件。对于英语,请使用“en”。对于繁体中文,请使用tw.UTF-8 

ask_and_load_lang_set en_US.UTF-8

mkdir -p /home/partimag/ 
ntfs-3g /dev/sda2 /home/partimag/ 

opt/drbl/sbin/ocs-sr -b -g auto -e1 auto -e2 -c -j2 -k -p reboot restoreparts "Your image file here" "sda1" 

放脚本

现在将此自定义 ocs 脚本文件插入位于 USB 驱动器的“LIVE”文件夹中。

编辑启动项

您需要编辑位于“SYSLINUX”文件夹中的“syslinux.cfg”文件。

注意:syslinux.cfg 文件看起来与 GRUB 菜单非常相似,您将像这样编辑菜单。只需编辑菜单中的第一个选项,分辨率为 1024x768...

kernel /live/vmlinuz1  append initrd=/live/initrd1.img boot=live union=aufs noprompt noprompt ocs_live_run="/live/image/live/custom-ocs" ocs_live_extra_param="" ocs_live_keymap="NONE" ocs_live_batch="yes" ocs_lang="en_US.UTF-8" vga=791 ip=frommedia nolocales

主要在 ocs_live_run="/live/image/live/custom-ocs 这句有用

最后

从 usb 启动


0x02 本地硬盘

场景

目标是安装一个带有 GRUB 的多引导系统,该系统提供了以批处理模式从硬盘驱动器实时启动 clonezilla 的选项

获取的备份将保存在本地网络的 samba 共享中。完成后,系统将重新启动。

在这个例子中,debian lenny 安装在 sda1 中,partion sda2 用于交换,sda3 和 sda5 将归属 clonezilla。

分区 /dev/sda3 用于引导进入 clonezilla 的交互模式,另一个分区 /dev/sda5 用于批处理模式引导选项

                                          Disk Drive: /dev/sda                                         

                                    Size: 5368709120 bytes, 5368 MB                                    

                          Heads: 255   Sectors per Track: 63   Cylinders: 652                          

     Name           Flags          Part Type     FS Type               [Label]            Size (MB)     

 ------------------------------------------------------------------------------------------------------

     sda1           Boot            Primary      Linux ext3                                 3002,23    

     sda2                           Primary      Linux swap / Solaris                       1003,49    

     sda3                           Primary      Linux ext3                                  501,75    

     sda5                           Logical      Linux ext3                                  855,43

实施

mkfs.ext3 /dev/sda3
mkfs.ext3 /dev/sda5
mount /dev/sda3 /mnt
cd /mnt

http://clonezilla.org/clonezilla-live/liveusb.php 下载您喜欢的 Clonezilla-ZIP-file 用于硬盘安装,并将其放在 /mnt 中

cd /mnt
unzip clonezilla-live-x.x.x.zip –d .
mv live live-hd

在 “/boot/grub/menu.lst” 中编辑 GRUB 引导菜单,以获得另外两个引导选项

在 menu.lst 的末尾添加一个部分,用于引导交互模式:

title           Clonezilla live on harddrive sda3 Jaunty
root            (hd0,2)
kernel /live-hd/vmlinuz1 boot=live union=aufs live-media-path=/live-hd vga=788 toram bootfrom=/dev/sda3 vga=791
initrd /live-hd/initrd1.img
boot

添加如下所示的第二部分,用于启动批处理模式:

title           Clonezilla live batch on harddrive sda5
root            (hd0,4)
kernel /live-hd/vmlinuz1 boot=live union=aufs live-media-path=/live-hd vga=788 toram bootfrom=/dev/sda5 noprompt noprompt ocs_live_run="custom-ocs" ocs_live_extra_param="" ocs_live_keymap="/usr/share/keymaps/i386/qwertz/de-latin1-nodeadkeys.kmap.gz" ocs_live_batch="yes" ocs_lang="en_US.UTF-8" vga=791 nolocales
initrd /live-hd/initrd1.img
boot

启动 GRUB 的 “interactive Clonezilla”;生成 CloneZilla Live 的自定义 ZIP
重新启动。在 GRUB 中选择交互式 clonezilla 模式。

选择您的语言和键盘映射,输入 clonezilla shell

使用“sudo su”成为 root。

挂载 /dev/sda5 /home/partimag” ;“cd /home/partimag”。

http://clonezilla.org/download/sourceforge/ 下载 clonezilla iso 映像(稳定版、测试版或实验版)并将其放入“/home/partimag”

将以下行放在 custom-ocs-1 中,并根据您的需要进行更改:

#!/bin/bash

# Author: Steven Shiau <steven _at_ stevenshiau org>

# License: GPL

# When this script is ready, you can run

# /opt/drbl/sbin/ocs-iso -g en -k NONE -s -m ./custom-ocs

# to create the iso file for CD/DVD. or

# /opt/drbl/sbin/ocs-live-dev -g en -k NONE -s -c -m ./custom-ocs

# to create the zip file for USB flash drive.

# Begin of the scripts:

# Load DRBL setting and functions

if [ ! -f "/opt/drbl/sbin/drbl-conf-functions" ]; then

  echo "Unable to find /opt/drbl/sbin/drbl-conf-functions! Program terminated!"

  exit 1

fi

. /opt/drbl/sbin/drbl-conf-functions

. /opt/drbl/sbin/ocs-functions

# load the setting for clonezilla live.

[ -e /etc/ocs/ocs-live.conf ] && . /etc/ocs/ocs-live.conf

# 加载语言文件。对于英语,请使用“en_US.UTF-8”。对于繁体中文,请使用“zh_TW.UTF-8 

ask_and_load_lang_set en_US.UTF-8

# 以上几乎是必需的,建议将它们包含在自己的自定义 ocs 中。

# 从这里,你可以编写自己的脚本

echo "#########################################################################################"

echo "# 1. Configure network"

dhclient

echo "#########################################################################################"

echo "# 2. Mount the clonezilla image home"

mkdir /home/partimag

mount -t cifs -o username=user01,password=passw0rd //servername/archiv /home/partimag

echo "#######################################after mounting, now showing mounts###########"

mount

echo "#########################################################################################"

echo "# 3. backing up sda3 "

/opt/drbl/sbin/ocs-sr -b -q -j2 -z1 -i 0 -p reboot savedisk "IMAGE" "sda"

echo "#########################################################################################"

在工作目录 /home/partimag 中执行 ocs-live-dev 命令,如下所示:
ocs-live-dev -g en_US.UTF-8 -k /usr/share/keymaps/i386/qwertz/de-latin1-nodeadkeys.kmap.gz -j ./clonezilla-live-1.2.1-39.iso -x noprompt -t -s -c -m ./custom-ocs-1

reating clonezilla Live without any clonezilla image embedded...

The output file name is: clonezilla-live-20090222.zip.

Estimated necessary space size in target dev: 96 MB

Copying the system files to working dir... This might take a few minutes... done!

Copying kernel, initrd, etc...

Trying to find the boot params from template live cd...

Adding syslinux menus for Clonezilla live...

Preparing syslinux.exe, syslinux, makeboot.bat and makeboot.sh...

Downloading http://free.nchc.org.tw/syslinux/syslinux-3.72.tar.bz2...

Extracting files...

syslinux-3.72/linux/syslinux

syslinux-3.72/win32/syslinux.exe

syslinux-3.72/mbr/mbr.bin

  adding: Clonezilla-Live-Version (stored 0%)

  adding: COPYING (stored 0%)

  adding: home/ (stored 0%)

  adding: home/partimag/ (stored 0%)

  adding: live/ (stored 0%)

  .

  .

  .

 adding: utils/mbr/ (stored 0%)

  adding: utils/mbr/mbr.bin (stored 0%)

The created release file is clonezilla-live-20090222.zip. You can extract all the files into your pendrive, and run makeboot.bat from pendrive in MS windows.

Warning: DO NOT RUN makeboot.bat from your local hard drive!! It is intended to be run from your USB device.

Cleaning tmp dirs...

Done!
将生成的 zip 文件解压到 /home/partimag 中并重新启动:
cd /home/partimag
unzip clonezilla-live-xxxxxx.zip –d .
mv live live-hd
reboot 

重启后即可选择批处理模式


暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇