Näytetään tekstit, joissa on tunniste Linux. Näytä kaikki tekstit
Näytetään tekstit, joissa on tunniste Linux. Näytä kaikki tekstit

perjantai 10. huhtikuuta 2020

Installing linux on Asus TF101

Years ago I bought myself an Asus Eee Pad Transformer TF101, which is an Android tablet with an (optional) keyboard dock. In the keyboard dock there is additional battery and two USB ports. I bought it as I- thought it could be used as a replacement for a laptop, but it turned out that Android is not very suitable for that. I never had any good use for the tablet..

Many years ago I rooted the tablet and installed a custom, newer Android ROM made by Timduru. It was nice, but still I didn't find much use for the tablet.

Some weeks ago I found out, that it is possible to install Linux on the tablet. It had been possible for many years already, and significant development had happened until 2016 or so. So I decided to go for it, and it turns out, the process was very easy with the already-rooted tablet!

In this post I present the process I used since the guides were scattered around multiple posts.

Sources

Main sources for the process were following:
  1. [Linux] [IMG] [Dev] [WIP] *Ubuntu images for Rootbind [TF101 / TF101G]
  2. [KERNEL/MOD] [LINUX] [Rootbind] [Native EMMC/all TF101&TF101G/fast/tested] [2-Jul-13]
  3. [GUIDE][Dual Boot][TheEasyway] How to setup Linux RootBind Method [Updated May 16th]

Preparation

To prepare for the installation, one needs an empty micro-SD card, at least some 2 GB or so. It is necessary to download to the SD card (root) following files:
  • tf101-14.04-Lubuntu-Tegra-armaf.tar.gz from the first source link and
  • Ubuntu-3.1.10-12-rootbind-oc1.2GHz.zip from the second source link
it may not be necessary, but I also downloaded
  • modules-3.1.10-12.tar.gz from the second link 
Note that in the first link there is also other distributions that can be used. I assume their installation is similar, but I used the lubuntu one.

Also in the second link there is different kernels. I understood that the difference is that 1.0GHz is the standard processor speed, while 1.2GHz is a bit overclocked and 1.5GHz is rather high overclock. I used the slightly overclocked 1.2 GHz version.

Make sure you have latest TWRP recovery on the tablet. It is needed to flash the kernel. You also need SuperSU or similar and a terminal emulator.

Installing the distribution

When all the necessary files are downloaded (or installed), it is time to uncompress the linux distribution. With these versions, they can reside side by side with Android, so it is possible to have both installed and run either one by just flashing the correct kernel.

In Android terminal run the following commands to uncompress the Linux distribution to /data/linuxroot: 
su

mkdir -p /data/linuxroot
busybox chmod 755 /data/linuxroot
cd /data/linuxroot
tar -xpjf /storade/6E20-1C26/lubuntu-14.04.tar.bz2
the external micro-SD card where I put all the files was in the path /storage/6E20-1C26/ so that needs to be changed to match where the SD-card is located.

It may be also necessary to copy the necessary kernel modules, at least for some kernel versions:
cd /data/linuxroot/lib/modules
tar -xzf /storage/6E20-1C26/modules-3.1.10-12.tar.gz
That is all for now, next is time to install the kernel.

Installing the kernel

To install the kernel, it is necessary to reboot to the recovery with the external micro-SD card still installed.

In the recovery, select Install. From the menu select SD card as the source directory, and then select the kernel zip file, Ubuntu-3.1.10-12-rootbind-oc1.2GHz.zip. Confirm flashing the image by swiping right.

After a moment the flash process is done and it is time to reboot the system.

Booting

After reboot, there was quite a long time with black screen, and then...

Two penguins! This is promising... waiting a bit more...

Linux boot messages! And no errors so far! And finally login screen! From the top right menu (after a few clicks) it was possible to get the on-screen keyboard.

Easy! The installation was a success on the first try!

Issues


