Tutorial  Updated

How to boot Linux on your Switch

THIS GUIDE IS DEPRECATED
THIS IS BETTER https://github.com/natinusala/painless-linux


I've successfully booted ArchLinux using ShofEL2. Here is a quick guide on how to do it - I'll assume you're computer literate and know how to use a terminal / Linux commands / git.
Everything is taken from the README of the ShofEL2 repo so if you want to go even faster, go read that instead.

Thanks to NightHammer1000 and Y2K-x for the help !

There is a simplified and faster version of this tutorial available here, with precompiled binaries so you don't have to build everything : https://github.com/SoulCipher/shofel2_linux

The result

Without a SD card ("waiting for root device mmcblk0p2") : https://photos.app.goo.gl/7y6ut5ObuHMUIMZg2
Stock Arch Linux : https://photos.app.goo.gl/yALqe3zMZRe2dSQf1
Arch Linux with LXDE : https://photos.app.goo.gl/xaEgRqeSi8jvAwpz5
RetroArch running : https://photos.app.goo.gl/vBLPo5wiBto1qiUH3
Arch Linux with GNOME : https://gbatemp.net/attachments/img_0005-jpg.121608/
Arch Linux with KDE : https://gbatemp.net/attachments/img_20180427_121605-jpg.121666/

What works / what doesn't
  • Desktop environment : Gnome, LXDE, KDE
  • Wi-Fi : works
    • You will need to reboot your Switch and run the exploit again to make the Wi-Fi work (it never works on the first boot)
    • Then enter the Network Manager Application and add your network from there
    • If it doesn't work, you will need to edit the configuration on the host computer (see the additional notes at the end of this post)
    • With LXDE : Can cause a kernel panic if used at the same time as Bluetooth
  • Bluetooth : works but Joy-Cons can't be paired
  • Touch screen : works, although LXDE is not very touch-friendly
  • Audio : doesn't work yet
  • GPU acceleration : works (via mesa), with OpenGL (and maybe Vulkan too ?)
  • Joy-Cons : not recognized
  • Volume buttons : working with Gnome but not doing anything since there is no audio device
  • Power button : doesn't do anything, no sleep mode, no graceful shutdown
  • USB : doesn't work
  • Dock : not tested yet, but I bet it doesn't do anything besides charging the battery
  • Power management / battery level : working with Gnome
