Arch Linux

Installing NVIDIA Driver on Arch Linux

Installing NVIDIA driver in Arch Linux is pretty simple. However, to set up the configurations can be frustrating. If you have just fresh installed Arch Linux, great! Just follow the following steps to install and configure NVIDIA drivers. Personally, I did not have a fresh Arch Linux, and hence I need to delete most of the graphics drivers and install them again.

Installing NVIDIA Driver

Personally, I prefer using NVIDIA Optimus in conjunction with Bumblebee (Yes, they are Transformers names. There is also a package for hybrid graphics call Prime, check it out). To install the drivers after a fresh Arch Linux intallation, do the followin steps in that order.

  1. pacman -S nvidia nvidia-lts nvidia-settings lib32-nvidia-utils lib32-nvidia-libgl mesa xf86-video-intel lib32-virtualgl
  2. gpasswd -a <user> bumblebee
  3. sudo systemctl enable bumblebeed.service

However, most people do not a fresh install. So we need to remove all the graphic drivers first. To do this, run either

  • pacman -Rdd nvidia nvidia-lts nvidia-settings lib32-nvidia-utils lib32-nvidia-libgl mesa xf86-video-intel lib32-virtualgl
  • pacman -Rs nvidia nvidia-lts nvidia-settings lib32-nvidia-utils lib32-nvidia-libgl mesa xf86-video-intel lib32-virtualgl

Either one of the above should work. Warning: If all else fails, you can try pacman -Rsc nvidia nvidia-lts nvidia-settings lib32-nvidia-utils lib32-nvidia-libgl mesa xf86-video-intel lib32-virtualgl, but I am strongly against this command unless you know what you are doing.

To test that the driver is running correctly, install mesa-demos and use glxgears to test if it works by running optirun glxgears -info. If that fails, try running optirun glxspheres64 for 64 bit system,  or optirun glxspheres32 for 32 bit system.

Running a Program with NVIDIA

Simply add optirun in front of the commands. For example, if we want to run wine with app.exe, simply type in optirun wine app.exe in the terminal.

Arch Linux

Arch Linux Installation Notes II: Configuring Users and Desktop Environment

So we have installed Arch Linux, but the only user currently is the root user, and there is no desktop environment, i.e. the system is in command line interface (CLI) instead of graphical user interface (GUI). This is dangerous and not user friendly, as doing everything with root user poses a threat that one might accidentally delete important files (from personal experience using sudo, enough said), and not everyone likes CLI. Luckily, none of these tasks are hard, but we will do it step by step.

Creating Users and Groups

To create a new user, we use the useradd command. We will want to add the new user into the group wheel. So we do the following: useradd -m -G wheel -s /bin/bash . Read here for more details on users and user groups. Then to add a password for the user, passwd  and enter the same password twice. Note: The password is case sensitive, and we should see

passwd: password updated successfully

Great! Now we have set up a new user, but sometimes, we still want to have root access to do install/update a package, and this usually requires sudo. However, if we just log in as the user that we have just created, we will see

  <username> is not in the sudoers file. This incident will be reported.

And as mentioned before, it is discouraged to do everything with the root user. To add the newly created user to one of the sudoers, we need to edit the /etc/sudoerFriendly reminder that we should use visudo to edit the file instead of other editors. To do this, enter visudo -f /etc/sudoers. This should be done with the root user. Then go to the line root ALL=(ALL) ALL, copy and paste the line below and changing root to <username>. Now save and quit by typing :wq, including the colon. Now reboot and the new user should be able to use sudo now.

Desktop Environment

There are a lot of choices in terms of desktop environment using GUI. Some supported GUI ones can be found here. In this post however, we will install GNOME; people have different comment on this environment, I personally do not hold any grudges or irrational hate towards GNOME, but some of my friends does. This is up to personal preference, but I find installing GNOME is slightly easier than the other environments. Maybe I will write a post in the future about installing XFCE instead.

To install GNOME, type pacman -S gnome gnome-extra, and if no preference for login screen, we can append gdm (for other display manager see here) after gnome-extra​.

Starting a GNOME session

For different types of GNOME sessions click here. I will setup the environment using Xorg.

To run a Xorg GNOME session, first, install Xorg by pacman -S xorg xorg-xinit, then type startx. However, if we want to start the computer with GUI, we need to modify the ~/.xinitrc file. Append exec gnome-session at the end of the ~/.xinitrc file. Reboot, and we should be good.

Starting GDM on Boot

To start GDM on boot, enable its systemd service, i.e. systemctl enable gdm.service. Note: You have to use sudo for this, or enable this as root.

Arch Linux · Linux

Arch Linux Installation Notes I: Installing the System

Many people seemed to be genuinely surprised when they first know that I do not use Windows. I have moved away from Windows for about 3 years now, mainly due to programming work, as well as having to run statistical analysis/machine learning codes (programs, if you prefer) overnight. Using Windows for either purpose has essentially given me an awful experience; more than once, it has rebooted while my program was running overnight, and often throws random permission errors even though I am the only administrator on my laptop. This blog entry is some notes and thoughts while installing Arch Linux on my 5-year-old laptop.

First and foremost, please read the Arch Linux Installation/Beginner’s Guide. It is really helpful. Secondly, download the iso image file, we will need to create a live USB flash drive for the installer. The next step depends on the OS that we are using, but I only know how to do it with Linux systems (apologizing to people using Windows and MacOS). To create a live USB installation medium, prepare a USB flash drive ( 2 GB is more than enough), and plug it into the USB port on the computer.

Creating Live USB Key

Now for Linux system, first ensure that the USB flash drive is detected, and is not mounted. To do this, first enter the following commands into the terminal
fdisk -l. This will show all the drives that are detected by the system. Usually, they are named /dev/sdb or in case of a hybrid drive  (SSD + HDD), it will show up as /dev/sdc.  Run lsblk to make sure that the USB key is not mounted.

