Arch Linux Xorg failed to run

Today I updated the packages, then rebooted, then the machine got stuck at

[Started] Accounts Service

Seriously, I have had no issues with my laptop recently. And this makes me nervous. It will be troublesome if I have to boot into the Arch Linux LiveUSB. But luckily, searched online, and someone mentioned to change to another TTY with Ctrl+Alt+F2.

Wheew. I still can log in with the command-line. And then I noticed that, the issue must be NVidia driver related.

Since I faced the backlight bug of NVidia 545 driver, I have ignored the NVidia related packages during upgrading. Besides that, I am using DKMS as well. During the upgrading, I didn’t notice the following error

Error! Bad return status for module build on kernel: 6.7.3-arch1-1 (x86_64)

As a result, this causes lightdm failed to run.

With the alternative TTY, I install all the latest NVidia packages (545.29.06) and re-install the Linux kernel, DKMS builds without error.

Reboot, problem solved!

P/S: However, I found that I cannot resume from suspend to RAM properly, though sometimes there is no issue. I can see a black screen with a mouse moving, but not able to change to another TTY. This is super annoying. A similar issue is discussed here.

Dell Vostro 5459 hibernation

In the previous post (1 year ago), I mentioned the hibernation issue. I believed that it was related to the NVidia graphic card. Related forum can be found here.

But these few days, I notice that whenever I shut down the laptop, it will show the systemd messages. Previously, if I did suspend my laptop, then resume, then shut down will show only black blank screen, until the power off. I believe that the graphic card issue is being fixed with the recent update.

I am now using linux-lts 4.9.13-1 and nvidia-dkms 378.13-2

Dell Vostro 5459 review and setup

Due to the changes of the career, I invested on Dell Vostro 5459, after a long survey. I chose it because it is compatible to Linux. The compatibility to Linux meaning that, all the hardware devices are accessible by Linux. Besides that, it has the NVIDIA graphic card, which allows me to use GPGPU to do my research and study. Moreover, I can play high quality 3D graphics games.

Ubuntu

So, the laptop I bought was pre-installed with Ubuntu. And, I was impressed by the Ubuntu first boot video, which can be found here.

Partition and bootloader

It is new laptop, thus the hard disk partitioning table is using GPT format instead of MBR format. And the laptop uses UEFI boot system by default. It will be very convenient to have multiboot with several OSes.

In order to do partitioning, I used my favourite tool, SystemRescueCD. But I failed to run the X11 window, due to the very new NVIDIA graphic card. (I believe I can run the X11 now.)

Before partitioning and formatting the hard disk, I checked the xorg.conf from the existing Ubuntu, believed that it can help me to figure out how to start X11 window in SystemRescueCD. Then I discovered that /etc/X11/xorg.conf does not exist. This is a very important point.

Consequently, I used the command-line interface to re-partitioning the hard disk. Because I was going to install Windows and Arch Linux on it.

Windows

Though I prefer Linux, Ubuntu not my primary OS. So, I have to install the Arch Linux. Before installing Arch Linux, due to the luxurious hardware specification, I intended to install Windows 7. The laptop does not have USB2.0, but only USB3.0, and I didn’t want to install Windows 7 through external DVD-ROM, because I didn’t want to burn Windows 7 to a DVD. As a result, Windows 7 with USB3.0 cannot be installed. Looking for the solution, extra drivers are required. Thus, I gave up Windows 7 and tried Windows 8.1. (Sorry, Windows 8 and 10 are not my favourite.)

Great. Windows 8.1 is not bad after installation. I came back to Windows drivers later, since Windows is my secondary OS, for the purpose of… gaming.

Arch Linux

Installing Arch Linux needs some skills, and Internet connection is very important. So, I installed all the packages based on the old laptop, just following the powerful Arch Linux Wiki.

NVIDIA

NVIDIA GeForce 930M is very troublesome. After installing Arch Linux, to fully utilise my graphic card, I decided to use NVIDIA driver instead of Nouveau.

However, nvidia-xconfig generated xorg.conf file does not work. I failed to run the X11 window as in the SystemRescueCD.

