7ced32de1d248f0be63c48d04f1a02aed00ce423
3 # mk-basefile, create basefiles for some distributions
5 # Thomas Lange, Uni Koeln, 2011-2024
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 (i386/amd64):
13 # Ubuntu 14.04/16.04/20.04/22.04
17 # Scientific Linux Cern 5/6
19 # Packages you might want to install to use this command:
20 # debootstrap, rinse, xz-utils
23 # Define your local mirros here
24 # For the first stage, set the CentOS/SLC mirror in /etc/rinse/rinse.conf
25 MIRROR_DEBIAN
=http
://deb.debian.org
/debian
/
26 MIRROR_UBUNTU
=http
://mirror.netcologne.de
/ubuntu
/
27 MIRROR_CENTOS
=http
://mirror.netcologne.de
/
29 EXCLUDE_SQUEEZE
=isc-dhcp-client
,isc-dhcp-common
,info
40 EXCLUDE_TRUSTY
=dhcp3-client
,dhcp3-common
,info
41 EXCLUDE_XENIAL
=udhcpc
,dibbler-client
,info
42 EXCLUDE_BIONIC
=udhcpc
,dibbler-client
,info
43 EXCLUDE_FOCAL
=udhcpc
,dibbler-client
,info
44 EXCLUDE_JAMMY
=udhcpc
,dibbler-client
,info
45 EXCLUDE_NOBLE
=udhcpc
,dibbler-client
,info
47 # here you can add packages, that are needed very early
54 if [ X
$1 = Xi386
]; then
61 if [ $
(id
-u) != 0 ]; then
62 echo "You must be root to create chroots."
65 mknod
$xtmp/test-dev-null c
1 3
67 echo "Cannot create device files on $xtmp, aborting."
68 echo "Perhaps this directory is mounted with option nodev."
72 echo test > $xtmp/test-dev-null
74 echo "Cannot create device files on $xtmp, aborting."
75 echo "Perhaps this directory is mounted with option nodev."
79 rm -f $xtmp/test-dev-null
85 # set local mirror for rinse post script
86 [ -z "$MIRROR_CENTOS" ] && return
87 cat <<EOM > $xtmp/post
89 mkdir -p $xtmp/etc/yum.repos.d/orig
90 cp -p $xtmp/etc/yum.repos.d/*.repo $xtmp/etc/yum.repos.d/orig
91 perl -pi -e 's,mirrorlist=,#mirrorlist=,; s,#baseurl=http://mirror.centos.org,baseurl=$MIRROR_CENTOS,;' $xtmp/etc/yum.repos.d/CentOS-Base.repo
99 # set local mirror for rinse post script
101 [ -z "$MIRROR_SLC" ] && return
102 cat <<EOM > $xtmp/post
104 mkdir -p $xtmp/etc/yum.repos.d/orig
105 cp -p $xtmp/etc/yum.repos.d/*.repo $xtmp/etc/yum.repos.d/orig
106 perl -pi -e 's,baseurl=http://linuxsoft.cern.ch,baseurl=$MIRROR_SLC,;' $xtmp/etc/yum.repos.d/slc$ver-os.repo
107 perl -pi -e 's,baseurl=http://linuxsoft.cern.ch,baseurl=$MIRROR_SLC,;' $xtmp/etc/yum.repos.d/slc$ver-updates.repo
116 chroot
$xtmp apt-get clean
117 rm -f $xtmp/etc
/hostname
$xtmp/etc
/resolv.conf \
118 $xtmp/var
/lib
/apt
/lists
/*_
* $xtmp/usr
/bin
/qemu-
*-static \
119 $xtmp/etc
/udev
/rules.d
/70-persistent-net.rules \
120 $xtmp/var
/lib
/dbus
/machine-id
121 > $xtmp/etc
/machine-id
127 # check if chroot works
128 echo "Installed packages in chroot:"
129 chroot
$xtmp rpm
-qa|
sort
130 echo -n "CHROOT rpm -qa: "
131 chroot
$xtmp rpm
-qa|
wc -l
133 rm -f $xtmp/etc
/resolv.conf
$xtmp/post
134 if [ -d $xtmp/etc
/yum.repos.d
/orig
]; then
135 mv $xtmp/etc
/yum.repos.d
/orig
/* $xtmp/etc
/yum.repos.d
/
136 rm -rf $xtmp/etc
/yum.repos.d
/orig
143 tar $attributes --numeric-owner --one-file-system -C $xtmp -cf - . |
$zip > $target.
$ext
152 local domain
=$
(domainname
)
156 $l32 rinse
--directory $xtmp --distribution $dist-$vers --arch $arch --before-post-install $xtmp/post
157 domainname
$domain # workaround for #613377
175 local domain
=$
(domainname
)
180 $l32 rinse
--directory $xtmp --distribution centos-
$vers --arch $arch --before-post-install $xtmp/post
181 domainname
$domain # workaround for #613377
195 $l32 rinse
--directory $xtmp --distribution slc-
$vers --arch $arch --before-post-install $xtmp/post
209 dist
=${DIST%%[0-9][0-9]}
210 local exc
="EXCLUDE_$dist"
211 [ -n "${!exc}" ] && exc
="--exclude=${!exc}" ||
unset exc
215 if [ -n "$INCLUDE_DEBIAN" ]; then
216 local inc
="--include=$INCLUDE_DEBIAN"
219 if [ -n "$arch" ]; then
220 qemu-debootstrap
--arch $arch ${exc} $inc $dist $xtmp $mirror
221 target
="${target}_${arch^^}"
223 if [[ $DIST =~
64 ]]; then
228 debootstrap
--arch $arch ${exc} $inc $dist $xtmp $mirror
241 CENTOS5_32 CENTOS5_64
242 CENTOS6_32 CENTOS6_64
243 CENTOS7_32 CENTOS7_64
259 BULLSEYE32 BULLSEYE64
260 BOOKWORM32 BOOKWORM64
270 mk-basefile, create minimal base files for a Linux distritubtion
272 Copyright (C) 2011-2023 by Thomas Lange
274 Usage: mk-basefile [OPTION] ... DISTRIBUTION
276 -s Show list of supported linux distributions
277 -f ARCH Build for foreign architecture ARCH.
278 -d DIR Use DIR for creating the temporary subtree structure.
279 -z Use zstd for compressing the tar file.
280 -J Use xz for compressing the tar file.
281 -k Keep the temporary subtree structure, do not remove it.
284 Usage example: mk-basefile -J STRETCH64
285 This will create a STRETCH64.tar.xz basefile.
297 attributes
="--xattrs --selinux --acls"
299 while getopts ashzJd
:kf
: opt
; do
301 a
) echo "$0: Warning. -a is ignored, because xtattrs, acls and selinux are always added." ;;
302 d
) export TMPDIR
=$OPTARG ;;
303 f
) export ARCH
=$OPTARG ;;
304 z
) zip="zstd -9"; ext
=tar.zst
;;
305 J
) zip="xz -8" ext
=tar.xz
;;
308 s
) prtdists
; exit 0;;
309 ?
) exit 3 ;; # error in option parsing
312 shift $
((OPTIND
- 1))
314 xtmp
=$
(mktemp
--tmpdir -d basefiles.XXXXXXXX
)
315 if [ $?
-eq 1 ]; then
316 echo "mktemp failed. Aborting."
321 target
=$1 # also the name of the output file
323 [ -z "$target" ] && usage
325 CENTOS5_32
) centos i386
5 ;;
326 CENTOS5_64
) centos amd64
5 ;;
327 CENTOS6_32
) centos i386
6 ;;
328 CENTOS6_64
) centos amd64
6 ;;
329 CENTOS7_32
) centos i386
7 ;;
330 CENTOS7_64
) centos amd64
7 ;;
331 CENTOS8_64
) centos amd64
8 ;;
332 ROCKY8_64
) rocky amd64
8 ;;
333 ROCKY9_64
) rocky amd64
9 ;;
334 ALMA9_64
) alma amd64
9 ;;
335 SLC5_32
) slc i386
5 ;;
336 SLC5_64
) slc amd64
5 ;;
337 SLC6_32
) slc i386
6 ;;
338 SLC6_64
) slc amd64
6 ;;
339 SLC7_64
) slc amd64
7 ;;
340 TRUSTY
*|XENIAL
*|BIONIC
*|FOCAL
*|JAMMY
*|NOBLE
*)
341 debgeneric
$target $MIRROR_UBUNTU ;;
342 SQUEEZE
*|WHEEZY
*|JESSIE
*|STRETCH
*|BUSTER
*|BULLSEYE
*|BOOKWORM
*|TRIXIE
*|FORKY
*|SID
*)
343 debgeneric
$target $MIRROR_DEBIAN $ARCH;;
344 *) echo "Unknown distribution. Aborting."
350 if [ $cleanup -eq 1 ]; then