Wednesday, April 9, 2014

Creating a developmental chroot system on Debian Linux

Lately, I've been trying many possibilities with chroot virtual systems. I found many uses with chroot: to create a live CD, to create a chrooted Web server, and to create a VNC desktop server. Now I want to create a temporary, disposable chroot for the purpose of compiling software.

This time I am going to create the chroot under /srv/develop, so I make the directory first.

mkdir /srv/develop

I install a minimal Debian system into /srv/develop.

apt-get install cdebootstrap-static
cdebootstrap-static --allow-unauthenticated --arch=i386 --flavour=minimal stable /srv/develop http://http.us.debian.org/debian

Then, I create essential device files in /srv/develop/dev.

cd /srv/develop/dev
MAKEDEV std

I mount proc and devpts for chroot.

mount -t proc -o nodev,noexec,nosuid proc /srv/develop/proc
mount --bind /dev/pts /srv/develop/dev/pts

I chroot into /srv/develop.

chroot /srv/develop

I type some commands to fix minor issues.

ln -s /proc/mounts /etc/mtab
dpkg --purge cdebootstrap-helper-rc.d

I check /etc/apt/sources.list and update the apt-get database.

apt-get update

Then, I run the following comand to install the basic compiler suite.

apt-get --no-install-recommends install binutils bison bzip2 flex gcc g++ gettext less libtool make patch perl pkg-config python texinfo vim-tiny wget whiptail xz-utils

Now I am ready for some basic coding and compiling. If I am really serious, I may install a full-blown GUI IDE. However, for now I just want to compile something quickly without messing up the main system, and then destroy the chroot.

Also Read

Friday, April 4, 2014

To Build a MinGW-w64 GCC toolchain

Let's build a MinGW-w64 GCC toolchain. It's going to be fun.

  1. Install MinGW-w64 as shown in this post. If you are going to build 32-bit applications, install MinGW-w64 for Windows 32. If you are going to build 64-bit applications, install MinGW-w64 for Windows 64.

    Also, install MSYS. Then, double-click on the batch file MSYS.BAT to start MSYS.

  2. Download the latest MinGW-w64 release tarball or SVN tarball. To download the SVN tarball, open this link and click on the “Download Snapshot” link.

    Wait a minute, and you'll receive a ZIP file. Using WinZip or 7-zip, unpack the ZIP file into the HOME folder (say, E:\mingw32\msys\1.0\home\User).

    Before compiling anything, set some environment variables.

    export CPPFLAGS='-I/mingw/include'
  3. Enter the MinGW-w64 source directory that you just unzipped. Install MinGW-w64 headers as follows:

    cd mingw-w64-code-6558-truck/mingw-w64-headers
    mkdir build
    cd build
    ../configure --build=i686-w64-mingw32 --prefix=/mingw/i686-w64-mingw32

    For 64-bit MinGW-w64, the configure command is different.

    ../configure --build=x86_64-w64-mingw32 --prefix=/mingw/x86_64-w64-mingw32

    Then, type:

    make install
  4. Compile GMP. The source is available here. I downloaded the latest release version (gmp-6.0.0a.tar.bz2).

    ./configure --prefix=/mingw --build=i686-w64-mingw32 --enable-cxx --disable-shared
    make CPPFLAGS="-fexceptions"
    make install

    For a 64-bit build, use --build=x86_64-w64-mingw32 instead.

  5. Compile MPFR. The source is available here. For a 64-bit build, specify --build=x86_64-w64-mingw32 instead.

    ./configure --prefix=/mingw --build=i686-w64-mingw32 --disable-shared
    make
    make install
  6. Build MPC. For a 64-bit build, use --build=x86_64-w64-mingw32 instead.

    ./configure --prefix=/mingw --build=i686-w64-mingw32 --disable-shared
    make
    make install
  7. This step is not mandatory, so you can skip it. Build isl or PPL, and ClooG. For ISL or PPL, run:

    ./configure --prefix=/mingw --build=i686-w64-mingw32 --disable-shared
    make
    make install

    For ClooG, run:

    ./configure --prefix=/mingw --build=i686-w64-mingw32 --disable-shared --with-isl=system --with-host-libstdcxx='-lstdc++ -lsupc++'
    make
    make install
  8. Build binutils. The source is available here.

    mkdir build
    cd build
    ../configure --prefix=/mingw --build=i686-w64-mingw32 --disable-multilib --disable-nls --disable-werror --with-sysroot=/mingw
    make
    make install

    To build 64-bit binutils, specify --build=x86_64-w64-mingw32 instead.

  9. Build the gcc core. GCC snapshot sources are available here. It is recommended to create a temporary build directory for gcc.

    mkdir -p build/gcc
    cd build/gcc
    ../../configure --prefix=/mingw --build=i686-w64-mingw32 --disable-multilib --disable-shared --disable-nls --disable-werror --with-sysroot=/mingw
    mkdir /mingw/mingw/include
    make all-gcc
    make install-gcc

    To build 64-bit gcc, specify --build=x86_64-w64-mingw32 instead.

  10. Build the C Runtime libraries. We need to create another temporary build directory. At the top of the GCC source tree:

    mkdir -p build/crt
    cd build/crt
    ../../configure --prefix=/mingw/i686-w64-ming32 --build=i686-w64-mingw32 --enable-sjlj-exceptions --disable-multilib --with-sysroot=/mingw --with-gmp=/mingw --with-mpfr=/mingw --with-mpc=/mingw

    Specify --prefix=/mingw/x86_64-w64-mingw32 --build=x86_64-w64-mingw32 instead to build 64-bit MinGW-w64. Before running make, copy everything from C:\MinGW\include and C:\MinGW\i686-w64-mingw32\include to gcc-4.7.2\libcpp\include. This will help avoid getting missing header errors later.

    Create a folder /mingw/i686-w64-mingw32/lib.

    mkdir -p /mingw/i686-w64-mingw32/include
    mkdir -p /mingw/i686-w64-mingw32/lib

    If building a 64-bit MinGW-w64, then

    mkdir -p /mingw/x86_64-w64-mingw32/include
    mkdir -p /mingw/x86_64-w64-mingw32/lib

    Then, run make.

    make CPPFLAGS="-fpermissive"
    make install

    If you get an error during configure due to missing libgcc.a, copy it from /mingw/lib/gcc/i686-w64-mingw32/4.7.0.

  11. Build the rest of GCC. Go back to the GCC build directory.

    cd build/gcc
    make CPPFLAGS="-fpermissive"
    make install
  12. Use strip.exe on executable files (*.exe) and dynamic libraries (*.dll) to reduce the size of the files.

    cd /mingw/bin
    strip *.exe *.dll
    
    cd /mingw/libexec/gcc/x86_64-w64-mingw32/4.7.2
    strip *.exe *.dll
    
    cd /mingw/x86_64-w64-mingw32/bin
    strip *.exe

