This repository has been archived by the owner on Jun 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
linwin_bootmaker.sh
executable file
·139 lines (119 loc) · 3.23 KB
/
linwin_bootmaker.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/bin/bash
## Based on instructions at: ##
## https://thornelabs.net/2013/06/10/create-a-bootable-windows-7-usb-drive-in-linux.html ##
## Please see LICENSE for license information. ##
# PRE-FLIGHT: Set some variables.
DISK=$1
WINISO=$2
# PRE-FLIGHT: Verify programs
# parted - partitioning
if [ -x "$(command -v parted)" ]; then
PARTED=$(command -v parted)
else
echo -e "[ ERROR ]: Cannot locate 'parted'; please install / make sure in PATH."
exit 1
fi
# ms-sys - Write Windows-compatible bootloaders
if [ -x /usr/local/bin/ms-sys ]; then
MSSYS=/usr/local/bin/ms-sys
elif [ -x "$(command -v ms-sys)" ]; then
MSSYS=$(command -v ms-sys)
else
echo -e "[ ERROR ]: Cannot locate 'ms-sys' (default '/usr/local/bin/ms-sys'); please install / make sure in PATH."
exit 1
fi
# Usage info
if [ "$1" == "--help" ] || [ "$1" == "-h" ] || [ $# -lt 1 ]; then
echo -ne "\n"
echo -e "Usage: ${0} {/dev/mydisk} {/path/to/windows.iso}"
exit 0
fi
# PRE-FLIGHT: A couple of sanity checks
# Check for disk parameter; verify it exists
if [ $# -gt 2 ]; then
echo -e "[ ERROR ]: Too many arguments. Please specify the disk device and path to ISO."
exit 1
elif [[ "${1}" != "/dev/"* ]]; then
echo -e "[ ERROR ]: Please specify a disk device. -- e.g. \"/dev/sdX\""
exit 1
fi
# Check for ISO
if [[ ! -a "${2}" ]]; then
echo -e "[ ERROR ]: Please verify path to ISO file. Cannot find ${2}."
exit 1
fi
if [ ! -b $DISK ]; then
echo -e "[ ERROR ]: Disk device doesn't exist. Please verify."
exit 1
fi
# Re-prompt about destroying. Quit if no.
echo -ne "\n"
echo -e ">> Using disk ${DISK}."
read -p ">> [ WARNING ]: ALL DATA WILL BE DESTROYED. ARE YOU SURE? (y/n)" -n 1 -r
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo -e "\n"
exit 1
fi
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# !!!! After here be dragons! !!!!!!
# !!!! Disk destruction below! !!!!!
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# Parted partitioning, create NTFS.
echo -ne "\n"
echo -e ">> Partitioning disk..."
$PARTED -s $DISK "mklabel msdos"
$PARTED -s $DISK "mkpart primary ntfs 1 -1"
sleep 1
$PARTED -s $DISK "set 1 boot on"
echo -ne "\n"
echo -e ">> Creating NTFS partition..."
mkfs.ntfs -f ${DISK}1
# Use ms-sys to make bootloader.
echo -ne "\n"
echo -e ">> Writing Windows boot loaders..."
$MSSYS -7 $DISK
$MSSYS -n ${DISK}1
# Mount and copy files to disk.
echo -ne "\n"
echo -e ">> Mounting disk to /mnt..."
if ! [[ -n $(ls -A /mnt) ]]; then
mount ${DISK}1 /mnt
else
echo -e "\n [ ERROR ]: /mnt not empty."
exit 1
fi
echo -ne "\n"
echo -e ">> Mounting Windows 7 ISO to /media..."
if ! [[ -n $(ls -A /media) ]]; then
mount -o loop $2 /media
if [ $? -ne 0 ]; then
echo -e "\n[ ERROR ]: Issue mounting ISO. Exiting."
exit 1
fi
else
echo -e "\n [ ERROR ]: /media not empty."
exit 1
fi
if [ -x "$(command -v rsync)" ]; then
echo -e ">> Copying files (Using rsync)..."
RSYNC=$(command -v rsync)
rsync -avP /media/ /mnt
if [ $? -ne 0 ]; then
echo -e "\n[ ERROR ]: Issue copying files. Exiting."
exit 1
fi
else
echo -e ">> Copying files (using cp -- no rsync found)..."
cp -av /media/* /mnt/
if [ $? -ne 0 ]; then
echo -e "\n[ ERROR ]: Issue copying files. Exiting."
exit 1
fi
fi
# Clean up.
echo -ne "\n"
echo -e ">> Unmounting disks..."
umount /mnt
umount /media
echo -ne "\n \n"
echo -e "Creation complete. Enjoy!"