1: ## Installing NetBSD 8.0 on a x86 system with UEFI
3: Modern x86 machines have UEFI instead of BIOS firmware. Unfortunately, as of the upcoming NetBSD 8.0 release the installer does not fully support this setup. We hope to address this shortcoming quickly after the NetBSD 8.0 release and provide full automatic installations for this kind of systems (and also mixed operating system setups) in NetBSD 8.1.
5: This tutorial shows how to semi-manually do it. For simplicity we assume that you have booted the UEFI install image from a USB stick and want to install NetBSD onto the whole disk in the machine.
7: ### Getting out of the Installer
9: The install image will offer a menu item to exit the install system. Using that will drop you to a shell prompt.
11: ![screenshot of sysinst main menu](https://netbsd.org/images/misc/uefi/01_exit_installer.png "Exit the Installer")
13: ### Identifying Disks
15: At the shell prompt let us find out what disks we have and which one we want to install to. We can find out what disk devices have been recognized by the kernel via the sysctl program:
17: # sysctl hw.disknames
18: hw.disknames = ld0 wd0 cd0 sd0 dk0 dk1
20: This output is from a typical desktop machine. Depending on details a SSD will show up as *ld* (NVME device) or *wd* (SATA device). Hard disks usually show up as *wd* as well. Other disks may show up as *ld* or *sd* (SCSI, SAN, RAID, ...). USB sticks typically show up as *sd* devices.
22: So here we have a SSD as ld0, a hard disk as wd0, a blueray drive as cd0, and the install image on USB stick as sd0.
24: The *dk* devices are logical wedges (partitions) on the hardware devices, and this early after boot we usually see them in order, that is: dk0 and dk1 are partitions on the installer USB stick sd0. We can verify that by asking for a list of wedges on sd0:
26: # dkctl sd0 listwedges
27: /dev/rsd0: 2 wedges:
28: dk0: EFI system, 262144 blocks at 2048, type: msdos
29: dk1: 2dfc926e-42bd-43fb-9bb5-b227c2c3fc99, 2560000 blocks at 264192, type: ffs
31: Let us look at another example, this time from a typical notebook:
33: # sysctl hw.disknames
34: hw.disknames = wd0 dk0 dk1 dk2 dk3 sd0 dk4 dk5
36: Here the internal SSD is showing up as wd0, and has Windows pre installed (dk0 .. dk3). The install image USB stick again shows up as sd0 with two wedges dk4 and dk5.
38: Just to be sure let us check which device the installer booted from:
40: # dmesg | fgrep "root on"
41: root on dk5
43: and verify this is indeed on sd0:
45: # dkctl sd0 listwedges
46: /dev/rsd0: 2 wedges:
47: dk4: EFI system, 262144 blocks at 2048, type: msdos
48: dk5: 2dfc926e-42bd-43fb-9bb5-b227c2c3fc99, 2560000 blocks at 264192, type: ffs
50: Now for fun check the internal ssd:
52: # dkctl wd0 listwedges
53: /dev/rwd0: 4 wedges:
54: dk0: EFI system partition, 204800 blocks at 2048, type: msdos
55: dk1: Microsoft reserved partition, 32768 blocks at 206848, type:
56: dk2: Basic data partition, 409602048 blocks at 239616, type:
57: dk3: 2d02bc12-8433-4e41-ac12-f89167b1a93e, 1024000 blocks at 499093504, type:
59: **NOTE**: if you keep following this tutorial on a machine like the above, the windows installation will be destroyed and all data lost!
61: You can check more details about individual disks by extracting parts of the kernel output from the dmesg output. Assuming we want to install onto disk wd0, let us check for it:
63: # dmesg | fgrep wd0
64: wd0 at atabus4 drive 0
65: wd0: <WDC WD4002FFWX-68TZ4N0>
66: wd0: drive supports 16-sector PIO transfers, LBA48 addressing
67: wd0: 3726 GB, 7752021 cyl, 16 head, 63 sec, 512 bytes/sect x 7814037168 sectors
68: wd0: drive supports PIO mode 4, DMA mode 2, Ultra-DMA moded 6 (Ultra/133)
69: wd0(ahcisata1:0:0): using PIO mode 4, DMA mode 2, Ultra-DMA mode 6 (Ultra/133) (using DMA)
71: **NOTE** for this tutorial screenshots have been created using VirtualBox. The following example uses a strange tiny 30 GB (virtual) hard disk. Also on VirtualBox it is quite tricky (or impossible?) to actually boot from a USB device - instead the USB install image was converted to a virtual disk image and the machine booted from that. This makes the install image show up as *wd1*.
73: Here are the target disk details:
75: ![screenshot of wd0 dmesg details](https://netbsd.org/images/misc/uefi/02_hard_disk_details.png "Disk Details")
77: ### Size Calculations
79: So now that we have identified the disk and got the details, we need to plan our disk layout.
81: We will need two partitions, one for UEFI to boot from, and the NetBSD root disk partition. Depending on planed use for the machine, we also will want a swap partition. This should not be smaller than the machines RAM size, so in case of a kernel panic a crash dump can be saved and recovered on next reboot. For this example let us calculate with 8 GB RAM and no special needs for more swap.
83: So we have a 30 GB disk, we subtract 8 GB of swap and a bit of space for the UEFI boot partition. That leaves us with (rounded down) 21 GB of space for the main NetBSD partition.
85: ### Partitioning and Formating the Disk
87: **NOTE** we are about to fully destroy all contents on this disk! Please stop if you are unsure or have no proper backup!
89: Just to make sure, we kill any old partition data on the disk:
91: # gpt destroy wd0
93: Next we create a new partition table and add the partitions with the sizes calculated above (the EFI partition usually is quite small):
95: # gpt create wd0
96: # gpt add -a 2m -l "EFI system" -t efi -s 128m wd0
97: # gpt add -a 2m -l NetBSD -t ffs -s 21g wd0
98: # gpt add -a 2m -l swap -t swap wd0
100: Then we check the result
102: # gpt show wd0
104: Note that the kernel messages between the commands also show us the wedge names (dk0...dk4) of the individual partitions we have just created. The mapping between partitions on a disk and wedge (dk) devices is not fixed, you can see below that managing partitions removes all old wedge devices and adds new ones.
106: ![screenshot of wd0 partitioning](https://netbsd.org/images/misc/uefi/03_create_gpt.png "Partitioning the Disk")
108: Just to make double sure, let us list the wedges on wd0 explicitly:
110: # dkctl wd0 listwedges
112: Now we need to format the EFI partition as type msdos, and the NetBSD partition as type ffs. Also we create a directory "EFI/boot" on the EFI partition and copy the bootloaders there.
114: The commands for this are:
116: # newfs_msdos /dev/rdk2
117: # mount -t msdos /dev/dk2 /mnt
118: # mkdir -p /mnt/EFI/boot
119: # cp /usr/mdec/*.efi /mnt/EFI/boot
120: # umount /mnt
121: # newfs -O 2 dk3
123: and it looks like this:
125: ![screenshot of wd0 formatting](https://netbsd.org/images/misc/uefi/04_manual_init.png "Formatting the Disk")
127: ### Main Installation
129: Now we are mostly done. We can leave the shell and return to the installer (sysinst). Type Ctrl-D or use the "exit" command.
131: Back in sysinst we choose "Install NetBSD to hard disk":
133: ![screenshot of sysinst](https://netbsd.org/images/misc/uefi/05_back_in_sysinst_install.png "Back in Sysinst")
135: The next steps are mostly the same as for other sysinst installations. We have to confirm (but actually all harm is already done as we manually repartitioned the disk above):
137: ![screenshot of sysinst asking for install confirmation](https://netbsd.org/images/misc/uefi/06_yes_i_mean_it.png "Are we sure?")
139: Since we already prepared everything, we can select a preformatted wedge (which we did name "NetBSD" above):
141: ![screenshot of sysinst selecting the target disk](https://netbsd.org/images/misc/uefi/07_select_target_wedge.png "Select the target wedge")
143: *NOTE* if you paid close attention, you will notice a bug in this screenshot. The dk1@wd1 wedge (right above the real target) would be dk1@sd0 on real hardware. That is: this is the install image root partition, which we currently have mounted. Sysinst should not offer this wedge here - a bug that might be fixed before the actual 8.0 release (but not in time for this tutorial).
145: Not quite usefull in this semi-manual setup, but sysinst asks again for confirmation:
147: ![screenshot of sysinst asking for confirmation again](https://netbsd.org/images/misc/uefi/08_go_for_it.png "Are we still sure?")
149: Sysinst does not know about the EFI boot partition, but it recognizes there is a swap partition on the same disk as the target partition we have selected. It correctly assumes that we will want to use this for swapping and offers to add it to the installed systems swap configuration:
151: ![screenshot of sysinst offering the swap partition](https://netbsd.org/images/misc/uefi/09_use_my_swap.png "Use the swap partition?")
153: Now just follow the remaining sysinst steps - they are the same as all other x86 NetBSD installations.
CVSweb for NetBSD wikisrc <wikimaster@NetBSD.org> software: FreeBSD-CVSweb