Annotation of wikisrc/kernel_debugging_with_qemu.mdwn, revision 1.3
1.1 wiki 1: # Introduction
2:
1.2 wiki 3: Virtual machines are a convenient way to test, debug or even audit different systems on one single host. This is particularly helpful when you need to set up a machine for which you do not necessarily have the hardware, or the access, in a very cheap way, without risking breaking your day-to-day system.
1.1 wiki 4:
1.2 wiki 5: This tutorial show the different steps required to set up a raw disk image like the one used by QEMU. It deals with two different point of views:
1.3 ! wiki 6:
1.1 wiki 7: * the host, which is the machine and OS hosting the different VMs.
8: * the guest(s), representing the different systems emulated/hosted on the host, through QEMU.
9:
10: # Setting up the environment
11:
1.2 wiki 12: ## Creating the raw disk image
13:
1.1 wiki 14: To start our VM, we need some disk space to provide an emulated hard drive. For QEMU, by default, this is done through raw disk images. Therefore, the first step will be the creation of a disk image file. Here, we create a 2GB file, filled with zeros:
15:
1.3 ! wiki 16: [[!template id=programlisting text="""
! 17: $ dd if=/dev/null of=netbsd-guest.img bs=1m count=2000
! 18: """]]
1.1 wiki 19:
20: /!\ if you want to mount the file image from within the host later through [[!template id=man name="vnconfig" section="8"]], it is recommended to use [[!template id=man name="dd" section="1"]] and not the *qemu-img* tool, as [[!template id=man name="vnd" section="4"]] does not support sparse disk image yet.
21:
1.2 wiki 22: Now that the disk image file is ready, we will need to install our system inside.
23:
1.3 ! wiki 24: ## Preparing the MBR, labels, and first stage boot loader
! 25:
! 26: Mount the image file as a [[!template id=man name="vnd" section="4"]] device. This will allow manipulating the image file just like a regular hard disk drive:
1.2 wiki 27:
1.3 ! wiki 28: [[!template id=programlisting text="""
! 29: # vnconfig -c vnd0 netbsd-guest.img
! 30: """]]
! 31:
! 32: ### Creating MBR
! 33:
! 34: Setup the MBR; it musts contain the NetBSD partition. This will be done interactively via [[!template id=man name="fdisk" section="8"]]:
! 35:
! 36: [[!template id=programlisting text="""
! 37: # fdisk -u -a -0 /dev/rvnd0
! 38: Disk: /dev/rvnd0d
! 39: [...]
! 40: Do you want to change our idea of what BIOS thinks? [n] *n*
! 41:
! 42: Partition 0:
! 43: <UNUSED>
! 44: The data for partition 0 is:
! 45: <UNUSED>
! 46: sysid: [0..255 default: 169] *press enter*
! 47: start: [0..255dcyl default: 63, 0dcyl, 0MB] *press enter*
! 48: size: [0..255dcyl default: 4095937, 255dcyl, 2000MB] *press enter*
! 49: bootmenu: [] *press enter*
! 50: Do you want to change the active partition? [n] *y*
! 51: Choosing 4 will make no partition active.
! 52: active partition: [0..4 default: 0] *press enter*
! 53: Are you happy with this choice? [n] *y*
! 54: We haven't written the MBR back to disk yet. This is your last chance.
! 55: Partition table:
! 56: 0: NetBSD (sysid 169)
! 57: start 63, size 4095937 (2000 MB, Cyls 0-254/245/55), Active
! 58: PBR is not bootable: All bytes are identical (0x00)
! 59: 1: <UNUSED>
! 60: 2: <UNUSED>
! 61: 3: <UNUSED>
! 62: Bootselector disabled.
! 63: First active partition: 0
! 64: Should we write new partition table? [n] *y*
! 65: """]]
! 66:
! 67: ### Editing labels
! 68:
! 69: Edit the labels, with [[!template id=man name="disklabel" section="8"]]. The example below will create:
! 70:
! 71: * label **a**, approximately 1.5GiB long -- will contain the future FFS / partition
! 72: * label **b**, 512MiB swap.
! 73:
! 74: [[!template id=programlisting text="""
! 75: # disklabel -e -I /dev/rvnd0
! 76: [...]
! 77: 4 partitions:
! 78: # size offset fstype [fsize bsize cpg/sgs]
! 79: a: 3047361 63 4.2BSD 0 0 0 # (Cyl. 0*- 1487)
! 80: b: 1048576 3047424 swap # (Cyl. 1488 - 1999)
! 81: d: 4096000 0 unused 0 0 # (Cyl. 0 - 1999)
! 82: """]]
! 83:
! 84: ### Copying first stage boot loader
! 85:
! 86: Lastly, we have to install the first stage boot loader, the one that will be able to read the second stage boot loader, which will reside in partition **a**. Use [[!template id=man name="installboot" section="8"]]:
! 87:
! 88: [[!template id=programlisting text="""
! 89: # installboot /dev/rvnd0a /usr/mdec/bootxx_ffsv2
! 90: """]]
! 91:
! 92: ## Format and mount the filesystem
! 93:
! 94: With [[!template id=man name="newfs" section="8"]], format label **a** in FFSv2:
! 95:
! 96: [[!template id=programlisting text="""
! 97: # newfs -O2 /dev/rvnd0a
! 98: /dev/rvnd0a: 1488.0MB (3047360 sectors) block size 16384, fragment size 2048
! 99: using 9 cylinder groups of 165.34MB, 10582 blks, 20544 inodes.
! 100: super-block backups (for fsck_ffs -b #) at:
! 101: 160, 338784, 677408, 1016032, 1354656, 1693280, 2031904, 2370528, 2709152,
! 102: """]]
! 103:
! 104: then [[!template id=man name="mount" section="8"]] it:
! 105:
! 106: [[!template id=programlisting text="""
! 107: # mkdir /tmp/netbsd-guest
! 108: # mount /dev/vnd0a /tmp/netbsd-guest
! 109: """]]
1.2 wiki 110:
111: # Installing the system
112:
113: ## Quick and easy way
114:
115: ## Through build.sh
116:
117: # Configuring the system
118:
119: # Starting-up the VM
1.1 wiki 120:
1.3 ! wiki 121: # Debugging
! 122:
1.2 wiki 123: # Convenient scripts
CVSweb for NetBSD wikisrc <wikimaster@NetBSD.org> software: FreeBSD-CVSweb