d449c604f4268c132360da66eb16abd17f9f2df1
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
52 # here you can add packages, that are needed very early
54 INCLUDE_ETIONA
=ifupdown
55 INCLUDE_NABIA
=ifupdown
56 INCLUDE_ARAMO
=ifupdown
61 if [ X
$1 = Xi386
]; then
68 if [ $
(id
-u) != 0 ]; then
69 echo "You must be root to create chroots."
72 mknod
$xtmp/test-dev-null c
1 3
74 echo "Cannot create device files on $xtmp, aborting."
75 echo "Perhaps this directory is mounted with option nodev."
79 echo test > $xtmp/test-dev-null
81 echo "Cannot create device files on $xtmp, aborting."
82 echo "Perhaps this directory is mounted with option nodev."
86 rm -f $xtmp/test-dev-null
92 # set local mirror for rinse post script
93 [ -z "$MIRROR_CENTOS" ] && return
94 cat <<EOM > $xtmp/post
96 mkdir -p $xtmp/etc/yum.repos.d/orig
97 cp -p $xtmp/etc/yum.repos.d/*.repo $xtmp/etc/yum.repos.d/orig
98 perl -pi -e 's,mirrorlist=,#mirrorlist=,; s,#baseurl=http://mirror.centos.org,baseurl=$MIRROR_CENTOS,;' $xtmp/etc/yum.repos.d/CentOS-Base.repo
106 # set local mirror for rinse post script
108 [ -z "$MIRROR_SLC" ] && return
109 cat <<EOM > $xtmp/post
111 mkdir -p $xtmp/etc/yum.repos.d/orig
112 cp -p $xtmp/etc/yum.repos.d/*.repo $xtmp/etc/yum.repos.d/orig
113 perl -pi -e 's,baseurl=http://linuxsoft.cern.ch,baseurl=$MIRROR_SLC,;' $xtmp/etc/yum.repos.d/slc$ver-os.repo
114 perl -pi -e 's,baseurl=http://linuxsoft.cern.ch,baseurl=$MIRROR_SLC,;' $xtmp/etc/yum.repos.d/slc$ver-updates.repo
124 if [[ -e $cmd ]]; then
126 chroot
$xtmp "/tmp/$cmd"
131 chroot
$xtmp apt-get clean
132 rm -f $xtmp/etc
/hostname
$xtmp/etc
/resolv.conf \
133 $xtmp/var
/lib
/apt
/lists
/*_
* $xtmp/usr
/bin
/qemu-
*-static \
134 $xtmp/etc
/udev
/rules.d
/70-persistent-net.rules \
135 $xtmp/var
/lib
/dbus
/machine-id
136 > $xtmp/etc
/machine-id
142 # check if chroot works
143 echo "Installed packages in chroot:"
144 chroot
$xtmp rpm
-qa|
sort
145 echo -n "CHROOT rpm -qa: "
146 chroot
$xtmp rpm
-qa|
wc -l
148 rm -f $xtmp/etc
/resolv.conf
$xtmp/post
149 if [ -d $xtmp/etc
/yum.repos.d
/orig
]; then
150 mv $xtmp/etc
/yum.repos.d
/orig
/* $xtmp/etc
/yum.repos.d
/
151 rm -rf $xtmp/etc
/yum.repos.d
/orig
158 tar $attributes --numeric-owner --one-file-system -C $xtmp -cf - . |
$zip > $target.
$ext
167 local domain
=$
(domainname
)
171 $l32 rinse
--directory $xtmp --distribution $dist-$vers --arch $arch --before-post-install $xtmp/post
172 domainname
$domain # workaround for #613377
190 local domain
=$
(domainname
)
195 $l32 rinse
--directory $xtmp --distribution centos-
$vers --arch $arch --before-post-install $xtmp/post
196 domainname
$domain # workaround for #613377
210 $l32 rinse
--directory $xtmp --distribution slc-
$vers --arch $arch --before-post-install $xtmp/post
224 dist
=${DIST%%[0-9][0-9]}
225 local exc
="EXCLUDE_$dist"
226 [ -n "${!exc}" ] && exc
="--exclude=${!exc}" ||
unset exc
227 local inc
="INCLUDE_$dist"
228 [ -n "${!inc}" ] && inc
="--include=${!inc}" ||
unset inc
233 if [ -n "$arch" ]; then
234 qemu-debootstrap
--arch $arch ${exc} $inc $dist $xtmp $mirror
235 target
="${target}_${arch^^}"
237 if [[ $DIST =~
64 ]]; then
242 debootstrap
--arch $arch ${exc} $inc $dist $xtmp $mirror
255 CENTOS5_32 CENTOS5_64
256 CENTOS6_32 CENTOS6_64
257 CENTOS7_32 CENTOS7_64
277 BULLSEYE32 BULLSEYE64
278 BOOKWORM32 BOOKWORM64
288 mk-basefile, create minimal base files for a Linux distritubtion
290 Copyright (C) 2011-2023 by Thomas Lange
292 Usage: mk-basefile [OPTION] ... DISTRIBUTION
294 -s Show list of supported linux distributions
295 -f ARCH Build for foreign architecture ARCH.
296 -d DIR Use DIR for creating the temporary subtree structure.
297 -z Use zstd for compressing the tar file.
298 -J Use xz for compressing the tar file.
299 -k Keep the temporary subtree structure, do not remove it.
300 -x CMD Run CMD in chroot. If CMD exists as a file, copy it and run it.
304 Usage example: mk-basefile -J STRETCH64
305 This will create a STRETCH64.tar.xz basefile.
317 attributes
="--xattrs --selinux --acls"
319 while getopts ashzJd
:kf
:x
: opt
; do
321 a
) echo "$0: Warning. -a is ignored, because xtattrs, acls and selinux are always added." ;;
322 d
) export TMPDIR
=$OPTARG ;;
323 f
) export ARCH
=$OPTARG ;;
324 z
) zip="zstd -9"; ext
=tar.zst
;;
325 J
) zip="xz -8" ext
=tar.xz
;;
328 s
) prtdists
; exit 0;;
330 ?
) exit 3 ;; # error in option parsing
333 shift $
((OPTIND
- 1))
335 xtmp
=$
(mktemp
--tmpdir -d basefiles.XXXXXXXX
)
336 if [ $?
-eq 1 ]; then
337 echo "mktemp failed. Aborting."
342 target
=$1 # also the name of the output file
344 [ -z "$target" ] && usage
346 CENTOS5_32
) centos i386
5 ;;
347 CENTOS5_64
) centos amd64
5 ;;
348 CENTOS6_32
) centos i386
6 ;;
349 CENTOS6_64
) centos amd64
6 ;;
350 CENTOS7_32
) centos i386
7 ;;
351 CENTOS7_64
) centos amd64
7 ;;
352 CENTOS8_64
) centos amd64
8 ;;
353 ROCKY8_64
) rocky amd64
8 ;;
354 ROCKY9_64
) rocky amd64
9 ;;
355 ALMA9_64
) alma amd64
9 ;;
356 SLC5_32
) slc i386
5 ;;
357 SLC5_64
) slc amd64
5 ;;
358 SLC6_32
) slc i386
6 ;;
359 SLC6_64
) slc amd64
6 ;;
360 SLC7_64
) slc amd64
7 ;;
361 BELENOS
*|FLIDAS
*|ETIONA
*|NABIA
*|ARAMO
*)
362 debgeneric
$target $MIRROR_TRISQUEL ;;
363 TRUSTY
*|XENIAL
*|BIONIC
*|FOCAL
*|JAMMY
*|NOBLE
*)
364 debgeneric
$target $MIRROR_UBUNTU ;;
365 SQUEEZE
*|WHEEZY
*|JESSIE
*|STRETCH
*|BUSTER
*|BULLSEYE
*|BOOKWORM
*|TRIXIE
*|FORKY
*|SID
*)
366 debgeneric
$target $MIRROR_DEBIAN $ARCH;;
367 *) echo "Unknown distribution. Aborting."
373 if [ $cleanup -eq 1 ]; then