如何制作可引导的无人值守 USB 恢复盘?

Oli*_*Oli 5 live-usb disk-image system-installation

我有 14.04 个自助服务终端系统,遍布全国各地。这些是可怕的小型集成设备。我需要将它们全部升级到 16.04 以支持新的软件堆栈。do-release-upgrade工作一半时间。另一半会破坏安装。此外,CPU真的很慢,某些站点的网络连接也很糟糕。因此,即使它有效,升级也需要很长时间。

这么新的计划。
我可以为 Virtualbox 或 LXC 中的每个信息亭制作一个完全安装的系统映像。
我需要一种方法将这些图像解压缩到系统上。

这里的主要问题是在另一端可用的技术人员很少。我不想自己飞 200 英里来做这件事。我需要几乎完全自动化并且不需要键盘的东西。

我正在想象一个场景:

  • 我为每个信息亭制作系统映像
  • 我为每个信息亭制作了一个可启动的 USB 驱动器,并复制到信息亭映像上。
  • 我给每一个贴上标签并张贴。
  • 在另一端,可以物理访问 USB 端口的工作人员只需插入正确的驱动器并重新启动。
  • 然后,它的可引导元素写入并扩展磁盘映像。

这就是我正在寻找的“可启动元素”。我期待这样的东西可能已经存在(对于批量重新映像安装),但我可能在新领域。任何在没有人工干预的情况下安装我的图像(过去插入它)的东西都会得到分数。

据我所知,像 Clonezilla 这样的选项需要有人用键盘来告诉它要做什么。我需要一些不需要键盘的东西,只需上手即可。

sud*_*dus 3

Shell脚本

我很喜欢制作一个 bash shellscript,它可以在已安装的、基于 Ubuntu 的持久实时系统以及基于 Debian Jessie 的小型“9w”系统中自动执行其操作。我希望它对您以及将来的其他人有用。

该脚本假设应该有两个可写驱动器(大容量存储设备):实时驱动器和目标驱动器。不要使用toram,它会破坏实时驱动器的识别。

shellscript 调用,它是mkusbdus-live的执行部分。所以它正在取代交互式 shellscript 。dus

dus-live可以管理以下类型的源文件,

  • 文件.iso
  • 文件.img
  • 文件.img.gz
  • 文件.img.xz

并且目标系统可以同时具有 MSDOS 和 GUID 分区表(当目标驱动器大于映像中原始系统的大小时)。

我用的名字是autoclone

#!/bin/bash

# Date        Sign     Comment
# 2017-06-30  sudodus  Created
# 2017-07-01  sudodus  checking that there is 1 possible target drive

wait=30

read -t "$wait" -p "WARNING: After $wait seconds '$0' will CLONE AUTOMATICALLY;
from the file given as parameter to the first detected drive
(except the live drive), so it will be overwritten.
If this is not what you want or if you are not sure, PRESS {ctrl + C} NOW !
...
"

function power_off {
read -t "$wait" -p "WARNING: After $wait seconds '$0' will POWEROFF automatically;
If this is not what you want or if you are not sure, PRESS {ctrl + C} NOW !
...
"
sudo poweroff
}

user=$(whoami)
if [ "$user" != "root" ]
then
 echo "run $0 with sudo or as root"
 exit
fi
if [ "$1" == "" ] || ! test -s "$1"
then
 echo "Usage:   sudo $0 <with an iso file or image file as parameter>"
 echo "Example: sudo $0 \"file.iso\""
 echo "Example: sudo $0 \"file.img\""
 echo "Example: sudo $0 \"file.img.xz\""
 exit
fi

source="$1"

livedrive=$(lsblk -lo name,type,mountpoint | \
grep -m1 -e /$ -e /cdrom$ -e /lib/live/mount/medium -e /lib/live/mount/persistence)
#echo "$livedrive"
livedrive=${livedrive:0:3}
echo "livedrive=/dev/$livedrive"

number_of_targets=$(lsblk -ldo name,type|grep -v "$livedrive"|grep -v zram|grep disk|wc -l)
           target=$(lsblk -ldo name,type|grep -v "$livedrive"|grep -v zram|grep disk)

