[HN Gopher] How to run FreeBSD 13 in QEMU on Apple Silicon Mac
       ___________________________________________________________________
        
       How to run FreeBSD 13 in QEMU on Apple Silicon Mac
        
       Author : codetrotter
       Score  : 92 points
       Date   : 2021-02-07 10:19 UTC (12 hours ago)
        
 (HTM) web link (gist.github.com)
 (TXT) w3m dump (gist.github.com)
        
       | u678u wrote:
       | I've spent way too long getting VMs to work on various platforms.
       | I hate paying for software but does vmware make it a lot easier?
       | It sucks to use free OSs, but then pay to virtualize.
        
         | mobilemidget wrote:
         | yes certainly would suck to pay, because in the end VMWare
         | isn't issue free either.
        
       | tbrock wrote:
       | Does setting CPU to cortex-a72 mean that it runs natively on the
       | m1 or with minimal translation?
        
         | pm215 wrote:
         | The command line argument that means 'run natively' is the
         | "-accel hvf" one, which makes QEMU use the Hypervisor.framework
         | macOS APIs. (This is why you have to use an out-of-tree
         | patchset at the moment -- mainline QEMU only supports hvf on
         | x86 CPUs right now.) The hvf support patches don't make any
         | attempt to make the guest CPU report different ID values or
         | features, so regardless of what actual cpu type you ask for
         | with -cpu the guest sees whatever the host CPU is.
        
       | pimeys wrote:
       | Next thing: run FreeBSD 13 natively on M1. It would be really
       | nice, because even on this X230 this OS is really damn fast and
       | snappy. Wayland and sway are super nice.
        
         | webmobdev wrote:
         | Doubt if that will ever happen as even older Intel Mac Minis
         | still have issues running FreeBSD -
         | https://wiki.freebsd.org/IntelMacMini
        
           | tyingq wrote:
           | There's 5 open PRs. Two seem to be boot related, which
           | probably wouldn't apply to the M1. The Xorg one and the drm
           | one are related to an Intel integrated GPU.
           | 
           | That leaves just the firewire one as possibly an issue.
           | 
           | Though I get the general point that hardware drivers could be
           | an issue. Perhaps, though, the upside of the M1 is sufficient
           | incentive for people to figure it out.
        
             | pimeys wrote:
             | Maybe Apple does a favor for us and releases docs for their
             | hardware, so it would be easier to write drivers for the
             | open source operating systems. That would be the best news
             | for 2021.
        
               | saagarjha wrote:
               | I would have been surprised if they did that before, and
               | I certainly can't see it happening now as they pull
               | things out of the open source releases...
        
         | gautamcgoel wrote:
         | Can you describe your desktop setup? What login manager do you
         | use? Does Zoom work? Does usb 3 work?
        
           | pimeys wrote:
           | I installed it to my fun and games laptop I carry with me
           | when I travel. It's the ThinkPad X230 that is small enough
           | and has hardware that Just Works with almost all the open
           | source operating systems. I'm not planning to work with this,
           | so I'm not really thinking about installing Zoom or any other
           | closed source software. I have other computers for work
           | business. I'm considering trying on jails and iocage to see
           | if I can get something similar to docker, but it's not my
           | biggest priority: I kind of like having a computer that I'm
           | not doing work with all the time.
           | 
           | What I now have is just a boot to console. I haven't decided
           | on a login manager yet, so I just run `sway` to get to the
           | desktop. I run sway window manager on wayland. I installed
           | rust, emacs, vim, a music player ncmpcpp and firefox. It
           | feels like this old laptop got lots of energy from this new
           | setup.
        
         | codetrotter wrote:
         | Oh yes, that would be so good. I hope to see the Linux on M1
         | project work out, and that the learnings from those people
         | could enable running FreeBSD natively on M1 too!
        
         | jamesfmilne wrote:
         | Someone is working on getting OpenBSD running on Apple M1, I
         | would imagine their work would be useful to assist porting
         | FreeBSD too:
         | 
         | https://twitter.com/bluerise/status/1354216838406823936
        
       | codetrotter wrote:
       | Remember to star the gist if it is helpful to you ;)
        
         | smarx007 wrote:
         | Now, I am really curious why would it be of any value (putting
         | aside the HN policy discouraging it) to anyone. I understand
         | that GH repo stars help project visibility and may be good on
         | CV but gists?
        
           | codetrotter wrote:
           | I use the number of stars as a measure for how much the guide
           | is of use to people.
           | 
           | If it's not useful to anyone then I know not to spend time on
           | that. Short though as the guide is, and even though it is
           | based on much hard work of others, it still took time to
           | make, much in part because when I write stuff like this I
           | spend a lot of time actually redoing steps to ensure to the
           | best of my ability that what I am writing will work for
           | others too. So I like to know that people find it useful.
        
             | llarsson wrote:
             | So you wrote it just for GitHub stars? Not because it was
             | useful to yourself?
        
               | codetrotter wrote:
               | The motivation to run FreeBSD in a VM on my M1 MBP comes
               | from being an active user of FreeBSD for a long time. For
               | example my mail, web and VPN server runs FreeBSD. And I
               | have been running FreeBSD both on desktops and laptops
               | for a long time as well.
               | 
               | The motivation to make a guide for others to follow is
               | that it should be useful for others too.
               | 
               | What I am saying is, when it's useful for others it's
               | worth spending the time on writing up how to do it and
               | share it with others.
        
         | ontouchstart wrote:
         | You definitely got my attention so I bookmarked you as a
         | comment here so I can find your post later myself.
         | 
         | https://news.ycombinator.com/from?site=gist.github.com
         | 
         | Learn to live in attention economy with HTTP.
        
         | MaxBarraclough wrote:
         | The FAQ asks you not to ask for upvotes.
         | 
         | https://news.ycombinator.com/newsfaq.html
        
           | codetrotter wrote:
           | I'm not asking for upvotes. I am saying to star it on GitHub
           | if it is useful.
           | 
           | GitHub stars and HN upvotes are two different unrelated
           | things.
        
             | ivanstegic wrote:
             | Smash that like button! Subscribe!
        
               | protomyth wrote:
               | I would love the origin person of that phrase because it
               | is almost universal with YouTubers.
        
               | codetrotter wrote:
               | What I have come to realize is that the default action
               | for people online, including myself, is often to
               | read/watch and move on. A gentle reminder to give a
               | signal back will push some people to take the time to do
               | so.
        
               | anotherhue wrote:
               | Beware a slow burning Time of Check to Time of Use
               | attack.
               | 
               | What you like/star today may change tomorrow, but your
               | public association with it will remain.
        
               | codetrotter wrote:
               | Not sure I follow what you mean.
        
               | vijayr02 wrote:
               | Not OP, but as an example: get lots of 5 star reviews for
               | a genuinely useful product and then on sell the listing
               | to a shady seller. I guess OP is thinking of an even more
               | high profile issue (exaggerated example: you donate to a
               | charity that espouses human rights and it later pivots to
               | genocide - your reputation is toast now).
        
               | codetrotter wrote:
               | I see. I think this will always be a potential problem
               | indeed. And there is no simple solution to it.
               | 
               | I used to have a friend who turned out to be very
               | different from what I had thought. And she started
               | interpreting stuff that I had posted to my Facebook in
               | all sorts of... well frankly crazy ways. And she turned
               | really unpleasant, and I ended up blocking her across all
               | channels where she was contacting me.
               | 
               | So I know first hand what it is like to be treated in a
               | very hostile manner by someone.
               | 
               | I still think about that sometimes. And I think of people
               | who have not just one person turn against them but whole
               | groups of people turn against them. And I don't have an
               | answer for what to do about it.
               | 
               | But my current thinking is that we should live our lives
               | as we see fit and not be deterred by anyone who has the
               | wrong picture and who insists on holding on to that
               | picture.
               | 
               | And to instead focus as much as possible on the people
               | that you have healthy interactions with.
               | 
               | What that means is, to be open for new things and new
               | ideas still, and engaging in discussion, but if you
               | encounter someone who is too antagonistic, stop
               | interacting with them.
               | 
               | So in the example of having associated with a project or
               | organization or group or something, that is taken over
               | and changes into something bad, disassociate from them
               | when you are made aware of it, and to anyone that asks
               | about it say as it is that they weren't like that before
               | and that you have left them.
               | 
               | Anyone that continues to insist that you have ties to
               | something you don't, cut off contact. Don't try to defend
               | against them or anything.
               | 
               | But like I said, for people that have a whole group of
               | people turn on them I don't know what they should do.
        
               | batterylow wrote:
               | Maybe something like this:
               | 
               | - I star a FreeBSD project on GitHub.
               | 
               | - The author changes the project to something racist.
               | 
               | - My GitHub profile now shows that I've starred a racist
               | project.
        
       | sarusso wrote:
       | Have you run any performance benchmarks?
        
       | gardaani wrote:
       | Linux can be run on Virtualization.framework on Mac M1 without
       | qemu [1].
       | 
       | Would it be possible to run FreeBSD similarly without qemu?
       | 
       | [1] https://github.com/evansm7/vftool
        
         | codetrotter wrote:
         | When I went on my quest to run FreeBSD on my M1, I was
         | originally looking at tools like the one you link.
         | 
         | As far as I could tell, the Virtualization framework is Linux
         | specific(?)
         | 
         | https://developer.apple.com/documentation/virtualization
         | 
         | And in the guide in the OP, we are using some patches that
         | someone wrote so that QEMU uses the Hypervisor framework.
         | 
         | https://developer.apple.com/documentation/hypervisor
         | 
         | And from what I understand but please correct me if I am wrong,
         | the Virtualization framework is actually a layer on top of the
         | Hypervisor framework. So if I am correct in my understanding
         | the way that the QEMU patches do it should in theory be
         | comparable in performance to the way that the Virtualization
         | framework does it.
         | 
         | I would like to do some benchmarking of Linux on the
         | Virtualization framework versus Linux on QEMU to see if there
         | is a difference. However, good benchmarking is no easy feat. So
         | ideally someone else who is really good at benchmarking Linux
         | would do this and write about it.
        
           | my123 wrote:
           | Yes, Virtualization.framework's XPC service (because VM is
           | out-of-process there) is implemented on top of
           | Hypervisor.framework.
        
       | kristiandupont wrote:
       | I am running an ARM Ubuntu server in QEMU. SSH'ing to that gives
       | me a complete dev environment that so far seems to work
       | flawlessly. I guess it's slower than if I was running things
       | natively but on the other hand, I get seamless Docker support and
       | it's still significantly snappier than my semi-beefy PC (and this
       | is the Air).
       | 
       | https://twitter.com/kristiandupont/status/135343863829033369...
        
       | drewg123 wrote:
       | I needed a FreeBSD/arm64 box, and so I did something similar a
       | few weeks ago based on instructions for running Windows ARM64 on
       | M1. The issue that I have is that the VM burns tons of battery
       | even when idle.
       | 
       | It was explained to me that there are 2 different instructions on
       | ARM to say "i'm idle, wake me up if something happens" (like x86
       | mwait), and Apple M1 uses one, while everybody else uses the
       | other. Is this fixed in either FreeBSD or Qemu at this point?
       | 
       | BTW, I'm super impressed that a 4-core VM on my M1 13" MBP can
       | build world in about 130% of the time of a 32-core Ampere EMAG.
        
         | tyingq wrote:
         | _" it was explained to me that there are 2 different
         | instructions on ARM to say "i'm idle, wake me up if something
         | happens" (like x86 mwait), and Apple M1 uses one, while
         | everybody else uses the other."_
         | 
         | That had me curious, so I searched around a bit.
         | 
         | And I found one QEMU patch that seems like the right one:
         | https://patchew.org/QEMU/20210120224444.71840-1-agraf@csgraf...
         | 
         | This appears to be his latest/greatest bundle:
         | https://patchew.org/QEMU/20210120224444.71840-1-agraf@csgraf...
        
           | drewg123 wrote:
           | Thanks, mine is indeed more than 2 weeks old..
        
             | tyingq wrote:
             | Yeah, it looks like the WFI handler was removed in the v3
             | patch series, then put back in for v6. WFI appears to be
             | one of the cpu sleep related instructions that don't work
             | well on the M1 (or maybe just don't work in QEMU?).
        
         | floatboth wrote:
         | > can build world in about 130% of the time of a 32-core Ampere
         | EMAG
         | 
         | This says more about the eMAG than the M1, to be honest :D The
         | APM X-Gene derived cores in the eMAG are far behind current
         | cores from everyone else. The new Ampere Altra is using stock
         | Arm Neoverse cores. (Which makes me wonder if all they got out
         | of the APM acquisition was just one dead-end generation of
         | product...)
         | 
         | > Is this fixed in either FreeBSD or Qemu at this point?
         | 
         | Not in FreeBSD for sure, as an obsessive commit watcher I can
         | say I haven't seen any M1 quirks land.
         | 
         | > 2 different instructions on ARM to say "i'm idle, wake me up
         | if something happens" (like x86 mwait), and Apple M1 uses one,
         | while everybody else uses the other
         | 
         | Everybody should use both in different circumstances:
         | https://community.arm.com/developer/ip-products/processors/f...
         | 
         | But according to Corellium's Linux work "the CPU tends to lose
         | state" when using WFI for system idle:
         | https://github.com/corellium/linux-m1/commit/b8ecd5924678f1c...
         | 
         | Not sure why this would have an impact on VM idling... (upd:
         | yeah it's QEMU-side stuff, see other comments)
        
       ___________________________________________________________________
       (page generated 2021-02-07 23:01 UTC)