There are several issues, some of which can be fixed and some do not at the moment seem to have a fix.
  • The tablet cannot be booted with the dock connected. Remove the dock before turning the tablet on!
  • Do not run apt-get update && apt-get upgrade. It seems to break something and the system no longer boots. Upgrade only the necessary packages.
  • Sometimes the mouse/GTK would hang if moving/resizing a window. It seemed to be fixed by upgrading anything libgtk-2.0 and libgtk-3.0 related (~6 packages or so).
  • Network-manager (wifi) icon is broken, fix is to re-install icon themes, as described here.
  • Lock-key in the upper right corner can be made to be delete key by adding /usr/sbin/mapdeletekey to startup applications.

Dock battery issue

There is a quite major issue with the keyboard and touchpad stopping working if dock battery goes low. My tablet had broken battery which I removed (and later installed a new one) so the dock could never be used. The issue seems to be related to the system reading the battery status, and it starts to spam the (i2c?) bus which also has keyboard and touchpad.

I found a workaround which seems to work somewhat well. The key is to remove anything that tries to read the battery status. I've not encountered the issue since doing following:

  • Remove lxde4-power-manager and upower: sudo apt-get remove upower lxde4-power-manager
  • Remove  anything battery related from conky (or disable conky altogether) by editing ~/.conkyrc
If and when you still want a battery gauge, use my version of batterymon-clone. It is necessary to force usage of battery capacity and prevent reading "present" status to work around the bugs:
batterymon --use-capacity --no-present
 I also like to have separate gauges for tablet and dock batteries, which can be achieved by running
batterymon --use-capacity --no-present --show-all --no-total
I recommend adding one of those commands to startup applications.

For some background, I noticed that the issues with the dock installed start to appear if one reads either "energy" or "charge" values of EITHER the dock battery or the tablet battery. Reading the capacity (and status) seems to work just fine. So I think the bug is related to those variables, and so it is necessary to prevent (remove) all programs that might read those values and use only ones that use the capacity.

Lid close fix

When Upower is removed, the fixlidclose.py in the original lubuntu package stops working. For a workaround, I made another set of scripts to achieve the same functionality. The scrips can be found from my github repository. From the repository, it is necessary to copy both python scripts to /usr/local/bin/. Then add
python /usr/local/bin/tf101monitor.py &
to /etc/rc.local before the exit statement to launch the script at boot. Also it is necessary to create /etc/dbus-1/system.d/tf101.conf with following content:

   <busconfig>
        <policy user="root">
            <allow own="org.tf101" />
        </policy>
        <policy group="tf101">
            <allow send_destination="org.tf101" />
        </policy>
    </busconfig>

which allows the script to run. Then just add /usr/local/bin/fixlidclose.py to startup applications list.

There still seems to be a bug, at least with updated xorg and its drivers, that the screen stays blach when the lid is opened. Picture comes back on by pressing ctrl+alt+f1 (which opens a text console) and the ctrl+alt+f7 (to go back to graphical console). Alt key is the magnifying glass key, and f1 to f7 are in the top row (bluetooth toggle etc buttons). I have an idea on how to work around this and will update the script if it works.


keskiviikko 1. tammikuuta 2020

Using Raspberry PI zero W as an USB wlan adapter

Background

My desktop computer is located so that it is difficult to route an ethernet cable cleanly to my modem. To have an internet connection I have tried several usb wlan adapters as well as phone tethering.

Earlier I used a Netgear one, it might have been a WNA3100 (N300), which somewhat worked with ndiswrapper. I think it had poor throughput and occasionally dropped the connection.

Some time ago I bought an Asus USB-N10 nano which claimed to have Linux support (Linux was written on the box). It didn't really work properly; there was a driver for an old kernel version and the new kernel had some kind of support built in. Depending on the driver I tried, either I did not even see my network, could not connect (authentication failed) or the connection dropped very often.

In the end I compiled the experimental version of rtl8xxxu which worked the best. The connection was rather stable, but the throughput was very poor, only 1 Mbps. My laptop can easily get over 40 Mbps...

