mkinstallusbstick.sh (make installer USB stick)
複数のインストールメディアに対応したUSBメモリーの作成 (exFAT対応) の備忘録
USBメモリー
パーティション構成
・ 128GiBのUSBメモリーの例
/dev/ | 用途 | フォーマット | 設定容量 | 使用容量 |
---|---|---|---|---|
sdX1 | MBR | 無し | 1GiB | 1GiB |
sdX2 | EFI | vFAT | 256MiB | 18MiB |
sdX3 | DATA | exFAT | 113GiB | 28GiB |
・sdXは各自の環境に合わせて読み替えの事
USBメモリーのパーティション/フォーマットを変更するので保存されたものが削除される事を理解した上で作業して下さい
initramfsの変更
USBメモリーのexFATフォーマット領域にアクセスするためinitrd*を変更
- モジュールの追加(以下を存在すれば取り込む)
モジュール名 |
---|
libaio1 |
libblkid1 |
libc-l10n |
libgcrypt20 |
libgnutls30 |
libmount1 |
libpcre3 |
libselinux1 |
libsmartcols1 |
libtinfo5 |
libzstd1 |
mount |
fuse |
libfuse2 |
ntfs-3 |
- スクリプトの変更
主な変更点 |
---|
ファイリングシステムの制限をしている部分にexfatとntfsを追加 |
ロードモジュールにfuse、fuse3、exfat、ntfs3を追加 |
ISOファイルをRAMディスク上に転送 |
無人インストール関連ファイルをRAMディスク上に転送 |
作業時の気づき
- 変更前のスクリプトのバグでエラーが発生しその後ろの処理が行われていなかった
- exFATとNTFSは検索先ファイルシステムから外されていた
- busyboxのmountだとfuseが使えない
- RAMディスク上に転送すればISOファイルと無人インストール関連ファイルに容易にアクセスできた
- /var/log/syslogの出力処理まで進まずに停止する場合があった
- /lib/modules/カーネルバージョンが異なる場合があった
- /lib/modules/カーネルバージョン/kernel/fs/にfuseとexfatが無いとアクセス不可だった
(分かる人にはあたり前かもしれないけど)
参考
関連ファイルについては以下のリンク先を参照して下さい
https://github.com/office-itou/Linux/tree/master/installer-usbstick
インストール用USBメモリーのディレクトリー構成例
ディレクトリー構成例
\
+---sdX1 (未フォーマット)
+---sdX2 (vFAT)
| +---.disk
| | info
| +---EFI
| | +---BOOT
| | BOOTX64.CSV
| | BOOTX64.EFI
| | grub.cfg
| | grubx64.efi
| | mmx64.efi
| +---boot
| +---grub
| | grub.cfg
| | grubenv
| +---fonts
| | unicode.pf2
| +---i386-pc
| | …
| +---locale
| | …
| +---x86_64-efi
| …
+---sdX3 (exFAT)
| menu.cfg
+---casper
| +---ubuntu.focal.server
| | initrd.img
| | vmlinuz.img
| +---ubuntu.jammy.server
| | …
| +---ubuntu.kinetic.server
| | …
| +---ubuntu.lunar.desktop
| | …
| +---ubuntu.lunar.server
| …
+---images
| AlmaLinux-9-latest-x86_64-boot.iso
| CentOS-Stream-9-latest-x86_64-boot.iso
| Fedora-Server-netinst-x86_64-38-1.6.iso
| MIRACLELINUX-9.0-rtm-minimal-x86_64.iso
| Rocky-9-latest-x86_64-boot.iso
| debian-10.13.0-amd64-netinst.iso
| debian-11.7.0-amd64-netinst.iso
| debian-bookworm-DI-rc3-amd64-netinst.iso
| debian-live-bkworm-DI-rc3-amd64-lxde.iso
| debian-live-testing-amd64-lxde.iso
| debian-testing-amd64-netinst.iso
| openSUSE-Leap-15.4-NET-x86_64-Media.iso
| ubuntu-18.04.6-server-amd64.iso
| ubuntu-20.04.6-live-server-amd64.iso
| ubuntu-22.04.2-live-server-amd64.iso
| ubuntu-22.10-live-server-amd64.iso
| ubuntu-23.04-desktop-amd64.iso
| ubuntu-23.04-live-server-amd64.iso
+---install.amd
| +---debian.bookworm.live
| | initrd.img
| | vmlinuz.img
| +---debian.bookworm.netinst
| | …
| +---debian.bullseye.netinst
| | …
| +---debian.buster.netinst
| | …
| +---debian.testing.live
| | …
| +---debian.testing.netinst
| | …
| +---ubuntu.bionic.server
| …
+---kickstart
| ks_almalinux.cfg
| ks_centos.cfg
| ks_fedora.cfg
| ks_miraclelinux.cfg
| ks_rocky.cfg
+---live
| +---debian.bookworm.live
| | initrd.img
| | vmlinuz.img
| +---debian.testing.live
| …
+---nocloud
| +---ubuntu.desktop
| meta-data
| network-config
| user-data
| vendor-data
| +---ubuntu.server
| …
+---preseed
+---debian
| preseed.cfg
| preseed_old.cfg
| preseed_old_server.cfg
| preseed_server.cfg
| sub_late_command.sh
+---ubuntu
preseed.cfg
preseed_old.cfg
preseed_old_server.cfg
preseed_server.cfg
sub_late_command.sh
sub_success_command.sh
Fedora/CentOS/openSUSE系は特殊な作業は必要としませんでした
スクリプトの変更点の例
/var/lib/dpkg/info/iso-scan.postinst
master@sv-server:~/mkusb$ diff ./ram/debian.testing.live/install/initrd/var/lib/dpkg/info/iso-scan.postinst ./wrk/debian.testing.live/install/initrd/var/lib/dpkg/info/iso-scan.postinst
299c299
< FS="ext2 ext3 ext4 fat vfat xfs jfs iso9660 hfsplus hfs ntfs btrfs"
---
> FS="ext2 ext3 ext4 fat vfat xfs jfs iso9660 hfsplus hfs ntfs btrfs fuse fuse3 exfat ntfs3"
スクリプトの抜粋
モジュールの追加処理
funcCopy_module
funcCopy_module () {
fncPrintf "${TXT_BLACK}${TXT_BYELLOW}copy module${TXT_RESET}"
mountpoint -q ./mnt/ && (umount -q -f ./mnt || umount -q -lf ./mnt) || true
mountpoint -q ./usb/ && (umount -q -f ./usb || umount -q -lf ./usb) || true
rm -rf ./mnt/
rm -rf ./bld/
rm -rf ./deb/
rm -rf ./tmp
mkdir -p ./mnt
mkdir -p ./bld
mkdir -p ./deb
mkdir -p ./tmp
# *** modules ***************************************************************
U=( \
libaio1\\\(-udeb\\\)*_.* \
libblkid1\\\(-udeb\\\)*_.* \
libc-l10n\\\(-udeb\\\)*_.* \
libgcrypt20\\\(-udeb\\\)*_.* \
libgnutls30\\\(-udeb\\\)*_.* \
libmount1\\\(-udeb\\\)*_.* \
# libntfs-3g\\\(-udeb\\\)*_.* \
libpcre3\\\(-udeb\\\)*_.* \
libselinux1\\\(-udeb\\\)*_.* \
libsmartcols1\\\(-udeb\\\)*_.* \
libtinfo5\\\(-udeb\\\)*_.* \
libzstd1\\\(-udeb\\\)*_.* \
# lvm2\\\(-udeb\\\)*_.* \
mount\\\(-udeb\\\)*_.* \
# ntfs-3g\\\(-udeb\\\)*_.* \
# util-linux\\\(-udeb\\\)*_.* \
)
for P in $(find ./iso/ \( -name 'debian-*-amd64-netinst.iso' \
-o -name 'ubuntu-2*-live-server-amd64.iso' \
-o -name 'ubuntu-1*[!live]-server-amd64.iso' \
-o -name 'debian-live-*-amd64-lxde.iso' \
-o -name 'ubuntu-*-desktop-amd64.iso' \) \
\( -type f -o -type l \))
do
# --- mount ---------------------------------------------------------------
fncPrintf "${TXT_BLACK}${TXT_BGREEN}mount iso: %s${TXT_RESET}\n" "${P}"
# --- get media info ------------------------------------------------------
F="$(basename ${P})"
L="$(LANG=C blkid -s LABEL ${P} | awk -F '\"' '{print $2;}')"
V="$(echo ${F} | sed -n -e 's/^.*-\([0-9\.]*\)-.*$/\1/p')"
N="$(echo ${F,,} | sed -n -e 's/^\([A-Za-z0-9]*\)-.*$/\1/p')"
I="$(echo ${F,,} | sed -n -e 's/^.*\(live\|dvd\|netinst\|netboot\|server\|boot\|minimal\|net\|rtm\).*$/\1/p')"
C=""
S=""
T=""
A=("")
# --- get code name -------------------------------------------------------
case "${F}" in
debian-*.iso | \
ubuntu-*.iso )
mount -r -o loop ${P} ./mnt
A=("$(ls ./mnt/dists/)")
umount ./mnt
C="$(echo "${A[@],,}" | sed -n '/^\(testing\|stable\|oldstable\|oldoldstable\|unstable\)$/!p')"
S="$(echo "${A[@],,}" | sed -n '/^testing$/p')"
if [ -z "${S}" ]; then S="$(echo "${A[@],,}" | sed -n '/^stable$/p')"; fi
if [ -z "${S}" ]; then S="$(echo "${A[@],,}" | sed -n '/^oldstable$/p')"; fi
if [ -z "${S}" ]; then S="$(echo "${A[@],,}" | sed -n '/^oldoldstable$/p')"; fi
if [ -z "${I}" ]; then I="desktop"; fi
case "${F}" in
debian-*testing-*.iso ) C="testing"; V="${C}";;
debian-*-DI-*.iso ) V="${C}";;
debian-*.iso ) if [ -z "${S}" ];then S="${C}"; fi;;
ubuntu-*.iso ) S="${C}";;
* ) V="unknown";;
esac
if [ -n "$(echo ${V} | sed -n '/^[0-9]/p')" ]; then
T="${S} - $(echo ${V} | sed -n -e 's/^\([0-9]*\.[0-9]*\).*$/\1/p')"
else
T="testing"
fi
;;
* )
;;
esac
mount -r -o loop ${P} ./mnt
# --- make directory ------------------------------------------------------
D="${N}.${C}.${I:-desktop}"
fncPrintf "copy initrd: %-24.24s : %s\n" "${D}" "${P}"
mkdir -p ./bld/${D}
mkdir -p ./lnx/${D}
mkdir -p ./deb/${D}
# *** copy initrd and vmlinuz *********************************************
L=""
if [ -d ./mnt/install/. ]; then L+="./mnt/install/ "; fi
if [ -d ./mnt/install.amd/. ]; then L+="./mnt/install.amd/ "; fi
if [ -d ./mnt/live/. ]; then L+="./mnt/live/" ; fi
if [ -d ./mnt/casper/. ]; then L+="./mnt/casper/" ; fi
for F in $(find ${L} \( -name 'initrd*' -o -name 'vmlinuz*' \) \( -type f -o -type l \))
do
fncPrintf "copy initrd: %-24.24s : %s\n" "${D}" "${F}"
T="$(dirname ${F#\./mnt/})"
mkdir -p ./bld/${D}/${T}
cp -a -u ${F} ./bld/${D}/${T}/
done
# *** copy deb file *******************************************************
T=($(find ./mnt/ -maxdepth 1 -name 'pool*' -type d))
M=(${U[@]})
case "${C%\.*}" in
stretch ) M+=(fuse\\\(-udeb\\\)*_.* libfuse2\\\(-udeb\\\)*_.* ntfs-3g\\\(-udeb\\\)*_.* );;
buster ) M+=(fuse\\\(-udeb\\\)*_.* libfuse2\\\(-udeb\\\)*_.* ntfs-3g\\\(-udeb\\\)*_.* );;
bullseye ) M+=(fuse\\\(-udeb\\\)*_.* libfuse2\\\(-udeb\\\)*_.* ntfs-3g\\\(-udeb\\\)*_.* );;
bookworm ) M+=(fuse\\\(-udeb\\\)*_.* libfuse2\\\(-udeb\\\)*_.* ntfs-3g\\\(-udeb\\\)*_.* );;
testing ) M+=(fuse\\\(-udeb\\\)*_.* libfuse2\\\(-udeb\\\)*_.* ntfs-3g\\\(-udeb\\\)*_.* );;
bionic ) M+=(fuse\\\(-udeb\\\)*_.* libfuse2\\\(-udeb\\\)*_.* );;
focal ) M+=(fuse\\\(-udeb\\\)*_.* libfuse2\\\(-udeb\\\)*_.* ntfs-3g\\\(-udeb\\\)*_.* );;
jammy ) M+=(fuse\\\(-udeb\\\)*_.* libfuse2\\\(-udeb\\\)*_.* ntfs-3g\\\(-udeb\\\)*_.* );;
kinetic ) M+=(fuse3\\\(-udeb\\\)*_.* );;
lunar ) M+=(fuse3\\\(-udeb\\\)*_.* );;
* ) ;;
esac
# *** copy module *********************************************************
for F in ${M[@]}
do
B=""
for P in $(find ${T[@]} -regextype posix-basic -regex ".*/${F}" \( -type f -o -type l \) | sed -n '/\(all\|amd64\)/p' | sed -n "/\(${F%\\.*}_\|-udeb_\)/p")
do
B="$(basename ${P})"
fncPrintf "copy module: %-24.24s : %s\n" "${F}" "${B}"
if [ -n "${P}" ]; then
cp -a -u ${P} ./deb/${D}/
fi
done
if [ -z "${B}" ]; then
O=("./opt/${N}.${C}")
if [ -d "./opt/${D}/." ]; then
O+=(./opt/${D})
fi
for P in $(find ${O[@]} -regextype posix-basic -regex ".*/${F}" \( -type f -o -type l \) | sed -n '/\(all\|amd64\)/p' | sed -n "/\(${F%\\.*}_\|-udeb_\)/p")
do
B="$(basename ${P})"
fncPrintf "copy module: %-24.24s : ${TXT_GREEN}%s${TXT_RESET}\n" "${F}" "${B}"
done
fi
if [ -z "${B}" ]; then
fncPrintf "copy module: %-24.24s : %s\n" "${F}" "${B}"
fi
done
# *** linux image *********************************************************
fncPrintf "$(find ${T[@]} -regextype posix-basic -regex '.*/\(linux\|linux-signed\(-amd64\)*\)/linux-\(image\|modules\).*-[0-9]*-\(amd64\|generic\)*_.*' \
\( -type f -o -type l \) -printf 'copy limg: %f\n' -exec cp -a -u '{}' ./deb/${D}/ \;)"
# *** packages file *******************************************************
cp -a -u ./mnt/dists ./deb/${D}/
# --- unmount -------------------------------------------------------------
umount ./mnt
done
}
スクリプトの変更処理
funcRemake_module
funcRemake_module () {
fncPrintf "${TXT_BLACK}${TXT_BYELLOW}remake module${TXT_RESET}"
S=$1
fncPrintf "${TXT_BLACK}${TXT_BGREEN}remk module: ${S}${TXT_RESET}"
shift
for D in $@
do
fncPrintf "remk module: ${D}"
B="$(basename ${D})"
# fncPrintf "remk module: ${B}"
case "${B}" in
live ) I="${S}/live" ;;
casper ) I="${S}/casper" ;;
* ) I="${S}/install";;
esac
# --- unpack: inird -> ./ram/${I}/initrd ----------------------------------
for W in 'initrd*-*' 'initrd*.*' 'initrd'
do
for F in $(find ${D} -maxdepth 1 -name "${W}" \( -type f -o -type l \))
do
fncPrintf "unpack file: ${F}"
mkdir -p ./ram/${I}/initrd
unmkinitramfs ${F} ./ram/${I}/initrd
break 2
done
done
# --- copy: vmlinuz -> ./ram/${I}/vmlinuz ---------------------------------
for W in 'vmlinuz*-*' 'vmlinuz*.*' 'vmlinuz'
do
for F in $(find ${D} -maxdepth 1 -name "${W}" \( -type f -o -type l \))
do
fncPrintf "copy file: ${F}"
mkdir -p ./ram/${I}/vmlinuz
cp -a -u ${F} ./ram/${I}/vmlinuz
break 2
done
done
# --- ram -> wrk ----------------------------------------------------------
if [ -d ./ram/${I}/initrd/main/. ]; then
D="./ram/${I}/initrd/main"
else
D="./ram/${I}/initrd"
fi
fncPrintf "copy fs: ${D}"
mkdir -p ./wrk/${I}/initrd
cp -a -u ${D}/. ./wrk/${I}/initrd/
# --- linux image -> wrk --------------------------------------------------
if [ -d ./wrk/${I}/initrd/lib/modules/*/kernel/. ]; then
V=$(find ./wrk/${I}/initrd/lib/modules/*/kernel/ -name 'fs' -type d | sed -e 's~^.*/modules/\(.*\)/kernel/.*$~\1~g')
else
V="$(find ./deb/${S}/ -name 'linux-image*' \( -type f -o -type l \) | sed -n -e 's~^.*/linux-image-\(.*\)_.*_.*$~\1~p')"
if [ -z "${V}" ]; then
fncPrintf "failed to get kernel version, exiting process."
exit 1
fi
mkdir -p ./wrk/${I}/initrd/lib/modules/${V}/kernel
fi
# R=false
if [ -d ./pac/${S}/. ]; then
M=( \
kernel/crypto \
kernel/drivers/block \
kernel/drivers/md \
kernel/fs/exfat \
kernel/fs/ext4 \
kernel/fs/fat \
kernel/fs/fuse \
kernel/fs/fuse3 \
kernel/fs/jbd2 \
kernel/fs/ntfs \
kernel/fs/ntfs3 \
kernel/lib \
)
for T in ${M[@]}
do
if [ -d ./pac/${S}/lib/modules/${V}/${T}/. ]; then
fncPrintf "copy module: ${T}"
cp -a -u --backup ./pac/${S}/lib/modules/${V}/${T} ./wrk/${I}/initrd/lib/modules/${V}/$(dirname ${T})
# R=true
fi
done
fi
# if [ R = true ]; then
touch ./wrk/${I}/initrd/lib/modules/${V}/modules.builtin.modinfo
depmod -a -b ./wrk/${I}/initrd ${V}
# fi
# --- create var/lib/dpkg/status ------------------------------------------
fncPrintf "create var/lib/dpkg/status"
if [ ! -f ./wrk/${I}/initrd/var/lib/dpkg/status ]; then
mkdir -p ./wrk/${I}/initrd/var/lib/dpkg
touch ./wrk/${I}/initrd/var/lib/dpkg/status
fi
# --- Fix out-of-spec version ---------------------------------------------
fncPrintf "edit ver.: debian-installer [$(sed -n -e '/^Package: debian-installer$/,/^Package:/ {/Version:/p}' ./wrk/${I}/initrd/var/lib/dpkg/status)]"
sed -i ./wrk/${I}/initrd/var/lib/dpkg/status \
-e '/^Package: debian-installer$/,/^Package:/ s/\(Version:\)[[:blank:]]*hd-media\(-gtk\)*-\([0-9]*\).*$/\1 \3/'
fncPrintf "edit ver.: debian-installer [$(sed -n -e '/^Package: debian-installer$/,/^Package:/ {/Version:/p}' ./wrk/${I}/initrd/var/lib/dpkg/status)]"
# --- dpkg --update-avail -------------------------------------------------
fncPrintf "update package data base"
for P in $(find ./deb/${S}/dists/ -name '*Packages*' \( -type f -o -type l \))
do
mkdir -p ./tmp
cp -a -u ${P} ./tmp/
if [ -f ./tmp/Packages.gz ]; then
gzip -d ./tmp/Packages.gz
fi
LANG=C dpkg --root=./wrk/${I}/initrd --update-avail ./tmp/Packages 2>&1 | \
sed -n '/\(Replacing\|Information\)/!p'
rm -rf ./tmp
done
# --- add package ---------------------------------------------------------
fncPrintf "inst package"
U=("")
C=("")
D=""
if [ -d ./deb/${S}/. ]; then D+="./deb/${S}/ "; fi
if [ -d ./opt/${S%\.*}/. ]; then D+="./opt/${S%\.*}/ "; fi
if [ -d ./opt/${S}/. ]; then D+="./opt/${S}/ "; fi
for P in $(find ${D} \
\( -not -name 'linux-image-*_amd64.deb' -a -not -name 'linux-modules-*_amd64.deb' \
-a \( -name '*.deb' -o -name '*.udeb' \) \) \( -type f -o -type l \) | sed -n '/\(all\|amd64\)/p' | sort -u)
do
F="$(basename ${P})"
M="${F%%_*}"
W="${M}\\(-udeb\\)*"
# --- exclusion check [ *-udev_, *_ ] -----------------------------------
if [ -z "$(echo ${P} | sed -n "/\/${M}\(-udeb\)*_/p")" ]; then
continue
fi
# --- priority [ *-udev, * ] / registration check -----------------------
for A in ${C[@]}
do
B="$(basename ${A})"
if [ "${F}" = "${B}" ] ||
[ "${M}" = "${B%%_*}" ] ||
[ "${M}-udeb" = "${B%%_*}" ]; then
continue 2
fi
done
# --- skip registered modules -------------------------------------------
if [ -n "$(sed -n "/^Package: ${W}$/p" ./wrk/${I}/initrd/var/lib/dpkg/status)" ]; then
continue
fi
# --- overriding busybox symlinks ---------------------------------------
C+=("${P} ")
case "${M}" in
mount* | \
libmount1* )
if [ -f ./wrk/${I}/initrd/bin/mount ]; then
if [ "$(readlink -q ./wrk/${I}/initrd/bin/mount)" != "busybox" ]; then
continue
fi
fncPrintf "overwr pack: ${F}"
mkdir -p ./tmp
dpkg -x ${P} ./tmp
for T in $(ls ./tmp/)
do
cp -a --backup ./tmp/${T}/. ./wrk/${I}/initrd/${T}
done
rm -rf ./tmp
continue
fi
;;
* )
;;
esac
fncPrintf "inst pack: ${F}"
U+=("${P} ")
done
# --- unpack package ------------------------------------------------------
#set +e
fncPrintf "unpack package"
LANG=C dpkg --root=./wrk/${I}/initrd --unpack ${U[@]} 2>&1 | \
sed -n '/\(Selecting\|Reading\|Preparing\|warning:\|missing\)/!p' | \
sed -e 's/^Unpacking \(.*\)$/unpack pack: \1/g'
#set -e
# --- config --------------------------------------------------------------
fncPrintf "config"
if [ -f ./wrk/${I}/initrd/var/lib/dpkg/info/iso-scan.postinst ]; then
sed -i ./wrk/${I}/initrd/var/lib/dpkg/info/iso-scan.postinst \
-e 's/^\([[:blank:]]*FS\)="\(.*\)".*$/\1="\2 fuse fuse3 exfat ntfs3"/'
fi
case "${S}" in
debian.* ) ;;
ubuntu.bionic.* )
if [ -f ./wrk/${I}/initrd/var/lib/dpkg/info/iso-scan.postinst ]; then
OLD_IFS=${IFS}
INS_ROW=$(
sed -n -e '/^[[:blank:]]*use_this_iso[[:blank:]]*([[:blank:]]*)/,/^[[:blank:]]*}$/ {/[[:blank:]]*mount .* \/cdrom/=}' \
./wrk/${I}/initrd/var/lib/dpkg/info/iso-scan.postinst
)
IFS= INS_STR=$(
cat <<- '_EOT_' | sed -e 's/^ //g' | sed -z -e 's/\n/\\n/g'
#
local ram=$(grep ^MemAvailable: /proc/meminfo | { read label size unit; echo ${size:-0}; })
local iso_size=$(ls -sk /hd-media/$iso_to_try | { read size filename; echo ${size:-0}; })
#
cd /
if [ $(( $iso_size + 100000 )) -lt $ram ]; then
# We have enough RAM to be able to copy the ISO to RAM,
# let's offer it to the user
db_input low iso-scan/copy_iso_to_ram || true
db_go
db_get iso-scan/copy_iso_to_ram
RET="true"
else
log "Skipping debconf question iso-scan/copy_iso_to_ram:" \
"not enough memory available ($ram kB) to copy" \
"/hd-media/$iso_to_try ($iso_size kB) into RAM and still" \
"have 100 MB free."
RET="false"
fi
if [ "$RET" = false ]; then
# Direct mount
log "Mounting /hd-media/$iso_to_try on /cdrom"
mount -t iso9660 -o loop,ro,exec /hd-media/$iso_to_try /cdrom 2>/dev/null
else
# We copy the ISO to RAM before mounting it
log "Copying /hd-media/$iso_to_try to /installer.iso"
cp /hd-media/$iso_to_try /installer.iso
log "Mounting /installer.iso on /cdrom"
mount -t iso9660 -o loop,ro,exec /installer.iso /cdrom 2>/dev/null
# So that we can free the original device
# log "Unmounting /hd-media"
# cd /
# umount /hd-media
# mount | sort
# log "USB media freed"
fi
_EOT_
)
IFS=${OLD_IFS}
sed -i ./wrk/${I}/initrd/var/lib/dpkg/info/iso-scan.postinst \
-e '/^[[:blank:]]*use_this_iso[[:blank:]]*([[:blank:]]*/,/^}$/ s~^\([[:blank:]]*mount .* /cdrom .*$\)~#\1~' \
-e "${INS_ROW:-1}a \\${INS_STR}"
cat <<- '_EOT_' >> ./wrk/${I}/initrd/var/lib/dpkg/info/iso-scan.templates
Template: iso-scan/copy_iso_to_ram
Type: boolean
Default: false
Description: copy the ISO image to a ramdisk with enough space?
Description-ja.UTF-8: ISO イメージを十分な容量のある RAM ディスクにコピーしますか?
_EOT_
fi
;;
ubuntu.* )
if [ -d ./wrk/${I}/initrd/scripts/casper-premount/. ]; then
OLD_IFS=${IFS}
IFS= INS_STR=$(
cat <<- '_EOT_' | sed -e 's/^ //g' | sed -z -e 's/\n/\\n/g'
/scripts/casper-bottom/99cloud_init "$@"
[ -e /conf/param.conf ] && . /conf/param.conf
_EOT_
)
IFS=${OLD_IFS}
sed -i ./wrk/${I}/initrd/scripts/casper-bottom/ORDER -e "$ a \\${INS_STR}"
sed -i ./wrk/${I}/initrd/scripts/casper-bottom/ORDER -e '/^$/d'
cat <<- '_EOT_' >> ./wrk/${I}/initrd/scripts/casper-bottom/99cloud_init
#!/bin/sh
PREREQ=""
prereqs()
{
echo "${PREREQ}"
}
case $1 in
# get pre-requisites
prereqs)
prereqs
exit 0
;;
esac
. /scripts/casper-functions
. /scripts/casper-helpers
if [ -f /scripts/lupin-helpers ]; then
. /scripts/lupin-helpers
fi
nocloud_path=
for x in $(cat /proc/cmdline); do
case ${x} in
ds=nocloud\;* | \
ds=nocloud-net\;* )
case ${x} in
*s=file:* | \
*seedfrom=file:* )
nocloud_path=${x#*=file:///}
break
;;
esac
;;
esac
done
if [ "${nocloud_path}" ]; then
if find_path "/${nocloud_path}" /isodevice rw; then
echo "mkdir -p /root/${nocloud_path}"
mkdir -p /root/${nocloud_path}
echo "cp -dR ${FOUNDPATH}/. /root/${nocloud_path}"
cp -dR ${FOUNDPATH}/. /root/${nocloud_path}
else
panic "
Could not find the nocloud /${nocloud_path}
"
fi
fi
_EOT_
chmod +x ./wrk/${I}/initrd/scripts/casper-bottom/99cloud_init
fi
if [ -f ./wrk/${I}/initrd/scripts/casper-helpers ]; then
OLD_IFS=${IFS}
INS_ROW=$(
sed -n -e '/^[[:blank:]]*find_files[[:blank:]]*([[:blank:]]*)/,/^[[:blank:]]*}$/ {/[[:blank:]]*vfat|ext2)/,/.*;;$/=}' \
./wrk/${I}/initrd/scripts/casper-helpers \
| awk 'END {print}'
)
IFS= INS_STR=$(
cat <<- '_EOT_' | sed -e 's/^ //g' | sed -z -e 's/\n/\\n/g'
exfat|ntfs)
:;;
_EOT_
)
IFS=${OLD_IFS}
sed -i ./wrk/${I}/initrd/scripts/casper-helpers \
-e '/[[:blank:]]*is_supported_fs[[:blank:]]*([[:blank:]]*)/,/[[:blank:]]*}$/ s/\(vfat.*\))/\1|exfat)/' \
-e '/[[:blank:]]*wait_for_devs[[:blank:]]*([[:blank:]]*)/,/[[:blank:]]*}$/ {/touch/i \\ mkdir -p /dev/.initramfs' -e '}' \
-e "${INS_ROW:-1}a \\${INS_STR}"
fi
if [ -f ./wrk/${I}/initrd/scripts/lupin-helpers ]; then
sed -i ./wrk/${I}/initrd/scripts/lupin-helpers \
-e '/[[:blank:]]*is_supported_fs[[:blank:]]*([[:blank:]]*)/,/[[:blank:]]*}$/ s/\(vfat.*\))/\1|exfat)/' \
-e '/[[:blank:]]*wait_for_devs[[:blank:]]*([[:blank:]]*)/,/[[:blank:]]*}$/ {/touch/i \\ mkdir -p /dev/.initramfs' -e '}'
fi
;;
* ) ;;
esac
done
}