📜 ⬆️ ⬇️

Raising the “virtualka” chroot with ubuntu to build packages

Greetings.

The other day, tired of assembling packages, I went on ssh to different machines and decided to pick up a couple of myself. I'll tell you about the rakes that I collected on 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 virtuals - 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, unconfigured locale, time zone ... the whole range of colors.
Adjust 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 groin 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 (with reservations). My example config is /etc/schroot/chroot.d/ubuntu.conf
 [ubuntu-trusty] description=Ubuntu 14.04 type=directory directory=/home/ubuntu_trusty users=clown,monkey,mrsam root-users=clown aliases=trusty,default profile=ubuntu [ubuntu-precise] description=Ubuntu 12.04 type=directory directory=/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 my knee for a very long time, I wanted to howl)
If you select “type = directory”, then the auto-point from the file ($ profile - the parameter “profile = ubuntu” in the config) is executed / etc / schroot / $ profile / fstab, all files from / etc / schroot / $ profile / copyfiles are copied and also 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 to copy into the chroot from the host system. # # <database name> passwd shadow group gshadow services protocols networks hosts 

Each time this bastard frayed my groups and users, which had a very negative effect on the chroot installation even vim, which was required by the crontab group. And also the networks item kills 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 files / etc / schroot / ubuntu / *
 $ cat copyfiles # Files to copy into 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 0 0 /sys /sys none rw,bind 0 0 /dev /dev none rw,bind 0 0 /dev/pts /dev/pts none rw,bind 0 0 /home /home none rw,bind 0 0 /tmp /tmp none rw,bind 0 0 # It may be desirable to have access to /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 0 0 #/run/lock /run/lock none rw,bind 0 0 #/dev/shm /dev/shm none rw,bind 0 0 #/run/shm /run/shm none rw,bind 0 0 $ cat nssdatabases # System databases to copy into the chroot from the host system. # # <database name> 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 -f done 


You can link together some configuration files that you 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, it is necessary 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 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.

Source: https://habr.com/ru/post/244373/


All Articles