Giter Site home page Giter Site logo

bcd-sys's Introduction

BCD-SYS

BASH script utility to setup the Boot Configuration Data store and system files for the Windows Boot Manager (WBM) from a Linux or macOS environment. This can be used to add boot files after applying a Windows image with the wimlib tools, configure the computer to boot from a virtual hard disk (VHDX) file, add a Windows installation to the current boot menu or recreate a system partition that has been corrupted or formatted. Similar to the bcdboot utility.

Example 1: Copy boot files then create BCD store for a physical Windows installation.

Example 2: Copy boot files then create BCD store for a Windows installation on a virtual hard disk.

Usage

Show help
bcd-sys --help
Create a new Windows entry
bcd-sys /media/user/mountpoint
Create a virtual hard disk entry
bcd-sys /media/user/mountpoint/images/windows.vhdx
Specify a system volume (no firmware entry)
bcd-sys /media/user/mountpoint -s /media/user/volname
Specify both UEFI and BIOS firmware
bcd-sys -f both /media/user/mountpoint
Add the WBM to the end of the UEFI boot order
bcd-sys -e /media/user/mountpoint
Specify a custom description
bcd-sys /media/user/mountpoint -n Windows\ 11\ Professional
Specify the locale parameter
bcd-sys -l en-us /media/user/mountpoint
Remove existing stores and create new entries
bcd-sys -c /media/user/mountpoint

Installation

Download from Releases or clone the repository.

git clone https://github.com/jpz4085/bcd-sys.git

Enter the folder for your platform and run for temporary usage.

cd $(uname)
./bcdsys.sh /media/user/mountpoint

Install or uninstall using the setup script if desired.

./setup.sh install | uninstall

Features

BCD-SYS has the following features and differences compared to bcdboot:

  • Global objects and settings remain unchanged when modifiying an existing BCD.
  • Any existing osloader objects for a Windows volume are replaced and not merged.
  • The system BCD-Template is ignored and a Windows10/11 equivalent is used.
  • The clean option will delete the existing configuration and create entries in new stores.
  • The boot files will be copied by default to a system partition on the Windows device, the
    current root device, or the first disk listed by the system if different from the previous.
  • When specifying a virtual hard disk the script will present a list of partitions contained
    in the file. Enter the device name of the volume which contains the Windows image.
  • The position of the WBM entry in the UEFI boot order will be preserved when updating
    an existing BCD. A new entry will only be created if missing or creating new stores.
  • The description can be specified when creating a new Windows entry.

Requirements

Common Packages: hivexsh and hivexregedit, (readpe - PE Utils1) pev/peres

Linux Packages: attr/setfattr and fatattr, VHDX Support: qemu-utils and NBD client module.2

macOS Packages: bash (above version 3.2), mtools, bootoption3, signmbr4 and NTFS write support.56

Legacy BIOS: ms-sys7

Footnotes

  1. Download and build from source when necessary.

  2. These are optional if only working with physical disks.

  3. This is optional and only tested on Hackintosh and VirtualBox.

  4. Create a Windows Disk Signature on MBR media before running the script.

  5. The script supports NTFS-3G as well as the commercial Tuxera and Paragon products.

  6. This is optional if not writing to any NTFS partitions (including system) from macOS.

  7. This is optional and not required if only using UEFI.

bcd-sys's People

Contributors

jpz4085 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

bcd-sys's Issues

BCD Error - Windows Failed to Start

Hello,

We received the attached error after doing this script. This is a Windows 10 (build 17763).

BCD-Error-20240508

Here is the log from this:

Get block device for mount point (sudo required later)...
/root/.hivexsh: Read-only file system
Remove entry at {cf4ca6b0-57e3-46f1-85ed-e8a96bd010e6}
/root/.hivexsh: Read-only file system
/root/.hivexsh: Read-only file system
Remove {cf4ca6b0-57e3-46f1-85ed-e8a96bd010e6} from WBM display order.
/root/.hivexsh: Read-only file system
/root/.hivexsh: Read-only file system
Remove entry at {d32da8ce-d3d7-4017-a889-79e9afc61bcf}
/root/.hivexsh: Read-only file system
/root/.hivexsh: Read-only file system
/root/.hivexsh: Read-only file system
Remove {d32da8ce-d3d7-4017-a889-79e9afc61bcf} from WBM resume object.
/root/.hivexsh: Read-only file system
Update main BCD hive with new entries...
/root/.hivexsh: Read-only file system
Loader GUID: {f697c3eb-534d-41f1-b3c4-816ccbf55481}
Resume GUID: {6371cb56-ea7f-4867-99a2-02d97ab025f9}
/root/.hivexsh: Read-only file system
/root/.hivexsh: Read-only file system
/root/.hivexsh: Read-only file system
Update recovery BCD hive with new entries...
/root/.hivexsh: Read-only file system
/root/.hivexsh: Read-only file system
Clean up temporary files...
Finished configuring UEFI boot files.

And here is the XML:

15371843041

109262 335963 41920901581 7696989766 0x01D8B2A8 0x8818FD5F 0x01D8B2A8 0x9C39C2D5 0 9 Microsoft® Windows® Operating System EnterpriseS Client 0 10.0.17763.2989;2016-01-01T00:00:00Z IMAGE_STATE_COMPLETE acpiapic WinNT Terminal Server en-US en-US 10 0 17763 3287 0 WINDOWS Factory_0

1 0 0 0 0x01D8B2A8 0x98BDFB35 0x01D8B2A8 0x9C3C254D 0 Factory_1 20-58977715 0 17 8 2022 15 16 2 0 0 99970187264 NTFS Factory_0 OS 2 3 0 0 4923064320 NTFS Factory_1 Imaging 2 5 3 0 6

Let me know any feedback or needs.

Thanks!

some minors errors with flash devices like /dev/nvme0n1

i got some errors when run: bcd-sys -v /mnt/windows
where /mnt/windows is mount point to /dev/nvme0n1p3 (win part) and EFI part /dev/nvme0n1p1

DEBUG: Length=3, String=MUI
DEBUG: Length=11, String=BOOTMGR.XSL
DEBUG: Length=3, String=MUI
DEBUG: Length=11, String=BOOTMGR.XSL
sfdisk: cannot open /dev/nvme0n1p: No such file or directory
Update main BCD hive with new entries...
Loader GUID: {005a0c6e-67ad-4e92-99e9-a0546faf8732}
Resume GUID: {71992148-7aca-4e78-afc5-4742c3e3e41f}
sfdisk: cannot open /dev/nvme0n1p: No such file or directory
sfdisk: cannot open /dev/nvme0n1p: No such file or directory
sfdisk: cannot open /dev/nvme0n1p: No such file or directory
sfdisk: cannot open /dev/nvme0n1p: No such file or directory
Update recovery BCD hive with new entries...
Clean up temporary files...
Finished configuring UEFI boot files.

error is "/dev/nvme0n1p", should be "/dev/nvme0n1".
probably same with device /dev/mmcblk0

Missing License

Awesome work, thank you! But there are some things I would like to change (and eventually pitch it to you). Would you care to add a license to your code?

Windows Install.app

Hello. I wrote to you there https://sourceforge.net/p/windows-install/discussion/general/thread/2fd478e439/?limit=25#ed25/cbdd/c114/1a05/5e38/eb08/67b0
But I think it’s convenient to communicate here.
I adapted the creation of BCD UEFI for the program and it works well. But there are difficulties with BCD BIOS.
This is an MBR disk

 iMac:~ sergey$ diskutil info /Volumes/Windows
 Device Identifier:         disk6s1
 Device Node:               /dev/disk6s1
 Whole:                     No
 Part of Whole:             disk6

 Volume Name:               Windows
 Mounted:                   Yes
 Mount Point:               /Volumes/Windows

 Partition Type:            Windows_NTFS
 File System Personality:   ExFAT
 Type (Bundle):             exfat
 Name (User Visible):       ExFAT

 OS Can Be Installed:       No
 Media Type:                Общий
 Protocol:                  USB
 SMART Status:              Not Supported
 Volume UUID:               7F7C6600-E4EC-32D9-9064-A2DBA7EFCD2A
 Partition Offset:          1048576 Bytes (2048 512-Byte-Device-Blocks)

 Disk Size:                 320.1 GB (320071532544 Bytes) (exactly 625139712 512-Byte-Units)
 Device Block Size:         512 Bytes

 Volume Total Space:        320.1 GB (320060129280 Bytes) (exactly 625117440 512-Byte-Units)
 Volume Used Space:         11.3 MB (11272192 Bytes) (exactly 22016 512-Byte-Units) (0.0%)
 Volume Free Space:         320.0 GB (320048857088 Bytes) (exactly 625095424 512-Byte-Units) (100.0%)
 Allocation Block Size:     512 Bytes

 Media OS Use Only:         No
 Media Read-Only:           No
 Volume Read-Only:          No

 Device Location:           External
 Removable Media:           Fixed

 Solid State:               Info not available

I get:

 iMac:~ sergey$ /Users/sergey/Desktop/test15 ; exit;
 part - /dev/disk6s1
 disk - /dev/disk6
 FDisk_partition_scheme
 Password:
 Disk: /dev/disk6	geometry: 38913/255/63 [625142448 sectors]
 Signature: 0xAA55
          Starting       Ending
  #: id  cyl  hd sec -  cyl  hd sec [     start -       size]
 ------------------------------------------------------------------------
  1: 07 1023 254  63 - 1023 254  63 [      2048 -  625139712] HPFS/QNX/AUX
  2: 00    0   0   0 -    0   0   0 [         0 -          0] unused      
  3: 00    0   0   0 -    0   0   0 [         0 -          0] unused      
  4: 00    0   0   0 -    0   0   0 [         0 -          0] unused      
 FDisk_partition_scheme
 disksig - 00000000
 partoffset - 1048576
 diskbytes - 00,00,00,00,00,00,00,00,00,00,00,00,0
 partbytes - 00,00,10,00,00,00,00,00,00,00,00,00,00,00,00,00
 logout

 Saving session...
 ...copying shared history...
 ...saving history...truncating history files...
 ...completed.

GPT disk with hybrid MBR

 iMac:~ sergey$ diskutil info /Volumes/Windows
 Device Identifier:         disk6s3
 Device Node:               /dev/disk6s3
 Whole:                     No
 Part of Whole:             disk6

 Volume Name:               Windows
 Mounted:                   Yes
 Mount Point:               /Volumes/Windows

 Partition Type:            Microsoft Basic Data
 File System Personality:   NTFS
 Type (Bundle):             ntfs
 Name (User Visible):       Windows NT File System (NTFS)

 OS Can Be Installed:       No
 Media Type:                Общий
 Protocol:                  USB
 SMART Status:              Not Supported
 Disk / Partition UUID:     0E7E4ACF-CE00-4595-B642-D972CDFEAB57
 Partition Offset:          139829706752 Bytes (273104896 512-Byte-Device-Blocks)

 Disk Size:                 100.1 GB (100092870656 Bytes) (exactly 195493888 512-Byte-Units)
 Device Block Size:         512 Bytes

 Volume Total Space:        100.1 GB (100092866560 Bytes) (exactly 195493880 512-Byte-Units)
 Volume Used Space:         11.1 GB (11061256192 Bytes) (exactly 21604016 512-Byte-Units) (11.1%)
 Volume Free Space:         89.0 GB (89031610368 Bytes) (exactly 173889864 512-Byte-Units) (88.9%)
 Allocation Block Size:     512 Bytes

 Media OS Use Only:         No
 Media Read-Only:           No
 Volume Read-Only:          Yes (read-only mount flag set)

 Device Location:           External
 Removable Media:           Fixed

 Solid State:               Info not available

