partition.scm 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2018 Mathieu Othacehe <m.othacehe@gmail.com>
  3. ;;;
  4. ;;; This file is part of GNU Guix.
  5. ;;;
  6. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 3 of the License, or (at
  9. ;;; your option) any later version.
  10. ;;;
  11. ;;; GNU Guix is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;;; GNU General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  18. (define-module (gnu installer newt partition)
  19. #:use-module (gnu installer parted)
  20. #:use-module (gnu installer steps)
  21. #:use-module (gnu installer utils)
  22. #:use-module (gnu installer newt page)
  23. #:use-module (gnu installer newt utils)
  24. #:use-module (guix i18n)
  25. #:use-module (ice-9 match)
  26. #:use-module (srfi srfi-1)
  27. #:use-module (srfi srfi-26)
  28. #:use-module (srfi srfi-34)
  29. #:use-module (srfi srfi-35)
  30. #:use-module (newt)
  31. #:use-module (parted)
  32. #:export (run-partioning-page))
  33. (define (button-exit-action)
  34. "Raise the &installer-step-abort condition."
  35. (raise
  36. (condition
  37. (&installer-step-abort))))
  38. (define (run-scheme-page)
  39. "Run a page asking the user for a partitioning scheme."
  40. (let* ((items
  41. '((root . "Everything is one partition")
  42. (root-home . "Separate /home partition")))
  43. (result (run-listbox-selection-page
  44. #:info-text (G_ "Please select a partitioning scheme.")
  45. #:title (G_ "Partition scheme")
  46. #:listbox-items items
  47. #:listbox-item->text cdr
  48. #:button-text (G_ "Exit")
  49. #:button-callback-procedure button-exit-action)))
  50. (car result)))
  51. (define (draw-formatting-page)
  52. "Draw a page to indicate partitions are being formated."
  53. (draw-info-page
  54. (format #f (G_ "Partition formatting is in progress, please wait."))
  55. (G_ "Preparing partitions")))
  56. (define (run-device-page devices)
  57. "Run a page asking the user to select a device among those in the given
  58. DEVICES list."
  59. (define (device-items)
  60. (map (lambda (device)
  61. `(,device . ,(device-description device)))
  62. devices))
  63. (let* ((result (run-listbox-selection-page
  64. #:info-text (G_ "Please select a disk.")
  65. #:title (G_ "Disk")
  66. #:listbox-items (device-items)
  67. #:listbox-item->text cdr
  68. #:button-text (G_ "Exit")
  69. #:button-callback-procedure button-exit-action))
  70. (device (car result)))
  71. device))
  72. (define (run-label-page button-text button-callback)
  73. "Run a page asking the user to select a partition table label."
  74. (run-listbox-selection-page
  75. #:info-text (G_ "Select a new partition table type. \
  76. Be careful, all data on the disk will be lost.")
  77. #:title (G_ "Partition table")
  78. #:listbox-items '("msdos" "gpt")
  79. #:listbox-item->text identity
  80. #:button-text button-text
  81. #:button-callback-procedure button-callback))
  82. (define (run-type-page partition)
  83. "Run a page asking the user to select a partition type."
  84. (let* ((disk (partition-disk partition))
  85. (partitions (disk-partitions disk))
  86. (other-extended-partitions?
  87. (any extended-partition? partitions))
  88. (items
  89. `(normal ,@(if other-extended-partitions?
  90. '()
  91. '(extended)))))
  92. (run-listbox-selection-page
  93. #:info-text (G_ "Please select a partition type.")
  94. #:title (G_ "Partition type")
  95. #:listbox-items items
  96. #:listbox-item->text symbol->string
  97. #:sort-listbox-items? #f
  98. #:button-text (G_ "Exit")
  99. #:button-callback-procedure button-exit-action)))
  100. (define (run-fs-type-page)
  101. "Run a page asking the user to select a file-system type."
  102. (run-listbox-selection-page
  103. #:info-text (G_ "Please select the file-system type for this partition.")
  104. #:title (G_ "File-system type")
  105. #:listbox-items '(ext4 btrfs fat32 swap)
  106. #:listbox-item->text user-fs-type-name
  107. #:sort-listbox-items? #f
  108. #:button-text (G_ "Exit")
  109. #:button-callback-procedure button-exit-action))
  110. (define (inform-can-create-partition? user-partition)
  111. "Return #t if it is possible to create USER-PARTITION. This is determined by
  112. calling CAN-CREATE-PARTITION? procedure. If an exception is raised, catch it
  113. an inform the user with an appropriate error-page and return #f."
  114. (guard (c ((max-primary-exceeded? c)
  115. (run-error-page
  116. (G_ "Primary partitions count exceeded.")
  117. (G_ "Creation error"))
  118. #f)
  119. ((extended-creation-error? c)
  120. (run-error-page
  121. (G_ "Extended partition creation error.")
  122. (G_ "Creation error"))
  123. #f)
  124. ((logical-creation-error? c)
  125. (run-error-page
  126. (G_ "Logical partition creation error.")
  127. (G_ "Creation error"))
  128. #f))
  129. (can-create-partition? user-partition)))
  130. (define (prompt-luks-passwords user-partitions)
  131. "Prompt for the luks passwords of the encrypted partitions in
  132. USER-PARTITIONS list. Return this list with password fields filled-in."
  133. (map (lambda (user-part)
  134. (let* ((crypt-label (user-partition-crypt-label user-part))
  135. (file-name (user-partition-file-name user-part))
  136. (password-page
  137. (lambda ()
  138. (run-input-page
  139. (format #f (G_ "Please enter the password for the \
  140. encryption of partition ~a (label: ~a).") file-name crypt-label)
  141. (G_ "Password required"))))
  142. (password-confirm-page
  143. (lambda ()
  144. (run-input-page
  145. (format #f (G_ "Please confirm the password for the \
  146. encryption of partition ~a (label: ~a).") file-name crypt-label)
  147. (G_ "Password confirmation required")))))
  148. (if crypt-label
  149. (let loop ()
  150. (let ((password (password-page))
  151. (confirmation (password-confirm-page)))
  152. (if (string=? password confirmation)
  153. (user-partition
  154. (inherit user-part)
  155. (crypt-password password))
  156. (begin
  157. (run-error-page
  158. (G_ "Password mismatch, please try again.")
  159. (G_ "Password error"))
  160. (loop)))))
  161. user-part)))
  162. user-partitions))
  163. (define* (run-partition-page target-user-partition
  164. #:key
  165. (default-item #f))
  166. "Run a page allowing the user to edit the given TARGET-USER-PARTITION
  167. record. If the argument DEFAULT-ITEM is passed, use it to select the current
  168. listbox item. This is used to avoid the focus to switch back to the first
  169. listbox entry while calling this procedure recursively."
  170. (define (numeric-size device size)
  171. "Parse the given SIZE on DEVICE and return it."
  172. (call-with-values
  173. (lambda ()
  174. (unit-parse size device))
  175. (lambda (value range)
  176. value)))
  177. (define (numeric-size-range device size)
  178. "Parse the given SIZE on DEVICE and return the associated RANGE."
  179. (call-with-values
  180. (lambda ()
  181. (unit-parse size device))
  182. (lambda (value range)
  183. range)))
  184. (define* (fill-user-partition-geom user-part
  185. #:key
  186. device (size #f) start end)
  187. "Return the given USER-PART with the START, END and SIZE fields set to the
  188. eponym arguments. Use UNIT-FORMAT-CUSTOM to format START and END arguments as
  189. sectors on DEVICE."
  190. (user-partition
  191. (inherit user-part)
  192. (size size)
  193. (start (unit-format-custom device start UNIT-SECTOR))
  194. (end (unit-format-custom device end UNIT-SECTOR))))
  195. (define (apply-user-partition-changes user-part)
  196. "Set the name, file-system type and boot flag on the partition specified
  197. by USER-PART, if it is applicable for the partition type."
  198. (let* ((partition (user-partition-parted-object user-part))
  199. (disk (partition-disk partition))
  200. (disk-type (disk-disk-type disk))
  201. (device (disk-device disk))
  202. (has-name? (disk-type-check-feature
  203. disk-type
  204. DISK-TYPE-FEATURE-PARTITION-NAME))
  205. (name (user-partition-name user-part))
  206. (fs-type (filesystem-type-get
  207. (user-fs-type-name
  208. (user-partition-fs-type user-part))))
  209. (bootable? (user-partition-bootable? user-part))
  210. (esp? (user-partition-esp? user-part))
  211. (flag-bootable?
  212. (partition-is-flag-available? partition PARTITION-FLAG-BOOT))
  213. (flag-esp?
  214. (partition-is-flag-available? partition PARTITION-FLAG-ESP)))
  215. (when (and has-name? name)
  216. (partition-set-name partition name))
  217. (partition-set-system partition fs-type)
  218. (when flag-bootable?
  219. (partition-set-flag partition
  220. PARTITION-FLAG-BOOT
  221. (if bootable? 1 0)))
  222. (when flag-esp?
  223. (partition-set-flag partition
  224. PARTITION-FLAG-ESP
  225. (if esp? 1 0)))
  226. #t))
  227. (define (listbox-action listbox-item)
  228. (let* ((item (car listbox-item))
  229. (partition (user-partition-parted-object
  230. target-user-partition))
  231. (disk (partition-disk partition))
  232. (device (disk-device disk)))
  233. (list
  234. item
  235. (case item
  236. ((name)
  237. (let* ((old-name (user-partition-name target-user-partition))
  238. (name
  239. (run-input-page (G_ "Please enter the partition gpt name.")
  240. (G_ "Partition name")
  241. #:default-text old-name)))
  242. (user-partition
  243. (inherit target-user-partition)
  244. (name name))))
  245. ((type)
  246. (let ((new-type (run-type-page partition)))
  247. (user-partition
  248. (inherit target-user-partition)
  249. (type new-type))))
  250. ((bootable)
  251. (user-partition
  252. (inherit target-user-partition)
  253. (bootable? (not (user-partition-bootable?
  254. target-user-partition)))))
  255. ((esp?)
  256. (let ((new-esp? (not (user-partition-esp?
  257. target-user-partition))))
  258. (user-partition
  259. (inherit target-user-partition)
  260. (esp? new-esp?)
  261. (mount-point (if new-esp?
  262. (default-esp-mount-point)
  263. "")))))
  264. ((crypt-label)
  265. (let* ((label (user-partition-crypt-label
  266. target-user-partition))
  267. (new-label
  268. (and (not label)
  269. (run-input-page
  270. (G_ "Please enter the encrypted label")
  271. (G_ "Encryption label")))))
  272. (user-partition
  273. (inherit target-user-partition)
  274. (need-formatting? #t)
  275. (crypt-label new-label))))
  276. ((need-formatting?)
  277. (user-partition
  278. (inherit target-user-partition)
  279. (need-formatting?
  280. (not (user-partition-need-formatting?
  281. target-user-partition)))))
  282. ((size)
  283. (let* ((old-size (user-partition-size target-user-partition))
  284. (max-size-value (partition-length partition))
  285. (max-size (unit-format device max-size-value))
  286. (start (partition-start partition))
  287. (size (run-input-page
  288. (format #f (G_ "Please enter the size of the partition.\
  289. The maximum size is ~a.") max-size)
  290. (G_ "Partition size")
  291. #:default-text (or old-size max-size)))
  292. (size-percentage (read-percentage size))
  293. (size-value (if size-percentage
  294. (nearest-exact-integer
  295. (/ (* max-size-value size-percentage)
  296. 100))
  297. (numeric-size device size)))
  298. (end (and size-value
  299. (+ start size-value)))
  300. (size-range (numeric-size-range device size))
  301. (size-range-ok? (and size-range
  302. (< (+ start
  303. (geometry-start size-range))
  304. (partition-end partition)))))
  305. (cond
  306. ((and size-percentage (> size-percentage 100))
  307. (run-error-page
  308. (G_ "The percentage can not be superior to 100.")
  309. (G_ "Size error"))
  310. target-user-partition)
  311. ((not size-value)
  312. (run-error-page
  313. (G_ "The requested size is incorrectly formatted, or too large.")
  314. (G_ "Size error"))
  315. target-user-partition)
  316. ((not (or size-percentage size-range-ok?))
  317. (run-error-page
  318. (G_ "The request size is superior to the maximum size.")
  319. (G_ "Size error"))
  320. target-user-partition)
  321. (else
  322. (fill-user-partition-geom target-user-partition
  323. #:device device
  324. #:size size
  325. #:start start
  326. #:end end)))))
  327. ((fs-type)
  328. (let ((fs-type (run-fs-type-page)))
  329. (user-partition
  330. (inherit target-user-partition)
  331. (fs-type fs-type))))
  332. ((mount-point)
  333. (let* ((old-mount (or (user-partition-mount-point
  334. target-user-partition)
  335. ""))
  336. (mount
  337. (run-input-page
  338. (G_ "Please enter the desired mounting point for this \
  339. partition. Leave this field empty if you don't want to set a mounting point.")
  340. (G_ "Mounting point")
  341. #:default-text old-mount
  342. #:allow-empty-input? #t)))
  343. (user-partition
  344. (inherit target-user-partition)
  345. (mount-point (and (not (string=? mount ""))
  346. mount)))))))))
  347. (define (button-action)
  348. (let* ((partition (user-partition-parted-object
  349. target-user-partition))
  350. (prev-part (partition-prev partition))
  351. (disk (partition-disk partition))
  352. (device (disk-device disk))
  353. (creation? (freespace-partition? partition))
  354. (start (partition-start partition))
  355. (end (partition-end partition))
  356. (new-user-partition
  357. (if (user-partition-start target-user-partition)
  358. target-user-partition
  359. (fill-user-partition-geom target-user-partition
  360. #:device device
  361. #:start start
  362. #:end end))))
  363. ;; It the backend PARTITION has free-space type, it means we are
  364. ;; creating a new partition, otherwise, we are editing an already
  365. ;; existing PARTITION.
  366. (if creation?
  367. (let* ((ok-create-partition?
  368. (inform-can-create-partition? new-user-partition))
  369. (new-partition
  370. (and ok-create-partition?
  371. (mkpart disk
  372. new-user-partition
  373. #:previous-partition prev-part))))
  374. (and new-partition
  375. (user-partition
  376. (inherit new-user-partition)
  377. (need-formatting? #t)
  378. (file-name (partition-get-path new-partition))
  379. (disk-file-name (device-path device))
  380. (parted-object new-partition))))
  381. (and (apply-user-partition-changes new-user-partition)
  382. new-user-partition))))
  383. (let* ((items (user-partition-description target-user-partition))
  384. (partition (user-partition-parted-object
  385. target-user-partition))
  386. (disk (partition-disk partition))
  387. (device (disk-device disk))
  388. (file-name (device-path device))
  389. (number-str (partition-print-number partition))
  390. (type (user-partition-type target-user-partition))
  391. (type-str (symbol->string type))
  392. (start (unit-format device (partition-start partition)))
  393. (creation? (freespace-partition? partition))
  394. (default-item (and default-item
  395. (find (lambda (item)
  396. (eq? (car item) default-item))
  397. items)))
  398. (result
  399. (run-listbox-selection-page
  400. #:info-text
  401. (if creation?
  402. (G_ (format #f "Creating ~a partition starting at ~a of ~a."
  403. type-str start file-name))
  404. (G_ (format #f "You are currently editing partition ~a."
  405. number-str)))
  406. #:title (if creation?
  407. (G_ "Partition creation")
  408. (G_ "Partition edit"))
  409. #:listbox-items items
  410. #:listbox-item->text cdr
  411. #:sort-listbox-items? #f
  412. #:listbox-default-item default-item
  413. #:button-text (G_ "OK")
  414. #:listbox-callback-procedure listbox-action
  415. #:button-callback-procedure button-action)))
  416. (match result
  417. ((item new-user-partition)
  418. (run-partition-page new-user-partition
  419. #:default-item item))
  420. (else result))))
  421. (define* (run-disk-page disks
  422. #:optional (user-partitions '())
  423. #:key (guided? #f))
  424. "Run a page allowing to edit the partition tables of the given DISKS. If
  425. specified, USER-PARTITIONS is a list of <user-partition> records associated to
  426. the partitions on DISKS."
  427. (define (other-logical-partitions? partitions)
  428. "Return #t if at least one of the partition in PARTITIONS list is a
  429. logical partition, return #f otherwise."
  430. (any logical-partition? partitions))
  431. (define (other-non-logical-partitions? partitions)
  432. "Return #t is at least one of the partitions in PARTITIONS list is not a
  433. logical partition, return #f otherwise."
  434. (let ((non-logical-partitions
  435. (remove logical-partition? partitions)))
  436. (or (any normal-partition? non-logical-partitions)
  437. (any freespace-partition? non-logical-partitions))))
  438. (define (add-tree-symbols partitions descriptions)
  439. "Concatenate tree symbols to the given DESCRIPTIONS list and return
  440. it. The PARTITIONS list is the list of partitions described in
  441. DESCRIPTIONS. The tree symbols are used to indicate the partition's disk and
  442. for logical partitions, the extended partition which includes them."
  443. (match descriptions
  444. (() '())
  445. ((description . rest-descriptions)
  446. (match partitions
  447. ((partition . rest-partitions)
  448. (if (null? rest-descriptions)
  449. (list (if (logical-partition? partition)
  450. (string-append " ┗━ " description)
  451. (string-append "┗━ " description)))
  452. (cons (cond
  453. ((extended-partition? partition)
  454. (if (other-non-logical-partitions? rest-partitions)
  455. (string-append "┣┳ " description)
  456. (string-append "┗┳ " description)))
  457. ((logical-partition? partition)
  458. (if (other-logical-partitions? rest-partitions)
  459. (if (other-non-logical-partitions? rest-partitions)
  460. (string-append "┃┣━ " description)
  461. (string-append " ┣━ " description))
  462. (if (other-non-logical-partitions? rest-partitions)
  463. (string-append "┃┗━ " description)
  464. (string-append " ┗━ " description))))
  465. (else
  466. (string-append "┣━ " description)))
  467. (add-tree-symbols rest-partitions
  468. rest-descriptions))))))))
  469. (define (skip-item? item)
  470. (eq? (car item) 'skip))
  471. (define (disk-items)
  472. "Return the list of strings describing DISKS."
  473. (let loop ((disks disks))
  474. (match disks
  475. (() '())
  476. ((disk . rest)
  477. (let* ((device (disk-device disk))
  478. (partitions (disk-partitions disk))
  479. (partitions*
  480. (filter-map
  481. (lambda (partition)
  482. (and (not (metadata-partition? partition))
  483. (not (small-freespace-partition? device
  484. partition))
  485. partition))
  486. partitions))
  487. (descriptions (add-tree-symbols
  488. partitions*
  489. (partitions-descriptions partitions*
  490. user-partitions)))
  491. (partition-items (map cons partitions* descriptions)))
  492. (append
  493. `((,disk . ,(device-description device disk))
  494. ,@partition-items
  495. ,@(if (null? rest)
  496. '()
  497. '((skip . ""))))
  498. (loop rest)))))))
  499. (define (remove-user-partition-by-partition user-partitions partition)
  500. "Return the USER-PARTITIONS list with the record with the given PARTITION
  501. object removed. If PARTITION is an extended partition, also remove all logical
  502. partitions from USER-PARTITIONS."
  503. (remove (lambda (p)
  504. (let ((cur-partition (user-partition-parted-object p)))
  505. (or (equal? cur-partition partition)
  506. (and (extended-partition? partition)
  507. (logical-partition? cur-partition)))))
  508. user-partitions))
  509. (define (remove-user-partition-by-disk user-partitions disk)
  510. "Return the USER-PARTITIONS list with the <user-partition> records located
  511. on given DISK removed."
  512. (remove (lambda (p)
  513. (let* ((partition (user-partition-parted-object p))
  514. (cur-disk (partition-disk partition)))
  515. (equal? cur-disk disk)))
  516. user-partitions))
  517. (define (update-user-partitions user-partitions new-user-partition)
  518. "Update or insert NEW-USER-PARTITION record in USER-PARTITIONS list
  519. depending if one of the <user-partition> record in USER-PARTITIONS has the
  520. same PARTITION object as NEW-USER-PARTITION."
  521. (let* ((partition (user-partition-parted-object new-user-partition))
  522. (user-partitions*
  523. (remove-user-partition-by-partition user-partitions
  524. partition)))
  525. (cons new-user-partition user-partitions*)))
  526. (define (button-ok-action)
  527. "Commit the modifications to all DISKS and return #t."
  528. (for-each (lambda (disk)
  529. (disk-commit disk))
  530. disks)
  531. #t)
  532. (define (listbox-action listbox-item)
  533. "A disk or a partition has been selected. If it's a disk, ask for a label
  534. to create a new partition table. If it is a partition, propose the user to
  535. edit it."
  536. (let ((item (car listbox-item)))
  537. (cond
  538. ((disk? item)
  539. (let ((label (run-label-page (G_ "Back") (const #f))))
  540. (if label
  541. (let* ((device (disk-device item))
  542. (new-disk (mklabel device label))
  543. (commit-new-disk (disk-commit new-disk))
  544. (other-disks (remove (lambda (disk)
  545. (equal? disk item))
  546. disks))
  547. (new-user-partitions
  548. (remove-user-partition-by-disk user-partitions item)))
  549. (disk-destroy item)
  550. `((disks . ,(cons new-disk other-disks))
  551. (user-partitions . ,new-user-partitions)))
  552. `((disks . ,disks)
  553. (user-partitions . ,user-partitions)))))
  554. ((partition? item)
  555. (let* ((partition item)
  556. (disk (partition-disk partition))
  557. (device (disk-device disk))
  558. (existing-user-partition
  559. (find-user-partition-by-parted-object user-partitions
  560. partition))
  561. (edit-user-partition
  562. (or existing-user-partition
  563. (partition->user-partition partition))))
  564. `((disks . ,disks)
  565. (user-partitions . ,user-partitions)
  566. (edit-user-partition . ,edit-user-partition)))))))
  567. (define (hotkey-action key listbox-item)
  568. "The DELETE key has been pressed on a disk or a partition item."
  569. (let ((item (car listbox-item))
  570. (default-result
  571. `((disks . ,disks)
  572. (user-partitions . ,user-partitions))))
  573. (cond
  574. ((disk? item)
  575. (let* ((device (disk-device item))
  576. (file-name (device-path device))
  577. (info-text
  578. (format #f (G_ "Are you sure you want to delete everything on disk ~a?")
  579. file-name))
  580. (result (choice-window (G_ "Delete disk")
  581. (G_ "OK")
  582. (G_ "Exit")
  583. info-text)))
  584. (case result
  585. ((1)
  586. (disk-delete-all item)
  587. `((disks . ,disks)
  588. (user-partitions
  589. . ,(remove-user-partition-by-disk user-partitions item))))
  590. (else
  591. default-result))))
  592. ((partition? item)
  593. (if (freespace-partition? item)
  594. (run-error-page (G_ "You cannot delete a free space area.")
  595. (G_ "Delete partition"))
  596. (let* ((disk (partition-disk item))
  597. (number-str (partition-print-number item))
  598. (info-text
  599. (format #f (G_ "Are you sure you want to delete partition ~a?")
  600. number-str))
  601. (result (choice-window (G_ "Delete partition")
  602. (G_ "OK")
  603. (G_ "Exit")
  604. info-text)))
  605. (case result
  606. ((1)
  607. (let ((new-user-partitions
  608. (remove-user-partition-by-partition user-partitions
  609. item)))
  610. (disk-delete-partition disk item)
  611. `((disks . ,disks)
  612. (user-partitions . ,new-user-partitions))))
  613. (else
  614. default-result))))))))
  615. (let* ((info-text (G_ "You can change a disk's partition table by \
  616. selecting it and pressing ENTER. You can also edit a partition by selecting it \
  617. and pressing ENTER, or remove it by pressing DELETE. To create a new \
  618. partition, select a free space area and press ENTER.
  619. At least one partition must have its mounting point set to '/'."))
  620. (guided-info-text (format #f (G_ "This is the proposed \
  621. partitioning. It is still possible to edit it or to go back to install menu \
  622. by pressing the Exit button.~%~%")))
  623. (result
  624. (run-listbox-selection-page
  625. #:info-text (if guided?
  626. (string-append guided-info-text info-text)
  627. info-text)
  628. #:title (if guided?
  629. (G_ "Guided partitioning")
  630. (G_ "Manual partitioning"))
  631. #:info-textbox-width 70
  632. #:listbox-items (disk-items)
  633. #:listbox-item->text cdr
  634. #:sort-listbox-items? #f
  635. #:skip-item-procedure? skip-item?
  636. #:allow-delete? #t
  637. #:button-text (G_ "OK")
  638. #:button-callback-procedure button-ok-action
  639. #:button2-text (G_ "Exit")
  640. #:button2-callback-procedure button-exit-action
  641. #:listbox-callback-procedure listbox-action
  642. #:hotkey-callback-procedure hotkey-action)))
  643. (if (eq? result #t)
  644. (let ((user-partitions-ok?
  645. (guard
  646. (c ((no-root-mount-point? c)
  647. (run-error-page
  648. (G_ "No root mount point found.")
  649. (G_ "Missing mount point"))
  650. #f))
  651. (check-user-partitions user-partitions))))
  652. (if user-partitions-ok?
  653. (begin
  654. (for-each (cut disk-destroy <>) disks)
  655. user-partitions)
  656. (run-disk-page disks user-partitions
  657. #:guided? guided?)))
  658. (let* ((result-disks (assoc-ref result 'disks))
  659. (result-user-partitions (assoc-ref result
  660. 'user-partitions))
  661. (edit-user-partition (assoc-ref result
  662. 'edit-user-partition))
  663. (can-create-partition?
  664. (and edit-user-partition
  665. (inform-can-create-partition? edit-user-partition)))
  666. (new-user-partition (and edit-user-partition
  667. can-create-partition?
  668. (run-partition-page
  669. edit-user-partition)))
  670. (new-user-partitions
  671. (if new-user-partition
  672. (update-user-partitions result-user-partitions
  673. new-user-partition)
  674. result-user-partitions)))
  675. (run-disk-page result-disks new-user-partitions
  676. #:guided? guided?)))))
  677. (define (run-partioning-page)
  678. "Run a page asking the user for a partitioning method."
  679. (define (run-page devices)
  680. (let* ((items
  681. '((entire . "Guided - using the entire disk")
  682. (entire-encrypted . "Guided - using the entire disk with encryption")
  683. (manual . "Manual")))
  684. (result (run-listbox-selection-page
  685. #:info-text (G_ "Please select a partitioning method.")
  686. #:title (G_ "Partitioning method")
  687. #:listbox-items items
  688. #:listbox-item->text cdr
  689. #:button-text (G_ "Exit")
  690. #:button-callback-procedure button-exit-action))
  691. (method (car result)))
  692. (cond
  693. ((or (eq? method 'entire)
  694. (eq? method 'entire-encrypted))
  695. (let* ((device (run-device-page devices))
  696. (disk-type (disk-probe device))
  697. (disk (if disk-type
  698. (disk-new device)
  699. (let* ((label (run-label-page
  700. (G_ "Exit")
  701. button-exit-action))
  702. (disk (mklabel device label)))
  703. (disk-commit disk)
  704. disk)))
  705. (scheme (symbol-append method '- (run-scheme-page)))
  706. (user-partitions (append
  707. (auto-partition disk #:scheme scheme)
  708. (create-special-user-partitions
  709. (disk-partitions disk)))))
  710. (run-disk-page (list disk) user-partitions
  711. #:guided? #t)))
  712. ((eq? method 'manual)
  713. (let* ((disks (filter-map disk-new devices))
  714. (user-partitions (append-map
  715. create-special-user-partitions
  716. (map disk-partitions disks)))
  717. (result-user-partitions (run-disk-page disks
  718. user-partitions)))
  719. result-user-partitions)))))
  720. (init-parted)
  721. (let* ((non-install-devices (non-install-devices))
  722. (user-partitions (run-page non-install-devices))
  723. (user-partitions-with-pass (prompt-luks-passwords
  724. user-partitions))
  725. (form (draw-formatting-page)))
  726. ;; Make sure the disks are not in use before proceeding to formatting.
  727. (free-parted non-install-devices)
  728. (format-user-partitions user-partitions-with-pass)
  729. (destroy-form-and-pop form)
  730. user-partitions))