debi.sh 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  1. #!/bin/sh
  2. # shellcheck shell=dash
  3. set -eu
  4. err() {
  5. echo "Error: $1." 1>&2
  6. exit 1
  7. }
  8. command_exists() {
  9. command -v "$1" > /dev/null 2>&1
  10. }
  11. # Sets variable:
  12. late_command=
  13. in_target() {
  14. local command=
  15. for argument in "$@"; do
  16. command="$command $argument"
  17. done
  18. if [ -n "$command" ]; then
  19. [ -z "$late_command" ] && late_command='true'
  20. late_command="$late_command;$command"
  21. fi
  22. }
  23. in_target_backup() {
  24. in_target "if [ ! -e \"$1.backup\" ]; then cp \"$1\" \"$1.backup\"; fi"
  25. }
  26. configure_sshd() {
  27. # !isset($sshd_config_backup)
  28. [ -z ${sshd_config_backup+1s} ] && in_target_backup /etc/ssh/sshd_config
  29. sshd_config_backup=
  30. in_target sed -Ei \""s/^#?$1 .+/$1 $2/"\" /etc/ssh/sshd_config
  31. }
  32. prompt_password() {
  33. local prompt=
  34. if [ $# -gt 0 ]; then
  35. prompt=$1
  36. elif [ "$username" = root ]; then
  37. prompt="Choose a password for the root user: "
  38. else
  39. prompt="Choose a password for user $username: "
  40. fi
  41. stty -echo
  42. trap 'stty echo' EXIT
  43. while [ -z "$password" ]; do
  44. echo -n "$prompt" > /dev/tty
  45. read -r password < /dev/tty
  46. echo > /dev/tty
  47. done
  48. stty echo
  49. trap - EXIT
  50. }
  51. download() {
  52. if command_exists wget; then
  53. wget -O "$2" "$1"
  54. elif command_exists curl; then
  55. curl -fL "$1" -o "$2"
  56. elif command_exists busybox && busybox wget --help > /dev/null 2>&1; then
  57. busybox wget -O "$2" "$1"
  58. else
  59. err 'Cannot find "wget", "curl" or "busybox wget" to download files'
  60. fi
  61. }
  62. set_security_archive() {
  63. case $suite in
  64. stretch|oldstable|buster|stable)
  65. security_archive="$suite/updates"
  66. ;;
  67. bullseye|testing)
  68. security_archive="$suite-security"
  69. ;;
  70. sid|unstable)
  71. security_archive=''
  72. ;;
  73. *)
  74. err "Unsupported suite: $suite"
  75. esac
  76. }
  77. set_daily_d_i() {
  78. case $suite in
  79. stretch|oldstable|buster|stable)
  80. daily_d_i=false
  81. ;;
  82. bullseye|testing|sid|unstable)
  83. daily_d_i=true
  84. ;;
  85. *)
  86. err "Unsupported suite: $suite"
  87. esac
  88. }
  89. set_suite() {
  90. suite=$1
  91. set_daily_d_i
  92. set_security_archive
  93. }
  94. set_debian_version() {
  95. case $1 in
  96. 9|stretch|oldstable)
  97. set_suite stretch
  98. ;;
  99. 10|buster|stable)
  100. set_suite buster
  101. ;;
  102. 11|bullseye|testing)
  103. set_suite bullseye
  104. ;;
  105. sid|unstable)
  106. set_suite sid
  107. ;;
  108. *)
  109. err "Unsupported version: $1"
  110. esac
  111. }
  112. has_cloud_kernel() {
  113. case $suite in
  114. stretch|oldstable)
  115. [ "$architecture" = amd64 ] && [ "$bpo_kernel" = true ] && return
  116. ;;
  117. buster|stable)
  118. [ "$architecture" = amd64 ] && return
  119. [ "$architecture" = arm64 ] && [ "$bpo_kernel" = true ] && return
  120. ;;
  121. bullseye|testing|sid|unstable)
  122. [ "$architecture" = amd64 ] || [ "$architecture" = arm64 ] && return
  123. esac
  124. local tmp; tmp=''; [ "$bpo_kernel" = true ] && tmp='-backports'
  125. echo "Warning: No cloud kernel is available for $architecture/$suite$tmp." 1>&2
  126. return 1
  127. }
  128. has_backports() {
  129. case $suite in
  130. stretch|oldstable|buster|stable|bullseye|testing) return
  131. esac
  132. echo "Warning: No backports kernel is available for $suite." 1>&2
  133. return 1
  134. }
  135. ip=
  136. netmask=
  137. gateway=
  138. dns='8.8.8.8 8.8.4.4'
  139. hostname=
  140. network_console=false
  141. set_debian_version 10
  142. mirror_protocol=http
  143. mirror_host=deb.debian.org
  144. mirror_directory=/debian
  145. security_repository=http://security.debian.org/debian-security
  146. account_setup=true
  147. username=debian
  148. password=
  149. authorized_keys_url=
  150. sudo_with_password=false
  151. timezone=UTC
  152. ntp=0.debian.pool.ntp.org
  153. disk_partitioning=true
  154. disk=
  155. force_gpt=true
  156. efi=
  157. filesystem=ext4
  158. kernel=
  159. cloud_kernel=false
  160. bpo_kernel=false
  161. install_recommends=true
  162. install='ca-certificates libpam-systemd'
  163. upgrade=
  164. kernel_params=
  165. bbr=false
  166. hold=false
  167. power_off=false
  168. architecture=
  169. boot_directory=
  170. firmware=false
  171. force_efi_extra_removable=true
  172. grub_timeout=5
  173. dry_run=false
  174. while [ $# -gt 0 ]; do
  175. case $1 in
  176. --cdn|--aws)
  177. mirror_protocol=https
  178. [ "$1" = '--aws' ] && mirror_host=cdn-aws.deb.debian.org
  179. security_repository=mirror
  180. ;;
  181. --china)
  182. dns='223.5.5.5 223.6.6.6'
  183. mirror_protocol=https
  184. mirror_host=mirrors.aliyun.com
  185. ntp=ntp.aliyun.com
  186. security_repository=mirror
  187. ;;
  188. --ip)
  189. ip=$2
  190. shift
  191. ;;
  192. --netmask)
  193. netmask=$2
  194. shift
  195. ;;
  196. --gateway)
  197. gateway=$2
  198. shift
  199. ;;
  200. --dns)
  201. dns=$2
  202. shift
  203. ;;
  204. --hostname)
  205. hostname=$2
  206. shift
  207. ;;
  208. --network-console)
  209. network_console=true
  210. ;;
  211. --version)
  212. set_debian_version "$2"
  213. shift
  214. ;;
  215. --suite)
  216. set_suite "$2"
  217. shift
  218. ;;
  219. --release-d-i)
  220. daily_d_i=false
  221. ;;
  222. --daily-d-i)
  223. daily_d_i=true
  224. ;;
  225. --mirror-protocol)
  226. mirror_protocol=$2
  227. shift
  228. ;;
  229. --https)
  230. mirror_protocol=https
  231. ;;
  232. --mirror-host)
  233. mirror_host=$2
  234. shift
  235. ;;
  236. --mirror-directory)
  237. mirror_directory=${2%/}
  238. shift
  239. ;;
  240. --security-repository)
  241. security_repository=$2
  242. shift
  243. ;;
  244. --no-user|--no-account-setup)
  245. account_setup=false
  246. ;;
  247. --user|--username)
  248. username=$2
  249. shift
  250. ;;
  251. --password)
  252. password=$2
  253. shift
  254. ;;
  255. --authorized-keys-url)
  256. authorized_keys_url=$2
  257. shift
  258. ;;
  259. --sudo-with-password)
  260. sudo_with_password=true
  261. ;;
  262. --timezone)
  263. timezone=$2
  264. shift
  265. ;;
  266. --ntp)
  267. ntp=$2
  268. shift
  269. ;;
  270. --no-part|--no-disk-partitioning)
  271. disk_partitioning=false
  272. ;;
  273. --disk)
  274. disk=$2
  275. shift
  276. ;;
  277. --no-force-gpt)
  278. force_gpt=false
  279. ;;
  280. --bios)
  281. efi=false
  282. ;;
  283. --efi)
  284. efi=true
  285. ;;
  286. --filesystem)
  287. filesystem=$2
  288. shift
  289. ;;
  290. --kernel)
  291. kernel=$2
  292. shift
  293. ;;
  294. --cloud-kernel)
  295. cloud_kernel=true
  296. ;;
  297. --bpo-kernel)
  298. bpo_kernel=true
  299. ;;
  300. --no-install-recommends)
  301. install_recommends=false
  302. ;;
  303. --install)
  304. install=$2
  305. shift
  306. ;;
  307. --no-upgrade)
  308. upgrade=none
  309. ;;
  310. --safe-upgrade)
  311. upgrade=safe-upgrade
  312. ;;
  313. --full-upgrade)
  314. upgrade=full-upgrade
  315. ;;
  316. --ethx)
  317. kernel_params="$kernel_params net.ifnames=0 biosdevname=0"
  318. ;;
  319. --bbr)
  320. bbr=true
  321. ;;
  322. --hold)
  323. hold=true
  324. ;;
  325. --power-off)
  326. power_off=true
  327. ;;
  328. --architecture)
  329. architecture=$2
  330. shift
  331. ;;
  332. --boot-directory)
  333. boot_directory=$2
  334. shift
  335. ;;
  336. --firmware)
  337. firmware=true
  338. ;;
  339. --no-force-efi-extra-removable)
  340. force_efi_extra_removable=false
  341. ;;
  342. --grub-timeout)
  343. grub_timeout=$2
  344. shift
  345. ;;
  346. --dry-run)
  347. dry_run=true
  348. ;;
  349. *)
  350. err "Unknown option: \"$1\""
  351. esac
  352. shift
  353. done
  354. [ -z "$architecture" ] && {
  355. architecture=$(dpkg --print-architecture 2> /dev/null) || {
  356. case $(uname -m) in
  357. x86_64)
  358. architecture=amd64
  359. ;;
  360. aarch64)
  361. architecture=arm64
  362. ;;
  363. i386)
  364. architecture=i386
  365. ;;
  366. *)
  367. err 'No "--architecture" specified'
  368. esac
  369. }
  370. }
  371. [ -z "$kernel" ] && {
  372. kernel="linux-image-$architecture"
  373. [ "$cloud_kernel" = true ] && has_cloud_kernel && kernel="linux-image-cloud-$architecture"
  374. [ "$bpo_kernel" = true ] && has_backports && install="$kernel/$suite-backports $install"
  375. }
  376. [ -n "$authorized_keys_url" ] && ! download "$authorized_keys_url" /dev/null &&
  377. err "Failed to download SSH authorized public keys from \"$authorized_keys_url\""
  378. installer="debian-$suite"
  379. installer_directory="/boot/$installer"
  380. save_preseed='cat'
  381. [ "$dry_run" = false ] && {
  382. [ "$(id -u)" -ne 0 ] && err 'root privilege is required'
  383. rm -rf "$installer_directory"
  384. mkdir -p "$installer_directory"
  385. cd "$installer_directory"
  386. save_preseed='tee -a preseed.cfg'
  387. }
  388. if [ "$account_setup" = true ]; then
  389. prompt_password
  390. elif [ "$network_console" = true ] && [ -z "$authorized_keys_url" ]; then
  391. prompt_password "Choose a password for the installer user of the SSH network console: "
  392. fi
  393. $save_preseed << 'EOF'
  394. # Localization
  395. d-i debian-installer/language string en
  396. d-i debian-installer/country string US
  397. d-i debian-installer/locale string en_US.UTF-8
  398. d-i keyboard-configuration/xkb-keymap select us
  399. # Network configuration
  400. d-i netcfg/choose_interface select auto
  401. EOF
  402. [ -n "$ip" ] && {
  403. echo 'd-i netcfg/disable_autoconfig boolean true' | $save_preseed
  404. echo "d-i netcfg/get_ipaddress string $ip" | $save_preseed
  405. [ -n "$netmask" ] && echo "d-i netcfg/get_netmask string $netmask" | $save_preseed
  406. [ -n "$gateway" ] && echo "d-i netcfg/get_gateway string $gateway" | $save_preseed
  407. [ -z "${ip%%*:*}" ] && [ -n "${dns%%*:*}" ] && dns='2001:4860:4860::8888 2001:4860:4860::8844'
  408. [ -n "$dns" ] && echo "d-i netcfg/get_nameservers string $dns" | $save_preseed
  409. echo 'd-i netcfg/confirm_static boolean true' | $save_preseed
  410. }
  411. if [ -n "$hostname" ]; then
  412. echo "d-i netcfg/hostname string $hostname" | $save_preseed
  413. hostname=debian
  414. domain=
  415. else
  416. hostname=$(cat /proc/sys/kernel/hostname)
  417. domain=$(cat /proc/sys/kernel/domainname)
  418. if [ "$domain" = '(none)' ]; then
  419. domain=
  420. else
  421. domain=" $domain"
  422. fi
  423. fi
  424. $save_preseed << EOF
  425. d-i netcfg/get_hostname string $hostname
  426. d-i netcfg/get_domain string$domain
  427. EOF
  428. echo 'd-i hw-detect/load_firmware boolean true' | $save_preseed
  429. [ "$network_console" = true ] && {
  430. $save_preseed << 'EOF'
  431. # Network console
  432. d-i anna/choose_modules string network-console
  433. d-i preseed/early_command string anna-install network-console
  434. EOF
  435. if [ -n "$authorized_keys_url" ]; then
  436. echo "d-i network-console/authorized_keys_url string $authorized_keys_url" | $save_preseed
  437. else
  438. $save_preseed << EOF
  439. d-i network-console/password password $password
  440. d-i network-console/password-again password $password
  441. EOF
  442. fi
  443. echo 'd-i network-console/start select Continue' | $save_preseed
  444. }
  445. $save_preseed << EOF
  446. # Mirror settings
  447. d-i mirror/country string manual
  448. d-i mirror/protocol string $mirror_protocol
  449. d-i mirror/$mirror_protocol/hostname string $mirror_host
  450. d-i mirror/$mirror_protocol/directory string $mirror_directory
  451. d-i mirror/$mirror_protocol/proxy string
  452. d-i mirror/suite string $suite
  453. EOF
  454. [ "$account_setup" = true ] && {
  455. password_hash=$(mkpasswd -m sha-256 "$password" 2> /dev/null) ||
  456. password_hash=$(openssl passwd -5 "$password" 2> /dev/null) ||
  457. password_hash=$(busybox mkpasswd -m sha256 "$password" 2> /dev/null) || {
  458. for python in python3 python python2; do
  459. password_hash=$("$python" -c 'import crypt, sys; print(crypt.crypt(sys.argv[1], crypt.mksalt(crypt.METHOD_SHA256)))' "$password" 2> /dev/null) && break
  460. done
  461. }
  462. $save_preseed << 'EOF'
  463. # Account setup
  464. EOF
  465. [ -n "$authorized_keys_url" ] && configure_sshd PasswordAuthentication no
  466. if [ "$username" = root ]; then
  467. if [ -z "$authorized_keys_url" ]; then
  468. configure_sshd PermitRootLogin yes
  469. else
  470. in_target "mkdir -m 0700 -p ~root/.ssh && busybox wget -O- \"$authorized_keys_url\" >> ~root/.ssh/authorized_keys"
  471. fi
  472. $save_preseed << 'EOF'
  473. d-i passwd/root-login boolean true
  474. d-i passwd/make-user boolean false
  475. EOF
  476. if [ -z "$password_hash" ]; then
  477. $save_preseed << EOF
  478. d-i passwd/root-password password $password
  479. d-i passwd/root-password-again password $password
  480. EOF
  481. else
  482. echo "d-i passwd/root-password-crypted password $password_hash" | $save_preseed
  483. fi
  484. else
  485. configure_sshd PermitRootLogin no
  486. [ -n "$authorized_keys_url" ] &&
  487. in_target "sudo -u $username mkdir -m 0700 -p ~$username/.ssh && busybox wget -O - \"$authorized_keys_url\" | sudo -u $username tee -a ~$username/.ssh/authorized_keys"
  488. [ "$sudo_with_password" = false ] &&
  489. in_target "echo \"$username ALL=(ALL:ALL) NOPASSWD:ALL\" > \"/etc/sudoers.d/90-user-$username\""
  490. $save_preseed << EOF
  491. d-i passwd/root-login boolean false
  492. d-i passwd/make-user boolean true
  493. d-i passwd/user-fullname string
  494. d-i passwd/username string $username
  495. EOF
  496. if [ -z "$password_hash" ]; then
  497. $save_preseed << EOF
  498. d-i passwd/user-password password $password
  499. d-i passwd/user-password-again password $password
  500. EOF
  501. else
  502. echo "d-i passwd/user-password-crypted password $password_hash" | $save_preseed
  503. fi
  504. fi
  505. }
  506. $save_preseed << EOF
  507. # Clock and time zone setup
  508. d-i time/zone string $timezone
  509. d-i clock-setup/utc boolean true
  510. d-i clock-setup/ntp boolean true
  511. d-i clock-setup/ntp-server string $ntp
  512. EOF
  513. [ "$disk_partitioning" = true ] && {
  514. $save_preseed << 'EOF'
  515. # Partitioning
  516. d-i partman-auto/method string regular
  517. EOF
  518. if [ -n "$disk" ]; then
  519. echo "d-i partman-auto/disk string $disk" | $save_preseed
  520. else
  521. # shellcheck disable=SC2016
  522. echo 'd-i partman/early_command string debconf-set partman-auto/disk "$(list-devices disk | head -n 1)"' | $save_preseed
  523. fi
  524. [ "$force_gpt" = true ] && echo 'd-i partman-partitioning/default_label string gpt' | $save_preseed
  525. echo "d-i partman/default_filesystem string $filesystem" | $save_preseed
  526. [ -z "$efi" ] && {
  527. efi=false
  528. [ -d /sys/firmware/efi ] && efi=true
  529. }
  530. $save_preseed << 'EOF'
  531. d-i partman-auto/expert_recipe string \
  532. naive :: \
  533. EOF
  534. if [ "$efi" = true ]; then
  535. $save_preseed << 'EOF'
  536. 106 106 106 free \
  537. $iflabel{ gpt } \
  538. $reusemethod{ } \
  539. method{ efi } \
  540. format{ } \
  541. . \
  542. EOF
  543. else
  544. $save_preseed << 'EOF'
  545. 1 1 1 free \
  546. $iflabel{ gpt } \
  547. $reusemethod{ } \
  548. method{ biosgrub } \
  549. . \
  550. EOF
  551. fi
  552. $save_preseed << 'EOF'
  553. 1075 1076 -1 $default_filesystem \
  554. method{ format } \
  555. format{ } \
  556. use_filesystem{ } \
  557. $default_filesystem{ } \
  558. mountpoint{ / } \
  559. .
  560. EOF
  561. echo 'd-i partman-auto/choose_recipe select naive' | $save_preseed
  562. $save_preseed << 'EOF'
  563. d-i partman-basicfilesystems/no_swap boolean false
  564. d-i partman/choose_partition select finish
  565. d-i partman/confirm boolean true
  566. d-i partman/confirm_nooverwrite boolean true
  567. EOF
  568. }
  569. $save_preseed << EOF
  570. # Base system installation
  571. d-i base-installer/kernel/image string $kernel
  572. EOF
  573. [ "$install_recommends" = false ] && echo "d-i base-installer/install-recommends boolean $install_recommends" | $save_preseed
  574. [ "$security_repository" = mirror ] && security_repository=$mirror_protocol://$mirror_host${mirror_directory%/*}/debian-security
  575. # If not sid/unstable
  576. [ -n "$security_archive" ] && {
  577. $save_preseed << EOF
  578. # Apt setup
  579. d-i apt-setup/services-select multiselect updates, backports
  580. d-i apt-setup/local0/repository string $security_repository $security_archive main
  581. d-i apt-setup/local0/source boolean true
  582. EOF
  583. }
  584. $save_preseed << 'EOF'
  585. # Package selection
  586. tasksel tasksel/first multiselect ssh-server
  587. EOF
  588. [ -n "$install" ] && echo "d-i pkgsel/include string $install" | $save_preseed
  589. [ -n "$upgrade" ] && echo "d-i pkgsel/upgrade select $upgrade" | $save_preseed
  590. $save_preseed << 'EOF'
  591. popularity-contest popularity-contest/participate boolean false
  592. # Boot loader installation
  593. d-i grub-installer/bootdev string default
  594. EOF
  595. [ "$force_efi_extra_removable" = true ] && echo 'd-i grub-installer/force-efi-extra-removable boolean true' | $save_preseed
  596. [ -n "$kernel_params" ] && echo "d-i debian-installer/add-kernel-opts string$kernel_params" | $save_preseed
  597. $save_preseed << 'EOF'
  598. # Finishing up the installation
  599. EOF
  600. [ "$hold" = false ] && echo 'd-i finish-install/reboot_in_progress note' | $save_preseed
  601. [ "$bbr" = true ] && in_target '{ echo "net.core.default_qdisc=fq"; echo "net.ipv4.tcp_congestion_control=bbr"; } > /etc/sysctl.d/bbr.conf'
  602. [ -n "$late_command" ] && echo "d-i preseed/late_command string in-target sh -c '$late_command'" | $save_preseed
  603. [ "$power_off" = true ] && echo 'd-i debian-installer/exit/poweroff boolean true' | $save_preseed
  604. save_grub_cfg='cat'
  605. [ "$dry_run" = false ] && {
  606. base_url="$mirror_protocol://$mirror_host$mirror_directory/dists/$suite/main/installer-$architecture/current/images/netboot/debian-installer/$architecture"
  607. [ "$daily_d_i" = true ] && base_url="https://d-i.debian.org/daily-images/$architecture/daily/netboot/debian-installer/$architecture"
  608. firmware_url="https://cdimage.debian.org/cdimage/unofficial/non-free/firmware/$suite/current/firmware.cpio.gz"
  609. download "$base_url/linux" linux
  610. download "$base_url/initrd.gz" initrd.gz
  611. [ "$firmware" = true ] && download "$firmware_url" firmware.cpio.gz
  612. gzip -d initrd.gz
  613. # cpio reads a list of file names from the standard input
  614. echo preseed.cfg | cpio -o -H newc -A -F initrd
  615. gzip -9 initrd
  616. mkdir -p /etc/default/grub.d
  617. tee /etc/default/grub.d/zz-debi.cfg 1>&2 << EOF
  618. GRUB_DEFAULT=debi
  619. GRUB_TIMEOUT=$grub_timeout
  620. GRUB_TIMEOUT_STYLE=menu
  621. EOF
  622. if command_exists update-grub; then
  623. grub_cfg=/boot/grub/grub.cfg
  624. update-grub
  625. elif command_exists grub2-mkconfig; then
  626. tmp=$(mktemp)
  627. grep -vF zz_debi /etc/default/grub > "$tmp"
  628. cat "$tmp" > /etc/default/grub
  629. rm "$tmp"
  630. # shellcheck disable=SC2016
  631. echo 'zz_debi=/etc/default/grub.d/zz-debi.cfg; if [ -f "$zz_debi" ]; then . "$zz_debi"; fi' >> /etc/default/grub
  632. grub_cfg=/boot/grub2/grub.cfg
  633. grub2-mkconfig -o "$grub_cfg"
  634. else
  635. err 'Could not find "update-grub" or "grub2-mkconfig" command'
  636. fi
  637. save_grub_cfg="tee -a $grub_cfg"
  638. }
  639. [ -z "$boot_directory" ] && {
  640. if grep -q '\s/boot\s' /proc/mounts; then
  641. boot_directory=/
  642. else
  643. boot_directory=/boot/
  644. fi
  645. }
  646. installer_directory="$boot_directory$installer"
  647. # shellcheck disable=SC2034
  648. mem=$(grep ^MemTotal: /proc/meminfo | { read -r x y z; echo "$y"; })
  649. [ $((mem / 1024)) -le 512 ] && kernel_params="$kernel_params lowmem/low=1"
  650. initrd="$installer_directory/initrd.gz"
  651. [ "$firmware" = true ] && initrd="$initrd $installer_directory/firmware.cpio.gz"
  652. $save_grub_cfg 1>&2 << EOF
  653. menuentry 'Debian Installer' --id debi {
  654. insmod part_msdos
  655. insmod part_gpt
  656. insmod ext2
  657. linux $installer_directory/linux$kernel_params
  658. initrd $initrd
  659. }
  660. EOF