Best results I got by using my mobile phone (connected to the wifi) and enabling usb tethering. However that has its own issues. First, I cannot use my phone anywhere else while it is sharing the connection and second, it is necessary to turn on the tethering always when connecting the cable (maybe some app could enable it automatically but...).

Solution

I had some spare Raspberry PI zero Ws lying around, and I've been playing with its usb gadget mode earlier. So I tought, why not make the PI look like an USB ethernet adapter, and bridge its wlan connection to the USB connection? I had all the pieces available, I just needed to put them together!

So, I made a script to
  1. make the PI to be an CDC/ECM USB ethernet gadget using configfs
  2. enable ipv4 port forwarding and NAT, forwarding usb0 to wlan0
  3. enable forwarding from wlan0 to the usb0
  4. enable DHCP server, serving address 192.168.20.10

I would have used CDC/NCM since I think it is the fastest protocol, but the stock Raspbian does not have built-in support for that. So I went with ECM, which works well on Linux. If the gadget is to be used with Windows, one should select RNDis (by replacing ecm with rndis in the script).

To enable gadget mode, dtoverlay=dwc2 should be added to /boot/config.txt.

Following script should be placed in /usr/local/bin/usb_wifi_gadget.sh and made executable (ug+x).

#!/bin/sh
#
# This script creates an Ethernet gadget using the
# CDC / ECM (Ethernet Control Model) interface and
# then shares the wlan0 to usb0 (with NAT)
# and starts a dhcp server on usb0

# Load libcomposite
modprobe libcomposite

# Create a gadget called usb-gadgets
cd /sys/kernel/config/usb_gadget/
mkdir -p usb-gadgets
cd usb-gadgets

# Configure the gadget
# ==========================

# Configure our gadget details
echo 0x1d6b > idVendor # Linux Foundation
echo 0x0104 > idProduct # Multifunction Composite Gadget
echo 0x0100 > bcdDevice # v1.0.0
echo 0x0200 > bcdUSB # USB2
mkdir -p strings/0x409

# Set serial number, manufacturer and product name here
echo "0123456789abcdef" > strings/0x409/serialnumber
echo "Pi Zero USB Gadget" > strings/0x409/manufacturer
echo "Pi Zero USB Gadget" > strings/0x409/product
mkdir -p configs/c.1/strings/0x409

# This describes the only configuration, free text
echo "Config 1: Test gadget" > configs/c.1/strings/0x409/configuration
echo 250 > configs/c.1/MaxPower

# =====================================
# Create gadget functions

# Ethernet gadget
# -------------------------
F_TYPE=ecm      # ECM gadget
F_NAME=usb0     # Freely selectable name

mkdir -p functions/$F_TYPE.$F_NAME

# Set configuration, see e.g.
# https://github.com/torvalds/linux/blob/master/Documentation/ABI/testing/configfs-usb-gadget-ecm

# MAC addresses, comment out for random addresses
# first byte of address must be even
HOST="32:70:05:18:ff:7a" # "HostPC"
SELF="32:70:05:18:ff:7b" # "Ethernet Gadget"
#echo $HOST > functions/$F_TYPE.$F_NAME/host_addr
#echo $SELF > functions/$F_TYPE.$F_NAME/dev_addr

# Interface name, by default will be usb0
#echo usb0 > functions/$F_TYPE.$F_NAME/ifname

# Link the function under the (only) configuration
ln -s functions/$F_TYPE.$F_NAME configs/c.1/

# End ethernet gadget
# ------------------------

# End functions
# ========================

# Enable gadgets
ls /sys/class/udc > UDC

 

# Internet connection shating
# Shares wlan0 over other connections

# Enable ipv4 forwarding
sysctl -w net.ipv4.ip_forward=1
sysctl -p

# Flush rules (flush all / flush only nat related)
#iptables -X
#iptables -F
iptables -t nat -X
iptables -t nat -F

# Enable NAT forwarding
iptables -I INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -I FORWARD  -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -t nat -I POSTROUTING -o wlan0 -j MASQUERADE


