2 # mk-basefile, create basefiles for some distributions
4 # Thomas Lange, Uni Koeln, 2011-2024
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 (i386/amd64):
12 # Ubuntu 14.04/16.04/20.04/22.04
16 # Scientific Linux Cern 5/6
18 # Packages you might want to install to use this command:
19 # debootstrap, rinse, xz-utils
22 # Define your local mirros here
23 # For the first stage, set the CentOS/SLC mirror in /etc/rinse/rinse.conf
24 MIRROR_DEBIAN
=http
://deb.debian.org
/debian
/
25 MIRROR_UBUNTU
=http
://mirror.netcologne.de
/ubuntu
/
26 MIRROR_TRISQUEL
=http
://mirror.fsf.org
/trisquel
/
27 MIRROR_CENTOS
=http
://mirror.netcologne.de
/
29 EXCLUDE_SQUEEZE
=isc-dhcp-client
,isc-dhcp-common
,info
40 EXCLUDE_BELENOS
=dhcp3-client
,dhcp3-common
,info
41 EXCLUDE_TRUSTY
=dhcp3-client
,dhcp3-common
,info
42 EXCLUDE_XENIAL
=udhcpc
,dibbler-client
,info
43 EXCLUDE_FLIDAS
=udhcpc
,dibbler-client
,info
44 EXCLUDE_BIONIC
=udhcpc
,dibbler-client
,info
45 EXCLUDE_ETIONA
=udhcpc
,dibbler-client
,info
46 EXCLUDE_FOCAL
=udhcpc
,dibbler-client
,info
47 EXCLUDE_NABIA
=udhcpc
,dibbler-client
,info
48 EXCLUDE_JAMMY
=udhcpc
,dibbler-client
,info
49 EXCLUDE_ARAMO
=udhcpc
,dibbler-client
,info
50 EXCLUDE_NOBLE
=udhcpc
,dibbler-client
,info
51 EXCLUDE_ECNE
=udhcpc
,dibbler-client
,info
53 # here you can add packages, that are needed very early
55 INCLUDE_ETIONA
=ifupdown
56 INCLUDE_NABIA
=ifupdown
57 INCLUDE_ARAMO
=ifupdown
63 if [ X
$1 = Xi386
]; then
70 if [ $
(id
-u) != 0 ]; then
71 echo "You must be root to create chroots."
74 mknod
$xtmp/test-dev-null c
1 3
76 echo "Cannot create device files on $xtmp, aborting."
77 echo "Perhaps this directory is mounted with option nodev."
81 echo test > $xtmp/test-dev-null
83 echo "Cannot create device files on $xtmp, aborting."
84 echo "Perhaps this directory is mounted with option nodev."
88 rm -f $xtmp/test-dev-null
94 # set local mirror for rinse post script
95 [ -z "$MIRROR_CENTOS" ] && 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,mirrorlist=,#mirrorlist=,; s,#baseurl=http://mirror.centos.org,baseurl=$MIRROR_CENTOS,;' $xtmp/etc/yum.repos.d/CentOS-Base.repo
108 # set local mirror for rinse post script
110 [ -z "$MIRROR_SLC" ] && return
111 cat <<EOM > $xtmp/post
113 mkdir -p $xtmp/etc/yum.repos.d/orig
114 cp -p $xtmp/etc/yum.repos.d/*.repo $xtmp/etc/yum.repos.d/orig
115 perl -pi -e 's,baseurl=http://linuxsoft.cern.ch,baseurl=$MIRROR_SLC,;' $xtmp/etc/yum.repos.d/slc$ver-os.repo
116 perl -pi -e 's,baseurl=http://linuxsoft.cern.ch,baseurl=$MIRROR_SLC,;' $xtmp/etc/yum.repos.d/slc$ver-updates.repo
126 if [[ -e $cmd ]]; then
128 chroot
$xtmp "/tmp/$cmd"
133 chroot
$xtmp apt-get clean
134 rm -f $xtmp/etc
/hostname
$xtmp/etc
/resolv.conf \
135 $xtmp/var
/lib
/apt
/lists
/*_
* $xtmp/usr
/bin
/qemu-
*-static \
136 $xtmp/etc
/udev
/rules.d
/70-persistent-net.rules \
137 $xtmp/var
/lib
/dbus
/machine-id
138 > $xtmp/etc
/machine-id
144 # check if chroot works
145 echo "Installed packages in chroot:"
146 chroot
$xtmp rpm
-qa|
sort
147 echo -n "CHROOT rpm -qa: "
148 chroot
$xtmp rpm
-qa|
wc -l
150 rm -f $xtmp/etc
/resolv.conf
$xtmp/post
151 if [ -d $xtmp/etc
/yum.repos.d
/orig
]; then
152 mv $xtmp/etc
/yum.repos.d
/orig
/* $xtmp/etc
/yum.repos.d
/
153 rm -rf $xtmp/etc
/yum.repos.d
/orig
160 tar $attributes --numeric-owner --one-file-system -C $xtmp -cf - . |
$zip > $target.
$ext
169 local domain
=$
(domainname
)
173 $l32 rinse
--directory $xtmp --distribution $dist-$vers --arch $arch --before-post-install $xtmp/post
174 domainname
$domain # workaround for #613377
192 local domain
=$
(domainname
)
197 $l32 rinse
--directory $xtmp --distribution centos-
$vers --arch $arch --before-post-install $xtmp/post
198 domainname
$domain # workaround for #613377
212 $l32 rinse
--directory $xtmp --distribution slc-
$vers --arch $arch --before-post-install $xtmp/post
226 dist
=${DIST%%[0-9][0-9]}
227 local exc
="EXCLUDE_$dist"
228 [ -n "${!exc}" ] && exc
="--exclude=${!exc}" ||
unset exc
229 local inc
="INCLUDE_$dist"
230 [ -n "${!inc}" ] && inc
="--include=${!inc}" ||
unset inc
235 if [ -n "$arch" ]; then
236 qemu-debootstrap
--arch $arch ${exc} $inc $dist $xtmp $mirror
237 target
="${target}_${arch^^}"
239 if [[ $DIST =~
64 ]]; then
244 debootstrap
--arch $arch ${exc} $inc $dist $xtmp $mirror
257 CENTOS5_32 CENTOS5_64
258 CENTOS6_32 CENTOS6_64
259 CENTOS7_32 CENTOS7_64
280 BULLSEYE32 BULLSEYE64
281 BOOKWORM32 BOOKWORM64
291 mk-basefile, create minimal base files for a Linux distritubtion
293 Copyright (C) 2011-2023 by Thomas Lange
295 Usage: mk-basefile [OPTION] ... DISTRIBUTION
297 -s Show list of supported linux distributions
298 -f ARCH Build for foreign architecture ARCH.
299 -d DIR Use DIR for creating the temporary subtree structure.
300 -z Use zstd for compressing the tar file.
301 -J Use xz for compressing the tar file.
302 -k Keep the temporary subtree structure, do not remove it.
303 -x CMD Run CMD in chroot. If CMD exists as a file, copy it and run it.
307 Usage example: mk-basefile -J STRETCH64
308 This will create a STRETCH64.tar.xz basefile.
320 attributes
="--xattrs --selinux --acls"
322 while getopts ashzJd
:kf
:x
: opt
; do
324 a
) echo "$0: Warning. -a is ignored, because xtattrs, acls and selinux are always added." ;;
325 d
) export TMPDIR
=$OPTARG ;;
326 f
) export ARCH
=$OPTARG ;;
327 z
) zip="zstd -9"; ext
=tar.zst
;;
328 J
) zip="xz -8" ext
=tar.xz
;;
331 s
) prtdists
; exit 0;;
333 ?
) exit 3 ;; # error in option parsing
336 shift $
((OPTIND
- 1))
338 xtmp
=$
(mktemp
--tmpdir -d basefiles.XXXXXXXX
)
339 if [ $?
-eq 1 ]; then
340 echo "mktemp failed. Aborting."
345 target
=$1 # also the name of the output file
347 [ -z "$target" ] && usage
349 CENTOS5_32
) centos i386
5 ;;
350 CENTOS5_64
) centos amd64
5 ;;
351 CENTOS6_32
) centos i386
6 ;;
352 CENTOS6_64
) centos amd64
6 ;;
353 CENTOS7_32
) centos i386
7 ;;
354 CENTOS7_64
) centos amd64
7 ;;
355 CENTOS8_64
) centos amd64
8 ;;
356 ROCKY8_64
) rocky amd64
8 ;;
357 ROCKY9_64
) rocky amd64
9 ;;
358 ALMA9_64
) alma amd64
9 ;;
359 SLC5_32
) slc i386
5 ;;
360 SLC5_64
) slc amd64
5 ;;
361 SLC6_32
) slc i386
6 ;;
362 SLC6_64
) slc amd64
6 ;;
363 SLC7_64
) slc amd64
7 ;;
364 BELENOS
*|FLIDAS
*|ETIONA
*|NABIA
*|ARAMO
*|ECNE
*)
365 debgeneric
$target $MIRROR_TRISQUEL ;;
366 TRUSTY
*|XENIAL
*|BIONIC
*|FOCAL
*|JAMMY
*|NOBLE
*)
367 debgeneric
$target $MIRROR_UBUNTU ;;
368 SQUEEZE
*|WHEEZY
*|JESSIE
*|STRETCH
*|BUSTER
*|BULLSEYE
*|BOOKWORM
*|TRIXIE
*|FORKY
*|SID
*)
369 debgeneric
$target $MIRROR_DEBIAN $ARCH;;
370 *) echo "Unknown distribution. Aborting."
376 if [ $cleanup -eq 1 ]; then