2 # mk-basefile, create basefiles for some distributions
4 # Thomas Lange, Uni Koeln, 2011-2018
5 # based on the Makefile implementation of Michael Goetze
7 # Usage example: mk-basefile -J STRETCH64
8 # This will create a STRETCH64.tar.xz basefile.
10 # Supported distributions (each i386/amd64):
14 # Scientific Linux Cern 5/6
16 # Packages you might want to install to use this command:
17 # debootstrap, rinse, xz-utils
20 # Define your local mirros here
21 # For the first stage, set the CentOS/SLC mirror in /etc/rinse/rinse.conf
22 MIRROR_DEBIAN
=http
://deb.debian.org
/debian
/
23 MIRROR_UBUNTU
=http
://mirror.netcologne.de
/ubuntu
/
24 MIRROR_TRISQUEL
=http
://mirror.fsf.org
/trisquel
/
25 MIRROR_CENTOS
=http
://mirror.netcologne.de
/
27 EXCLUDE_SQUEEZE
=isc-dhcp-client
,isc-dhcp-common
,info
34 EXCLUDE_BELENOS
=dhcp3-client
,dhcp3-common
,info
35 EXCLUDE_TRUSTY
=dhcp3-client
,dhcp3-common
,info
36 EXCLUDE_XENIAL
=udhcpc
,dibbler-client
,info
37 EXCLUDE_FLIDAS
=udhcpc
,dibbler-client
,info
38 EXCLUDE_BIONIC
=udhcpc
,dibbler-client
,info
39 EXCLUDE_ETIONA
=udhcpc
,dibbler-client
,info
41 # here you can add packages, that are needed very early
48 if [ X
$1 = Xi386
]; then
55 if [ `id -u` != 0 ]; then
56 echo "You must be root to create chroots."
59 mknod
$xtmp/test-dev-null c
1 3
61 echo "Cannot create device files on $xtmp, aborting."
62 echo "Perhaps this directory is mounted with option nodev."
66 echo test > $xtmp/test-dev-null
68 echo "Cannot create device files on $xtmp, aborting."
69 echo "Perhaps this directory is mounted with option nodev."
73 rm -f $xtmp/test-dev-null
79 # set local mirror for rinse post script
80 [ -z "$MIRROR_CENTOS" ] && return
81 cat <<EOM > $xtmp/post
83 mkdir -p $xtmp/etc/yum.repos.d/orig
84 cp -p $xtmp/etc/yum.repos.d/*.repo $xtmp/etc/yum.repos.d/orig
85 perl -pi -e 's,mirrorlist=,#mirrorlist=,; s,#baseurl=http://mirror.centos.org,baseurl=$MIRROR_CENTOS,;' $xtmp/etc/yum.repos.d/CentOS-Base.repo
93 # set local mirror for rinse post script
95 [ -z "$MIRROR_SLC" ] && return
96 cat <<EOM > $xtmp/post
98 mkdir -p $xtmp/etc/yum.repos.d/orig
99 cp -p $xtmp/etc/yum.repos.d/*.repo $xtmp/etc/yum.repos.d/orig
100 perl -pi -e 's,baseurl=http://linuxsoft.cern.ch,baseurl=$MIRROR_SLC,;' $xtmp/etc/yum.repos.d/slc$ver-os.repo
101 perl -pi -e 's,baseurl=http://linuxsoft.cern.ch,baseurl=$MIRROR_SLC,;' $xtmp/etc/yum.repos.d/slc$ver-updates.repo
111 if [[ -e $cmd ]]; then
113 chroot
$xtmp "/tmp/$cmd"
118 chroot
$xtmp apt-get clean
119 rm -f $xtmp/etc
/hostname
$xtmp/etc
/resolv.conf \
120 $xtmp/var
/lib
/apt
/lists
/*_
* $xtmp/usr
/bin
/qemu-
*-static \
121 $xtmp/etc
/udev
/rules.d
/70-persistent-net.rules
122 > $xtmp/etc
/machine-id
128 # check if chroot works
129 echo "Installed packages in chroot:"
130 chroot
$xtmp rpm
-qa|
sort
131 echo -n "CHROOT rpm -qa: "
132 chroot
$xtmp rpm
-qa|
wc -l
134 rm -f $xtmp/etc
/resolv.conf
$xtmp/post
135 if [ -d $xtmp/etc
/yum.repos.d
/orig
]; then
136 mv $xtmp/etc
/yum.repos.d
/orig
/* $xtmp/etc
/yum.repos.d
/
137 rm -rf $xtmp/etc
/yum.repos.d
/orig
144 tar $attributes --one-file-system -C $xtmp -cf - . |
$zip > $target.
$ext
152 local domain
=$
(domainname
)
157 $l32 rinse
--directory $xtmp --distribution centos-
$vers --arch $arch --before-post-install $xtmp/post
158 domainname
$domain # workaround for #613377
172 $l32 rinse
--directory $xtmp --distribution slc-
$vers --arch $arch --before-post-install $xtmp/post
186 dist
=${DIST%%[0-9][0-9]}
187 local exc
="EXCLUDE_$dist"
188 [ -n "${!exc}" ] && exc
="--exclude=${!exc}" ||
unset exc
192 if [ -n "$INCLUDE_DEBIAN" ]; then
193 local inc
="--include=$INCLUDE_DEBIAN"
196 if [ -n "$arch" ]; then
197 qemu-debootstrap
--arch $arch ${exc} $inc $dist $xtmp $mirror
198 target
="${target}_${arch^^}"
200 if [[ $DIST =~
64 ]]; then
205 debootstrap
--arch $arch ${exc} $inc $dist $xtmp $mirror
215 CENTOS5_32 CENTOS5_64
216 CENTOS6_32 CENTOS6_64
217 CENTOS7_32 CENTOS7_64
238 mk-basefile, create minimal base files for a Linux distritubtion
240 Copyright (C) 2011-2018 by Thomas Lange
242 Usage: mk-basefile [OPTION] ... DISTRIBUTION
244 -s Show list of supported linux distributions
245 -f ARCH Build for foreign architecture ARCH.
246 -d DIR Use DIR for creating the temporary subtree structure.
247 -z Use gzip for compressing the tar file.
248 -J Use xz for compressing the tar file.
249 -k Keep the temporary subtree structure, do not remove it.
250 -x CMD Run CMD in chroot. If CMD exists as a file, copy it and run it.
254 Usage example: mk-basefile -J STRETCH64
255 This will create a STRETCH64.tar.xz basefile.
267 attributes
="--xattrs --selinux --acls"
269 while getopts ashzJd
:kf
:x
: opt
; do
271 a
) echo "$0: Warning. -a is ignored, because xtattrs, acls and selinux are always added." ;;
272 d
) export TMPDIR
=$OPTARG ;;
273 f
) export ARCH
=$OPTARG ;;
274 z
) zip="gzip -9"; ext
=tar.gz
;;
275 J
) zip="xz -8" ext
=tar.xz
;;
278 s
) prtdists
; exit 0;;
280 ?
) exit 3 ;; # error in option parsing
283 shift $
(($OPTIND - 1))
285 xtmp
=$
(mktemp
--tmpdir -d basefiles.XXXXXXXX
)
286 if [ $?
-eq 1 ]; then
287 echo "mktemp failed. Aborting."
292 target
=$1 # also the name of the output file
294 [ -z "$target" ] && usage
296 CENTOS5_32
) centos i386
5 ;;
297 CENTOS5_64
) centos amd64
5 ;;
298 CENTOS6_32
) centos i386
6 ;;
299 CENTOS6_64
) centos amd64
6 ;;
300 CENTOS7_32
) centos i386
7 ;;
301 CENTOS7_64
) centos amd64
7 ;;
302 SLC5_32
) slc i386
5 ;;
303 SLC5_64
) slc amd64
5 ;;
304 SLC6_32
) slc i386
6 ;;
305 SLC6_64
) slc amd64
6 ;;
306 SLC7_64
) slc amd64
7 ;;
307 BELENOS
*|FLIDAS
*|ETIONA
*)
308 debgeneric
$target $MIRROR_TRISQUEL ;;
309 TRUSTY
*|XENIAL
*|BIONIC
*)
310 debgeneric
$target $MIRROR_UBUNTU ;;
311 SQUEEZE
*|WHEEZY
*|JESSIE
*|STRETCH
*|BUSTER
*|SID
*)
312 debgeneric
$target $MIRROR_DEBIAN $ARCH;;
313 *) echo "Unknown distribution. Aborting."
319 if [ $cleanup -eq 1 ]; then