全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

CeraNetworks网络延迟测速工具IP归属甄别会员请立即修改密码
12
返回列表 发新帖
楼主: LiuJia

通过debian-installer远程dd安装Windows

[复制链接]
 楼主| 发表于 2022-12-29 15:55:14 | 显示全部楼层
本帖最后由 LiuJia 于 2022-12-29 15:56 编辑
zxxx 发表于 2022-12-29 15:13
https://github.com/fincham/kexec-remote-debian-install/raw/master/build.py

这个脚本大佬保存了吗 ...


大概内容是这样的:

  1. #!/usr/bin/env python
  2. #
  3. # Copyright (c) 2015 Catalyst.net Ltd
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. #

  17. import argparse
  18. import os
  19. import random
  20. import shutil
  21. import StringIO
  22. import subprocess
  23. import tempfile

  24. """
  25. Produce an initrd image which can be used to remotely re-install Debian or Ubuntu.

  26. Michael Fincham <michael.fincham@catalyst.net.nz>
  27. """

  28. def find(root):
  29.     for root, dirs, files in os.walk(root):
  30.         print dirs
  31.         print files

  32. if __name__ == "__main__":

  33.     parser = argparse.ArgumentParser(description=__doc__)
  34.     parser.add_argument('initrd', help='path to initrd.gz file to repack')
  35.     parser.add_argument('interface', help='which interface to configure')
  36.     parser.add_argument('address', help='IP address to configure on INTERFACE')
  37.     parser.add_argument('netmask', help='netmask to configure on interface')
  38.     parser.add_argument('gateway', help='default gateway to use')
  39.     parser.add_argument('nameservers', help='space separated list of name servers to use')
  40.     parser.add_argument('--locale', default='en_NZ.UTF-8', help='locale to use, defaults to en_NZ.UTF-8')
  41.     parser.add_argument('--keymap', default='us', help='keyboard keymap to use, defaults to us')

  42.     args = parser.parse_args()

  43.     password = "".join("{:02x}".format(ord(c)) for c in open("/dev/urandom","rb").read(16))

  44.     preseed_template = """
  45. d-i anna/choose_modules string network-console
  46. d-i preseed/early_command string anna-install network-console

  47. d-i network-console/password password {password}
  48. d-i network-console/password-again password {password}

  49. d-i netcfg/choose_interface select {interface}
  50. d-i netcfg/disable_dhcp boolean true
  51. d-i netcfg/get_ipaddress string {address}
  52. d-i netcfg/get_netmask string {netmask}
  53. d-i netcfg/get_gateway string {gateway}
  54. d-i netcfg/get_nameservers string {nameservers}
  55. d-i netcfg/confirm_static boolean true

  56. d-i debian-installer/locale string {locale}
  57. d-i console-keymaps-at/keymap select {keymap}
  58.     """

  59.     preseed = preseed_template.format(
  60.         password=password,
  61.         interface=args.interface,
  62.         nameservers=args.nameservers,
  63.         address=args.address,
  64.         netmask=args.netmask,
  65.         gateway=args.gateway,
  66.         locale=args.locale,
  67.         keymap=args.keymap,
  68.     )

  69.     print preseed

  70.     initrd_path = os.path.abspath(args.initrd)
  71.     original_cwd = os.getcwd()

  72.     working_directory = tempfile.mkdtemp()
  73.     os.chdir(working_directory)

  74.     with open('initrd.cpio','wb') as initrd_cpio:
  75.         print "Unpacking initrd..."
  76.         subprocess.check_call(("gzip -cd %s" % initrd_path).split(), stdout=initrd_cpio)

  77.     with open('initrd.cpio','rb') as initrd_cpio:
  78.         subprocess.check_call(("cpio -id").split(), stdin=initrd_cpio)

  79.     print ""
  80.     print "Re-packing initrd..."

  81.     os.unlink('initrd.cpio')
  82.     with open('preseed.cfg', 'w') as preseed_file:
  83.         preseed_file.write(preseed)

  84.     file_list = subprocess.check_output("find .".split())

  85.     with open('initrd.cpio', 'w') as initrd_cpio:
  86.         cpio_process = subprocess.Popen('cpio -H newc -o'.split(), stdin=subprocess.PIPE, stdout=initrd_cpio)
  87.         cpio_process.communicate(file_list)

  88.     with open(initrd_path,'wb') as initrd_cpio:
  89.         subprocess.check_call("gzip -c initrd.cpio".split(), stdout=initrd_cpio)

  90.     os.chdir(original_cwd)
  91.     shutil.rmtree(working_directory)
复制代码
发表于 2022-12-29 17:37:11 来自手机 | 显示全部楼层
LiuJia 发表于 2022-12-29 15:55
大概内容是这样的:

感谢
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2024-3-29 06:12 , Processed in 0.056403 second(s), 7 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表