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,

00Cancer

Well-Known Member
Newcomer
Joined
Feb 1, 2017
Messages
67
Trophies
0
Age
20
XP
103
Country
United States
This very same SD card I'm using for this does NOT work in an adapter for WiiU homebrew, so yeah. sometimes they just don't work for some reason.

If three different cards don't work then yeah, I'd expect it to be something going wrong with the setup rather than a card just not working.

You both definitely have two partitions on your SD card right? A small FAT32 one, and a larger ext4 one that actually has the rootfs on it?

EDIT: Also, it has an MBR partition table and not a GPT one right?
I can confirm that trying a different sdcard, an 8 gb one, did not work.
EDIT: Both are MBR
 
Last edited by 00Cancer,

Eastonator12

Well-Known Member
Member
Joined
Aug 16, 2016
Messages
630
Trophies
0
Age
23
XP
999
Country
United States
Do you have pkg-config installed?

sudo apt install pkg-config
that works. thank you

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

Do you have pkg-config installed?

sudo apt install pkg-config
a new problem.... when trying to boot linux, it gives me this in terminal.
config file <./imx_usb.conf>
vid=0x0955 pid=0x701a file_name=switch.conf
config file <./switch.conf>
parse ./switch.conf
Trying to open device vid=0x0955 pid=0x701a.........................
Could not open device vid=0x0955 pid=0x701a
what should I do? restart switch and pc and try again?
 

Gren22

Well-Known Member
Newcomer
Joined
Apr 24, 2018
Messages
63
Trophies
0
Age
26
XP
210
Country
United States
that works. thank you

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


a new problem.... when trying to boot linux, it gives me this in terminal.
config file <./imx_usb.conf>
vid=0x0955 pid=0x701a file_name=switch.conf
config file <./switch.conf>
parse ./switch.conf
Trying to open device vid=0x0955 pid=0x701a.........................
Could not open device vid=0x0955 pid=0x701a
what should I do? restart switch and pc and try again?
Run the last command with sudo
 

00Cancer

Well-Known Member
Newcomer
Joined
Feb 1, 2017
Messages
67
Trophies
0
Age
20
XP
103
Country
United States
I can confirm that trying a different sdcard, an 8 gb one, did not work.
EDIT: Both are MBR
Well I figured out why it wasn't working... Apparently after I had disasembled my switch one time (Don't know why I did), I forgot to properly reseat the sdcard reader, so it was never reading the sdcard. Now that I fixed it, linux works fine.
 
  • Like
Reactions: Kobigov

Sayora

Well-Known Member
Member
Joined
Feb 6, 2018
Messages
135
Trophies
0
XP
671
Country
United States
So it seems like the current method requires a seperate sd card for linux. Is it possible to have the first partition on the sd card sized to act as the normal partition for the switch, and the second partition be for linux? Is it possible to use exfat for the first partition instead of fat32 if that is the case?
 

Eastonator12

Well-Known Member
Member
Joined
Aug 16, 2016
Messages
630
Trophies
0
Age
23
XP
999
Country
United States
So it seems like the current method requires a seperate sd card for linux. Is it possible to have the first partition on the sd card sized to act as the normal partition for the switch, and the second partition be for linux? Is it possible to use exfat for the first partition instead of fat32 if that is the case?
nope

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

I can confirm that trying a different sdcard, an 8 gb one, did not work.
EDIT: Both are MBR
do you have to convert to GPT for this to work?
 

Admiral124

Active Member
Newcomer
Joined
May 19, 2015
Messages
41
Trophies
0
XP
183
Country
United States
So it seems like the current method requires a seperate sd card for linux. Is it possible to have the first partition on the sd card sized to act as the normal partition for the switch, and the second partition be for linux? Is it possible to use exfat for the first partition instead of fat32 if that is the case?
I don't think so. The Switch OS will write to partition one if you boot to it (Your small fat32 partition).
 

Sayora

Well-Known Member
Member
Joined
Feb 6, 2018
Messages
135
Trophies
0
XP
671
Country
United States
I mean what if you transfer all the files old files from a current switch sd card to a new partition that is bigger as the partition size doesn't matter.
 

Type_O_Dev

Developer
Developer
Joined
Dec 12, 2017
Messages
683
Trophies
0
XP
1,469
Country
United States
any idea to what this error is, thanks
 

Attachments

  • Screenshot from 2018-04-25 17-35-46.png
    Screenshot from 2018-04-25 17-35-46.png
    12.5 KB · Views: 190

Gren22

Well-Known Member
Newcomer
Joined
Apr 24, 2018
Messages
63
Trophies
0
Age
26
XP
210
Country
United States
Anyone who is having issues with their specific SD card not working to load the Linux Filesystem from the Kernel, try using the SD card that comes with the 3DS. If that doesn't work then your problem is elsewhere.
 

Cyberevan

Well-Known Member
Newcomer
Joined
Oct 16, 2014
Messages
89
Trophies
0
Age
36
Location
Manila, Philippines
XP
1,041
Country
Do be careful with USB-C cables (any type)
Only buy name brand or known good ones that have the correct resistance.
Some of them have the wrong resistance and can actually fry your PC or at the very least fry the USB ports on it.
The Switch also does not behave according to USB-C spec so with a bad cable the Switch could potentially be damaged as well.

Yeap I will be using a Type C cable that came with Nexus 6p.
 

flagrama

Active Member
Newcomer
Joined
Jan 23, 2011
Messages
29
Trophies
0
XP
179
Country
United States
ah. when I make it MBR, it gives me a EXT3, EXT2 error, then goes back 2 rcm mode, did i screw up the sd?