What you'll need
  • A computer running Linux with a blue USB SuperSpeed port, or a Mac
    • A Linux VM can work in theory, but it depends on how the USB passthrough is implemented (apparently VMWare works, VirtualBox doesn't)
  • A USB A-to-C cable (with data support, obviously)
    • be careful as cheap cables were reported to work randomly / not work at all
  • Some time (you know, Linux is kinda large)

Prep work

First, you'll need to install the required toolchains. Open this link and download the tar.gz binaries for
  • aarch64-linux-gnu
  • arm-linux-gnueabi
Be careful to choose the right architecture for your PC (for me it was x86_64 so "gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabi.tar.xz").

Once you have them, extract them somewhere nice and add the "bin" (not "lib" as I previously stated) folder of both toolchains to your PATH ("$ export PATH=$PATH:/path/to/toolchain1/lib:/path/to/toolchain2/lib"). The building process won't work otherwise.

Then, install those dependencies (how to install them and their name might depend on your distribution) :
  • build-essential (sorry I didn't add it it was obvious to me)
  • libssl-dev
  • swig
  • bison
  • pkg-config
  • flex
  • zlib1g-dev
  • python3
  • python-dev
  • python3-pip
  • pyusb 1.0.0 : "$ sudo pip3 install pyusb==1.0.0"
  • libusb-1.0-0-dev

Compiling

Clone each required repository :

Code:
$ git clone https://github.com/fail0verflow/shofel2.git
$ git clone --recursive --depth=1 https://github.com/fail0verflow/switch-coreboot.git coreboot
$ git clone https://github.com/fail0verflow/switch-u-boot.git u-boot
$ git clone --depth=1 https://github.com/fail0verflow/switch-linux.git linux
$ git clone https://github.com/boundarydevices/imx_usb_loader.git

You can grab a coffee or two because Linux has more than 5 million files to download.

Then, build everything :

Code:
$ cd shofel2/exploit
$ make

Code:
$ cd u-boot
$ export CROSS_COMPILE=aarch64-linux-gnu-
$ make nintendo-switch_defconfig
$ make

Code:
$ cd coreboot
$ make nintendo_switch_defconfig
$ make iasl
$ make

If you have a tegra_mtc.bin file error, you'll have to extract it from a Pixel C stock image :
"$ ./build/util/cbfstool/cbfstool bootloader-dragon-google_smaug.7900.97.0.img extract -n fallback/tegra_mtc -f tegra_mtc.bin"

Or you can download it directly from here : https://0w0.st/tegra_mtc.bin (thanks to @CptPotato for uploading this)

You'll have to put it in the "coreboot/src/soc/nvidia/tegra210" directory.

Code:
$ cd imx_usb_loader
$ git reset --hard 0a322b01cacf03e3be727e3e4c3d46d69f2e343e
$ make

The big one :

Code:
$ cd linux
$ export ARCH=arm64
$ export CROSS_COMPILE=aarch64-linux-gnu-
$ make nintendo-switch_defconfig
$ make

If you encounter issues about a missing rule "/lib/firmware/nvidia/tegra210/vic04_ucode.bin" for the target "firmware" you'll have to :
  • install the firmware-misc-nonfree package
  • if you can't install it, or if it still doesn't work, download the package manually from debian sid and extract the file "/lib/firmware/nvidia/tegra210/vic04_ucode.bin" (from the root of your PC, not on the cloned repo) from the DEB (and chmod it if needed)
If you encounter issues about a missing rule "/lib/firmware/brcm/brcmfmac4356-pcie.txt", download this file and put it in "/lib/firmware/brcm/" (from the root of your PC, not on the cloned repo)

Building the rootfs

This is the annoying part. Download the archive / image corresponding to the distribution you want to use :
If it's a tarball you just downloaded

While it's downloading, you'll have to take a microSD card and, using the software of your choice (I used GParted) :
  • remove every existing partition to only have unallocated space on it (do I need to tell you that you're going to loose everything on the card ?)
  • create a tiny FAT32 partition (I chose 200mb but it doesn't matter) - that'll be mmcbkl0p1, you can label it "garbage"
  • create an ext4 partition on the remaining part of the card - that'll be mmcblk0p2, you can label it "rootfs"
  • it's important that the FAT32 partition comes first and the ext4 one comes after - on the Switch, Linux will look for mmcblk0p2, the second partition, if you have scrolling boot logs and then back to RCM it means you did it wrong
Once the rootfs tarball is downloaded, you can simple extract it to the mounting point of the ext4 partition you just created :

Code:
$ tar xvf ArchLinuxARM-aarch64-latest.tar.gz -C /mounting/point/of/ext4/partition && sync
$ cp ArchLinuxARM-aarch64-latest.tar.gz /mounting/point/of/ext4/partition/root && sync

("/mounting/point/of/ext4/partition/root" is the "root" directory on the partition)

Don't forget to properly eject the SD Card !

If "tar xvf" doesn't work for you you can install "bsdtar" and use "bsdtar -xpf" instead

Then you can put the SD card in the console.

If it's a img / bin file you just downloaded

You can simply write it on your SD card using :
  • If you're on Windows, Ether or Win32DiskImager
  • If you're on Linux / Mac OS : "sudo dd if=yourimage.img of=/dev/sdX && sync" where /dev/sdX is the device of your SD card (unmounted)
You will probably want to open a partition manager to resize the ext4 partition once it's flashed, so that it fits your SD card.

Then you can put the SD card in the console.

Booting linux

Run the exploit :

Code:
$ cd shofel2/exploit
$ sudo ./shofel2.py cbfs.bin ../../coreboot/build/coreboot.rom

Your terminal should now be waiting for the Switch to enter RCM mode.

To do so : (I don't have pictures but that's the same method as fusée gelée, just look at some video tutorials)
  • plug the Switch on your PC using the USB A-to-C cable - use a blue SuperSpeed port if you have one
  • shut it down
  • remove the right joy-con
  • using a method of your choice, short the 10th pin of the right joy-con (the last pin on the right, away from the screen, closer to the back) with the ground : that can be pin 1, 2 or 7, that can also be a screw on the joy-con rack or the console's fan - I personnaly stick a RPi jumper wire in the fan and touch the 10th pin on the other side, works everytime (like this)
  • keep the pins shorted and power the Switch while pressing the volume UP button
If it worked, the console will show a black screen and you'll see the exploit running on your terminal. If you see the Nintendo logo, it has failed. You can power off the console and try again.

Then, run those last commands :

Code:
$ cd shofel2/usb_loader
$ ../../u-boot/tools/mkimage -A arm64 -T script -C none -n "boot.scr" -d switch.scr switch.scr.img
$ sudo ../../imx_usb_loader/imx_usb -c .

Linux should then boot on your console - first the boot logs with the penguins, and then an ArchLinux login prompt. Voilà !
Again, if you have the boot logs and then a black screen, it means you did the SD card part wrong.

Additional notes

Hardware graphics acceleration


The most recents image already contain this fix.

To add mesa drivers install this package using pacman :
https://0w0.st/mesa-full-tegra-r101876.bf5e0276b6-1-aarch64.pkg.tar.xz

You will need a working internet connection to do so.

Then, use this script to choose your power profile : https://0w0.st/power.sh

Full speed RAM


According to the blog post ("Linux on Switch boot chain" section), you need to extract a file from a Pixel C factory image in order to have the RAM working at full speed. I didn't do it so I won't cover it here.

Fixing calibration issues of the touch screen (thanks to @Wizardy)

To fix calibration issues of the touch screen, edit the file /usr/share/X11/xorg.conf.d/10-evdev.confg (of the rootfs)

And change the InputClass section to :

Code:
Section "InputClass"
        Identifier "evdev touchscreen catchall"
        MatchIsTouchscreen "on"
        MatchDevicePath "/dev/input/event*"
        Driver "evdev"
        Option "InvertX" "no"
        Option "InvertY" "yes"
        Option "SwapAxes" "yes"
        Option "Calibration" "0 1279 0 719"
EndSection

Wi-Fi

To setup Wi-Fi, mount the rootfs partition on your host PC and edit the configuration for your network in the file "/etc/NetworkManager/system-connections" (if it doesn't exist, take Gigaspot).

To have a working Wi-Fi you must reboot your Switch and run the exploit again each time you power it off

Moving the rootfs to another partition

If you want to move the rootfs to another partition on your SD card, edit the "shofel2/usb_loader/switch.scr" file and replace "/dev/mmcblk0p2" by the partition you want to use.
 
Last edited by natinusala,

jul2003

Member
Newcomer
Joined
Mar 25, 2018
Messages
7
Trophies
0
Age
45
XP
163
Country
France
Neat, will check it out.

If you somehow got it compiled you would still have to modify the python script to be more mac "friendly. That's not easy, trust me i tried.
If i where you i would just install linux on spare computer (with usb3) or just dual boot it on your mac.

Ok thank you for your answer , i'll do that
 
  • Like
Reactions: Gigaa

DuckWithAKnife

New Member
Newbie
Joined
Apr 29, 2018
Messages
2
Trophies
0
Age
22
Website
aaronjs.me
XP
50
Country
United States
Huh, people seems to have different results with my rootfs. This is all very strange as you are all using the same rootfs.
All i can think of is that maybe some you didn't sync or you got a strange sd card or something as it should most definitely work.

I got it working just now. I extracted the file as root to the SD card, and it seemed to work. I don't know if that's why it worked, but it does work now.
 

Mittytoto

Member
Newcomer
Joined
Apr 27, 2018
Messages
21
Trophies
0
Location
Auckland
XP
140
Country
New Zealand
Tried compiling it myself, still no luck on wifi with KDE image. I might try one of the other images later.

One of the last lines output before the GUI starts is:
brcmfmmc 0000:01:00.0 wlp1s0: renamed from wlan0

Am I correct that I should be able to see something besides loopback in ifconfig, at least after rebooting?
Did you compile the original on f0f Github? That will not work as Wifi only added to SoulCipher/kombos prebuilt binary, in short we dont have the source of the Wifi kernel to build it ourselves at the moment...

Everyone, please correct if I am wrong?
 

Gigaa

Well-Known Member
Member
Joined
Apr 25, 2018
Messages
108
Trophies
0
Age
26
Location
Norway
Website
giga.is
XP
130
Country
Norway
Did you compile the original on f0f Github? That will not work as Wifi only added to SoulCipher/kombos prebuilt binary, in short we dont have the source of the Wifi kernel to build it ourselves at the moment...

Everyone, please correct if I am wrong?
Well i gave @kombos my kernel that i built from f0f's github and he merged it. f0f's kernel will try to get the wifi firmware from your own linux firmware folder.
 
Last edited by Gigaa,

cmsj

Well-Known Member
Newcomer
Joined
Apr 25, 2018
Messages
61
Trophies
0
Age
46
XP
223
Country
United Kingdom
Ok thanks but when are we having this? f0f's last commit was 2 months ago. Or you guys have a fork we can clone please?

Cheers

I think if people are making source fixes to f0f's kernel, the reasonable thing to do would be to offer them back to f0f as pull requests, otherwise we'll end up with dozens of weirdly different kernels out there, some of which patches are available for, and some of which aren't, and anyone vaguely trying to maintain an OS image for the Switch will have a much harder time.
 

Mittytoto

Member
Newcomer
Joined
Apr 27, 2018
Messages
21
Trophies
0
Location
Auckland
XP
140
Country
New Zealand
I think if people are making source fixes to f0f's kernel, the reasonable thing to do would be to offer them back to f0f as pull requests, otherwise we'll end up with dozens of weirdly different kernels out there, some of which patches are available for, and some of which aren't, and anyone vaguely trying to maintain an OS image for the Switch will have a much harder time.
Yes, agreed but I am not sure about the life circle of the PRs on f0f's, could take weeks to get this merged, maybe? While I just need to apply the dirty patch for the Samsung cards to work. At least 3 people on this thread are having troubles with Samsung's. Obviously I would need to have the latest wifi fix source first OR @kombos is happy to patch it on his binary.
 

cmsj

Well-Known Member
Newcomer
Joined
Apr 25, 2018
Messages
61
Trophies
0
Age
46
XP
223
Country
United Kingdom
Yes, agreed but I am not sure about the life circle of the PRs on f0f's, could take weeks to get this merged, maybe? While I just need to apply the dirty patch for the Samsung cards to work. At least 3 people on this thread are having troubles with Samsung's. Obviously I would need to have the latest wifi fix source first OR @kombos is happy to patch it on his binary.

I don't really care if they get merged, I'm not expecting f0f to carry the burden of maintaining a kernel for Switch, but just having the PRs there would mean I only have to look in one place to get useful fixes/improvements for my Ubuntu image, and the same for everyone else and theirs.

Of course long term I would hope that all of this makes its way into the upstream kernel.org kernel, but baby steps :)

Edit: also, regarding the wifi fix - what exactly is that? Does it bring the wifi up on first boot? I would be very keen to get such a patch, but if it's been posted, I missed it. These threads are growing faster than I can keep up!
 
Last edited by cmsj,
  • Like
Reactions: awtgrduzwt5r9

Mittytoto

Member
Newcomer
Joined
Apr 27, 2018
Messages
21
Trophies
0
Location
Auckland
XP
140
Country
New Zealand
I don't really care if they get merged, I'm not expecting f0f to carry the burden of maintaining a kernel for Switch, but just having the PRs there would mean I only have to look in one place to get useful fixes/improvements for my Ubuntu image, and the same for everyone else and theirs.

Of course long term I would hope that all of this makes its way into the upstream kernel.org kernel, but baby steps :)

Edit: also, regarding the wifi fix - what exactly is that? Does it bring the wifi up on first boot? I would be very keen to get such a patch, but if it's been posted, I missed it. These threads are growing faster than I can keep up!
You wont get wifi with the original f0f no matter how many time you reboot. So thats it the fix - to have wifi.
 

Mittytoto

Member
Newcomer
Joined
Apr 27, 2018
Messages
21
Trophies
0
Location
Auckland
XP
140
Country
New Zealand
I meant it got pushed to @kombos 's github aka the guy that made the precompiled binaries https://github.com/SoulCipher/shofel2_linux
Thanks, that the prebuilt binary everyone is using. I guess I haven't made myself clear. I would like to know the source of the wifi fix too, if possible. Because I just want to get over the Samsung card fix too.
Anyway, no big deal, so far only 3 people having the Samsung's. So no hard feeling.
Cheers

--------------------- MERGED ---------------------------

That's not right, I'm running a kernel built from the f0f repos and I get wifi after a warm reboot. I'd still like to know what this fix is :)
Oh right? Thanks for confirming. I was trying the KDE rootfs and wifi didnt work. Too early to make assumptions - sorry my bad. Will try another rootfs. Cheers
 
  • Like
Reactions: KIT786

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    SylverReZ @ SylverReZ: @BakerMan @I-need-help-with-wup-wiiu...