--- title: NetBSD VM Installation Instructions --- OK, here we go... First of all, I do not expect you to solve all the problems you run into on you own. It is good if you do try. But don't spend too much time on it. Give it a try and then ask me for help, please. I will try had to not make too many assumptions. And I expect that you try to read documenation and man pages. But I will give you hints on what to read and what to look for. We also need to establish some common ground. Let's start with a bit of directory organization. I've made a "netbsd-gsoc" directory in my home directory (~ is an abbreviation for the home directory) and created a directory "vm" to hold files realted to the NetBSD VM. ``` mkdir ~/netbsd-gsoc cd ~/netbsd-gsoc mkdir vm cd vm ``` I visited http://mail-index.netbsd.org/netbsd-announce/2024/02/thread1.html to look at the NetBSD 10.0 RC5 announcement and followed the first link to the "iso" directory with the CD images. Then downloaded the ISO image for amd64: ``` ftp https://cdn.netbsd.org/pub/NetBSD/NetBSD-10.0_RC5/iso/NetBSD-10.0_RC5-amd64.iso cd .. ``` Now I am in the ~/netbsd-gsoc directory again. Yesterday I experimented with virt-manager, but I find the UI confusing for what I want to do. So today I experimented with qemu. As I said yesterday, the -kernel option is not correct. First lets create a file that will serve as the virtual disk for the VM. ``` qemu-image create -f qcow2 vm/netbsd10.0-root 10g ``` This sets up an image file that can hold 10 GB. It is actually smaller, but will grow with usage. Then I created a VM with the following command ``` qemu-system-x86_64 -M q35 -cpu host -accel kvm -smp 2 -m 2g \ -object rng-random,id=rng0,filename=/dev/urandom -device virtio-rng,rng=rng0 \ -nic user,model=virtio-net-pci \ -drive if=ide,index=0,id=wd0,file=vm/netbsd10.0-root \ -drive if=ide,index=1,id=cd0,file=vm/NetBSD-10.0_RC5-amd64.iso,media=cdrom \ -nographic \ -boot once=d ``` NetBSD really needs a random number generator, that's what the second line is for. The "-nographic" option sometimes leaves the terminal behind in a weird state. In that case use "tput smam" or "tput reset" to reset the terminal. The "-boot once=d" is only necessary to boot from the ISO image to install the NetBSD in the VM. You can leave that and the second "-drive ..." line out on after initial installation. (Also do not include the "\" after the "-nographic" in that case.) (It doesn't hurt to leave in the "-drive ... media=cdrom line", we just don't normally need the installation ISO image to be available.) Also, instead of "-nographic" using "-display curses" worked well for me. But let us use "-nographic". The first thing that shows is the NetBSD/x86 BIOS Boot loader. We need to tell it to use the serial device as console. In the "-nographic" case: Press SPACE to stop the countdown. The press 3 to "Drop to the boot prompt". Then enter ``` consdev com0,115200 boot ``` When prompted for the terminal type, enter "xterm" and hit ENTER. End of "-nographic" case. The system starts the "sysinst" installer and paints the background blue. Take your time to read the messages. I'll just give you instructions on how to proceed in the quickst way. Press ENTER. Press ENTER again to select "a: Install NetBSD to hard disk". Press "b" and ENTER. Press ENTER to select "wd0" and press ENTER again. Press ENTER to select "Guid Partition Table (GPT)". Press ENTER. Press "b" for "Use the default partition sizes" and ENTER. Press ENTER for "x: Partition sizes ok". Press "b" and ENTER. Select "a: BIOS console" and ENTER. Select "x: Continue" and press ENTER. Next select "d: Custom installation". Select "g: Compiler tools" and ENTER. Select "i: Manual pages" and ENTER. Select "l: Test programs" and ENTER. Select "q: Source and debug sets" and ENTER. Select "f: Debug symbols" and ENTER. Select "x: Install selected sets" and ENTER. Select "x: Install selected sets" and ENTER. Press ENTER to install from CD-ROM. The installer extracts the distribution sets and then prompts you to "Hit enter to continue". Do so. Set a root password. You are now at the menu to configure additional items. Now you have to be very careful and do exactly what I describe. This is a week area of the installer and any errors are not easily correctable except by restarting the installer from scratch. Select "a: Configure network" and ENTER. Select "a: vioif0" and ENTER. Press ENTER at the "Network media type:" prompt. Do NOT enter anything else. Press ENTER to perform autoconfiguration. Enter "netbsd10" for the host name and "local" for the DNS domain. Check the values that are presented and if they are OK press ENTER to acknowlege them. The "Host IP" should be "10.0.2.15". Press ENTER to install the setting to /etc. Press "g" and ENTER to Enable sshd. Press "o" and ENTER to add a user for youself. (You can abort this by leaving the user name empty.) Select "a" and press ENTER to add the user to group wheel. You need this so that the user can use "su" and "sudo" to become root. Press ENTER to select /bin/sh as the shell. Enter a password. Select "x: Finished configuring" Press ENTER. Select "d: Reboot the computer" and press ENTER. You may have to use the "consdev" dance in the boot loader again, if you booted with "nographic" The VM reboots from the virtual disk and you can login as the user that you created or as root. Wow, it took me 2 hours to go through all the steps and write them down in this email. But I had to restart the installation a couple of times because I got confused about what exactly I did. It will take you less time. Now lets have some fun! Log in to the VM as your user and run the following commands: ``` cd /usr/tests/fs/nullfs atf-run | atf-report ``` Congrats, we have run some quick tests for the nullfs file system and they all passed! This test uses rump to run exercise the file system code in user space. Yay! To stop the VM execute "su root -c "shutdown -p now". #xxx - more tasks You can do the following when you have time. You will have to do this if you start the project in earnest. - If you intend to boot the VM with the -nographic option of qemu, configure /boot.cfg. `vi /boot.cfg` insert the string "consdev com0,115200;" before every occurance of "rndseed". Save and exit the editor. - duplicate the first menu= line of /boot.cfg and append "netbsd.old" to the line; replace "normally" with "old kernel" on that line. - install your ssh public key in the VM in ~/.ssh/authorized_keys so that you can log in without password. Become root with su(1) and copy the authorized_keys-file to /root/.ssh. Pay attention to file ownership and permissions. - add the following 3 lines early in your ~/.ssh/config file: Host nbvm Hostname 127.1 Port 2222 Start the vm with "run-qemu --ssh" and verify that you can slogin into the VM as unprivileged user and root. - install 3 packages in the VM ssh into the VM as root. start "sysinst" Go to the utility menu and - turn on logging - turn on scripting Go to the config menu and - enable installation of binary packages - network configuration is ok - do not install the network configuration in /etc. (you already did when you installed the VM) - "g: additional packages" "sudo screen" - "x install pkgin and update package summary" - you can also install the "comp" set. That contains the compiler, debugger an other software development commands. Kinda like "build-essential" on Linux. Doing so should reduce the number of failures when you run "atf-run" in /usr/tests. - exit from sysinst the log and script files are in /tmp/sysinst.*. save them to your laptop with scp(1). - configure sudo. As root run "visudo", find the first lines that has "%wheel" and uncomment it by deleting the first 2 characters. It should read "%wheel ALL=(ALL:ALL) ALL". Save the file and exit from the editor. Verify that as the unprivileged user you can "sudo -s" and become root by entering your password. - share local directories with the VM build a NetBSD kernel with vio9p(4) enabled ``` cd src cat >> sys/arch/amd64/conf/GENERIC.local <<-EOT vio9p* at virtio? # Virtio 9P device EOT run-build.sh -j6 -u kernel=GENERIC 2>&1 >>$TD/logs/build-kernel.log.YYYYMMDD ``` at the end of the log file, build.sh prints where exactly the kernel is. log in as root to the VM and move /netbsd to /onetbsd scp as root the new kernel to the VM as /netbsd shutdown the VM Restart the VM by running ``` cd ~/netbsd-gsoc run-qemu.sh --ssh --fsdev src,ro ``` log into the vm as root. run "dmesg |grep vio9p". It should show lines about "vio9p0". create the device nodes for vio9p devices. ``` cd /dev sh MAKEDEV vio9p0 vio9p1 ``` you can mount the shared file system with e.g. ``` mount -r -t 9p -o-c,-u /dev/vio9p0 /mnt ``` run "ls /mnt" to verify that there are files in /mnt. You can do the same for the "obj" directory. But it needs to be writeable. Use ``` --fsdev obj ``` And leave out the option "-r" in the mount command line. You also need to remove "readonly=on" from the "-fsdev" argument. You will probably need to change "security_model=none" to something else. I haven't tested that. The qemu documentation at https://www.qemu.org/docs/master/ may be helpful. If you run into trouble, please let me know. If you succeed you can try running some ATF tests. E.g. in the VM ``` cd /mnt/destdir.amd64/usr/tests/fs/nullfs && atf-run | atf-report ``` - if you feel adventurous modify a test case. E.g. ``` cd src/tests/fs/nullfs ``` edit t_basic.c to print some messages. compile and install the test program. ``` # still in src/tests/fs/nullfs nbmake-amd64 && nbmake-amd64 install ``` Now you can run the test program manually in the VM. ``` cd /mnt/destdir.amd64/usr/tests/fs/nullfs ./t_basic -l ./t_basic basic ``` You should see the messages that you have added.