Upgrading from Debian Jesse 8 to Unstable

As we all know Debian is a very stable Linux distribution which is partly what makes it great, sometimes however you want access to newer packages, while it’s possible to mix stable packages and unstable it often leads to quite a mess, some packages have so many dependencies it’s often easier just to go entirely to unstable.

Unstable despite its name is actually fairly stable for the most part, so upgrading to it isn’t usually a big issue, upgrading is best done as a two step process, first from stable to testing, then testing to unstable, trying to go directly generally will not work except for a freshly installed base system, for you average user I’d recommend stopping at testing and then just install what you need from unstable since package problems can and do occur.

Upgrade Process

First you need to edit /etc/apt/sources.list and change jesse to testing like so, use a mirror closest to you for best performance:

deb ftp://ftp.uk.debian.org/debian/ testing main
deb-src ftp://ftp.uk.debian.org/debian/ testing main
deb ftp://ftp.uk.debian.org/debian/ testing contrib
deb-src ftp://ftp.uk.debian.org/debian/ testing contrib
deb ftp://ftp.uk.debian.org/debian/ testing non-free
deb-src ftp://ftp.uk.debian.org/debian/ testing non-free

Once that is done run the following:

sudo apt-get clean
sudo apt-get update
sudo apt-get dist-upgrade

All being well there should be no package errors here, go ahead and let it upgrade to testing, once it’s done it’s best to reboot and make sure everything is working, in some cases you may have to reinstall your gpu driver.

Once you’re happy everything is working you have two options, you can stay on testing and add the unstable repositories, or dist-upgrade to unstable, to get the latest packages you want, you can use the -t switch with apt-get, aptitude and synaptic to select the target release for example:

sudo apt-get -t testing install some-package
sudo apt-get -t unstable install some-package
sudo synaptic -t unstable

There is also an option in synaptic to set your preferred release.

If you do dist-upgrade to unstable be aware things can break from time to time, mostly packages that are being worked on, fixing this is a simple matter of switching whatever is broken back to the testing version, if you’re not comfortable with doing this stay on testing.

Installing Gentoo Linux Tips

586px-Gblend

Gentoo is a very popular source based distribution primarily intended for more experienced Linux users, although really it’s not as hard as people make it seem, certainly you should have experience using Linux and be comfortable using the terminal.

Since it would be a waste of my time to repeat the excellent Gentoo handbook I’m going to just cover the bits that may cause your first time user trouble, it’s recommend you do your first install in a virtual machine rather than on a physical machine so you can get a feel for it.

Prerequisites

  • Around 40GB free disk space for a decent install
  • A reasonably fast CPU
  • Access to the Gentoo handbook throughout the install
  • 1GB of RAM or more

The fast CPU is so you can get it installed in a short amount of time, compiling is an intensive task that can take days on a slower machine, for comparison a 1.8GHz Intel Celeron took me around 40 hours for a full desktop install, so I recommend at least a dual core processor, of course if you’re not in a hurry that’s fine.

It’s important you do your research before proceeding with the install, some thing you really need to know are:

  • What hardware do you have, use lspci and lsusb or other tools
  • Is your hardware supported in the kernel

The easiest way to check this is to run a Linux distribution, the Gentoo desktop live cd will work fine for this, if all your hardware works then your good to go, although you should note down the loaded modules so you can optimize your kernel to just what you need.

Finally it’s a good idea to note down your network configuration, particularly if you’re not used to setting up your network from the terminal.

Base System

For this install I’m going to assume you’re installing x86_64 (64 bit), most of this will apply to x86 (32 bit) as well.

First get the Gentoo minimal install cd from here, once it’s downloaded you can burn it to a cd, or as I’d recommend instead a flash memory stick with unetbootin since the image is updated very frequently.

When booting you should be asked to select your keyboard key map, if for some reason you can’t select it or need to change it later use loadkeys.

Wireless

Wireless in general is a pain in the ass when it comes to Linux in my opinion, mainly due to highly variable support, it’s often easier to buy a well supported adapter than try get a poorly supported one working.

To connect to a WPA-PSK secured network, as most are these days you need wpa_supplicant which is included on the install cd, you first need to make a configuration file for your network:

wpa_passphrase [ssid] [passphrase] > /etc/wpa_supplicant.conf

The ssid is the network ID you wish to connect to, the output is stored for later use, if you don’t know which is your network you can use the either of the following commands to scan:

iwlist [interface] scan
iw dev [interface] scan

The interface is the name of your wireless interface which should be displayed if you type iwconfig, if you don’t see anything it usually means the driver is not loaded or not available.

Once you have your configuration file you can connect to the network with:

wpa_supplicant -i  [interface] -c /etc/wpa_supplicant.conf -B -D [driver]

The -B option runs the wpa_supplicant daemon in the background so you may want to omit it the first time you run so you can check for errors, for the driver wext or nl80211 are the most common, nl80211 is preferable if supported.

