-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsimpleiso
executable file
·175 lines (140 loc) · 4.35 KB
/
simpleiso
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/bin/bash
#
# Generate a basic ISO boot image from vmlinuz & initramfs. The resulting image
# should be bootable by BIOS or UEFI systems.
set -euxo pipefail
# Optional parameters.
INITRAMFS=
BOOT_PARAMS=
# From xorriso package.
MKISOFS=/usr/bin/xorriso
# From the isolinux package.
ISOLINUX_BIN=/usr/lib/ISOLINUX/isolinux.bin
# From the syslinux-common package.
LDLINUX_C32=/usr/lib/syslinux/modules/bios/ldlinux.c32
function help() {
echo "usage: ${0} [OPTIONS] vmlinuz isoname"
echo
echo "where OPTIONS are:"
echo " -h show this help"
echo " -i FILE initramfs filesystem image for kernel"
echo " -x ARGS extra kernel command line args"
}
# Check for required binaries.
if [ ! -f "${MKISOFS}" ]; then
echo "Error: mkisofs not found, please install or update PATH"
exit 1
fi
# Parse command line parameters.
while getopts "hi:x:" opt; do
case ${opt} in
h)
help
exit 0
;;
i)
INITRAMFS="${OPTARG}"
;;
x)
BOOT_PARAMS="${OPTARG}"
;;
esac
done
# Adjust positional parameters after processing with getopts.
shift $((OPTIND - 1))
# Assign positional parameters.
VMLINUZ=${1:?Error: Please provide a vmlinuz image}
ISO_NAME=${2:?Error: Please provide an ISO output file name}
function setup_isofs() {
local isofs_dir=$1
local efiboot_img=$2
local vmlinuz=$3
local initramfs=$4
local boot_params=$5
local initramfs_config=
local initramfs_config_efi=
# Setup the mkisofs filesystem.
cp $vmlinuz ${isofs_dir}/vmlinuz
if test -f "$initramfs" ; then
cp $initramfs ${isofs_dir}/initramfs
initramfs_config="INITRD initramfs"
initramfs_config_efi="initrdefi /initramfs"
fi
# Generate isolinux.cfg
cat > ${isofs_dir}/isolinux.cfg <<EOF
SAY ePoxy ISO boot image: $ISO_NAME
SAY Kernel parameters: $boot_params
TIMEOUT 30
DEFAULT linux
LABEL linux
KERNEL vmlinuz
APPEND $boot_params
$initramfs_config
EOF
cat > ${isofs_dir}/grub.cfg <<EOF
set timeout=5
set color_highlight=black/light-magenta
menuentry 'linux: ${ISO_NAME}' {
linuxefi /vmlinuz $boot_params
$initramfs_config_efi
}
EOF
make_bootefi_img ${efiboot_img} ${isofs_dir}
# Copy isolinux bootloader.
install -D -m 644 ${ISOLINUX_BIN} ${isofs_dir}/isolinux/isolinux.bin
touch ${isofs_dir}/$( date +%Y%m%d-%H%M%S )
# Syslinux 6.x requires the LDLINUX_C32 file.
cp ${LDLINUX_C32} ${isofs_dir}
}
function make_bootefi_img() {
local bootefi_img=$1
local isofs_dir=$2
local tmp=$( mktemp --directory )
local raw_size_k=$(
du --dereference --summarize --block-size=1K ${isofs_dir} \
| awk '{ print $1; }'
)
local size=$(( $raw_size_k + 4096 ))
# Make the grub efi boot loader image.
grub-mkimage -o ${tmp}/bootx64.efi -p / -O x86_64-efi fat iso9660 part_gpt \
part_msdos normal boot linux linuxefi efinet lsefi lsefisystab lsefimmap \
configfile loopback chain efifwsetup efi_gop efi_uga ls search \
search_label search_fs_uuid search_fs_file gfxterm gfxterm_background \
gfxterm_menu test all_video loadenv exfat ext2 ntfs udf
# Ignore meaningless sector alignment failures.
export MTOOLS_SKIP_CHECK=1
# Creates an empty fat16 disk image. NB: fat32 min size is 256MB.
truncate --size ${size}K ${tmp}/data.fat16
mkfs.vfat ${tmp}/data.fat16 -F16
# Creates the necessary subdirectories.
mmd -i ${tmp}/data.fat16 ::/efi ::/efi/boot
mcopy -bsQ -i ${tmp}/data.fat16 ${tmp}/bootx64.efi ::/efi/boot
mcopy -bsQ -i ${tmp}/data.fat16 ${isofs_dir}/grub.cfg ::/
mcopy -bsQ -i ${tmp}/data.fat16 ${isofs_dir}/vmlinuz ::/
mcopy -bsQ -i ${tmp}/data.fat16 ${isofs_dir}/initramfs ::/
# Copy the fat16 formatted data as the complete bootefi img file.
cp ${tmp}/data.fat16 ${bootefi_img}
# Clean up temporary directory.
rm -rf ${tmp}
}
function main() {
local isodir=$( mktemp -d /tmp/iso.dir.XXXXXX )
setup_isofs $isodir ${isodir}/efiboot.img "$VMLINUZ" "$INITRAMFS" "${BOOT_PARAMS}"
# Generate the ISO image. File paths are relative to the ${isodir}.
${MKISOFS} -as mkisofs \
-isohybrid-mbr /usr/lib/ISOLINUX/isohdpfx.bin \
-c isolinux/boot.cat \
-b isolinux/isolinux.bin \
-no-emul-boot \
-boot-load-size 4 \
-boot-info-table \
-eltorito-alt-boot \
-e efiboot.img \
-no-emul-boot \
-isohybrid-gpt-basdat \
-output ${ISO_NAME} \
${isodir}
# Clean up temporary directory.
rm -fr ${isodir}
}
main