1: # Installing NetBSD on a x86 system with UEFI
3: Modern x86 machines have UEFI instead of BIOS firmware.
4: The boot procedure is slightly different, and the installation needs to take care of this.
6: Starting with NetBSD 9.0 the installer should be able to handle this automatically. Earlier NetBSD versions were able to boot in this setups, but needed a bit manual help to get everything installed.
8: As of now NetBSD/amd64 provide separate images for installation, depending on how your machine boots. This will be integrated into a single image in the (near?) future. If you look at the <a href="//nycdn.NetBSD.org/pub/NetBSD-daily/HEAD/latest/images/">images</a> directory of your NetBSD release you will find
9: a `NetBSD-XXX-amd64-uefi-install.img.gz`, which is intended to be written to a USB disk and booted via UEFI. Alternatively there are `NetBSD-XXX-amd64-install.img.gz` and `NetBSD-XXX-i386-install.img.gz`, also intended to be written to USB sticks and booted via BIOS. Or if your machine has a DVD drive, there are `NetBSD-XXX-i386.iso` and `NetBSD-XXX-amd64.iso`, intended to be burned to a CD or DVD.
11: Preparing the USB medium on NetBSD works like this:
13: # gunzip NetBSD-9.0-amd64-uefi-install.img.gz
14: # sudo dd if=NetBSD-9.0-amd64-uefi-install.img of=/dev/rsd0d bs=1m conv=sync
16: If you do not (yet) have a NetBSD machine installed, you can use <a href="//www.NetBSD.org/~martin/rawrite32">Rawrite32</a> on a Windows machine.
18: ## Installing NetBSD 9.0 or newer on a x86 system with UEFI
20: After booting from the USB stick there is nothing special you need to do to get UEFI booting set up properly. The installer will recognize the way you booted your install medium (either BIOS or UEFI) and prepare the installation on your hard disk for the same boot method.
22: First you need to select the target disk. The installation USB stick will usually show up as sd0.
24: ![screenshot of sysinst disk selection](https://netbsd.org/images/misc/uefi/uefi9_01.png "Select Disk")
26: Here we have an (artificially tiny) harddisk wd0 and select that as install target. In this setup the disk had been completely wiped before, so now we can choose what type of partitioning scheme we want to use. GPT is the more universal method, and also allows using disks of arbitrary size.
28: ![screenshot of sysinst partitioning scheme selection](https://netbsd.org/images/misc/uefi/uefi9_02.png "Select type of partitions")
30: After the partitioning scheme selection (which will be skipped if the installer already finds valid partitions on your disk) you are presented size suggestions for the to-be-created NetBSD partitions.
32: ![screenshot of sysinst partition size display](https://netbsd.org/images/misc/uefi/uefi9_03.png "Partition Sizes")
34: Details depend on the size of the target disk and available memory (swap is also used to store kernel crash dumps, so with more installed RAM the installer will suggest bigger swap partitions). Note the MSDOS partition on the above screenshot, it is used by UEFI instead of bootblocks to load the bootloader.
36: Just continue the regular installation process from here - it should automatically create a UEFI bootable hard disk.
38: ## Installing NetBSD 8 on a x86 system with UEFI
40: Unfortunately the installer on the netbsd-8 branch does not fully support an UEFI setup.
42: The tutorial below shows (__only for NetBSD 8.x!__) 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.
44: ### Getting out of the Installer
46: The install image will offer a menu item to exit the install system. Using that will drop you to a shell prompt.
48: ![screenshot of sysinst main menu](https://netbsd.org/images/misc/uefi/01_exit_installer.png "Exit the Installer")
50: ### Identifying Disks
52: 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:
54: # sysctl hw.disknames
55: hw.disknames = ld0 wd0 cd0 sd0 dk0 dk1
57: 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.
59: 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.
61: 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:
63: # dkctl sd0 listwedges
64: /dev/rsd0: 2 wedges:
65: dk0: EFI system, 262144 blocks at 2048, type: msdos
66: dk1: 2dfc926e-42bd-43fb-9bb5-b227c2c3fc99, 2560000 blocks at 264192, type: ffs
68: Let us look at another example, this time from a typical notebook:
70: # sysctl hw.disknames
71: hw.disknames = wd0 dk0 dk1 dk2 dk3 sd0 dk4 dk5
73: 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.
75: Just to be sure let us check which device the installer booted from:
77: # dmesg | fgrep "root on"
78: root on dk5
80: and verify this is indeed on sd0:
82: # dkctl sd0 listwedges
83: /dev/rsd0: 2 wedges:
84: dk4: EFI system, 262144 blocks at 2048, type: msdos
85: dk5: 2dfc926e-42bd-43fb-9bb5-b227c2c3fc99, 2560000 blocks at 264192, type: ffs
87: Now for fun check the internal ssd:
89: # dkctl wd0 listwedges
90: /dev/rwd0: 4 wedges:
91: dk0: EFI system partition, 204800 blocks at 2048, type: msdos
92: dk1: Microsoft reserved partition, 32768 blocks at 206848, type:
93: dk2: Basic data partition, 409602048 blocks at 239616, type:
94: dk3: 2d02bc12-8433-4e41-ac12-f89167b1a93e, 1024000 blocks at 499093504, type:
96: **NOTE**: if you keep following this tutorial on a machine like the above, the windows installation will be destroyed and all data lost!
98: 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:
100: # dmesg | fgrep wd0
101: wd0 at atabus4 drive 0
102: wd0: <WDC WD4002FFWX-68TZ4N0>
103: wd0: drive supports 16-sector PIO transfers, LBA48 addressing
104: wd0: 3726 GB, 7752021 cyl, 16 head, 63 sec, 512 bytes/sect x 7814037168 sectors
105: wd0: drive supports PIO mode 4, DMA mode 2, Ultra-DMA moded 6 (Ultra/133)
106: wd0(ahcisata1:0:0): using PIO mode 4, DMA mode 2, Ultra-DMA mode 6 (Ultra/133) (using DMA)
108: **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*.
110: Here are the target disk details:
112: ![screenshot of wd0 dmesg details](https://netbsd.org/images/misc/uefi/02_hard_disk_details.png "Disk Details")
114: ### Size Calculations
116: So now that we have identified the disk and got the details, we need to plan our disk layout.
118: We will need two partitions, one for UEFI to boot from, and the NetBSD root disk partition. Depending on planned use for the machine, we also will want a swap partition. This should not be smaller than the machine's 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.
120: 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.
122: ### Partitioning and Formating the Disk
124: **NOTE** we are about to fully destroy all contents on this disk! Please stop if you are unsure or have no proper backup!
126: Just to make sure, we kill any old partition data on the disk:
128: # gpt destroy wd0
130: Next we create a new partition table and add the partitions with the sizes calculated above (the EFI partition usually is quite small):
132: # gpt create wd0
133: # gpt add -a 2m -l "EFI system" -t efi -s 128m wd0
134: # gpt add -a 2m -l NetBSD -t ffs -s 21g wd0
135: # gpt add -a 2m -l swap -t swap wd0
137: Then we check the result:
139: # gpt show wd0
141: 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.
143: ![screenshot of wd0 partitioning](https://netbsd.org/images/misc/uefi/03_create_gpt.png "Partitioning the Disk")
145: Just to make double sure, let us list the wedges on wd0 explicitly:
147: # dkctl wd0 listwedges
149: 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.
151: The commands for this are:
153: # newfs_msdos /dev/rdk2
154: # mount -t msdos /dev/dk2 /mnt
155: # mkdir -p /mnt/EFI/boot
156: # cp /usr/mdec/*.efi /mnt/EFI/boot
157: # umount /mnt
158: # newfs -O 2 dk3
160: and it looks like this:
162: ![screenshot of wd0 formatting](https://netbsd.org/images/misc/uefi/04_manual_init.png "Formatting the Disk")
164: ### Main Installation
166: Now we are mostly done. We can leave the shell and return to the installer (sysinst). Type Ctrl-D or use the "exit" command.
168: Back in sysinst we choose "Install NetBSD to hard disk":
170: ![screenshot of sysinst](https://netbsd.org/images/misc/uefi/05_back_in_sysinst_install.png "Back in Sysinst")
172: 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):
174: ![screenshot of sysinst asking for install confirmation](https://netbsd.org/images/misc/uefi/06_yes_i_mean_it.png "Are we sure?")
176: Since we already prepared everything, we can select a preformatted wedge (which we did name "NetBSD" above):
178: ![screenshot of sysinst selecting the target disk](https://netbsd.org/images/misc/uefi/07_select_target_wedge.png "Select the target wedge")
180: *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).
182: Not quite usefull in this semi-manual setup, but sysinst asks again for confirmation:
184: ![screenshot of sysinst asking for confirmation again](https://netbsd.org/images/misc/uefi/08_go_for_it.png "Are we still sure?")
186: 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:
188: ![screenshot of sysinst offering the swap partition](https://netbsd.org/images/misc/uefi/09_use_my_swap.png "Use the swap partition?")
190: 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