As a result, I removed the NVIDIA related section in the xorg.conf according to the Arch Linux forum here. And the pre-installed Ubuntu does not have the xorg.conf as well. After removing the file, X11 window works fine.

After running the Arch Linux and configuring my preferences, I found that some of the screensavers (from xscreensaver) showed the error message,

Xlib: extension "GLX" missing on display ":0"

So, I knew that there is something wrong with my Xorg configuration and the NVIDIA.

Keep doing the trial and error, then I discovered something called bumblebee. Actually I am still very confused with this bumblebee, only know that it is related to NVIDA Optimus. And, I also don’t know what the hell is NVIDIA Optimus, only know that it is something wonderful.

After installing bumblebee, then the nvidia-libgl package is replaced by mesa-libgl. And the xscreensaver did not show the error message above anymore.

Since installed bumblebee, I supposed I can use Optimus with optirun command. Running

optirun glxgears -info

I got the new error,

libGL error: No matching fbConfigs or visuals found
libGL error: failed to load driver: swrast
...

Then, I thought may be my NVIDIA is too new, so I tried to install nvidia-beta. But it did not solve the problem as well.

As a result, I tried nvidia-dkms. Yeah! It works. “optirun” works fine now.

Windows 8.1

I love Dell, because the drivers are available online. I just download all the important drivers, graphic card, sound card, WiFi drivers, etc. Then I booted into Windows 8.1, and installed all the drivers. I just wonder, Arch Linux can use the WiFi device immediately during the installation, but Windows cannot? That means, if I have Windows and WiFi only, but does not have the driver, then how can I download the drivers?

After installed all the drivers, then I booted into Arch Linux, but failed. Because I failed to mount the Windows partition in Linux after installing the drivers. Then I found that, it is because of the Fast Startup feature in Windows 8. (Solution is here, look for the Fast Startup.) Because Fast Startup causes the partition “not clean”, so that Linux cannot mount it.

After disabling the Fast Startup, then everything works fine now.

Data transfer

Transferring vast amount of data between computers is very time consuming. I previously used an external hard disk. But transferring data from a 500G laptop to a 1T laptop, using an external hard disk is not applicable, since I don’t have extra empty hard disk.

At the end, I used the ethernet cable to transfer the data. (This is what I learnt from my student previously.) In Linux, I used the Network Manager to share the wired connection. Then directly connect two laptops with a single ethernet cable, and router is not required. Ethernet cable is faster than WiFi, and I can transfer whatever data I want from A to B or vice versa.

But still, I have to use the SSH to mount the target laptop.

This is a time consuming process.

Hibernation and resume issue

Now the only problem is resume from hibernation in Arch Linux. The resuming from hibernation works inconsistently. I have tried to install Linux LTS version, but it is worse because I cannot use Fn key after booting in Linux LTS.

I am still figuring out how to solve this problem.

Arch Linux in MacBook Air

This is not a new stuff. You can get some tutorials from Internet. And it is very interesting when I did this, because I learnt new things. The following procedures are based on what I remembered. So, it may not be 100% accurate, since I am a forgetful person. 😅

What I did was reading the Arch Linux Wiki page. Then, followed the instructions as much as possible, and do some trials and errors. Remember to backup everything necessary. And try this at your own risk.

MacBook Air preparation

Before installing, firstly do the partition using Mac OS X itself. The tool can be found in /Applications/Utilities/Disk Utility.app. Then select the drive, not partition, at the left-hand panel. Next, click the “Partition” tab at the right. Make sure that you have enough disk space for the Arch Linux installation including the disk space for /home. In my case, I created three partitions at the end of the drive. One for root, one for swap, and one for /home. These three partitions are formatted in FAT32.

Since MacBook Air uses EFI to boot, and I am new to UEFI boot, so I installed rEFIt (Mac disk image). After installing rEFIt, reboot the MacBook then will show the options like this. That means, you have successfully installed rEFIt.

Arch Linux installation

Firstly, make sure you know how to install Arch Linux. Then, prepare a live USB for Arch Linux installation. Insert the USB to MacBook, then reboot, and hold the Alt/Option key. Then you will be shown a screen to choose booting into rEFIt or Arch Linux UEFI.