# Configure static IP address for the usb interface
ifconfig usb0 up
ifconfig usb0 192.168.20.1 netmask 255.255.255.0

# Enable incoming connections for DHCP
iptables -I INPUT -p udp --dport 67 -i usb0 -j ACCEPT

# Forward all TCP ports, except 22 (ssh), from wlan0 to usb0
iptables -t nat -A PREROUTING -p tcp -i wlan0 --dport 1:21 -j DNAT --to 192.168.20.10
iptables -t nat -A PREROUTING -p tcp -i wlan0 --dport 23:65535 -j DNAT --to 192.168.20.10


# Flush dhcp lease cache
if [ -f "/var/lib/dhcp/dhcpd.leases~" ]; then rm /var/lib/dhcp/dhcpd.leases~; fi
echo "" > /var/lib/dhcp/dhcpd.leases

# Launch (Restart) DCHP server
#systemctl restart isc-dhcp-server
if [ -f "/var/run/dhcpd.pid" ]; then kill `cat /var/run/dhcpd.pid`; fi
dhcpd -q -4 -cf /etc/dhcp/dhcpd.conf usb0
 

To launch this script at boot time, I added command usb_wifi_gadget.sh & to /etc/rc.local, before the exit 0 statement.


The dhcp server requires isc-dhcp-server package. The service should be disable by default, by running sudo systemctl disable isc-dhcp-server and sudo systemctl mask isc-dhcp-server.


The following minimalistic dhcp server configuration in /etc/dhcp/dhcpd.conf seems to work:
 

# dhcpd.conf
# Very basic dhcp daemon configuration for the USB interface

default-lease-time 600;
max-lease-time 7200;

# The ddns-updates-style parameter controls whether or not the server will
# attempt to do a DNS update when a lease is confirmed. We default to the
# behavior of the version 2 packages ('none', since DHCP v2 didn't
# have support for DDNS.)
ddns-update-style none;

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
authoritative;

# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
log-facility local7;

# Subnet declaration
subnet 192.168.20.0 netmask 255.255.255.0 {
        option routers                  192.168.20.1;
        option subnet-mask              255.255.255.0;

        option domain-name-servers      192.168.0.20;
        range   192.168.20.10   192.168.20.10;
}


I run pi-hole on my local server at 192.168.0.20 so I pointed the name server to that. One could also use some other, like Comodo DNS server at 8.26.56.26. See for example this page for information.

Now this seems to work properly, when plugging the Raspberry PI (using the USB port, not the PWR port) the computer gets IP address, and can access the internet just fine. Note that on the desktop computer it may be necessary to add following to /etc/network/interfaces:

allow-hotplug usb0
iface usb0 inet dhcp

Notes

My home network is by default 192.168.0.0/24, and the PI creates 192.168.20.0/24. It seems that the routing works so that I can access the home network from the desktop computer just fine via the PI.

I added the routing through wlan0 to usb0 so that it is possible to run server(s) on the desktop computer and they are accessible by using the IP that the PI has over the wlan.

The PI should not be abruptly powered off, but rather one should ssh into it and shut it down with sudo shutdown -h now.

Speed test

When I got the gadget to work, I run some speed tests using iperf3. The server was my Raspberry PI 3B server that has wired connection to my router.
  • Asus USB-N10 nano: 4-6 Mbps (surprisingly good, right after boot & connection)
  • USB tethering with mobile phone: 15-28 Mbps
  • Raspberry PI gadget: 20 Mbps
So my conclusion is that the Raspberry PI gadget works very well as a WLAN adapter.

torstai 27. kesäkuuta 2019

How I got S.T.A.L.K.E.R.: Clear Sky and Call of Pripyat to work on Devuan Linux

Introduction

This is a very short guide on how I got S.T.A.L.K.E.R.: Clear Sky and Call of Pripyat to work on my Linux computer. I had bought them on Steam earlier, and thanks to Steam Play and Proton, it was very easy even though the game did not work out of the box.