I get:

 iMac:~ sergey$ /Users/sergey/Desktop/test15 ; exit;
 part - /dev/disk6s3
 disk - /dev/disk6
 GUID_partition_scheme
 Password:
 Disk: /dev/disk6	geometry: 29185/255/63 [468862128 sectors]
  Signature: 0xAA55
          Starting       Ending
  #: id  cyl  hd sec -  cyl  hd sec [     start -       size]
 ------------------------------------------------------------------------
  1: EE    0   0   2 -   25 127  14 [         1 -     409639] <Unknown ID>
  2: AF   25 127  15 - 1023 254  63 [    409640 -  272431832] HFS+        
 *3: 07 1023 254  63 - 1023 254  63 [ 273104896 -  195493888] HPFS/QNX/AUX
  4: 08 1023 254  63 - 1023 254  63 [ 272841472 -     263424] AIX fs      
 FDisk_partition_scheme
 disksig - 00000000
 partoffset - 139829706752
 diskbytes - 00,00,00,00,00,00,00,00,00,00,00,00,0
 partbytes - 00,00,80,8e,20,00,00,00,00,00,00,00,00,00,00,00
 logout

 Saving session...
 ...copying shared history...
 ...saving history...truncating history files...
 ...completed.

Script-Test for testing

#!/bin/bash

endian () {
 v=$1
 i=${#v}

 while [ $i -gt 0 ]
 do
     i=$[$i-2]
    echo -n ${v:$i:2}
 done
 echo
}

guid_bytes () {
guidstr="$1"
IFS='-'

read -a strarr <<< "$guidstr"

guidbytes=$(endian ${strarr[0]})
guidbytes+=$(endian ${strarr[1]})
guidbytes+=$(endian ${strarr[2]})
guidbytes+=${strarr[3]}
guidbytes+=${strarr[4]}

echo $guidbytes
}

blksize () {
sectsz=$(diskutil info $1 | grep "Device Block Size:" | awk '{print $4}')
echo $sectsz
}

mntpoint=/Volumes/Windows
part=$(diskutil info "$(basename "$mntpoint")" | grep "Device Node:" | awk '{print $3}')
echo part - $part
disk=$(printf $part | sed 's/s[0-9]*$//')
echo "disk - $disk"
scheme=$(diskutil info $disk | grep "Content (IOContent):" | awk '{print $3}')
echo $scheme

if [[ "$scheme" == "GUID_partition_scheme" ]]; then
    if [[ ! -z $(sudo fdisk "$disk" | grep -E '2:|3:|4:' | grep -v unused) ]]; then
       scheme="FDisk_partition_scheme" #Use fdisk option for GPT disk with hybrid MBR.
    fi
fi
sudo fdisk -y "$disk" <<EOF
   p
   quit
EOF
echo $scheme  

if   [[ "$scheme" == "GUID_partition_scheme" ]]; then
     sectsize=$(blksize $disk)
     echo "sectsize- $sectsize"
     diskbytes=$(sudo xxd -u -p -s $(($sectsize + 56)) -l 16 $disk | sed 's/.\{2\}/&,/g;s/,$//')
     partguid=$(diskutil info $part | grep "Partition UUID:" | awk '{print $5}')
     echo "partguid - $partguid"
     partbytes=$(printf "%s" $(guid_bytes $partguid) | sed 's/.\{2\}/&,/g;s/,$//')
     schemebyte="00"
elif [[ "$scheme" == "FDisk_partition_scheme" ]]; then
     disksig=$(sudo xxd -u -p -s 440 -l 4 $disk)
     partoffset=$(diskutil info $part | grep "Partition Offset:" | awk '{print $3}')
     echo "disksig - $disksig"
     echo "partoffset - $partoffset"
     if [[ -z $partoffset ]]; then
        hidsect=$(sudo fdisk $disk | tail -n +6 | awk -v partnum=${part##*s} 'FNR == partnum {print $11}')
        sectsize=$(blksize $disk)
        partoffset=$(($sectsize * $hidsect))
     fi
     diskbytes=$(printf "%s" $(printf "%x%024x" "0x$disksig") | sed 's/.\{2\}/&,/g;s/,$//')
     partbytes=$(printf "%s" $(endian $(printf "%032x" "$partoffset")) | sed 's/.\{2\}/&,/g;s/,$//')
     schemebyte="01"
fi
echo "diskbytes - $diskbytes"
echo "partbytes - $partbytes"

exit

Recovery\BCD Error

I am back with this Recovery\BCD Error:
image

I have tried several times, and the issue repeats.

Attached is the file from the error:
BCD.zip

Let me know any information you need or anything you would like to try.

BCD-SYS with .WIM files

Hi,

I am trying to use your scripts in conjunction with .WIM images.

If possible, I would like to discuss this with you.

Let me know. Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.