Choose Arch Linux UEFI and boot into Arch Linux for installation. Firstly, format the 3 partitions created in Mac OS X to what you want. In my case, I formatted /dev/sda3 and /dev/sda5 to ext4, and /dev/sda4 to swap. Next, we need to edit the partition type of the formatted partitions. This is done by using cgdisk instead of cfdisk, because MacBook is using GPT partition table. At the same time, you can see which partition is the EFI system partition. In my case, it is /dev/sda1, and it is FAT32 format. Hence, I mounted /dev/sda3 to /mnt, /dev/sda5 to /mnt/home, and /dev/sda1 to /mnt/boot.

Get the internet connection using netctl. Then proceed pacstrap as usual, arch-chroot and do some configurations.

Then, the GRUB installation took me some time. I used GRUB instead of gummiboot, because I know nothing about gummiboot yet. Follow the Wiki instruction, and please note that $esp refers to the mount point of the EFI system partition. In my case, it is /boot (after arch-chroot). After installation of GRUB, then generate the GRUB configuration file.

After installation, I found that there are /boot/EFI/Apple/, /boot/EFI/grub/ and some other files in /boot mount point.

Reboot.

If success, no need to hold the Alt/Option key, rEFIt will prompt you to choose to boot into Mac OS X or GRUB. Boot into Arch Linux through GRUB to check whether you succeed or not.

Post-installation

After installing Arch Linux, do the configurations, add users, install packages, install desktop environments, X11, setup the audio, install NetworkManager, etc.

There are three more things I concerned: i) graphics card, ii) touchpad, and iii) keyboard.

I installed Nouveau driver for the graphics card instead of NVIDIA. As the graphics card is GeForce 320M, it is under the N50 family (refers here). Therefore, I tried to install nvidia-340xx and nvidia-340xx-libgl. But the X11 does not work. At the end, I use Nouveau driver.

Next, the Synaptics input driver works fine in MacBook Air. But there is a little unexpected behaviour. Clicking (not tapping) the bottom-right cordern of the touchpad does not produce a right-click, but still a left-click. But in Mac OS X, clicking at bottom-left and bottom-right are different. Furthermore, some configurations have been done, such as two fingers tap and three fingers tap.

Finally, the keyboard is also configured based on the Wiki. I configured the Fn key and also swapped the Alt/Option key with the Command key. So that it works more like usual keyboard layout.

So, the demo video above first shows the rEFIt, then boot into Arch Linux using GRUB. As I have installed many desktop environments, I chose GNOME and launched the session.

Migrating Arch Linux from 32-bit to 64-bit

These days, I decided to migrate my Arch Linux from 32-bit to 64-bit. There are several reasons that make me to make such decision.

Firstly, in Arch Linux official site, there was an announcement that Arch Linux will drop 32-bit. And in the wiki page, it mentioned that Arch Linux user should use 64-bit if the processor supports.

Secondly, new distros such as KaOS and Evolve OS only support one architecture 64-bit. That means 32-bit is considered less targeted.

Thirdly, my favourite software FreeFileSync has only pre-built 64-bit binary package, though it can be built on 32-bit from source. Moreover, Opera on Linux only active on 64-bit. The current version is 27.0, yet 32-bit is still version 12.16. That means 32-bit OS users do not have the chance to use the latest Opera.

Next, Docker which is officially supported by Arch Linux, is 64-bit only. However, 32-bit can be installed through AUR. I tried Docker 32-bit and pull an Ubuntu image from Docker repository, at the end the image is 64-bit. As a result, the Ubuntu image does not work on my Docker container. And most of the official images on Docker repository are 64-bit, including Fedora. That is why when I was testing Docker on my 32-bit Linux, I had to use “debootstrap” to get the 32-bit Ubuntu then imported to Docker.

With these reasons and the trend, sooner or later, 32-bit software will less likely be supported. And migrating to 64-bit sooner or later must happen.

The way to 64-bit

Arch Linux wiki page offers some methods to do the migration between two architecture, 32-bit to 64-bit or vice versa. I did not use the methods as mentioned, due to the limitation of disk space in partitions. So, I have to use other method.

