-
Notifications
You must be signed in to change notification settings - Fork 0
/
start
597 lines (597 loc) · 17.6 KB
/
start
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
#!/bin/bash
#
# NOTE - disk sdb no longer exists - left the code in place in case it's resurrected
# this disk is now sda and sda1 is used as swap
# Assuming disk sdb exists then -
# There are three disks here: disk sdb has 10 partitions with 3 operating systems -
# change sdb to suit your needs
# M.2 ssd nvme0n1 has 9 available partitions
# 1 to 3 have Arch OS loadeded. nvme0n1p1 is an EFI system partition and mounted as /boot
# NOTE all the kernels for the entire system are on this partition.
# 4 to 6 are for an LFS OS (Xfce)
# 7 to 9 are for another LFS OS of your choosing
# M.2 ssd nvme1n1 has 3 available partitions. 1 to 5 are reserved for Windows 11
# 6 to 8 are for an LFS OS.
#
# sdb (1TB) used to contain these partitions
# sdb1 - EFI system partition
# sdb2 - BIOS boot partition
# sdb3 - 5 LFS xfce
# sdb6 - 9 LFS kf5 plasma
# sdb10 - 12 Arch KF5 plasma
# sdb13 swap
#
as_root=true
if [ $UID -ne 0 ]; then
as_root=false
echo "Running as $(whoami)"
echo "will run in test mode but will not mount any partitions"
echo "Run as root to mount the selected partitions."
fi
LFS=$LFS
nvme0="nvme0n1"
nvme1="nvme1n1"
label="sdb"
# Note - the sdb disk has been removed (03/2022) Its now used as a swap partition
# the code for it has been left in place. sdb may reappear in the future
# but it is not maintained at the moment
diskLabel=$label
disk4=""
# sda1 is used as a swap partition (50 MB)
#
# which disk is mounted
isNvme0=false
isNvme1=false
isDisk=false
clear
if [ "$LFS" = "" ]; then
echo "The LFS variable is not set"
echo "Will set it to /mnt/lfs"
export LFS="/mnt/lfs"
fi
if [ ! -d $LFS ]; then
if $as_root; then
echo "Directory $LFS doesn't exit"
echo "Create it? (y/N)"
read reply
case $reply in
[yY]|[yY][Ee][Ss])
echo "Will create dir $LFS"
mkdir -pv $LFS
;;
[nN]|[nN][Oo])
echo "Dir $LFS must exist to continue"
echo "Exiting now"
exit 1
;;
*)
echo "Dir $LFS must exist to continue"
echo "Exiting now"
exit 1
;;
esac
else
echo "Not running as root. Cannot create $LFS"
fi
else
echo "Directory $LFS exists"
fi
echo "LFS is set to $LFS"
#
checkRootPart () {
# checks that the root partition, partToFind, is in the array of Partitions
# $1 is the array of partition - mountpoint pairs
# $2 is the root partition without /dev/ on the front
declare -a arrayParts=("${!1}")
local partToFind=$2
local part
for part in ${arrayParts[@]}; do
case $part in
$partToFind)
return 0 # found
;;
esac
done
return 1 # not found
} # end checkRootPart
#
# functions to test if device or path is mounted
# return 0 = found; 1 = not found
isMounted () { findmnt -rno SOURCE,TARGET "$1" >/dev/null;} #path or device
isDevMounted () { findmnt -rno SOURCE "$1" >/dev/null;} #device only
isPathMounted() { findmnt -rno TARGET "$1" >/dev/null;} #path only
#where: -r = --raw, -n = --noheadings, -o = --output
#
runit=true # by default the requested partitions are mounted
# if sdb chosen then set runit=false
#
# determine which partitions are already mounted
echo "Looking for partitions that are mounted:"
if [ "$LFS" = /mnt/lfs ]; then
nvme0Parts=($(lsblk --noheadings --raw -o NAME,MOUNTPOINT | awk '{if ($1~/nvme0n1p/ && $2~/[/]/) {print $1, $2}}'))
numnvme0=${#nvme0Parts[@]}
if [ $numnvme0 -gt 0 ]; then
echo "disk $nvme0 is mounted"
echo "these partitions are mounted"
echo "${nvme0Parts[@]}"
isNvme0=true
theOne=$nvme0
diskMounted="${nvme0Parts[@]}"
else
echo "disk $nvme0 is not mounted"
fi
nvme1Parts=( $(lsblk --noheadings --raw -o NAME,MOUNTPOINT | awk '{if ($1~/nvme1n1p/ && $2~/[/]/) {print $1, $2}}') )
numnvme1=${#nvme1Parts[@]}
if [ $numnvme1 -gt 0 ]; then
echo "disk $nvme1 is mounted"
echo "these partitions are mounted"
echo "${nvme1Parts[@]}"
isNvme1=true
theOne=$nvme1
diskMounted="${nvme1Parts[@]}"
else
echo "disk $nvme1 is not mounted"
fi
#
labelParts=( $(lsblk --noheadings --raw -o NAME,MOUNTPOINT | awk '{if ($1~/sdb/ && $2~/[/]/) {print $1, $2}}') )
numsdb=${#labelParts[@]}
if [ $numsdb -gt 0 ]; then
echo "disk $label is mounted"
echo "these partitions are mounted"
echo "${labelParts[@]}"
isDisk=true
theOne=$label # the sdb disk
diskMounted="${labelParts[@]}"
else
echo "disk $label doesn't currently exist"
fi
#
# get the root partition to identify the host
rootSystem=$(findmnt -n -o SOURCE /)
echo "root partition is $rootSystem"
rootNoDev=${rootSystem/\/dev\//}
# echo "rootNoDev is $rootNoDev"
# check that the root partition, rootSystem, is in the array of mounted partitions
checkRootPart diskMounted[@] $rootNoDev
if [ "$?" = 0 ]; then
echo "root partition $rootSystem found on the mounted disk $theOne - ** this is the host **"
else
echo "root partition $rootSystem is not one of ${diskMounted[@]}"
echo "You need to unmount ${diskMounted[@]}"
echo "Aborting"
exit 1
fi
if $isNvme0; then # Offer to mount partitions on label, nvme0 or nvme1
suite1="${label}3, 4 and 5 (LFS)"
suite2="${label}6, 7, 8 and 9 (LFS)"
suite3="${label}10, 11 and 12 (Arch KF5 plasma)"
case $rootSystem in
*p2) # Arch is mounted
suite4="${nvme0}p4, p5 and p6 (LFS Xfce)"
one="p4"
two="p5"
three="p6"
suite5="${nvme0}p7, p8, p9 (LFS)"
four="p7"
five="p8"
six="p9"
suite6="${nvme1}p6, p7 and p8 (LFS)"
seven="p6"
eight="p7"
nine="p8"
;;
*p4) # LFS Xfce mounted
suite4="${nvme0}p2 and p3 (Arch)"
one="p2"
two="p3"
three=""
suite5="${nvme0}p7, p8, p9 (LFS)"
four="p7"
five="p8"
six="p9"
suite6="${nvme1}p6, p7 and p8 (LFS)"
seven="p6"
eight="p7"
nine="p8"
;;
*p7) # LFS mounted
suite4="${nvme0}p2 and p3 (Arch)"
one="p2"
two="p3"
three=""
suite5="${nvme0}p4, p5 and p6 (LFS Xfce)"
four="p4"
five="p5"
six="p6"
suite6="${nvme1}p6, p7 and p8 (LFS)"
seven="p6"
eight="p7"
nine="p8"
;;
esac
echo "will chroot into one of the following -"
echo "Choose one:"
echo " "
PS3="> "
options=("$suite1" "$suite2" "$suite3" "$suite4" "$suite5" "$suite6")
select opt in "${options[@]}" "Quit"; do
case "$REPLY" in
1)
echo "If sdb existed, would create a file system on partitions $suite1"
disk1=3
disk2=4
disk3=5
runit=false
break
;;
2)
echo "If sdb existed, would create a file system on partitions $suite2"
disk1=6
disk2=7
disk3=8
disk4=9
runit=false
break
;;
3)
echo "If sdb existed, would create a file system on partitions $suite3"
disk1=10
disk2=11
disk3=12
runit=false
break
;;
4)
echo "Will mount partitions on $suite4"
disk1=$one
disk2=$two
disk3=$three
diskLabel=$nvme0
break
;;
5)
echo "Will mount partitions on $suite5"
disk1=$four
disk2=$five
disk3=$six
diskLabel=$nvme0
break
;;
6)
echo "Will mount partitions on $suite6"
disk1=$seven
disk2=$eight
disk3=$nine
disklabel=$nvme0
if [ "$disk1" = p6 ]; then diskLabel=$nvme1; fi
break
;;
$((${#options[@]}+1)))
echo "Okay, will exit"
exit 1
;;
*) echo "Invalid option. Type 1, 2, 3, 4, 5, 6 or 7"
:
;;
esac
done
#
elif $isNvme1; then # if this disk is the host the partitions are p6, p7 and p8
suite1="${label}3, 4 and 5 (LFS)"
suite2="${label}6, 7, 8 and 9 (LFS)"
suite3="${label}10, 11 and 12 (Arch KF5 plasma)"
suite4="${nvme0}p2 and p3 (Arch)"
suite5="${nvme0}p4, p5 and p6 (LFS Xfce)"
suite6="${nvme0}p7, p8, and p9 (LFS)"
echo "will chroot into one of the following -"
echo "Choose one:"
echo " "
PS3="> "
options=("$suite1" "$suite2" "$suite3" "$suite4" "$suite5" "$suite6")
select opt in "${options[@]}" "Quit"; do
case "$REPLY" in
1)
echo "If sdb existed, would mount partitions on $suite1"
disk1=3
disk2=4
disk3=5
runit=false
break
;;
2)
echo "If sdb existed, would mount partitions on $suite2"
disk1=6
disk2=7
disk3=8
disk4=9
runit=false
break
;;
3)
echo "If sdb existed, would mount partitions on $suite3"
disk1=10
disk2=11
disk3=12
runit=false
break
;;
4)
echo "Will mount partitions on $suite4"
disk1=p2
disk2=p3
disk3=""
diskLabel=$nvme0
break
;;
5)
echo "Will mount partitions on $suite5"
disk1=p4
disk2=p5
disk3=p6
diskLabel=$nvme0
break
;;
6)
echo "Will mount partitions on $suite6"
disk1=p7
disk2=p8
disk3=p9
diskLabel=$nvme0
break
;;
$((${#options[@]}+1)))
echo "Okay, will exit"
exit 1
;;
*) echo "Invalid option. Type 1, 2, 3, 4, 5, 6 or 7"
:
;;
esac
done
# disk sdb1 not currently used so cannot be the host. Left the code in place as this may change
# elif $isDisk; then # offer to create a file system on partitions on remaining label partitions, nvme0 and nvme1
# suite1="${nvme0}p3, p4 and p5 (Ububtu)"
# suite2="${nvme0}p6, p7 and p8 (Arch rolling)"
# suite3="${nvme0}p9, p10, p11 and p12 (LFS)"
# suite4="${nvme1}p6, p7 and p8 (LFS xfce)"
# suite5="${nvme1}p9, p10, p11 and p12 (LFS)"
# case $rootSystem in
# *sdb4)
# one="6"
# two="7"
# three="8"
# four="9"
# suite6="${label}6, 7, 8 and 9"
# five="10"
# six="11"
# seven="12"
# eight=""
# suite7="${label}10, 11 and 12"
# ;;
# *sdb7)
# one="3"
# two="4"
# three="5"
# four=""
# suite6="${label}3, 4 and 5"
# five="10"
# six="11"
# seven="12"
# eight=""
# suite7="${label}10, 11 and 12"
# ;;
# *sdb11)
# one="3"
# two="4"
# three="5"
# four=""
# suite6="${label}3, 4 and 5"
# five="6"
# six="7"
# seven="8"
# eight="9"
# suite7="${label}6, 7, 8 and 9"
# ;;
# esac
# echo "will chroot into one of the following -"
# echo "Choose one:"
# echo " "
# PS3="> "
# options=("$suite1" "$suite2" "$suite3" "$suite4" "$suite5" "$suite6" "$suite7")
# select opt in "${options[@]}" "Quit"; do
# case "$REPLY" in
# 1)
# echo "Will create a file system on partitions $suite1"
# disk1=p3
# disk2=p4
# disk3=p5
# diskLabel=$nvme0
# break
# ;;
# 2)
# echo "Will create a file system on partitions $suite2"
# disk1=p6
# disk2=p7
# disk3=p8
# diskLabel=$nvme0
# break
# ;;
# 3)
# echo "Will create a file system on partitions $suite3"
# disk1=p9
# disk2=p10
# disk3=p11
# disk4=p12
# diskLabel=$nvme0
# break
# ;;
# 4)
# echo "Will create a file system on partitions $suite4"
# disk1=p6
# disk2=p7
# disk3=p8
# diskLabel=$nvme1
# break
# ;;
# 5)
# echo "Will create a file system on partitions $suite5"
# disk1=p9
# disk2=p10
# disk3=p11
# disk4=p12
# diskLabel=$nvme1
# break
# ;;
# 6)
# echo "Will create a file system on partitions $suite6"
# disk1=$one
# disk2=$two
# disk3=$three
# if [ ! -z "$four" ]; then disk4=$four; fi
# break
# ;;
# 7)
# echo "Will create a file system on partitions $suite7"
# disk1=$five
# disk2=$six
# disk3=$seven
# if [ ! -z "$eight" ]; then disk4=$eight; fi
# break
# ;;
# $((${#options[@]}+1)))
# echo "Okay, will exit"
# exit 1
# ;;
# *) echo "Invalid option. Type 1, 2, 3, 4, 5, 6, 7 or 8"
# :
# ;;
# esac
# done
fi
if ! $as_root; then
echo "If running as root, would mount these partitions:"
echo "/dev/${diskLabel}${disk1}"
echo "/dev/${diskLabel}${disk2}"
echo "/dev/${diskLabel}${disk3}"
if [ ! -z "$disk4" ]; then
echo "/dev/${diskLabel}${disk4}"
fi
# if root, would mount the ESP partition on LFS/boot
echo "would also mount the ESP partition"
echo "/dev/nvme0n1p1"
echo "Aborting"
# exit 1
else #as root
echo "Running as root, will mount these partitions:"
echo "/dev/${diskLabel}${disk1}"
echo "/dev/${diskLabel}${disk2}"
echo "/dev/${diskLabel}${disk3}"
if [ ! -z "$disk4" ]; then
echo "/dev/${diskLabel}${disk4}"
fi
# mount the ESP partition on $LFS/boot
echo "will also mount the ESP partition"
echo "/dev/nvme0n1p1 to $LFS/boot"
#
# exit 1
fi # test as root
if ! $runit; then
echo "Partitions on sdb chosen. Will do nothing"
else
if ! $as_root; then
echo "disk1 is $disk1"
else # if disk1 is p2 then requested Arch. mount p2 as $LFS and p3 as $LFS/home
case $disk1 in
*p2) # Arch p2 and p3
mount -v -t ext4 /dev/${diskLabel}${disk1} $LFS
mount -v -t ext4 /dev/${diskLabel}${disk2} $LFS/home
useutmp=997 # Arch
;;
*) # mount LFS partitions
mount -v -t ext4 /dev/${diskLabel}${disk1} $LFS
mount -v -t ext4 /dev/${diskLabel}${disk2} $LFS/home
mount -v -t ext4 /dev/${diskLabel}${disk3} $LFS/opt
useutmp=13 # LFS
# disk4 not currently used. Was used with disk sdb
# if [ ! -z "$disk4" ]; then
# if [ ! -d $LFS/opt ]; then mkdir -pv $LFS/opt; fi
# mount -v -t ext4 /dev/${diskLabel}${disk4} $LFS/opt
# fi
;;
esac
# mount $LFS/boot on p1
if [ ! -d $LFS/boot ]; then mkdir -pv $LFS/boot; fi
mount -v -t vfat /dev/nvme0n1p1 $LFS/boot
# see if swap is available
if [ -e /dev/sda1 ]; then
echo "swap is partition /dev/sda1"
${LFS}/usr/bin/swapon -v /dev/sda1
fi
#
# mount virtual kernel file systems
mount -v --bind /dev $LFS/dev
mount -v --bind /dev/pts $LFS/dev/pts
mount -vt proc proc $LFS/proc
mount -vt sysfs sysfs $LFS/sys
mount -vt tmpfs tmpfs $LFS/run
if [ -h $LFS/dev/shm ]; then
mkdir -pv $LFS/$(readlink $LFS/dev/shm)
fi
chmod 1777 $LFS/dev/shm
fi # test as root
echo "using useutmp $useutmp"
if $as_root; then
touch $LFS/var/log/{btmp,lastlog,wtmp}
chgrp -v $useutmp $LFS/var/log/{lastlog,btmp,wtmp}
chmod -v 664 $LFS/var/log/{lastlog,wtmp}
chmod -v 660 $LFS/var/log/btmp
fi
# if using Package User install, set some install files if using LFS partitions
ispkguser=true
echo "Installing as pkguser? [Y/n]"
read reply
case $reply in
[nN]|[nN][Oo])
ispkguser=false # installing as root
;;
esac
if $as_root; then
if $ispkguser; then # check if Arch root partition
case $disk1 in
*p2) # Arch p2 and p3
echo "Requested the Arch partitions - no changes required"
;;
*) # LFS so make some changes
chmod 1775 $LFS/var
chmod 1775 $LFS/var/{cache,lib,log}
if [ -d $LFS/srv ]; then
chgrp 9999 $LFS/srv # install group
chmod 1775 $LFS/srv
fi
if [ -d $LFS/var/spool ]; then
chgrp 9999 $LFS/var/spool # install group
chmod 1775 $LFS/var/spool
fi
mkdir -pv $LFS/run/lock
chmod 1777 $LFS/run/lock
;;
esac
fi # test is pkguser
# enter chroot
if [ -e /usr/bin/env ]; then
chroot "$LFS" /usr/bin/env -i \
HOME=/root TERM="$TERM" \
PS1='(lfs chroot) \u:\w\$ ' \
PATH=/bin:/usr/bin \
/bin/bash --login
else
echo "Can't enter chroot. No /usr/bin/env present"
fi
fi # test as root
fi # test runit
else
echo "Don't recognise variable LFS as $LFS"
echo "Do export LFS=/mnt/lfs and try again"
echo "exit"
exit 1
fi