3 # mk-basefile, create basefiles for some distributions
5 # Thomas Lange, Uni Koeln, 2011-2018
6 # based on the Makefile implementation of Michael Goetze
8 # Usage example: mk-basefile -J STRETCH64
9 # This will create a STRETCH64.tar.xz basefile.
11 # Supported distributions (each i386/amd64):
15 # Scientific Linux Cern 5/6
17 # Packages you might want to install to use this command:
18 # debootstrap, rinse, xz-utils
21 # Define your local mirros here
22 # For the first stage, set the CentOS/SLC mirror in /etc/rinse/rinse.conf
23 MIRROR_DEBIAN
=http
://deb.debian.org
/debian
/
24 MIRROR_UBUNTU
=http
://mirror.netcologne.de
/ubuntu
/
25 MIRROR_CENTOS
=http
://mirror.netcologne.de
/
27 EXCLUDE_SQUEEZE
=isc-dhcp-client
,isc-dhcp-common
,info
34 EXCLUDE_TRUSTY
=dhcp3-client
,dhcp3-common
,info
35 EXCLUDE_XENIAL
=udhcpc
,dibbler-client
,info
36 EXCLUDE_BIONIC
=udhcpc
,dibbler-client
,info
38 # here you can add packages, that are needed very early
45 if [ X
$1 = Xi386
]; then
52 if [ `id -u` != 0 ]; then
53 echo "You must be root to create chroots."
56 mknod
$xtmp/test-dev-null c
1 3
58 echo "Cannot create device files on $xtmp, aborting."
59 echo "Perhaps this directory is mounted with option nodev."
63 echo test > $xtmp/test-dev-null
65 echo "Cannot create device files on $xtmp, aborting."
66 echo "Perhaps this directory is mounted with option nodev."
70 rm -f $xtmp/test-dev-null
76 # set local mirror for rinse post script
77 [ -z "$MIRROR_CENTOS" ] && return
78 cat <<EOM > $xtmp/post
80 mkdir -p $xtmp/etc/yum.repos.d/orig
81 cp -p $xtmp/etc/yum.repos.d/*.repo $xtmp/etc/yum.repos.d/orig
82 perl -pi -e 's,mirrorlist=,#mirrorlist=,; s,#baseurl=http://mirror.centos.org,baseurl=$MIRROR_CENTOS,;' $xtmp/etc/yum.repos.d/CentOS-Base.repo
90 # set local mirror for rinse post script
92 [ -z "$MIRROR_SLC" ] && return
93 cat <<EOM > $xtmp/post
95 mkdir -p $xtmp/etc/yum.repos.d/orig
96 cp -p $xtmp/etc/yum.repos.d/*.repo $xtmp/etc/yum.repos.d/orig
97 perl -pi -e 's,baseurl=http://linuxsoft.cern.ch,baseurl=$MIRROR_SLC,;' $xtmp/etc/yum.repos.d/slc$ver-os.repo
98 perl -pi -e 's,baseurl=http://linuxsoft.cern.ch,baseurl=$MIRROR_SLC,;' $xtmp/etc/yum.repos.d/slc$ver-updates.repo
107 chroot
$xtmp apt-get clean
108 rm -f $xtmp/etc
/hostname
$xtmp/etc
/resolv.conf \
109 $xtmp/var
/lib
/apt
/lists
/*_
* $xtmp/usr
/bin
/qemu-
*-static \
110 $xtmp/etc
/udev
/rules.d
/70-persistent-net.rules
111 > $xtmp/etc
/machine-id
117 # check if chroot works
118 echo "Installed packages in chroot:"
119 chroot
$xtmp rpm
-qa|
sort
120 echo -n "CHROOT rpm -qa: "
121 chroot
$xtmp rpm
-qa|
wc -l
123 rm -f $xtmp/etc
/resolv.conf
$xtmp/post
124 if [ -d $xtmp/etc
/yum.repos.d
/orig
]; then
125 mv $xtmp/etc
/yum.repos.d
/orig
/* $xtmp/etc
/yum.repos.d
/
126 rm -rf $xtmp/etc
/yum.repos.d
/orig
133 tar $attributes --one-file-system -C $xtmp -cf - . |
$zip > $target.
$ext
141 local domain
=$
(domainname
)
146 $l32 rinse
--directory $xtmp --distribution centos-
$vers --arch $arch --before-post-install $xtmp/post
147 domainname
$domain # workaround for #613377
161 $l32 rinse
--directory $xtmp --distribution slc-
$vers --arch $arch --before-post-install $xtmp/post
175 dist
=${DIST%%[0-9][0-9]}
176 local exc
="EXCLUDE_$dist"
180 if [ -n "$INCLUDE_DEBIAN" ]; then
181 local inc
="--include=$INCLUDE_DEBIAN"
184 if [ -n "$arch" ]; then
185 qemu-debootstrap
--arch $arch --exclude=${!exc} $inc $dist $xtmp $mirror
186 target
="${target}_${arch^^}"
188 if [[ $DIST =~
64 ]]; then
193 debootstrap
--arch $arch --exclude=${!exc} $inc $dist $xtmp $mirror
203 CENTOS5_32 CENTOS5_64
204 CENTOS6_32 CENTOS6_64
205 CENTOS7_32 CENTOS7_64
224 mk-basefile, create minimal base files for a Linux distritubtion
226 Copyright (C) 2011-2018 by Thomas Lange
228 Usage: mk-basefile [OPTION] ... DISTRIBUTION
230 -s Show list of supported linux distributions
231 -f ARCH Build for foreign architecture ARCH.
232 -d DIR Use DIR for creating the temporary subtree structure.
233 -z Use gzip for compressing the tar file.
234 -J Use xz for compressing the tar file.
235 -k Keep the temporary subtree structure, do not remove it.
238 Usage example: mk-basefile -J STRETCH64
239 This will create a STRETCH64.tar.xz basefile.
251 attributes
="--xattrs --selinux --acls"
253 while getopts ashzJd
:kf
: opt
; do
255 a
) echo "$0: Warning. -a is ignored, because xtattrs, acls and selinux are always added." ;;
256 d
) export TMPDIR
=$OPTARG ;;
257 f
) export ARCH
=$OPTARG ;;
258 z
) zip="gzip -9"; ext
=tar.gz
;;
259 J
) zip="xz -8" ext
=tar.xz
;;
262 s
) prtdists
; exit 0;;
263 ?
) exit 3 ;; # error in option parsing
266 shift $
(($OPTIND - 1))
268 xtmp
=$
(mktemp
--tmpdir -d basefiles.XXXXXXXX
)
269 if [ $?
-eq 1 ]; then
270 echo "mktemp failed. Aborting."
275 target
=$1 # also the name of the output file
277 [ -z "$target" ] && usage
279 CENTOS5_32
) centos i386
5 ;;
280 CENTOS5_64
) centos amd64
5 ;;
281 CENTOS6_32
) centos i386
6 ;;
282 CENTOS6_64
) centos amd64
6 ;;
283 CENTOS7_32
) centos i386
7 ;;
284 CENTOS7_64
) centos amd64
7 ;;
285 SLC5_32
) slc i386
5 ;;
286 SLC5_64
) slc amd64
5 ;;
287 SLC6_32
) slc i386
6 ;;
288 SLC6_64
) slc amd64
6 ;;
289 SLC7_64
) slc amd64
7 ;;
290 TRUSTY
*|XENIAL
*|BIONIC
*)
291 debgeneric
$target $MIRROR_UBUNTU ;;
292 SQUEEZE
*|WHEEZY
*|JESSIE
*|STRETCH
*|BUSTER
*|SID
*)
293 debgeneric
$target $MIRROR_DEBIAN $ARCH;;
294 *) echo "Unknown distribution. Aborting."
300 if [ $cleanup -eq 1 ]; then