Once it’s connected run the DHCP daemon to auto configure the network:

dhcpcd

If all goes well your wireless network should now be working.

Wired

For a wired ethernet connection this will usually work right away without any configuration, if your network adapter appears when you type ifconfig you’re generally good to go, run dhcpcd if needed or perform a manual configuration, check the ifconfig man pages for more info.

Setting up disks

The most basic partition scheme you can really go with is:

Partition    Usage       Size    Filesystem
/dev/sda1    BIOS Boot   2MB     none
/dev/sda2    Swap        4GB     swap
/dev/sda3    /boot       128MB   vfat
/dev/sda4    /           ~       ext4

I strongly recommend you carefully read the difference between MBR and GPT, if in doubt go for GPT, the above partition scheme should work in either case.

I generally recommend that if you’re dual booting with Windows that you put your Linux install on a different disk, this helps to avoid any problems with the Windows bootloader.

Setting up compile and USE flags

This is one of the more important bits to get right, for compile options you should not go over the top, -O2 -pipe -mtune=native is good enough 99.9% of the time, for 1GB of memory and below do not use -pipe, for the USE flags you really need to think ahead about what you want your system to do, in particular if you ever want to run 32 bit applications put in the multilib USE flag right away, also make sure you set MAKEOPTS=”-j9″ as well since it speeds up compilation a huge amount, the number you use should be the total number of logical CPU cores plus 1.

If you run in to segmentation faults when compiling, as can happen if you don’t have enough memory, put the following in /etc/portage/make.conf

FEATURES="keepwork"

Remove it when no longer needed.

When it comes to setting your profile you should generally go for Desktop, otherwise you’ll need to add a whole bunch of USE flags, finally when you emerge a package always use –ask and look at the flags in blue, consider if you may need the features those flags provide now or in future.

Kernel Configuration

This is a really critical step, not getting this right can in certain cases cause serious issues (like forgetting wifi support), other minor problem can be fixed by reconfiguring the kernel.

Take a good amount of time to read through all the configuration options, some may not make any sense but it general you don’t have to worry too much as the defaults are mostly sensible, if you have any doubts use genkernel, you can always tweak things later.

Only thing I would really change always is to increase the scroll back buffer as the default is tiny in my opinion.

For driver support save the configuration and open the .config file in nano, have a search through and you should find your needed drivers if they’re available in the kernel.

Network Configuration

This is one place where the handbook failed me, in the end I had to put the needed commands to launch wpa_supplicant in a script in /etc/init.d in any case this isn’t difficult to do but keep it in mind if you run in to the same problem as me.

If you’re using wifi make sure you emerge these packages before you reboot otherwise you are screwed:

  • net-wireless/wpa_supplicant
  • net-wireless/iw

After Installation

Once you’ve rebooted in to your new Gentoo installation you can start installing more packages, Gentoo for a source distribution is very easy to use, during the months that I’ve been using it I only had one minor package issue.

If you made a serious mistake during the installation all is not lost, you can boot the install disk again, once you’ve mounted the partitions and chrooted you can fix whatever problem there is without doing a full reinstall.

If you do run into trouble make sure you visit the Gentoo IRC channel which has a lot of helpful people, or if the problem is with a specific package post on the forum.

Updating Gnu GCC on Linux

GCC is a major part of any Linux system, it contains a C, C++, Fortran and Java compiler (plus some extras if compiled), it’s also the only compiler recommended to build the GNU C library (glibc) which is required to make a Linux system work, other alternatives are available but not as common.

Most systems use an older compiler for stability reasons since it has been significantly tested, however it’s sometimes desirable to use a cutting edge compiler for maximum performance, generally however you should not replace your system compiler unless you’re happy to deal with any bugs that may appear, this is mainly a concern on a source based system like Arch, Gentoo or BSD.

For this post I’m going to be installing GCC 5.30 on XUbuntu 15.10 x64 with the following libraries:

  • GMP 6.10
  • ISL 0.16
  • MPC 1.03
  • MPFR 3.1.3

You can use your systems version of these or build them with GCC which I chose to do.

Prerequisites

The follow tools must be on your system if you intend to follow this post:

  • Gnu Bash (Tested 4.3.42)
  • Gnu Make > 3.80 (Tested 4.0)
  • Gnu GCC > 4.9.x (Tested 5.2.1)
  • Gnu G++ > 4.9.x (Tested 5.2.1)
  • binutils > 2.25 (Tested 2.25.1)
  • awk (Tested mawk 1.3.3)
  • tar, gzip and bzip2 (for unpacking sources)
  • InfoZIP (Tested 3.0)
  • DejaGnu
  • TCL
  • Expect

On XUbuntu 15.10 x64 I only had to do the following:

sudo apt-get install g++ dejagnu

Setting up your build environment

For this I decided to use a separate partition mounted at /media/dev
Make a folder for your sources and build, you need around 15GB of free space, this is what I ended up with:

/media/dev
    sources/
    build/gcc-build/
    tools/

In the sources folder I downloaded and unpacked GCC 5.30 and the support libraries listed above, these are optional but I recommend you build them instead of using the system ones.

If you decide to build the support libraries you need to move or create a symbolic link to them in the gcc source directory so it ends up like this:

/media/dev/sources/gcc-5.3.0
            gmp/
            isl/
            mpc/
            mpfr/

Once that is done go to your build directory /media/dev/build/gcc-buld, unlike many applications you keep the build directory and source completely separate.

Configuration

There are a lot of configuration options available so I highly recommend you check out the official documentation and other sources (the official documentation is surprisingly sparse), this is what I used to configure:

../../sources/gcc-5.3.0/configure --prefix=/media/dev/tools --disable-nls --disable-multilib

Let’s take a look at each bit:

../../sources/gcc-5.3.0/configure
This is the path to the configure script, you could use a non-relative path here instead.

–prefix=/media/dev/tools
The prefix is where I want the fully built compiler and related files to be installed when I run make install, other good locations are /usr/local and /usr/opt, do not put it in /usr unless you are completely sure, also do not leave this unset or it will default to /usr.

–disable-nls
This disables the native language system which provides errors in your native language, unless you have trouble with English or are building it for distribution you should turn nls off.

–disable-multilib
Without this gcc will be built for x86 and x64, for my system I have no interest in 32 bit so it’s disabled, keep in mind you will need a 32 bit version of gcc and glibc installed in order to build multilib.

One thing you might want to add is –disable-werror as during the build process it may run into an error, this is nothing to worry about since you will be checking the compiler later.

Once the configuration is complete we can proceed with the build.

Compiling

The next steps are really simple but rather time consuming, for a complete build of gcc you should allocate at least 4 hours on a fast system (I built on an Intel Core I7 4790 and it took quite a while), for a very slow system you might want to run it overnight.

As for why this takes so long it’s due to two reasons, first Gnu GCC is a complicated bit of software and secondly it has to be built at the bare minimum three times.

The first build known as stage 1 uses your system compiler to build the new version of GCC, this is called bootstrapping, if all is well it goes on to stage 2 where it builds the compiler again with the new version you just built, this ensures the compiler is properly optimized, a final build is done and a comparison is made between stage 2 and 3, this verifies that the compiler is stable.

One important warning should be given though, if you’re going from a rather old compiler straight to the latest there is a very good chance the compile will fail or other strange errors will appear in the compiler, if this occurs you must used a version closer to the system compiler and build your way up to the latest, from a very old compiler this can take several steps so always start with the latest available compiler for your system.

The binutils version isn’t as important, if you want to you can put it in the source tree and it will be built along with gcc.

To compile run the following:

make -j9 bootstrap

The -j9 option tells make to use 9 parallel threads, this speeds up the process many times so make sure you include it, the number should be the total number of logical cores plus 1 (as a general rule), for an I7 with 4 physical cores and hyper threading this comes to 9.

If you don’t have much disk space try bootstrap-lean instead, this will take longer but should use less disk space (I have no idea how much less).

BOOT_CFLAGS can be set to adjust how it’s built, the default is -g -O2, feel free to adjust but be aware if you go too far it may break.

Do not run make without bootstrap, that’s only for when the versions are the same.

Testing

Once bootstrapping is complete, hopefully without errors you can move on to the checking process, this take a long time as well but it’s really a bad idea to skip unless you are repeating a build, let me say this again, it’s really a bad idea to skip.

To run the tests:

make -j9 -k check

The -k option ensures it will not stop on any error, at the end you will get a report consisting of:

  • Tests performed
  • Tests that passed
  • Tests that passed unexpectedly
  • Tests that failed
  • Tests that failed unexpectedly

Only the last one you really need to worry about, if the number is low (preferably zero) you should be okay, if it’s more than five you really need to stop and check them, it’s a good idea to report any failures on the gcc-testresults mailing list.

Installing

To install simply run:

sudo make install

Assuming you remembered to set your prefix it should all be in the right place, if you really want to install in /usr it’s a good idea to set either –program-prefix= or –program-suffix so it will have a different name to your system compiler.

Go to the bin folder and run ./gcc -v, you should see something similar:

Using built-in specs.
COLLECT_GCC=./gcc
COLLECT_LTO_WRAPPER=/media/dev/tools/libexec/gcc/x86_64-unknown-linux-gnu/5.3.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../../sources/gcc-5.3.0/configure --prefix=/media/dev/tools --disable-nls --disable-multilib : (reconfigured) ../../sources/gcc-5.3.0/configure --prefix=/media/dev/tools --disable-nls --disable-multilib
Thread model: posix
gcc version 5.3.0 (GCC)

Conclusion

It really isn’t that hard to update GCC and well worth it if you’re a programmer or just want to optimize your system as much as possible.