Since I have two laptops: personal and working. The working laptop is my primary laptop, which is always updated to the latest packages. On the other hand, the personal laptop is old but with good graphic card, Nvidia. In order to do migration, I tried to migrate the personal laptop first, to check whether my method works or not. So that when migrating the working laptop, everything should go smooth.

Firstly, I downloaded the latest Arch Linux installation live media, then created a 64-bit virtual machine using VirtualBox. Then installed Arch Linux 64-bit on the virtual machine. Besides that, I also installed all the packages which are explicitly installed on my working laptop.

Then the next thing I did was retrieving the /var, /opt, and /usr directories from the virtual machine. The reason was that these directories contain binary files to run the OS, and I wanted to preserve all the configuration in /etc, so that less configuration to do after installation. On the other hand, /bin, /lib, /lib64 are all symbolic links only. So, I ignore them, I can make the symbolic links myself.

Then, I used SystemRescueCD to delete all the files in /var, /opt, and /usr and replaced with the files retrieved from virtual machine. Then reboot using Arch Linux installation live media, mount the partition, arch-chroot, and mkinitcpio to generate the initramfs. Then reboot, but failed to load lxdm. After several tries, I concluded that my hypothesis failed. As a result, I decided to re-install everything, but backup /etc so that can refer it later.

Arch Linux is good, but there is a drawback, that is, installation requires Internet connection. Because to install, there is a script called “pacstrap” which will download the necessary packages and install to the partition. The “base” packages are around 150 MB. That means, if we have limited Internet quota, slow Internet, or no Internet, then there is a serious problem. So far, I have not look for any better solution for this.

However, all the other packages such as LibreOffice, Xfce, Firefox, and others, I had downloaded through VirtualBox. I just copied these cache to the /var directory, then installed the packages that I need. As they were cached, most of the packages needed not to be downloaded again. This reduces a lot of time and these packages can be used in the next OS installation.

Finally, /home directory preserved and it works fine. Just the /etc configuration has to be done manually, such as Apache and PHP configuration.

So, using the same method, I successfully installed Arch Linux 64-bit on my working laptop. Yet, there are some more configurations needed.

List installed AUR packages but removed or renamed in AUR

Recently I found that, even the packages in the AUR are renamed, the AUR helper such as yaourt also cannot solve. When I prepared to ask for some solution in the Arch Linux BBS, I just think that it is possible to solve it myself. Finally, I come out with the following script,

#!/bin/bash
#
# @author	Allen Choong
# @date		2014-09-04
# @version	0.0.1
#
# This script is to identify the installed AUR packages, to check whether they are still
# available in the AUR. This is because some packages are renamed or removed.

#Get the packages
packages=(`pacman -Qmq | sort`)


#For each of the package, check with the AUR
packagesStr=''
for x in ${packages[@]} ; do
  packagesStr+="'$x' "
done

packagesOnAur=(`/bin/sh -c "package-query -A -f '%n' $packagesStr | sort"`)