Now we will assume that the USB drive is name /dev/sdb for simplicity (in Arch Linux wiki, it is usually denoted with /dev/sdx instead, in case anyone reads it and wonder what it is). Then open terminal, and type in

dd bs=4M if=/path/to/archlinux.iso of=/dev/sdb status=progress && sync

Here, the if option means input file and of means output file. Now sit back and relax, the computer will do the rest to create a live USB key.

Installing Arch Linux

First plugin the USB key and reboot the computer. Whenever possible (usually at the beginning while booting), press F12 to enter boot menu. There, we should see the live USB flash drive that we have just created as an option, choose this and wait for it to boot.

Before we setup any installation, we need to verify the boot mode. Enter ls /sys/firmware/efi/efivars and make sure the system is booting in UEFI mode. If the directory does not exists (i.e. nothing shows up upon hitting Enter/Return key), then the system is either booting in BIOS or CSM mode. To check this, press F2 before booting the system (before F12) and we should see the boot mode. The installation process is basically still the same, with BIOS and CSM having an extra step or two. Personally, I have to go through the BIOS installation process.

Connecting to the Internet

To install Arch Linux, we must have an Internet connection, either through Ethernet or WiFi. To check if the Internet is connected, type ping If the laptop starts pinging responding, then we are done! Otherwise, we should see something as follows

ping: Name or service not known

To set up the Internet through WiFi, first type in wifi-menu -o <interface> where <interface> can be obtained by either checking ip link or iw dev. It often looks something like wlpxxx replacing the last three x’s appropriately. Here, we will just use wlan0 as a substitute. Then we are required to select the network and key in the password, and voila! We are now connected to the Internet through WiFi. (Optional: Do ping again to confirm the computer is actually connected to the Internet. Or not. I am not a police.)

Update System Clock (Optional)

Enter timedatectl set-ntp true into the console. This will set the clock to be in sync with the UTC time (i.e. timezone +00:00). Use timedatectl status to check that the time is indeed correct. To set timezone, do timedatectl set-timezone <timezone name> where <timezone name> can be obtained via timedatectl list-timezone.

Partitioning the Disks

Check the name of the disks using fdisk -l. We should see a list of /dev/sdx followed with /dev/sdxY for each disks, including the USB flash drive. The Y here should be a partition number of /dev/sdx, and there can be multiple of them.

Using cfdisk or parted, we can partition the disk into different partitions. In my case (BIOS Boot System) , I need 4 partitions:

  • BIOS Bootable System (BIOS boot)
  • Root directory, i.e. / (Linux File System)
  • Swap partition (Linux Swap)
  • Home directory i.e. ~/home (Linux File System)

Note that the partition above is for BIOS boot mode only, where the BIOS bootable system is the first 1007 KB of the disk. There are other partition layouts. For more examples click on this link.

Remark: My swap partition is the size of my RAM, but the actual size can vary. For the root directory, I have about I used 10 GB 2 GB space allocated to it, which should be more than enough. Usually home directory gets the rest of the space, and in case of a hybrid drive, the root directory and swap space should be on SSD while home directory should be on HDD.

Formatting the Disks

To format the disks, we need to format it according tot he type. Using above example, Linux file systems can be formatted using mkfs.ext4 /dev/sda1, assuming my /dev/sda1 has partition type Linux file system. Assuming /dev/sda3 is of type EFI System, then we need mkfs.vfat /dev/sda3. For Linux swap, (in my case, /dev/sda2) we need to first do mkswap /dev/sda2 and then swapon /dev/sda2. Details of formatting for each partition type can be found here.

Mounting the Disks

There are several ways to do this, depending on the partitions. For simplicity, assume the following from now onwards:

  • /dev/sda1 is for the partition for root directory
  • /dev/sda2 is the swap partition
  • /dev/sda3 is the partition for home directory

Then we should first mount the root directory partition onto /mnt. Simply type mount /dev/sda1 /mnt to do this. Next, we will need to create /mnt/home for home directory, which we can do by typing mkdir /mnt/home, and to mount this drive, we need to follow up with mount /dev/sda3 /mnt/home. To check which directory is mounted and the details, type lsblk -f.

Installing the system

Now we can finally install the system. Use pacstrap /mnt base, or personally, I prefer pacstrap /mnt base base-devel as it install some of the functionalities that I already am using. Generally speaking, to install a package, simply append to the command with the package name, followed with a space (so to install GRUB just do pacstrap /mnt base grub. Now we can sit back and relax for a bit, it will take some time to install.

Configuring the system

We need to now generate the fstab file, using UUID or by the labels. So type genfstab -U /mnt >> /mnt/etc/fstab if UUID is used, otherwise replace -U with -L instead. Now we need to configure the local system itself. This is very standard. Do arch-chroot /mnt, and then just follow the Arch Wiki Guide until the last step, where we are required to run the boot loader. In general, run

grub-install --target=i386-pc /dev/sda

Then, we want to do

grub-mkconfig -o /boot/grub/grub.cfg

to allow the microcode to update and configure GRUB appropriately. Now type exit and reboot the system. Remember to unplug the USB flash drive at this point.

Final Comments

Congratulations! We have now installed Arch Linux on our computer. For some of us, great! Now we can play with our new toy. For others, this is bad news. Basic Arch Linux is running on Command Line Interface (CLI), but do not be afraid! We can configure a desktop environment running on Arch Linux! Read this for some general recommendations on how to manage the system, and [this]9 for a list of applications that is useful. I would suggest first adding a user, setting up a desktop environment, and configuring NVIDIA if required.