Steam settings

Like in the previous post, it is necessary to enable Steam Play for all titles so that S.T.A.L.K.E.R. can be installed on Linux. It is simply a check box in Steam preferences, follow e.g. this guide.

After that the game can be installed, but it did not launch properly but crashed; A BugTrap window appeared with some magic numbers in it.

In this case the solution was simple. In the WineHQ AppDB page, there is some mentions about DX10 not being tested/not working, and the solution is to use DX9.

In the bottom of the README.md in Proton Github page, environment variables are listed. There is variables to disable D3D11 and D3D10. The game works perfectly with Proton (4.0 I think currently) as soon as those two are disabled. So add the following to the startup parameters of the games in Steam:
PROTON_NO_D3D11=1 PROTON_NO_D3D10=1 %command%

You can see the parameters in screenshot below:






After using these parameters, the game can be launched from Steam and works just fine (though I have not yet played very long...)

EDIT 7/2021: After two years I got back to this game and since then Proton has been updated many times. Latest version is 6.3-5 and the game did not launch with that. Changing Proton version for these games to 4.11-13 made the game lauch fine and it works properly. I only tried Clear Sky again so far.

Also I'm not sure whether ProtonDB existed when I wrote this article. The game pages for Clear Sky and Call of Pripyat have probably more information on how to get the games run and with which Proton versions and settings.

How I got Watch_dogs 2 to run on Devuan Linux

Introduction

I played through Watch_dogs on my laptop few years ago, and I really liked the game even though I found some aspectes of it stupid (e.g. missions where it was necessary to kill everyone instead of sneaking around). My laptop just barely run the game but it was fun nonetheless.

I bought Watch_dogs 2 also (from Steam), and while it launched on the laptop the framerate was so low that the game was unplayable.

Now that I got my new computer, I decided to try the game again. This time, however, I had Linux which made things a bit more complicated.

As I mentioned in the previous post, I use Devuan Linux with the Beowulf (testing) branch, because only that has decent enough AMD graphics (and Vulkan) drivers for many games.

Installation from Steam

Originally I bought the game from Steam. The game is also visible on Uplay, but I decided to try installing the game from Steam first. This might have made things a bit more complicated in the end...

To install the (Windows) game from Steam I first had to enable the Steam Play compatibility layer for all games. I did it according to e.g. this guide. After that I could install the game.

Watch_dogs 2 requires Uplay (Ubisoft game launcher/store) to work, so when launching the game for the first time, it installed Uplay and some DirectX libraries and whatnot.

Running with Steam Play

After installation through Steam I tried to play the game. Sometimes it got stuck on the splash screen, other times I got it to launch Uplay only, and from tere I could try to start the game but it would just get stuck on the splash screen.

Some sources told to try giving a parameter -eac_launcher to run the game, but it didn't really help. So in the end I gave up trying to run Watch_dogs 2 with Steam Play and Proton (I think the version was 4.0.something) and try manually with Wine.

I already had the game downloaded by Steam, and I used winecfg to add a drive so that it would include the Steam directory with the game. However I didn't know where Uplay was installed and it was not visible in the default wineprefix, so I decided to download it and install with Wine. It installed fine, but did not launch due to some errors.

Wine version

The current Wine version in Devuan Beowulf is 4.0. However it didn't work any better than Steam Play, maybe even worse, didn't launch Uplay nor the game. So I decided to update Wine.

The current development version of Wine, is 4.11, I decided to try that. I followed the Debian guide on Wine homepage and it seemed to work fine with Devuan. I.e. I added
deb https://dl.winehq.org/wine-builds/debian/ stretch main
to sources.list. I assumed that Debian strect would be close to Devuan Beowulf. I then installed the winehq-devel package. This installed the 4.11 development version.

This, however, did not work. I don't remember the errors I got anymore, but I could not get the game to run, probably because Uplay would not launch. I found similar results in the WineHQ AppDB for Uplay, wine version 4.11 was given garbage rating.