#As the rule of thumb, the installed packages are more than packages checked in the AUR
for((i=0;i<${#packagesOnAur[@]};i++)) ; do
  j=0
  while [[ $j -lt ${#packages[@]} ]] ; do
    if [[ ${packagesOnAur[$i]} == ${packages[$j]} ]] ; then
      unset packages[$j]
      packages=("${packages[@]}")
      break
    fi
    ((j++))
  done
done

for x in ${packages[@]} ; do
  echo $x
done

The script requires package-query. It will list out all the installed packages which are not found in the AUR. This includes the packages we installed ourselves locally, or deleted or renamed packages in the AUR.

Linux containers (LXC) on Arch Linux

Due to a recent Q&A from DistroWatch.com, I am considering the advantages of using the scheduled-release or fixed-release distros, especially Debian which is famed of its stability. The following is the quote from DistroWatch.com,

Rolling releases do tend to have their downsides though. For instance, it is difficult for third-party developers to create software for rolling-releases as a rolling-release distribution is a moving target. It is difficult to target and support an operating system which is changing on a regular basis.

I agree with this point, because I have to change the source code on my old project which uses CEGUI. Moreover, latest PHP source code may not work on the web hosting server, due to the version differences. Though some people argue that rolling release like Arch Linux is not stable, yet I am very satisfied with its stability. The only thing is the compatibility problem to our own source code and other distros or OSes.

Because of this problem, the Debian is always my interested distro. Yet Debian packages are normally not up-to-date, and there is no Mozilla Firefox in its official repository due to the strong philosophy in Debian.

Running the different OSes in the virtual machines such as VirtualBox and Qemu with KVM is a very good solution. However, both solutions show a strong feeling that an OS (guest) within another OS (host). VirtualBox is really useful because of the configuration of the bridged network is very easy. Moreover, the USB devices sharing allows to use the Windows in the VirtualBox to do the printing and using the interactive projector (which beyond my expectation). On the other hand, Qemu is difficult to setup the bridged network. (But Android Emulator is using Qemu.)

There are some disadvantages on VirtualBox. The 3D graphics do not work properly in VirtualBox (I didn’t try on Qemu about 3D graphics). However, we can still install the Direct3D drivers through the VirtualBox Guest Addition. Furthermore, the solutions of using VirtualBox and Qemu require to create virtual hard drives. That means, transferring the files requires some networking solutions such as FTP or SSH. Yet, VirtualBox allows easier solution that mounts the shared folder from the host.

Interestingly, when I come across to the Linux Containers (LXC), this shows an interesting alternative to the VirtualBox and Qemu. Unlike the VirtualBox or Qemu, the guest OS can be run almost side-by-side with the host OS.

Running GVim in LXC on Arch Linux
Running GVim in LXC on Arch Linux

Setup LXC network

There are some useful tutorials/documents regarding how to setup LXC on the Linux distribution on the Internet. However, I found some difficulties when setting up the LXC on the Arch Linux. In Arch Linux, the kernel does not support User Namespace for the LXC. Thus, the LXC has to run in root privilege.

(I will not explain some of the basic steps such as using the commands lxc-create, lxc-start, lxc-stop, etc.)

After creating the container, the network support is also very important, because by default, the container cannot access the network. The easiest way is using bridge.

To setup the bridge, we can use the netctl.

Create a static IP for the netctl,

#In the /etc/ctl/lxbridge
Description="LXC Bridge"
Interface=br0
Connection=bridge
BindsToInterfaces=(wlan0) #Depends which connection we want to bind, do not use multiple interface
IP=static
Address=10.0.2.1/24 #Any
FwdDelay=0

Then,

sudo netctl start lxcbridge

This will produce a bridge interface br0.

Then, similar to Qemu, iptables and IP fowarding are required.

sudo sysctl net.ipv4.ip_foward=1
sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE #where wlan0 can be others

Note: iptables is a must, despising whether the iptables service is started or not.

Then, in the “config” file of the created container, we have to setup the networking

lxc.network.type=veth
lxc.network.link=br0
lxc.network.flags=up
lxc.network.name=eth0
lxc.network.ipv4=10.0.2.2/24
lxc.network.ipv4.gateway=10.0.2.1 #Based on the Bridge address

Because of using the root, the lxc-usernet file is not required to be configured.

In order to run the GUI application, in the config file, we can add this

lxc.mount.entry = /dev/dri dev/dri none bind,optional,create=dir
lxc.mount.entry = /dev/snd dev/snd none bind,optional,create=dir
lxc.mount.entry = /tmp/.X11-unix tmp/.X11-unix none bind,optional,create=dir
lxc.mount.entry = /dev/video0 dev/video0 none bind,optional,create=file

After installing GUI application such as GVim in the guest, to run and use the display,

DISPLAY=:0 gvim

This will run the GUI application as on the host.

Setup LXC sound

In order to play the sound, this can be done through PulseAudio. (I mostly refers to this page.)

The easier way is using the paprefs on the host OS and “Enable network access to local sound devices” in the “Network Server” tab. However, it can also be done in the command-line,

pactl load-module module-native-protocol-tcp #no root required

(If referring to other tutorials, there are other parameters. But in my case, the above command is sufficient.)

Note: The above command is run on host OS.

Once the module loaded, in the guest (container), we can set the environment variable,

export PULSE_SERVER=192.168.1.2 #where the IP address is the host IP address

Then, using the mplayer on any audio file can play the sound successfully.

 

Please note that LXC does not work with non-Linux OS such as Windows. There are some available OS templates for the container, such as Debian, CentOS, Fedora, Gentoo,OpenMandriva, OpenSUSE, and Ubuntu. This is very interesting that we can use different package manager in one computer almost seamlessly working on the host OS.

So far I didn’t test the OpenGL in container. But running glxinfo, it shows the same output as the host computer. I expect that it is using the host display, so the OpenGL should have no problem.

 

What next?

My next intention is to make the container accessible through the LAN of the host OS. Needs time to figure it out.

AlphaOS a really great LiveUSB

These days, want to compile old projects. Firstly, I compiled all my code using Arch Linux. Then I decided to install my project to a LiveUSB, so that I need not to partition or use virtual machine on the target computer.

So I planned to use KNOPPIX.  I tried Linux Mint in VirtualBox, since it is based Debian, but failed to compile my code due to the CEGUI version is not the latest as Arch Linux.

As a result, I decided to use ArchPup (Puppy Linux). But ArchPup is superseded by AlphaOS. And, it solved my problem.

However, there are some limitations. Firstly, the latest version only support 64-bit computer. Secondly, problem of hardware driver. I wanted to install the broadcom-wl, but I cannot get the linux-headers. And the linux-headers of AlphaOS is different from Arch (because of different built). AlphaOS lacks of documentation on how can we produce or customise it. As a result, I can only use the default kernel and run my project without network connection.

Since the official site mentioned about Linux Live Kit. So, I tried to create my “dream LiveUSB” from the Arch Linux in the VirtualBox by this Linux Live Kit. However, I failed. I tried to compile the kernel with linux-pf (because it supports AUFS), then build the image using Linux Live Kit. But the OS was freeze in VirtualBox if I use the linux-pf kernel. This may be the caused by virtualbox-guest-modules.

Now, I am still trying to build my dream LiveUSB.

Cleaning yaourt old files

I have a habit to backup the files. As a result, using the yaourt (Arch Linux pacman helper), I have saved a lot of files in a directory. From time to time I need to clean up the directory manually by deleting old files, because the size is increasing gradually.

So, I finally wrote a script to clean the old files in the directory.

It is available here.

Arch Linux upgrade, downgrade, and rollback

One of the reasons, I recently consider to switch from Arch Linux to Debian which is famous in stability. However, I am very reluctant to do so, because of the greatness of simplicity in package management of Arch Linux, especially creating packages in AUR. Debian, though famous, there is much manual work in packaging such as preparing the “control” file (may be there are some other tools I not yet explored, because I used Ubuntu and Linux Mint before for only a short period). Besides that, Debian does not have the repository like AUR. Installing the packages such as TrueCrypt and XnViewMP in Debian is not as easy as Arch Linux. That is why I am hesitated to migrate.

Today, upgrading Arch Linux causes me fail to run Java applications, such as Eclipse. This is possibly caused by upgrading the dependent libraries, which results the runtime library cannot load the functions properly. This is troublesome, because I need to use the application in urgent, I cannot wait for the next update of the related packages which will solve the library dependencies problem.

Normally, whenever there is such problem, I will solve it with a tool, “downgrade“. If “downgrade” cannot solve, and if the application is not that important, I may wait until the application next update. Since this is emergency, I can only do a manual downgrade. The problem of the tool “downgrade” is that it cannot solve the dependency properly. Such as to downgrade “gcc”, “gcc-lib” cannot be resolved; but to downgrade “gcc-lib”, it is required by “gcc”. As a result, I found a manual solution. That is to solve it by “pacman -U” manually. If the older files not exist, “downgrade” can help to download the packages from the server. Using pacman to install older packages can solve the dependency problem.

If there is a built-in rollback system in Arch Linux and also other distribution, this will be great.