During implementation of DistTest I faced with necessity of building a lot of different linux kernel versions. As a first solution I chose downloading archives from kernel.org for each used version. But I soon realized that about 1000 versions of sources with size 0.5-1GB each would consume a lot of disk space. It’s also impossible to build kernel with exact commit precision using this approach.
Set of base versions with corresponding patches can save disk space, but uses a lot of random I/O during applying patches, so it’s slow on HDD and consume finite rewrite resource of SSD. Temporary nature of sources leads to conclusion “use tmpfs”. But aufs offers much less RAM consuming method – store in RAM only diffs.
Also it’s a lot easier to checkout sources with commit level precision if there are no need to store them in persistent location.
aufs has following layout in this case:
- repo – repo location(with .git directory)
- seed – sources with some close to needed version
- tmp – diffs storage location
- aufs – aufs mount point to combine all directories above
For example linux v4.5 building can be performed as follows:
1 2 3 4 5 6 7 8 9 10 11 12 |
mount none tmp -t tmpfs mount none aufs -t aufs -o br:tmp:seed=ro:repo=ro #tmp is the only rw layer cd aufs git reset --mixed v4.5 #switch tag to v4.5 and rebuild index git reset --hard v4.5 #replace all not matched files git clean -d -x -f #clean all new and ignored files cp path/to/conf .config #copy kernel configuration make -j9 #and build it cp arch/x86/boot/bzImage path/to/store/bzImage cd .. umount aufs umount tmp |
There is a single drawback of this approach: mount should be performed by root user. It can be easily fixed by adding corresponding records to /etc/fstab:
1 2 |
none /home/user/tmp tmpfs noauto,user,exec 0 0 none /home/user/aufs aufs noauto,br:/home/user/tmp:/home/user/seed=ro:/home/user/repo=ro,user,exec 0 0 |
Fixed mount points doesn’t give a lot of flexibility, but at least symlinks can be used as aufs branches:
1 2 3 4 |
drwxrwxr-x 2 user user 4096 Mar 22 20:29 aufs lrwxrwxrwx 1 user user 12 Mar 23 21:39 repo -> /path/to/repo lrwxrwxrwx 1 user user 12 Mar 23 21:39 seed -> /path/to/seed drwxrwxrwx 2 user user 4096 Mar 23 21:39 tmp |