malabar // boot netbsd on bare-metal and kvm

bsd/ext2fs | bsd/ext2fs-boot | xen guest | kvm guest

descr

for bare-metal or kvm, we need a boot-code and some place for it hence a partition table

requirements

grab NetBSD binary kernel

virtual disk

guest=nbext2fs

start clean

losetup --list
losetup --all
losetup --detach /dev/loop0

virsh list --all
virsh destroy $guest

prepare the vdisk

mkdir /root/guests/$guest/
cd /root/guests/$guest/

rm -f $guest.sparse
dd if=/dev/zero of=$guest.sparse bs=1G count=0 seek=10
# bs=1000k count=0 seek=4000

DOS partition & boot-code

prepare the DOS partitions

fdisk -v # util-linux 2.37.2
fdisk $guest.sparse

n p 1 2048 ALL t a9 a/BOOTABLE
p w

create the file-system

losetup --find --partscan --show $guest.sparse
ls -lF /dev/loop*

vdisk_partition=/dev/loop0p1

mkfs.ext2 -O^dir_index,^ext_attr $vdisk_partition
tune2fs -l $vdisk_partition | grep features
# ==> resize_inode filetype sparse_super large_file

and proceed

mkdir lala/
mount $vdisk_partition lala/
ls -alF lala/ # lost+found/
cp -v /data/kernels/netbsd100.pfcom lala/netbsd

grub-install --version # v2
grub-install --target=i386-pc --boot-directory=lala/boot $guest.sparse
# /dev/loop0

e.g. for KVM (ld0 and default/broken partition)

cat > lala/boot/grub/grub.cfg <<EOF
serial --unit=0 --speed=115200
terminal_input serial
terminal_output serial

set timeout=3

menuentry "netbsd" {
        insmod ext2
        set root=(hd0,msdos1)
        knetbsd /netbsd --serial=com0,115200 --root=ld0e
}
EOF

more options

serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1

kvm guest skeleton

cat > $guest <<EOF
<domain type='kvm'>
  <name>nbext2fs</name>
  <memory unit='GiB'>1</memory>
  <vcpu placement='static'>3</vcpu>
  <os>
    <type arch='x86_64' machine='q35'>hvm</type>
    <boot dev='hd'/>
  </os>
  <devices>
    <emulator>/usr/bin/qemu-system-x86_64</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='raw'/>
      <source file='/data/guests/nbext2fs/nbext2fs.sparse'/>
      <target dev='vda' bus='virtio'/>
    </disk>
    <interface type='bridge'>
      <source bridge='virbr0'/>
      <model type='virtio'/>
    </interface>
    <graphics type='vnc' port='5900' sharePolicy='allow-exclusive'>
      <listen type='address' address='127.0.0.1'/>
    </graphics>
    <serial type='pty'>
      <target type='isa-serial' port='0'>
        <model name='isa-serial'/>
      </target>
    </serial>
    <console type='pty'>
      <target type='serial' port='0'/>
    </console>
  </devices>
</domain>
EOF

ready to go

umount lala/
losetup --detach=/dev/loop0

virsh list --all
    virsh create $guest.xml --console

and in case nothing shows up, you can always check there

#xtightvncviewer localhost:5900

Additional notes

grub legacy hehaved differently, you could define several terminals and you would have to “Press Key” to pick one

terminal --timeout=1 serial console

Troubleshooting

ext2

modstat | grep ext2fs

# fsck_ext2fs /dev/xbd0a                                                       
** /dev/rxbd0a
BAD SUPER BLOCK: VALUES IN SUPER BLOCK DISAGREE WITH THOSE IN FIRST ALTERNATE

LOOK FOR ALTERNATE SUPERBLOCKS? [yn] y


CANNOT READ: BLK 8388608
CONTINUE? [yn] ^C

reproduce with

#mkfs.ext2 -r0 $guest.data.sparse
mkfs.ext2 -O^dir_index,^ext_attr $guest.data.sparse

disklabel -e xbd1 

 d:   8000000         0 Linux Ext2   4096     0        # (Cyl.      0 -   3906*)

fixed by mlelstvsbin/fsck_ext2fs/setup.c 1.36

resources

http://netbsd.gw.com/cgi-bin/man-cgi?disklabel+8

http://netbsd.gw.com/cgi-bin/man-cgi?newfs_ext2fs+8

http://netbsd.gw.com/cgi-bin/man-cgi?fsck_ext2fs+8

https://wiki.netbsd.org/users/mlelstv/using-large-disks/

https://www.netbsd.org/docs/guide/en/chap-misc.html#chap-misc-delete-disklabel

https://wiki.netbsd.org/tutorials/how_to_install_a_server_with_a_root_lfs_partition/

grub2

https://gnu.org/software/grub/manual/grub/grub.html

https://gnu.org/software/grub/manual/grub/html_node/Serial-terminal.html

https://gnu.org/software/grub/manual/grub/html_node/Simple-configuration.html

https://gnu.org/software/grub/manual/grub/html_node/terminal_005finput.html

https://gnu.org/software/grub/manual/grub/html_node/terminal_005foutput.html

https://gnu.org/software/grub/manual/grub/html_node/serial.html

grub legacy

https://gnu.org/software/grub/manual/legacy/terminal.html

https://gnu.org/software/grub/manual/legacy/Serial-terminal.html

https://web.archive.org/web/20220929170715/https://docstore.mik.ua/orelly/weblinux2/lian/ch04_04.htm

troubles

https://mail-index.netbsd.org/netbsd-users/2010/05/17/msg006226.html

http://www.netbsd.org/~jschauma/netbsd-solidstate.html


HOME | GUIDES | LECTURES | LAB | SMTP HEALTH | HTML5 | CONTACT
Copyright © 2024 Pierre-Philipp Braun