#echo "target=$target"
# echo "number_of_targets=$number_of_targets"
# sudo lsblk -o name,model,size,type,fstype,label,mountpoint | \
#  grep -v "$livedrive"|grep -v zram| grep -v loop|grep -v ' rom '
####

if [ $number_of_targets -ne 1 ]
then
 echo '--------------------------------------------------------'
 sudo lsblk -o name,model,size,type,fstype,label | \
  grep -v "$livedrive"|grep -v zram| grep -v loop|grep -v ' rom '
 echo "$number_of_targets possible target drives found, but
1 possible target drive should be found
for '$0' to work correctly."
 if [ $number_of_targets -gt 1 ]
 then
  echo "--------------------------------------------------------
- Please remove every other possible target drive!
- Or are you running in the wrong computer?"
 fi
 echo "--------------------------------------------------------"
 wait=60
 power_off
 exit
fi
target=/dev/${target:0:3}

echo "target=$target"

umount "$target"?*

paramfromfile=$(mktemp)

echo "$source
$target" > "$paramfromfile"

# do it with dus-live, which comes with mkusb version 12-

echo "calling 'dus-live' ..."
dus-live pff:"$paramfromfile"

power_off
Run Code Online (Sandbox Code Playgroud)

在持久实时系统中进行测试

我测试它在两个持久实时系统中工作,可以从压缩图像文件安装,

在此链接中查看有关此方法的更多详细信息,

自动启动

在 Lubuntu 中通过以下命令将以下行附加到自动启动时,可以自动启动该脚本:

echo 'xterm -fa default -fs 12 -title autoclone -e sudo /home/lubuntu/autoclone dd_no-biggie-68MB.img.xz' >> ~/.config/lxsession/Lubuntu/autostart
Run Code Online (Sandbox Code Playgroud)

修改它以匹配实际的“dd”图像/path/name和 shellscript 的实际位置。

9w中对应的命令是

echo '@xterm -fa default -fs 12 -title autoclone -e sudo /root/autoclone /root/dd_no-biggie-68MB.img.xz' >> ./.config/lxsession/LXDE/autostart
Run Code Online (Sandbox Code Playgroud)

您自己的定制系统

您可能想要或必须创建自己的自定义系统(实时、持久实时或安装在 USB 驱动器或存储卡中)。您也许可以dus-live用简单的dd命令行进行替换,至少如果您要安装的系统使用 MSDOS 分区表的话。

免责声明

这个shellscript制作得相当快,经过我的测试,它可以工作,但是有很多情况没有经过测试,可能会发生意想不到的事情。因此,请测试一下,如果没有驱动器包含有价值的数据,则可能会被覆盖。

截图

Lubuntu 截图三

在前 30 秒内,您可以使用热键组合ctrl + C停止自动克隆,

在此输入图像描述

控制台输出:在此阶段系统正在同步(将缓冲区刷新到目标驱动器),

在此输入图像描述

在 30 秒内,您可以使用热键组合ctrl + C来避免关机(如果您希望留在 Lubuntu 桌面会话中),

在此输入图像描述

9w对应截图

在此输入图像描述


end*_*ias 0

您是否考虑过在双鸭模式下使用 Hak5 https://hakshop.com/collections/usb-rubber-ducky的 USB 橡皮鸭。我用它们在 7 台机器上安装了 Ubuntu。在每一个上,我所要做的就是用插入 USB 端口的橡皮鸭重新启动系统,因为我的系统总是优先从 USB 启动,这很容易。但是您可以使用两只橡皮鸭,用其中一个来调整 BIOS 首选项并从 USB 启动,同时使用另一个作为实时启动闪存驱动器和键盘来导航启动安装菜单生成的设置启动屏幕unetbootin。只要有一点耐心和反复试验,你就可以做到。由于不需要现场技术人员,您可以将准备好的橡皮鸭邮寄给距离较近且可以访问系统的人员。

在 Twin-Duck 模式下,橡皮鸭既充当 HID(在我们的例子中为键盘)又充当 USB 大容量存储设备。因此,您只需unetbootin在 Rubber Ducky 的 USB 大容量存储上制作一个可启动闪存盘,并使用 HID(键盘)自动化 - 击键注入 - 功能来自动安装操作系统时所需的导航(击键)。您甚至可以在无头系统上执行此操作。