be00fe2d6aa997f2dd9766c9f11dec0cc0cdf269
3 # mk-basefile, create basefiles for some distributions
5 # Thomas Lange, Uni Koeln, 2011-2020
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
35 EXCLUDE_TRUSTY
=dhcp3-client
,dhcp3-common
,info
36 EXCLUDE_XENIAL
=udhcpc
,dibbler-client
,info
37 EXCLUDE_BIONIC
=udhcpc
,dibbler-client
,info
38 EXCLUDE_FOCAL
=udhcpc
,dibbler-client
,info
40 # here you can add packages, that are needed very early
47 if [ X
$1 = Xi386
]; then
54 if [ $
(id
-u) != 0 ]; then
55 echo "You must be root to create chroots."
58 mknod
$xtmp/test-dev-null c
1 3
60 echo "Cannot create device files on $xtmp, aborting."
61 echo "Perhaps this directory is mounted with option nodev."
65 echo test > $xtmp/test-dev-null
67 echo "Cannot create device files on $xtmp, aborting."
68 echo "Perhaps this directory is mounted with option nodev."
72 rm -f $xtmp/test-dev-null
78 # set local mirror for rinse post script
79 [ -z "$MIRROR_CENTOS" ] && return
80 cat <<EOM > $xtmp/post
82 mkdir -p $xtmp/etc/yum.repos.d/orig
83 cp -p $xtmp/etc/yum.repos.d/*.repo $xtmp/etc/yum.repos.d/orig
84 perl -pi -e 's,mirrorlist=,#mirrorlist=,; s,#baseurl=http://mirror.centos.org,baseurl=$MIRROR_CENTOS,;' $xtmp/etc/yum.repos.d/CentOS-Base.repo
92 # set local mirror for rinse post script
94 [ -z "$MIRROR_SLC" ] && return
95 cat <<EOM > $xtmp/post
97 mkdir -p $xtmp/etc/yum.repos.d/orig
98 cp -p $xtmp/etc/yum.repos.d/*.repo $xtmp/etc/yum.repos.d/orig
99 perl -pi -e 's,baseurl=http://linuxsoft.cern.ch,baseurl=$MIRROR_SLC,;' $xtmp/etc/yum.repos.d/slc$ver-os.repo
100 perl -pi -e 's,baseurl=http://linuxsoft.cern.ch,baseurl=$MIRROR_SLC,;' $xtmp/etc/yum.repos.d/slc$ver-updates.repo
109 chroot
$xtmp apt-get clean
110 rm -f $xtmp/etc
/hostname
$xtmp/etc
/resolv.conf \
111 $xtmp/var
/lib
/apt
/lists
/*_
* $xtmp/usr
/bin
/qemu-
*-static \
112 $xtmp/etc
/udev
/rules.d
/70-persistent-net.rules
113 > $xtmp/etc
/machine-id
119 # check if chroot works
120 echo "Installed packages in chroot:"
121 chroot
$xtmp rpm
-qa|
sort
122 echo -n "CHROOT rpm -qa: "
123 chroot
$xtmp rpm
-qa|
wc -l
125 rm -f $xtmp/etc
/resolv.conf
$xtmp/post
126 if [ -d $xtmp/etc
/yum.repos.d
/orig
]; then
127 mv $xtmp/etc
/yum.repos.d
/orig
/* $xtmp/etc
/yum.repos.d
/
128 rm -rf $xtmp/etc
/yum.repos.d
/orig
135 tar $attributes --numeric-owner --one-file-system -C $xtmp -cf - . |
$zip > $target.
$ext
143 local domain
=$
(domainname
)
148 $l32 rinse
--directory $xtmp --distribution centos-
$vers --arch $arch --before-post-install $xtmp/post
149 domainname
$domain # workaround for #613377
163 $l32 rinse
--directory $xtmp --distribution slc-
$vers --arch $arch --before-post-install $xtmp/post
177 dist
=${DIST%%[0-9][0-9]}
178 local exc
="EXCLUDE_$dist"
179 [ -n "${!exc}" ] && exc
="--exclude=${!exc}" ||
unset exc
183 if [ -n "$INCLUDE_DEBIAN" ]; then
184 local inc
="--include=$INCLUDE_DEBIAN"
187 if [ -n "$arch" ]; then
188 qemu-debootstrap
--arch $arch ${exc} $inc $dist $xtmp $mirror
189 target
="${target}_${arch^^}"
191 if [[ $DIST =~
64 ]]; then
196 debootstrap
--arch $arch ${exc} $inc $dist $xtmp $mirror
206 CENTOS5_32 CENTOS5_64
207 CENTOS6_32 CENTOS6_64
208 CENTOS7_32 CENTOS7_64
222 BULLSEYE32 BULLSEYE64
230 mk-basefile, create minimal base files for a Linux distritubtion
232 Copyright (C) 2011-2020 by Thomas Lange
234 Usage: mk-basefile [OPTION] ... DISTRIBUTION
236 -s Show list of supported linux distributions
237 -f ARCH Build for foreign architecture ARCH.
238 -d DIR Use DIR for creating the temporary subtree structure.
239 -z Use gzip for compressing the tar file.
240 -J Use xz for compressing the tar file.
241 -k Keep the temporary subtree structure, do not remove it.
244 Usage example: mk-basefile -J STRETCH64
245 This will create a STRETCH64.tar.xz basefile.
257 attributes
="--xattrs --selinux --acls"
259 while getopts ashzJd
:kf
: opt
; do
261 a
) echo "$0: Warning. -a is ignored, because xtattrs, acls and selinux are always added." ;;
262 d
) export TMPDIR
=$OPTARG ;;
263 f
) export ARCH
=$OPTARG ;;
264 z
) zip="gzip -9"; ext
=tar.gz
;;
265 J
) zip="xz -8" ext
=tar.xz
;;
268 s
) prtdists
; exit 0;;
269 ?
) exit 3 ;; # error in option parsing
272 shift $
((OPTIND
- 1))
274 xtmp
=$
(mktemp
--tmpdir -d basefiles.XXXXXXXX
)
275 if [ $?
-eq 1 ]; then
276 echo "mktemp failed. Aborting."
281 target
=$1 # also the name of the output file
283 [ -z "$target" ] && usage
285 CENTOS5_32
) centos i386
5 ;;
286 CENTOS5_64
) centos amd64
5 ;;
287 CENTOS6_32
) centos i386
6 ;;
288 CENTOS6_64
) centos amd64
6 ;;
289 CENTOS7_32
) centos i386
7 ;;
290 CENTOS7_64
) centos amd64
7 ;;
291 CENTOS8_64
) centos amd64
8 ;;
292 SLC5_32
) slc i386
5 ;;
293 SLC5_64
) slc amd64
5 ;;
294 SLC6_32
) slc i386
6 ;;
295 SLC6_64
) slc amd64
6 ;;
296 SLC7_64
) slc amd64
7 ;;
297 TRUSTY
*|XENIAL
*|BIONIC
*|FOCAL
*)
298 debgeneric
$target $MIRROR_UBUNTU ;;
299 SQUEEZE
*|WHEEZY
*|JESSIE
*|STRETCH
*|BUSTER
*|BULLSEYE
*|SID
*)
300 debgeneric
$target $MIRROR_DEBIAN $ARCH;;
301 *) echo "Unknown distribution. Aborting."
307 if [ $cleanup -eq 1 ]; then