summaryrefslogtreecommitdiff
path: root/hurd/running/qemu.mdwn
blob: 9f085d2442c431b8fa7bca32af5b3b064b7e84fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
[[!meta copyright="Copyright © 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free
Software Foundation, Inc."]]

[[!meta license="""[[!toggle id="license" text="GFDL 1.2+"]][[!toggleable
id="license" text="Permission is granted to copy, distribute and/or modify this
document under the terms of the GNU Free Documentation License, Version 1.2 or
any later version published by the Free Software Foundation; with no Invariant
Sections, no Front-Cover Texts, and no Back-Cover Texts.  A copy of the license
is included in the section entitled [[GNU Free Documentation
License|/fdl]]."]]"""]]

This page discusses things for [[Unix]] systems, there is a separate page for
[[Microsoft_Windows]] systems.

# Readily Available Images

You can use the following images to give the GNU/Hurd a try.

## Debian GNU/Hurd

[[!inline pages=hurd/running/debian/qemu_image raw=yes feeds=no]]

## Unofficial Images

Note that the following images are unofficial ones: they have been prepared by
volunteers and may not have been tested extensively.

* [Disk image](http://draketo.de/dateien/hurd/bab-hurd-qemu-2008-10-29.img.tar.bz2) 
  with a short intro on translators. Just start it with 'qemu *disk_image.img*'. 
  It should work without any of the configuration below. If you want to know what you can do 
  with it, please have a look at [[its_wikipage|hurd/running/qemu/babhurd_image]]. And when 
  you use it, please [tell me your experience with it](http://draketo.de/contact)! - [[community/weblogs/ArneBab]]

# Arch Hurd Live CD

Also you can use QEMU to easily try one of the
[[Hurd_LiveCDs|hurd/running/live_cd/]].


# What is Needed to create a QEMU image

## Debian Installer

Instructions for creating a qemu image from the install CDs from debian installer can be found in the README alongside the d-i Hurd images: <http://people.debian.org/~sthibault/hurd-i386/installer/cdimage/>

## Old method

1. First thing is to install [[/QEMU]].
2. A [[grub]] boot disk for the floppy disk image needed for booting. The [0\.97 version](ftp://alpha.gnu.org/gnu/grub/grub-0.97-i386-pc.ext2fs) works fine. I downloaded it and renamed to `floppy.img`. Alternatively, the Debian grub-disk package (up till version 0.97-28) is fine as well.
3. You will need a [Debian/Hurd installation CD](http://www.debian.org/ports/hurd/hurd-cd). K16 works fine.

# KVM acceleration

Check if your CPU supports kvm:

    $ egrep '^flags.*(vmx|svm)' /proc/cpuinfo

#### If you don't have hardware support (slow):
    $ apt-get install qemu

Do not enable kernel-kqemu, as that assumes some particular behavior from the guest kernel, which we are reluctant to artificially add to gnumach.

If QEMU with KVM is not available, [[Virtualbox]] reportedly has better
performance.

#### If you have hardware support (recommended):
    $ apt-get install qemu-kvm
    $ modprobe kvm

Intel VTx/VTd: Enable Intel kvm in the BIOS

On a HP xw4600 Workstation: F10, Security->System Security; Enable VTx and VTd

Check that the kvm module is loaded:

    $ lsmod|grep kvm
    kvm_intel              38050  0
    kvm                   213800  1 kvm_intel

    $ ls -l /dev/kvm
    crw-rw----+ 1 root kvm 10, 232 Mar 14 15:02 /dev/kvm

Add yourself to the kvm group: 

    $ adduser your_user kvm; logout; login

AMD SVM (AMD-V): Enable AMD-V in the BIOS if not enabled.

Check that the kvm module is loaded:

    $ lsmod|grep kvm
    kvm_amd               31862  0
    kvm                   214088  1 kvm_amd

More info on kvm at: http://www.linux-kvm.org/page/FAQ

If your machine supports hardware acceleration, you should really use the kvm variant of qemu, as it speeds things quite a lot. Note however that kvm tends to make assumptions when accelerating things in the linux kernel, you may need some -no-kvm-something option. At the moment in Debian you need to pass

    -no-kvm-irqchip

to the command line, see below, if you are running Linux kernels 2.6.37 or 2.6.38 else IRQs may hang sooner or later. The kvm irq problems will be solved in kernel 2.6.39. 

# Installing Debian/Hurd with QEMU using the Debian installer

Note: If you have hardware support, replace the qemu commands below with kvm, e.g. qemu-ing -> kvm-img.

First off you will need to create a disk image using `qemu-img`. I have set mine to 4 GiB, although you should be able to get away with less.

    $ qemu-img create hd0.img 4G

Next you will want to start up QEMU and begin the installation process.

    $ qemu -m 512 -hda hd0.img -cdrom mini.iso -net nic,model=rtl8139 -net user

Now at his point do the regular install using `hd0` as your harddrive. Partition it and install the base system.

In the installer make your choice of install option: Default install (or your choice)

    Language: English
    Country, territory or area: your_choice
    Locale: your_choice

Note that even if you can set the country and locale, your local keyboard is not yet supported.

In case of problems with timezone or locale settings do the following after the installation is completed

    To get the correct timezone:
    $ dpkg-reconfigure tzdata
    To get your locale setting: 
    $ nano /etc/locale.gen
    $ locale-gen

Network: Now configured automatically with dhcp

    IP address: 10.0.2.15
    Netmask: 255.255.0.0
    Gateway: 10.0.2.2
    Nameserver: 10.0.2.3

    Qemu network setup:
    QEMU VLAN     <------>  Firewall/DHCP server <-----> Internet
                      |          (10.0.2.2)
                      |
                      ---->  DNS server (10.0.2.3)
                      |
                      ---->  SMB server (10.0.2.4)

Partitioning method: Guided (or your choice)

Partitioning `/dev/hd0`: All files in one partition.

**Important**: Since partman does not yet mount other partitions than / automatically at reboot, it is crucial that you choose this option for now.

Once you have finished installing the base system (might take some time) the system is rebooted and next boot will be from the hard disk. Now you are able to log in to your newly installed GNU/Hurd system. 

Also see another text about how to [[gnu/create_an_image]] for the
[[GNU_system|gnu]].

## Running the installed system

Starting qemu/qemu-kvm:

    $ kvm -m 512 -net nic,model=rtl8139 -net user,hostfwd=tcp::5555-:22 -hda hd0.img -vga vmware
    vmsvga_value_write: guest runs Linux.

Note: See below on port forwarding in the networking section.

Note: Using the vmware vga driver is useful for setting up X windows, see [Debian GNU/Hurd](http://www.debian.org/ports/hurd/hurd-install)

If you have problems with grub hanging during boot with the vmware vga driver: Disable the graphic boot

    $ nano /etc/default/grub
    uncomment GRUB_TERMINAL=console
    $ /usr/sbin/update-grub

### A few words about the qemu console

During the graphical emulation, you can use the following keys:

    <Ctrl><Alt>-f Toggle full screen
    <Ctrl><Alt>-u Restore the screen's un-scaled dimensions
    <Ctrl><Alt>-n Switch to virtual console 'n'. Standard console mappings are:
    1 Target system display
    2 Monitor
    3 Serial port
    <Ctrl><Alt> Toggle mouse and keyboard grab.


# Transferring Files

## Mounting Disk Image on Host

You may wish to mount your disk image on your host system to transfer files. To do this you will first need to find the offset of the partition you wish to mount.

    # fdisk -ul hd0.img
    ...
    128 heads, 63 sectors/track, 0 cylinders, total 0 sectors
    Units = sectors of 1 * 512 = 512 bytes

       Device Boot      Start         End      Blocks   Id  System
    hd0.img1   *          63     3515903     1757920+  83  Linux
    hd0.img2         3515904     4193279      338688   82  Linux swap / Solaris

Now take the number of sectors for the beginning of the partition and multiply it by the sector size. My partition starts at sector 63 and I have a sector size of 512 therefore my offset is 32256. For a start at 2048 the ofsset is 1048576.

    # mount -o loop,offset=32256 hd0.img /mnt/diskimage

## Having QEMU create *virtual FAT disk images*

[Link to the manual](http://www.nongnu.org/qemu/qemu-doc.html#SEC25).

QEMU has a facility to create FAT file systems on-the-fly:

    qemu [...] -hdc fat:[somewhere]

The Hurd [[`fatfs`_translator|translator/fatfs]] currently is read-only, but
for testing executables (etc.) that is enough.  And it is much easier than
loop-mounting the file systems images.  (Also you don't need `root' rights.)

However, note that there is a bug in [[translator/fatfs]]: [[!GNU_Savannah_bug
25961]].


# Networking in QEMU

Some further notes about [[networking]] and home hints about
[[networking/sharing_files]].

## Internet Access

If you just want to access the internet from within QEMU, you can setup pfinet for QEMU's user-networking:

    # settrans -afgp /servers/socket/2 /hurd/pfinet -i eth0 -a 10.0.2.15 -g 10.0.2.2 -m 255.255.255.0
    # echo "nameserver 10.0.2.3" > /etc/resolv.conf

If you are on [[Debian GNU/Hurd|debian]], you can even use [[debian/DHCP]].

To get ssh working:

    # apt-get install random-egd openssh-server (Similarly for telnet if preferred)

(See also <http://www.nongnu.org/qemu/qemu-doc.html#SEC32>.)

Outgoing internet connections should just work then.
Testing it can be difficult with a minimal installation,
but `apt-get update` should work after you have filled out
`/etc/apt/sources.list`.
After that you should be able to install other network packages,
but note that `ping` doesn't work with QEMU's user-networking stack.

If you want to connect from the host system to the Hurd system running in QEMU, you can use port forwarding in QEMU or to setup something more advanced, like bridged networking.

## Port Forwarding in QEMU
(In the following we assume we use kvm!)

#### Logging in to Hurd from a terminal in  your host system
This is the recommended way to work with a Command Line Interface (CLI) since all your keyboard and locale settings are preserved.

a) with ssh (assuming you have installed openssh-server)

    $ kvm -m 1024 -net nic,model=rtl8139 -net user,hostfwd=tcp::5555-:22 -hda hd0.img &

Logging in to the running Hurd:

    $ ssh -p5555 localhost

Copying files:

    1) On your host
    To Hurd:   scp -p -P5555 file localhost:
    From Hurd: scp -p -P5555 localhost:file .
    2) On Hurd
    To host:   scp -p file {10.0.2.2,your_host_ip}: .
    From host: scp -p {10.0.2.2,your_host_ip}:file .

b) with telnet (assuming you have installed a telnet server, like telnetd)

    $ kvm -m 1024 -net nic,model=rtl8139 -net user,hostfwd=tcp::5556-:23 -hda hurd-install.qemu &

Logging in to the running Hurd:

    $ telnet localhost 5556

c) With the tap interface, see below.

## Bridged Networking

### What is Needed

1. Your Linux kernel will need 802.1d Ethernet Bridging support and TUN/TAP device driver support.
2. You will need to install [bridge-utils](http://bridge.sourceforge.net).


### Setting Up the Host Bridge

You need to setup a bridge on the host first. This assumes `eth0` is down. I have modified my hosts network startup scripts to automatically setup a bridge, you may want to do this also.

    # brctl addbr br0
    # ifconfig eth0 0.0.0.0 promisc up
    # brctl addif br0 eth0

At this point you will need to setup `br0` as you would normally `eth0` (`dhcpcd br0` for example).

### The qemu-ifup Script

This script gets called when QEMU starts and will attach the tun device to the bridge. QEMU will look for this file at `/etc/qemu-ifup` and that is where I keep mine.

    #!/bin/sh
    sudo ifconfig $1 0.0.0.0 promisc up
    sudo brctl addif br0 $1


### Setting up the Network in the Hurd

Now it is time to start-up your QEMU Hurd system and get networking going in there.

**Important:** Remember you may need to use the `-M isapc` or `-isa` flag if using an older version of the gnumach package.

    $ qemu -hda hd0.img -cdrom debian-K9-hurd-i386-CD1.iso -fda floppy.img -boot a -net nic -net tap

Once you have logged in as `root` run the `pfinet` translator with values that apply to your network. Think of your QEMU client as another computer in your network.

    # settrans -fgap /servers/socket/2 /hurd/pfinet -i eth0 -a xxx.xxx.xxx.xxx -g xxx.xxx.xxx.xxx -m xxx.xxx.xxx.xxx

That should do it! Do not forget to edit/update `/etc/resolv.conf` to get DNS working.


# Related Links

These are links that users may find helpful.

Debian [[debian/after_install]] -- good source of information pertaining to your
system after installation.

[[Image_for_L4]] -- a QEMU image for the Hurd/L4 project.

<http://eyeside.net/hurd/Hurd-on-QEMU.html>