Thursday, April 3, 2014

Using hsetroot to tile a wallpaper with gradient

hsetroot is a pretty neat tool for Linux desktop that I like better than other tools. One particular feature I love about hsetroot is adding a fading tint to the background wallpaper. For example, let's say you want to place the following picture on the desktop, nicely tiled.

The hsetroot command to use is:

hsetroot -tile thumb10.jpg

The desktop screen after running that command comes out like this.

To add a varying tint to the desktop background, use the -add, -gradient and -alpha options with hsetroot. The -add option is used to specify colors and the -gradient option is used to specify the direction of gradient, in the range 0 to 360. The alpha option in the range 0 to 255 specifies how transparent the background wallpaper should be. For example, you could run the following hsetroot command:

hsetroot -tile thumb10.jpg -alpha 127 -add \#b5d045 -add \#81c0c5 -gradient 240

And it comes out like this:

Also Read

Wednesday, April 2, 2014

Adding applications to chrooted VNC desktop

After successfully setting up a chrooted VNC desktop server in /srv/vnc, as described previously, I am installing additional applications into the chroot system.

  1. Again, I enter the /srv/vnc chroot environment.

    chroot /srv/vnc
  2. I update the /etc/apt/sources.list file to include security updates.

    deb http://http.us.debian.org/debian stable main contrib non-free
    deb http://http.us.debian.org/debian stable-updates main contrib non-free
    deb http://security.debian.org stable/updates main contrib non-free

    Then, I update existing packages that have been installed.

    apt-get update
    apt-get upgrade
  3. I run the following command to add my favorite applications, including IceWeasel and LibreOffice.

    apt-get --no-install-recommends install evince-gtk filezilla genisoimage gtk-gnutella hunspell-en-us icedove iceweasel icedtea-7-plugin idesk libmysql-java libreoffice-base libreoffice-calc libreoffice-impress libreoffice-math libreoffice-writer openssh-client p7zip-full plzip rar ttf-wqy-microhei xarchiver

    I run apt-get again to add some more applications without "--no-install-recommends" option.

    apt-get install graphicsmagick xfonts-mathml
  4. Then, I install some Java applications that I like.

  5. I put some fonts into the /usr/local/share/fonts folder to support foreign languages. The fonts I use include Aegean, Akshar Unicode, Dilyana, Everson Mono, Gentium Plus, GohaTibebZemen, Hapaxber, IPA Mincho, KhmerKep/KhmWatPhnom, Malithi Web, Myanmar 3, New Athena, Nuosu SIL, Phaisarn, Nastaliq, PhetSarath, Sakal Bharati, Saweri, Seoul, Simplified Baosong 2, TCRC Youtso, etc. Then, I run:

    fc-cache -s

    That's it. My VNC server is almost complete.

Also Read

Monday, March 31, 2014

Creating a chrooted VNC desktop server

I want to create a chrooted Linux system that serves X11 desktop applications through VNC. I'm going to write down the steps to achieve the goal.

  1. I'll put the virtual Linux system under /srv/vnc. So I create the /srv/vnc directory.

    mkdir /srv/vnc
  2. Then, I install cdebootstrap-static.

    apt-get install cdebootstrap-static

    I run the following command to install a minimal Debian system in /srv/vnc.

    cdebootstrap-static --allow-unauthenticated --arch=i386 --flavour=minimal stable /srv/vnc http://http.us.debian.org/debian
  3. I mount /proc, /dev and /dev/pts inside /srv/vnc.

    mount -t proc -o nodev,noexec,nosuid proc /srv/vnc/proc
    mount -t devtmpfs -o size=8192k,nr_inodes=64k none /srv/vnc/dev
    mkdir /dev/pts
    mount --bind /dev/pts /srv/vnc/dev/pts
  4. I check the file /srv/vnc/etc/apt/sources.list.

    deb http://http.us.debian.org/debian stable main contrib non-free
    deb http://http.us.debian.org/debian stable-updates main contrib non-free
    deb http://security.debian.org stable/updates main contrib non-free
  5. Then, I run chroot on /srv/vnc.

    chroot /srv/vnc

    Now, I am inside the /srv/vnc chroot.

About This Blog

KBlog logo This blog seeks to provide useful information to people, based on the author's knowledge and experience. Thanks for visiting the blog and posting your comments.

© Contents by KBlog

© Blogger template by Emporium Digital 2008

Follow by Email

Total Pageviews