I don't know what error you're getting exactly, nor what it means from just that description. Do you have a more complete version of the error message?

Just for reference here is what I did to partition my SD card and put the rootfs on it:

Start fdisk to partition the SD card:
fdisk /dev/sdX
At the fdisk prompt, delete old partitions and create a new one:
Type o. This will clear out any partitions on the drive.
Type p to list partitions. There should be no partitions left.
Type n, then p for primary, 1 for the first partition on the drive, press ENTER to
accept the default first sector, then type +100M for the last sector.
Type t, then c to set the first partition to type W95 FAT32 (LBA).
Type n, then p for primary, 2 for the second partition on the drive, and then press
ENTER twice to accept the default first and last sector.
Write the partition table and exit by typing w.
Create the FAT filesystem:
mkfs.vfat /dev/sdX1
Create and mount the ext4 filesystem:
mkfs.ext4 /dev/sdX2
mkdir root
mount /dev/sdX2 root
Download and extract the root filesystem (as root, not via sudo):
wget http://os.archlinuxarm.org/os/ArchLinuxARM-aarch64-latest.tar.gz
bsdtar -xpf ArchLinuxARM-aarch64-latest.tar.gz -C root
sync
Unmount the partition:
umount root
Insert the SD card into the Switch and run the exploit and usb-loader commands.
Modified from the instructions found for the Raspberry Pi here: https://elinux.org/ArchLinux_Install_Guide#Flashing_the_Image

You've done all of this, correct? (It doesn't have to be the same way I did it, just an equivalent one) Also, you may need to do it again after you changed the partition table of the SD card back to MBR.
 
Last edited by flagrama,

clank714

Active Member
Newcomer
Joined
Sep 28, 2010
Messages
33
Trophies
1
XP
174
Country
United States
Anyone get this error?

make[1]: *** No rule to make target '/lib/firmware/nvidia/gm20b/pmu/desc.bin', needed by 'firmware/nvidia/gm20b/pmu/desc.bin.gen.o'. Stop.

This is while compiling the linux kernel
 

flagrama

Active Member
Newcomer
Joined
Jan 23, 2011
Messages
29
Trophies
0
XP
179
Country
United States
Anyone get this error?

make[1]: *** No rule to make target '/lib/firmware/nvidia/gm20b/pmu/desc.bin', needed by 'firmware/nvidia/gm20b/pmu/desc.bin.gen.o'. Stop.

This is while compiling the linux kernel
If you are using Debian I believe you need to have the 'firmware-misc-nonfree' package installed. It may also need to be the one from the Sid apt repos rather than from stable. (Going by an IRC discussion here, not actual experience)
 

clank714

Active Member
Newcomer
Joined
Sep 28, 2010
Messages
33
Trophies
1
XP
174
Country
United States
If you are using Debian I believe you need to have the 'firmware-misc-nonfree' package installed. It may also need to be the one from the Sid apt repos rather than from stable. (Going by an IRC discussion here, not actual experience)
Thank you, this fixed the issue!
 

00Cancer

Well-Known Member
Newcomer
Joined
Feb 1, 2017
Messages
67
Trophies
0
Age
20
XP
103
Country
United States
To anyone who got graphics output working, what packages did you install? I got LXDM to display with touch input last night but after wiping my SD and trying to set it up again it doesn't work. The VT login shows up on default boot, but I just get dropped to a black screen after enabling LXDM(.service). The lxdm log complans about not being able to load any DRI libs in /usr/lib/dri. Errors also reference tegra_dri.so being missing, though I don't remember copying that in or installing a package that might have contained it last night, though maybe I just don't remember as it was 3AM.

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Also, here are some instruction for chrooting into the ArchArm sd to install packages. (instructions only tested on Arch as the root user
1. Install qemu-user-static from the aur (Other distributions likely have a compariable package to this) (There is a qemu-user-static-bin package if you don't want to compile but I have not tested this package)
2. Create a rule for the linux kernel to user qemu to run aarch64 binaries. Put the following in /etc/binfmt.d/qemu-arm64.conf
Code:
:qemu-arm64:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-aarch64-static:OC
3. Run the related systemd service to enable this rule
Code:
systemctl start systemd-binfmt
4. Mount the Arch ARM sd's root partition. (/mnt/root is used for this)
Code:
mount /dev/sda2 /mnt/root
5. Copy the qemu binary into the chroot
Code:
cp /usr/bin/qemu-aarch64-bin /mnt/root/usr/bin
6. Do some other mounting logic (I made this into a script and put it into /mnt to make this easier)
Code:
mount /dev/sda2 root
mount -o bind /dev root/dev
mount -t proc /proc root/proc
mount -o bind /dev/pts root/dev/pts
chroot root /bin/bash
7. Run the commands you would like.
8. Leave the chroot
Code:
exit
9. Unmount everything so you can remove the sdcard
Code:
sync
umount -R /mnt/root


Some notes:
In order to use the network in the chroot you will have to setup resolv.conf. I suggest moving the existing file (actually its a symlink) at /etc/resolv.conf to /etc/resolv.conf.bak and make a temporary /etc/esolv.conf with the contents
Code:
nameserver 8.8.8.8
Make sure to revert this back before leaving the chroot


My system sometimes becomes wierdly unstable while using this. If anyone has any idea why I would be interested. i think based on what I've read it's maybe forwarding some x86 binaries to qemu but I can't see why it would be doing this.


If this is completely broken let me know and I'll see what I forgot to write up.

Everything works until I try to install something. There is no Internet connectivity. I can ping google just fine, but everything else is borked. I tried setting the nameserver as well, but that did not work.
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    Xdqwerty @ Xdqwerty: @OmDRetro, but hey atleast you will not die