mirror of
https://github.com/bin456789/reinstall.git
synced 2025-01-19 04:49:13 +08:00
dd: 支持 raw vhd 格式
This commit is contained in:
parent
7f34bf36c8
commit
7edc57c5a3
@ -151,7 +151,7 @@ bash reinstall.sh centos 9
|
|||||||
|
|
||||||
### Feature 2: DD
|
### Feature 2: DD
|
||||||
|
|
||||||
- Supports `gzip` and `xz` formatted images
|
- Supports `raw` `vhd` `gzip` and `xz` formatted images
|
||||||
- When using DD with a Windows image, the script will automatically expand the system partition. For static IP machines, the IP will be configured automatically, and it may take a few minutes to take effect on first boot
|
- When using DD with a Windows image, the script will automatically expand the system partition. For static IP machines, the IP will be configured automatically, and it may take a few minutes to take effect on first boot
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
@ -151,7 +151,7 @@ bash reinstall.sh centos 9
|
|||||||
|
|
||||||
### 功能 2: DD
|
### 功能 2: DD
|
||||||
|
|
||||||
- 支持 `gzip`、`xz` 格式的镜像
|
- 支持 `raw` `vhd` `gzip`、`xz` 格式的镜像
|
||||||
- DD Windows 镜像时,会自动扩展系统盘。静态的机器会自动配置好 IP,可能首次开机几分钟后才生效
|
- DD Windows 镜像时,会自动扩展系统盘。静态的机器会自动配置好 IP,可能首次开机几分钟后才生效
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
33
reinstall.sh
33
reinstall.sh
@ -52,8 +52,7 @@ Usage: $reinstall____ centos 9
|
|||||||
kali
|
kali
|
||||||
arch
|
arch
|
||||||
gentoo
|
gentoo
|
||||||
dd --img='http://xxx.com/xxx.xz'
|
dd --img='http://xxx.com/xxx.raw' (supports raw vhd gzip xz)
|
||||||
dd --img='http://xxx.com/xxx.gzip'
|
|
||||||
windows --image-name='windows xxx yyy' --lang=xx-yy
|
windows --image-name='windows xxx yyy' --lang=xx-yy
|
||||||
windows --image-name='windows xxx yyy' --iso='http://xxx.com/xxx.iso'
|
windows --image-name='windows xxx yyy' --iso='http://xxx.com/xxx.iso'
|
||||||
netboot.xyz
|
netboot.xyz
|
||||||
@ -1063,10 +1062,32 @@ setos() {
|
|||||||
|
|
||||||
# shellcheck disable=SC2154
|
# shellcheck disable=SC2154
|
||||||
setos_dd() {
|
setos_dd() {
|
||||||
test_url $img 'xz|gzip' img_type
|
# 下面两种都是 raw
|
||||||
|
# DOS/MBR boot sector
|
||||||
|
# x86 boot sector; partition 1: ...
|
||||||
|
test_url $img 'xz|gzip|dos/mbr|x86' img_type
|
||||||
|
|
||||||
|
# 修正 raw 的 img_type
|
||||||
|
if [ "$img_type" = dos/mbr ] || [ "$img_type" = x86 ]; then
|
||||||
|
img_type=raw
|
||||||
|
fi
|
||||||
|
|
||||||
if is_efi; then
|
if is_efi; then
|
||||||
install_pkg hexdump $img_type
|
install_pkg hexdump
|
||||||
|
|
||||||
|
if ! [ "$img_type" = raw ]; then
|
||||||
|
install_pkg $img_type
|
||||||
|
fi
|
||||||
|
|
||||||
|
extract() {
|
||||||
|
if [ "$img_type" = raw ]; then
|
||||||
|
cat "$1"
|
||||||
|
else
|
||||||
|
# xz/gzip -d 文件必须有正确的扩展名,否则报扩展名错误
|
||||||
|
# 因此用 stdin
|
||||||
|
$img_type -dc <"$1"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# openwrt 镜像 efi part type 不是 esp
|
# openwrt 镜像 efi part type 不是 esp
|
||||||
# 因此改成检测 fat?
|
# 因此改成检测 fat?
|
||||||
@ -1079,7 +1100,7 @@ setos() {
|
|||||||
|
|
||||||
# 仅打印前34个扇区 * 4096字节(按最大的算)
|
# 仅打印前34个扇区 * 4096字节(按最大的算)
|
||||||
# 每行128字节
|
# 每行128字节
|
||||||
"$img_type" -dc <"$tmp/img-test" | hexdump -n $((34 * 4096)) -e '128/1 "%02x" "\n"' -v >$tmp/img-test-hex
|
extract "$tmp/img-test" | hexdump -n $((34 * 4096)) -e '128/1 "%02x" "\n"' -v >$tmp/img-test-hex
|
||||||
if grep -q '^28732ac11ff8d211ba4b00a0c93ec93b' $tmp/img-test-hex; then
|
if grep -q '^28732ac11ff8d211ba4b00a0c93ec93b' $tmp/img-test-hex; then
|
||||||
echo 'DD: Image is EFI.'
|
echo 'DD: Image is EFI.'
|
||||||
else
|
else
|
||||||
@ -1087,7 +1108,7 @@ setos() {
|
|||||||
warn '
|
warn '
|
||||||
The current machine uses EFI boot, but the DD image is not an EFI image.
|
The current machine uses EFI boot, but the DD image is not an EFI image.
|
||||||
Continue with DD?
|
Continue with DD?
|
||||||
当前机器使用 EFI 引导,但 DD 镜像不是 EFI 镜像。
|
当前机器使用 EFI 引导,但 DD 镜像可能不是 EFI 镜像。
|
||||||
继续 DD?'
|
继续 DD?'
|
||||||
read -r -p '[y/N]: '
|
read -r -p '[y/N]: '
|
||||||
if [[ "$REPLY" = [Yy] ]]; then
|
if [[ "$REPLY" = [Yy] ]]; then
|
||||||
|
31
trans.sh
31
trans.sh
@ -1650,18 +1650,27 @@ get_http_file_size_to() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dd_gzip_xz_raw() {
|
||||||
|
# 用官方 wget,一来带进度条,二来自带重试
|
||||||
|
# alpine busybox 自带 gzip xz,但官方版也许性能更好
|
||||||
|
# raw 包括 vhd
|
||||||
# shellcheck disable=SC2154
|
# shellcheck disable=SC2154
|
||||||
dd_gzip_xz() {
|
|
||||||
case "$img_type" in
|
case "$img_type" in
|
||||||
gzip) prog=gzip ;;
|
xz | gzip) apk add wget $img_type ;;
|
||||||
xz) prog=xz ;;
|
raw) apk add wget ;;
|
||||||
*) error_and_exit 'Not supported' ;;
|
*) error_and_exit 'Not supported' ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# alpine busybox 自带 gzip xz,但官方版也许性能更好
|
pipe_extract() {
|
||||||
# 用官方 wget,一来带进度条,二来自带重试
|
if [ "$img_type" = raw ]; then
|
||||||
apk add wget $prog
|
cat
|
||||||
if ! command wget $img -O- --tries=5 --progress=bar:force | $prog -dc >/dev/$xda 2>/tmp/dd_stderr; then
|
else
|
||||||
|
$img_type -dc
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
if ! command wget $img -O- --tries=5 --progress=bar:force |
|
||||||
|
pipe_extract >/dev/$xda 2>/tmp/dd_stderr; then
|
||||||
# vhd 文件结尾有 512 字节额外信息,可以忽略
|
# vhd 文件结尾有 512 字节额外信息,可以忽略
|
||||||
if grep -iq 'No space' /tmp/dd_stderr; then
|
if grep -iq 'No space' /tmp/dd_stderr; then
|
||||||
apk add parted
|
apk add parted
|
||||||
@ -4084,17 +4093,17 @@ trans() {
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
gzip | xz)
|
gzip | xz | raw)
|
||||||
# 暂时没用到 gzip xz 格式的云镜像
|
# 暂时没用到 gzip xz 格式的云镜像
|
||||||
dd_gzip_xz
|
dd_gzip_xz_raw
|
||||||
resize_after_install_cloud_image
|
resize_after_install_cloud_image
|
||||||
modify_os_on_disk linux
|
modify_os_on_disk linux
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
elif [ "$distro" = "dd" ]; then
|
elif [ "$distro" = "dd" ]; then
|
||||||
case "$img_type" in
|
case "$img_type" in
|
||||||
gzip | xz)
|
gzip | xz | raw)
|
||||||
dd_gzip_xz
|
dd_gzip_xz_raw
|
||||||
modify_os_on_disk windows
|
modify_os_on_disk windows
|
||||||
;;
|
;;
|
||||||
qemu) # dd qemu 不可能到这里,因为上面已处理
|
qemu) # dd qemu 不可能到这里,因为上面已处理
|
||||||
|
Loading…
x
Reference in New Issue
Block a user