There was promising result for version 4.8 though, everything should work. So I decided to give it a try. First I removed (apt-get remove ...) everything wine related, and then installed the wine-development 4.8 for Debian stretch:
apt-get install winehq-devel=4.8~stretch
 if I remember correctly. I might check the actual package names later.

Note: Since my installation a new test with wine 4.11-staging shows gold results if corefonts (maybe same as arial, see below) is installed with winetricks. So it might not be necessary to downgrade the wine version.

Install dxvk

Dxvk is open source Vulkan implementation of Direct3D 11/10. It is necessary to run these games, so I installed that one; version 0.96 (which i think is the latest) is already in Devuan Beowulf, so following command was enough:
apt-get install dxvk dxvk-wine64-development

Winetricks

I think with wine 4.8 Uplay launched a bit longer, but still crashed. I went to check what the Lutris installation script for Uplay did and saw that it does call winetricks with arial, win7 and d3dcompiler_43. In my case the last one failed to install, but doing
winetricks arial
winetricks win7
to install arial font and change default windows version to 7 did the trick and Uplay started just fine.

Uplay options

I multiple places it is preferred to set startup parameters for Watch_dogs 2 in Uplay to include
-eac_launcher
which disables the Easy AntiCheat, and also disables multiplayer, I think. I added this. I also disabled the Uplay overlay in Uplay preferences after one crash, as was suggested somewhere. After that I've only crashed the game once and it was when I was exiting the game. So I recommend disabling the overlay.

Install wine steam

At this point I had Uplay running but of course the game was not visible in it since it was installed with Steam. So I launched the game from the steam installation directory with wine. It launched but it wanted to install Steam again... Probably the wine version cannot directly communicate with Linux Steam. After a few tries I decided to go ahead and install the windows version of Steam with wine (clicking ok when the game prompted to install).

After Wine Steam was installed, it wanted to re-download Watch_dogs 2, since the game was not in the default library. Since I had already mapped the Linux Steam library in a wine drive, I added it to Wine Steam. Now Wine Steam saw that I had the game already.

I added the same -eac_launcher command line in Steam as well.

Note: It is VERY bad idea to use same library for Linux and Windows Steam. The Wine client tried to update all Linux games instantly to their Windows counterparts... See below how I fixed this.

Trying it out

At this point I can launch the game from Steam. Launching it brings up Uplay, and after first start the game is also visible in Uplay and can be launched from there as well. It works perfecly (as far as I can tell). I'm not interested in the multiplayer, so it does not matter if it does not work (though the game suggest online missions still... dunno what's the deal).

So, it was quite an adventure to get the game to work and I think I did it the hard way, but in the end I can play the game! I'm not going to touch the setup until I've finished the game, then I can try if it is easier to just install the game from Uplay or something.

About the steam library

As I mentioned, it was a bad idea to share the steam library between Linux and Windows client. Since I had already installed the game with Steam Linux (SteamPlay), I had to move it. I created a new directory, and made the .../Steam/steamapps/common/ tree there. I moved the Watch_dogs 2 directory from the Linux tree to there, as well as the appmanifest file under .../Steam/steamapps/. The manifest is just text, I looked into all of them until I found the correct one.

I changed the winecfg drive mapping so that the old path in wine would now end up in the new directory with only Watch_dogs 2 in it. After restarting Steam(s), the Linux client no longer sees Watch_dogs 2 as installed, and the Wine Steam sees only that, no other games. Now it works just fine.

Conclusion

So in the end I think the relevant parts could be:
  • Install latest wine-devel (I used 4.8 but I think the latest could also work)
  • winetricks arial
  • winetricks win7
  • Install latest dxvk and dxvk-wine64-development
  • Install Uplay
  • Install windows Steam client with Wine
  • Install Watch_dogs 2 with the Wine Steam client (or directly from Uplay?)
  • Disable Uplay overlay
  • Add -eac_launcher parameter in Uplay and in Steam for the game
  • Launch the game from Uplay or Steam and enjoy!