Raising the “virtualka” chroot- with ubuntu to build packages

    Greetings.

    The other day, tired of assembling packages to go on ssh to different machines and decided to raise a couple of them. I'll tell you about the rakes that I collected along the road and about the crutches that I made.

    All actions were performed on Arch linux, but the steps for setting up chroot virtual machines and schroot should be very similar.

    Everything described below, of course, is scattered throughout the network. But there are many trials and mistakes along the way.

    Bootstrap


    So, everything begins, one might say, trite, there is a description of the bootstrap process in this article
    For myself, I put 2 virtual machines - precise and trusty:
    yaourt -S --nocnofirm --asdeps ubuntu-keyring gnupg1 # ставим пакеты, как зависимости
    yaourt -S --nocnofirm debootstrap schroot
    for distr in trusty precise
      do sudo debootstrap --include=vim,language-pack-ru,language-pack-ru-base,devscripts,subversion,git --arch amd64 $distr /home/ubuntu_$distr http://mirror.yandex.ru/ubuntu/
    done


    After some time, when the bags arrive

    We have unconfigured weights, an unconfigured locale, a time zone ... the whole range of colors.
    Set up the weights:
    for distr in trusty precise
    do sudo sh -c "cat > /home/ubuntu_$distr/etc/apt/sources.list <<EOF
    deb http://mirror.yandex.ru/ubuntu $distr main restricted universe multiverse
    deb http://mirror.yandex.ru/ubuntu $distr-updates main restricted universe multiverse
    deb http://mirror.yandex.ru/ubuntu $distr-security main restricted universe multiverse
    EOF"done

    We will return to the locale and time zone a little later.

    The following rake ...

    Carefully filed at the groin level: schroot configuration
    In short, this thing allows you to chroot into a directory without superuser rights, automatically mounting and copying into the child OS what is specified in the config file (with reservations). My example config is /etc/schroot/chroot.d/ubuntu.conf
    [ubuntu-trusty]
    description=Ubuntu14.04type=directorydirectory=/home/ubuntu_trusty
    users=clown,monkey,mrsam
    root-users=clown
    aliases=trusty,defaultprofile=ubuntu
    [ubuntu-precise]
    description=Ubuntu12.04type=directorydirectory=/home/ubuntu_precise
    users=clown,monkey,mrsam
    root-users=clown
    aliases=precise
    profile=ubuntu

    What you should pay attention to in man schroot.conf : the item “Plain and directory chroots” (shot at the knee for a very long time, I wanted to howl)
    If you choose “type = directory”, then the auto-count from the file is executed ($ profile - the “profile = ubuntu ”in the config) / etc / schroot / $ profile / fstab, all files from / etc / schroot / $ profile / copyfiles are copied, and all the“ databases ”from / etc / schroot / $ profile / nssdatabases are updated. This circumstance even complained about the launch pad.
    The default is "profile = default", and / etc / schroot / default / nssdatabases contains these lines
    # System databases tocopyinto the chroot from the host system.
    #
    # <databasename>
    passwd
    shadow
    group
    gshadow
    services
    protocols
    networks
    hosts
    

    Each time this bastard frayed my groups and users, which had a very negative impact on the chroot installation even vim, which was required by the crontab group. And also the networks item kills the work of the network (for my distribution, it’s not at all a fact that it’s everywhere, especially if the parent OS is ubuntu too), such things.
    Just in case, my / etc / schroot / ubuntu / * files
    $ cat copyfiles 
    # Files tocopyinto the chroot from the host system.
    #
    # <source and destination>
    /etc/resolv.conf
    $ cat fstab 
    # fstab: static file system information for chroots.
    # Note that the mount point will be prefixed by the chroot path
    # (CHROOT_PATH)
    #
    # <file system> <mount point>   <type>  <options>       <dump>  <pass>
    /proc           /proc           none    rw,bind         00
    /sys            /sys            none    rw,bind         00
    /dev            /dev            none    rw,bind         00
    /dev/pts        /dev/pts        none    rw,bind         00
    /home           /home           none    rw,bind         00
    /tmp            /tmp            none    rw,bind         00
    # It may be desirable to have accessto /run, especially if you wish
    # to run additional services in the chroot.  However, note that this
    # may potentially cause undesirable behaviour on upgrades, such as
    # killing services on the host.
    #/run           /run            none    rw,bind         00
    #/run/lock      /run/locknone    rw,bind         00
    #/dev/shm       /dev/shm        none    rw,bind         00
    #/run/shm       /run/shm        none    rw,bind         00
    $ cat nssdatabases 
    # System databases tocopyinto the chroot from the host system.
    #
    # <databasename>
    protocols
    hosts


    Little tricks


    To have the same encoding everywhere, you need to do:
    for distr in trusty precise
        do sudo cp /etc/locale.gen /home/ubuntu_$distr/var/lib/locales/supported.d/local# если etc и home на одном диске, можно ln -fdone


    You can link together some configuration files that I would like to always have in the same form, for example:
    sudo ln -f /home/ubuntu_trusty/etc/bash.bashrc /home/ubuntu_precise/etc/bash.bashrc

    And in order to avoid problems when updating packages, you need to prevent some packages from doing this:
    apt-mark hold initscripts udev plymouth mountall

    Yes, in each of the chroot ...

    And finally, we will regenerate the encodings and tzdata:
    sudo locale-gen
    sudo dpkg-reconfigure tzdata


    Thanks for attention. I hope, will reduce the time to raise the environment for the assembly.

    Also popular now: