-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathUEFI-GRUB2-system
676 lines (401 loc) · 18.8 KB
/
UEFI-GRUB2-system
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
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
############################################
### Installing a Arch Linux System
UEFI Motherboard
64 bit x86 CPU
Normal spinning disk
GPT Partition
GRUB 2
GNOME 3
Wired connection
############################################
### Make a Arch Linux USB drive ###
# replacing /dev/sdx with your drive, e.g. /dev/sdb.
(do not append a partition number, so do not use something like /dev/sdb1)
$ dd bs=4M if=/path/to/archlinux.iso of=/dev/sdx && sync
### Make a GParted Live USB drive ###
The GParted Live CD image can be written directly to a USB flash drive.
Download the GParted Live iso file.
Insert the USB flash drive your Linux computer and wait a few seconds. Next, from a terminal window run the command:
dmesg
This command queries the device name of the USB flash drive.
For example, you might find the device name is /dev/sde.
From a terminal window, enter the following command using the gparted .iso file name
and USB device path you discoved in the previous steps.
For example:
sudo dd if=/path-to-gparted-live.x.y.z-w.iso of=/dev/sde bs=4M; sync
### ######################################
#A# Setting upp storage partitions
### ######################################
### ######################################
### Check supported boot methods.
Check if the motherboard supports UEFI.
### ######################################
# Master Boot Record, MBR
The old BIOS boot table, pre 2013 motherboards.
# GUID Partition Table, GPT
UEFI, post 2014 motherboards.
1. Check UEFI support.
$ efivar -l
If efivar lists the uefi variables properly, then you have booted in UEFI mode.
Thus UEFI is supported.
#Note: In case you have a UEFI motherboard and UEFI Boot mode is enabled
# the live CD or USB will automatically launch Arch Linux kernel.
2. Check if the live USB was booted as UEFI USB in the BIOS/UEFI menu.
### ######################################
### Partition the storage media.
### ######################################
On a computer with a newer EFI rather than a BIOS:
boot loaders are not stored:
in the MBR,
in officially-unallocated post-MBR sectors,
or in BIOS Boot Partitions;
instead, boot loaders reside as ordinary files on a FAT partition known as the EFI System Partition (ESP).
(Confusingly, Debian and Ubuntu installers refer to the ESP by the name "EFI boot partition")
but this name is non-standard.
GParted and parted identify the ESP as having its "boot flag" set,
(although that terminology means something completely different on MBR disks.)
An ESP can exist on either a GPT disk or an MBR disk,
but the former is much more common on EFI-based computers.
The EFI approach is much safer and much more flexible than the BIOS approach,
since it doesn't tuck raw code away in weird places.
With ESP the boot loaders reside in files, just like OS-level programs.
This makes them easier to identify and manipulate.
### Use GNUParted Live CD or USB. ###
1. In advanced settings choose GPT and make the storage use GPT.
2. Manage the partition scheme.
#Note: This is a basic partition scheme:
==== - Make 2 MB spare space for UEFI?
sdX1 @ FAT32 partition - 512 MB
==== - Make 1 MB of spare space for security reasons
sdX2 @ Ext4 - Can be the rest of the space
==== - Make 1 MB of spare space for security reasons
#Note: More advanced partitions using swap partitions and other filesystems like btrfs can be set up.
4. Do the partitioning.
5. Set the FAT32 to have the flag "boot"
### Using GNU Parted ###
Parted has two modes: command line and interactive. Parted should always be started with:
$ parted device
where device is the hard disk device to edit (for example /dev/sda).
If you omit the DEVICE argument, Parted will attempt to guess which device you want.
Interactive mode
In interactive mode, commands are entered one at a time at a prompt, and modify the disk immediately.
For example:
(parted) mklabel gpt
(parted) mkpart P1 ext3 1MiB 8MiB
Create a mebibyte partition {+1MiB with gdisk) on the disk with no file system and type ef02 (or bios_grub in parted).
parted /dev/hda
set 1 boot on
quit
### ######################################
#B# Installing Arch
### ######################################
1. Show the storage medias. Find the sdX name of the storage media that was partitioned with GPT. In this guide the X = a
$ fdisk -l
2. Mount the partitions. First the main storage partition then the boot partition referred as the $esp.
$ mount /dev/sda2 /mnt
#The simplest option is to mount it at /boot, since this allows pacman to directly
#update the kernel that the EFI firmware will read.
#For both BIOS and UEFI system mount the boot like:
# The esp /boot/efi used by: Ubuntu and Manjaro
$ mkdir /mnt/boot
$ mkdir /mnt/boot/efi
$ mount /dev/sda1 /mnt/boot/efi
#$ mount /dev/sda1 /mnt/boot
#If you mount the EFI System Partition, the $esp location, elsewhere than /boot (such as /boot/efi),
#you will need to copy boot files to that location after a kernel update.
#If the $esp location is other than /boot then you need to set up a copy hook when
#pacman updates the kernel in the future. https://wiki.archlinux.org/index.php/EFISTUB
#The efi folder is just a standard name convention for UEFI (Not Mandatory!)
# grub-install --target=x86_64-efi --efi-directory=/boot
# will install on the location /boot/EFI
# grub-install --target=x86_64-efi --efi-directory=/boot/efi
# will install on the location /boot/efi/EFI
3. Check that there is an internet connection.
$ ping -c 3 www.google.com
4. Dowload the base installation on the storage partition.
$ pacstrap /mtn base
#Note: It is actually Grub2 that is installed.
$ pacstrap /mnt grub-efi-x86_64
$ pacstrap /mnt efibootmgr
#Note: For BIOS system the grub package is just,
#$ pacstrap /mnt grub
5. Create a file system table.
$ genfstab -p /mnt >> /mnt/etc/fstab
5X. If there is an SSD then add the discard option to /mnt/etc/fstab
$ nano /mnt/etc/fstab
> /dev/sda1 / ext4 defaults,noatime,discard 0 1
> /dev/sda2 /home ext4 defaults,noatime,discard 0 2
#Note: The last column (6) defines if the fsck should check the system.
# By default, fsck checks a filesystem every 30 boots (counted individually for each partition).
# 0 = Do not check
# 1 = The first partition to check, the root partition should be set to this.
# 2 = Check this partition, this is not the root partition.
6. Change to arch on the storage partition as root user.
$ arch-chroot /mnt
7. Create the initcpio file, which is the initial RAM disk filesystem.
$ mkinitcpio -p linux
8. Make a grub config file.
#Note: To fix an error.
$ nano /etc/default/grub
#Note: Add the line at the end of the file.
> GRUB_DISABLE_SUBMENU=y
$ grub-mkconfig -o /boot/grub/grub.cfg
9. Install GRUB 2 boot loader
$ mount -t efivarfs efivarfs /sys/firmware/efi/efivars
#Note: efibootmgr is only necesary for UEFI system
#If not installed do,
#$ pacman -S grub efibootmgr
#NOTE:
# http://lists.gnu.org/archive/html/help-grub/2012-12/msg00025.html
# --efi-directory=/boot/efi on UEFI system is just established convention.
# grub-install will search through several likely locations and /boot/efi
# is one of them. The ESP can be given directly as --efi-directory, the $esp path.
# grub-install simply looks for /boot/efi, /boot/EFI and is using root
# directory as last resort if it is FAT. That's all. I would not call
# this "automatic" - someone has to mount /boot/efi first and this is
# manual step.
$ grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=arch --recheck --debug
#Note: If success this is the output.
> Installation finished. No error reported
#Note: For BIOS system 32 or 64 bit the grub-install command is
#$ grub-install --target=i386-pc --recheck --debug /dev/sdX
# where sdX is the disk where the /boot partition is mounted. In this guide it is /dev/sda
10. Set a password for the root.
$ passwd
11. Exit the arch-root user.
$ exit
12. Unmount the storage media.
#Note: The spelling for the command is U M O U N T
$ umount -R /mnt/boot/efi /mnt
13. Reboot the computer with the systemd command.
$ systemctl reboot
### ############################################
#C# Configure the installed Arch system
### ############################################
1. Set a hostname with sytemd. The name of the computer in this example it is set to box.
$ hostnamectl set-hostname box
2. Find the right timezone.
$ cd /usr/share/zoneinfo
$ ls -al
#Note: This lists available zones and each have subzones.
3. Set the timezone. In this example the zone is US and the subzone is Pacific.
$ timedatectl set-timezone US/Pacific
#Note: Europe/Stockholm
4. Set the locale. The info about the language and keyboardlayout to be used.
$ vi /etc/locale.gen
Uncomment the lines corresponding to the encoding and the language that can be used on the system.
In this example the encoding is UTF-8 and the language is en_US.
$ locale-gen
$ localectl set-locale LANG="en_US.UTF-8"
5. Find available internet interfaces. This can be shown like eth0, enp2s0 or something else.
#Note: This changes if there is another PCI express card added or removed.
$ ls /sys/class/net
6. Start the wired connection. In this example the internet interface was named enp2s0.
$ dhcpcd enp2s0
$ ping -c 3 www.google.com
7. Make the wired connection start at boot with systemd. In this example the internet interface was named enp2s0.
$ systemctl enable [email protected]
$ systemctl start [email protected]
8. Install NTP to get the correct time from the internet.
$ pacman -S ntp
$ systemctl enable ntpd.service
9. Reboot the system
$ systemctl reboot
### #############################################
#D# Add a new user
### #############################################
#Note: To add a new user, use the useradd command.
# useradd -m -g [initial_group] -G [additional_groups] -s [login_shell] [username]
1. Adding a user named archie specifying bash as the login shell.
$ useradd -m -s /bin/bash archie
#Note: To later add the user to other groups use.
# usermod -aG [additional_groups] [username]
### ###############################################
### Make the user able to use sudo
### ###############################################
1. Install sudo.
$ pacman -S sudo
2. Use visudo to alter the sudo file /etc/sudoers.
$ visudo
#Note: Add the line. Where USER_NAME is the name of the user.
> USER_NAME ALL=(ALL) ALL
### ############################################
#E# Install graphical interfaces
X11 server
GNOME Desktop environment
### ############################################
1. Install X.
$ pacman -S xorg-server xorg-server-utils xorg-xinit xterm
2. Install mesa graphics driver.
$ pacman -S mesa
3. Check available video cards.
$ lspci | grep VGA
4. Show a list of available drivers.
$ pacman -Ss xf86-video | less
5. Install vesa driver | intel driver | ati driver.
#NOTE: The default graphics driver is xf86-video-vesa, which handles a large number of chipsets
# but does not include any 2D or 3D acceleration.
# If a better driver cannot be found or fails to load, Xorg will fall back to vesa.
$ pacman -S xf86-video-vesa
$ pacman -S xf86-video-intel
$ pacman -S xf86-video-ati
##6. Install some basic X applications.
##
##$ pacman -S xorg-twm xorg-xclock xterm
7X. If Xorg was installed before creating the non-root user
there will be a template .xinitrc file in your home directory
that needs to be either deleted or commented out.
$ rm ~/.xinitrc
7. Test the X11 environment
$ startx
$ exit
7X. If exit doesnt work try
$ pkill X
$ reboot
8. Install Gnome 3 desktop environment.
$ pacman -S gdm gnome-shell gnome-control-center gnome-tweak-tool
$ systemctl enable gdm.service
$ systemctl start gdm.service
### ##############################################
### Install web browser and get info files
### ##############################################
1. Install gnome web browser.
$ pacman -S epiphany
2. Install git and vim.
$ pacman -S git vim
3. Get the linux-arch-install repository
$ cd
$ git clone https://github.com/thedemz/linux-arch-install
### ############################################
#F# Partition examples
### ############################################
Use GParted live disk for GPT disks.
a) download from http://sourceforge.net/projects/gparted/
b) then write the .iso to CD or USB.
c) Documentation http://gparted.org/documentation.php
#####
/boot 512 MB - Set flag bootable
#####
This will be used for thee bootloader GRUB2 or syslinux etc.
#####
/
#####
The main partition where the systemfiles will be stored.
#####
/home
#####
The main partition where the users files are to be stored.
#####
/swap
#####
If the system have more than 8 GB om RAM, this partition is mostly not needed. Can be replaced by a file instead in another partition if skipped, this option is easier to resize also. If this partition is wanted the size is often recomended to be twice as large as the available RAM.
MBR partition: mkswap /dev/sdXY
swapon /dev/sdXY
swapon -s
#####
/var 12288 MB
#####
This node stores cache files such as logs. Often frequent read and writes. Place this on a disk hard drive to spare the SSD.
#####
/tmp
#####
### ############################################
#G# SSD - Solid State Disk
### ############################################
A Trim command (commonly typeset as TRIM) allows an operating system to inform a solid-state drive (SSD)
which blocks of data are no longer considered in use and can be wiped internally.
Most SSDs support the ATA_TRIM command for sustained long-term performance and wear-leveling.
As of linux kernel version 3.7, the following filesystems support TRIM:
Ext4
Btrfs
JFS
XFS
Using partitions that are aligned with the erase block size is highly recommended.
In past, this required manual calculation and intervention when partitioning.
Many of the common partition tools handle partition alignment automatically
(assuming users are using an up-to-date version):
fdisk
gdisk
gparted
parted
1. Verify a partition is aligned, query it using /usr/bin/blockdev as shown below
if a '0' is returned, the partition is aligned:
$ blockdev --getalignoff /dev/sdX
> 0
2. Verify TRIM Support
$ hdparm -I /dev/sda | grep TRIM
> Data Set Management TRIM supported (limit 1 block)
> Deterministic read data after TRIM
The output could be limit 1 block or limit 8 block
3. Enable TRIM by Mount Flags
Using this flag in one's /etc/fstab enables the benefits of the TRIM command
Edit /etc/fstab and add the discard option for the SDD partitions:
> /dev/sda1 / ext4 defaults,noatime,discard 0 1
> /dev/sda2 /home ext4 defaults,noatime,discard 0 2
4. Check that the SSD have the latest firmware to further improve the lifetime of the storage media.
### ###################################################
#H# Dual boot, like windows or more OS:es
### ###################################################
1. To make grub automatically add other systems to boot meny install os-prober
$ pacman -S os-prober
2. regenerate the grub config
$ grub-mkconfig -o /boot/efi/EFI/GRUB/grub.cfg
#Note: for BIOS system
#$ grub-mkconfig -o /boot/grub/grub.cfg
### ###################################################
### How GRUB 2 works
### ###################################################
GRUB 2 works like this:
/etc/default/grub contains customization;
/etc/grub.d/ scripts contain GRUB menu information and operating system boot scripts.
When the grub-mkconfig command is run,
it reads the contents of the grub file and the grub.d scripts and creates the grub.cfg file.
That's all.
### ###################################################
### /etc/grub.d/ scripts
### ###################################################
Let's review the scripts:
00_header The script that loads GRUB settings from /etc/default/grub,
including timeout, default boot entry, and others.
05_debian_theme Defines the background, colors and themes.
The name of this script is definitely going to change,
when other distributions adopt GRUB 2.
10_linux Loads the menu entries for the installed distribution.
20_memtest86+ Loads the memtest utility.
30_os-prober Is the script that will scan the hard disks for other operating systems
and add them to the boot menu.
40_custom Is a template that you can use to create additional entries to be added to the boot menu.
The numbering in the script names is somewhat similar to the order of Start/Kill scripts used in different runlevels.
The numbering defines precedence.
This means that 10_linux will be executed before 20_memtest86+ and therefore placed higher in the boot menu order.
Be very careful when working with these scripts!
Like the grub.cfg file, they are not intended to be edited, save custom edits for the 40_custom script.
### ###########################################################
#I# Troubleshooting
### ############################################################
? Can not run fsck on a separate /usr partition
1. Make sure you have the required hooks in
/etc/mkinitcpio.conf
#Note: Remembered to re-generate your initramfs image after editing this file.
2. Check your fstab file!
#Note: Only the root partition needs "1" at the end.
# Everything else should have either "2" or "0".
? There are times (due to power failure) in which an ext(3/4) file system can corrupt beyond normal repair.
? Normally, there will be a prompt from fsck indicating that it cannot find an external journal.
1. Unmount the partition based on its directory
$ umount <directory>
#Note: finde the mounted partitions and their directories with
#$ #TODO
2. Write a new journal to the partition
$ tune2fs -j /dev/<partition>
3. Run an fsck to repair the partition
$ fsck -p /dev/<partition>
### ##########################################################
#J# Tips
### ##########################################################
Changing the fsck check frequency to 20
$ tune2fs -c 20 /dev/sda1
#Note: In this example, 20 is the number of boots between two checks.
# If set to 1 makes it scan at every boot, while 0 would stop scanning altogether.
To see the frequency number and the current mount count for a specific partition
$ dumpe2fs -h /dev/sda1 | grep -i 'mount count'