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