Cdebootstrap
Jump to navigation
Jump to search
Debian minimal distribution
To install cdebootstrap, you can follow the Cdebootstrap_(Application) insturctions and adapt it at your needs
Debian 12 "Bookworm"
- Note, the tgz containing a minimal Debian system root folder can be produced from any linux machine and used into any other linux with same arch (for instance amd64)
## debian base image creation su - #### define Debian flavors export TARGET=bookworm # debian guest version export ARCH=amd64 # the guest target must be the same of the host export VARIANT=minbase # minbase is the minimal debian environment export MIRROR=http://ftp.debian.org/debian/ # debian mirror to use export BASE_PATH=/srv export DEST_DIR=DEBIAN_${TARGET}_${ARCH} #### get cd ${BASE_PATH} CDE_SHARE_PATH=$(type -p cdebootstrap-static | sed s:/usr/bin/:/usr/share/:g) cdebootstrap-static --configdir=${CDE_SHARE_PATH} --helperdir=${CDE_SHARE_PATH} --allow-unauthenticated --arch ${ARCH} --include=apt,init,dialog,nano ${TARGET} ${BASE_PATH}/${DEST_DIR} ${MIRROR} #### make a backup of the downloaded system # REMEMBER: to restore, use tar --numeric-owner -xzf <FILENAME> tar -czf "bkp_${DEST_DIR}_cdebootstrapped_`date +%Y-%m-%d`.tgz" ${DEST_DIR} # make a backup of ~80MB ls -lsh --color du -hs ${DEST_DIR} ## configure and run the system in one terminal cat /etc/hostname > ${DEST_DIR}/etc/hostname echo 127.0.0.1 localhost `cat /etc/hostname` > ${DEST_DIR}/etc/hosts cat /etc/resolv.conf > ${DEST_DIR}/etc/resolv.conf mkdir -p ${DEST_DIR}/dev/pts mount -o bind /proc ${DEST_DIR}/proc mount -o bind /sys ${DEST_DIR}/sys mount -o bind /dev/pts ${DEST_DIR}/dev/pts chroot ${DEST_DIR} env -i LC_ALL=C TERM="$TERM" HOME=/root bash --login --posix ######################################## #### INSIDE CHROOT GUEST ENV passwd --delete root ###echo none / auto rw 0 0 > /etc/mtab echo "source ~/.profile" > ~/.bashrc cat > ~/.profile << 'EOF' test 0 -eq 1 && PS1='\u@CHROOT:\w\# ' || PS1='\u@CHROOT:\w$ ' umask 0027 export HISTTIMEFORMAT='%F %T ' export HISTSIZE=10000 export HISTFILESIZE=10000 export HISTCONTROL=ignorespace alias cp="cp -i" alias mv="mv -i" alias rm="rm -i" EOF login root # login again to use the changes above apt-get -y update apt-get -y install dialog locales tzdata dpkg-reconfigure locales # choose en_US.UTF8 and set en_US.UTF8 as default dpkg-reconfigure tzdata # choose None of the above -> UTC apt-mark auto `apt-mark showmanual` # mark all packages as "not requested by the user" apt-get -y install apt bash binutils bsdutils bzip2 coreutils debconf dialog dpkg findutils grep gzip init iptables kmod less libc-bin locales login lsof mount nano passwd procps psmisc readline-common rsyslog sed sysvinit-utils tar util-linux apt-get -y autoremove --purge # remove all "not requested" packages apt-get -y dist-upgrade apt-get -y clean rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/* exit # exit from previous logi exit # exit from chroot ######################################## #### OUTSIDE CHROOT GUEST ENV umount ${DEST_DIR}/dev/pts umount ${DEST_DIR}/sys umount ${DEST_DIR}/proc #### make a backup of the configured system, if you want to test changes # REMEMBER: to restore, use tar --numeric-owner -xzf <FILENAME> tar -czf "bkp_${DEST_DIR}_cdebootstrapped_configured_`date +%Y-%m-%d`.tgz" ${DEST_DIR} # make a backup of ~90MB ls -lsh --color du -hs ${DEST_DIR}
Older versions
# BUSTER amd64 example ######################################## #### OR FROM ANY LINUX MACHINE WITH SAME ARCH (e.g. amd64) #apt-get install -y binutils xz-utils || yum install binutils xz mkdir /srv/tmp cd /srv/tmp curl -s -O http://ftp.debian.org/debian/pool/main/c/cdebootstrap/cdebootstrap-static_0.7.7+b1_amd64.deb ar -x cdebootstrap-static_0.7.7+b1_amd64.deb data.tar.xz tar -xJf data.tar.xz cd .. file ./tmp/usr/bin/cdebootstrap-static #### set guest options export TARGET=buster # debian guest version export ARCH=amd64 # the guest target must be the same of the host export VARIANT=minbase # minbase is the minimal debian environment export MIRROR=http://ftp.debian.org/debian/ # debian mirror to use export BASE_PATH=/srv export DEST_DIR=DEBIAN_${TARGET}_${ARCH} #### get ./tmp/usr/bin/cdebootstrap-static --configdir=./tmp/usr/share/cdebootstrap-static --allow-unauthenticated --arch ${ARCH} --include=apt,init,dialog,nano,systemd-container ${TARGET} ${BASE_PATH}/${DEST_DIR} ${MIRROR} rm -f ${BASE_PATH}/${DEST_DIR}/var/cache/apt/archives/*.deb systemd-nspawn --directory=${BASE_PATH}/${DEST_DIR} passwd --delete root #### make a backup of the downloaded system, if you want to test changes # REMEMBER: to restore, use tar --numeric-owner -xzf <FILENAME> tar -czf "bkp_${DEST_DIR}_debootstrapped_`date +%Y-%m-%d`.tgz" ${DEST_DIR} # make a backup of ~70MB ls -lsh --color du -hs ${BASE_PATH}/${DEST_DIR}
# JESSIE amd64 example ### setting up export TARGET=jessie export ARCH=amd64 export FLAVOUR=minimal export DEST_DIR=DEBIAN_"$TARGET"_"$ARCH" ### start apt-get update apt-get install cdebootstrap LD_LIBRARY_PATH=/lib/x86_64-linux-gnu:/lib/i386-linux-gnu cdebootstrap --arch "$ARCH" --flavour="$FLAVOUR" "$TARGET" /srv/"$DEST_DIR" http://ftp.debian.org/debian/ ln -s "$DEST_DIR" /srv/CHROOT cat /etc/resolv.conf > /srv/CHROOT/etc/resolv.conf cat /etc/hostname > /srv/CHROOT/etc/hostname echo 127.0.0.1 localhost `cat /etc/hostname` > /srv/CHROOT/etc/hosts mount -o bind /proc /srv/CHROOT/proc mount -o bind /sys /srv/CHROOT/sys mount -o bind /dev/pts /srv/CHROOT/dev/pts chroot /srv/CHROOT ### inside chroot env passwd --delete root echo none / auto rw 0 0 > /etc/mtab export LC_ALL=C LANGUAGE=C LANG=C ### prevent services startup on install # NO MORE NEEDED #echo -e \#\!/bin/sh > /usr/sbin/policy-rc.d #echo -e exit 101 >> /usr/sbin/policy-rc.d #chmod a+x ./usr/sbin/policy-rc.d ### configuring apt sources echo -e \# "$TARGET" > /etc/apt/sources.list echo deb http://ftp.debian.org/debian/ "$TARGET" main contrib non-free >> /etc/apt/sources.list echo deb http://ftp.debian.org/debian/ "$TARGET"-updates main contrib non-free >> /etc/apt/sources.list echo -e \\n\# security >> /etc/apt/sources.list echo deb http://security.debian.org/ "$TARGET"/updates main contrib non-free >> /etc/apt/sources.list apt-get update apt-get install dialog apt-get dist-upgrade ### configuring locales and time apt-get install locales dpkg-reconfigure locales # choose en_US.UTF8, None default dpkg-reconfigure tzdata # choose None of the above -> UTC echo "export LC_ALL=en_US.UTF-8 LANGUAGE=en_US.UTF-8 LANG=en_US.UTF-8" >> /etc/profile echo "test `id -u` -eq 1 && PS1='\u@CHROOT:\w\# ' || PS1='\u@CHROOT:\w\$ '" >> /etc/profile echo "source /etc/profile" >> ~/.bashrc ### install basic system tools bash # to apply locales apt-get install binutils nano psmisc lsof findutils grep less tar gzip bzip2 module-init-tools iptables procps cron # optionally: apt-get install wget dnsutils mutt man nmap apt-get clean exit # bash history -c exit # chroot ### outside chroot env umount /srv/CHROOT/dev/pts umount /srv/CHROOT/sys umount /srv/CHROOT/proc
From RedHat
- TO BE UPDATED
root@host:~# cd /srv root@host:~# mkdir bootstrap root@host:~# cd bootstrap root@host:~# wget http://ftp.debian.org/debian/pool/main/c/cdebootstrap/cdebootstrap-static_0.5.7_amd64.deb root@host:~# yum install binutils.x86_64 # if needed for ar root@host:~# ar xv cdebootstrap-static_0.5.7_amd64.deb root@host:~# tar -xzf data.tar.gz root@host:~# mkdir -p var/log root@host:~# cp -a /etc /bin /sbin /lib /lib64 . root@host:~# cp -a /usr/bin/wget usr/bin root@host:~# cp -a /usr/lib64/libssl.so.10 /usr/lib64/libssl.so.1.0.0g lib64 root@host:~# cp /usr/bin/md5sum usr/bin root@host:~# chroot . /sbin/ldconfig root@host:~# chroot . usr/bin/cdebootstrap-static -v --debug --allow-unauthenticated --flavour=minimal stable /DEBIAN_stable_amd64 http://ftp.debian.org/debian/ root@host:~# mv DEBIAN_stable_amd64 /srv root@host:~# cd .. root@host:~# rm -rf bootstrap/ root@host:~# ln -s DEBIAN_stable_amd64 /srv/CHROOT root@host:~# cp -a /etc/resolv.conf /srv/CHROOT/etc root@host:~# echo -n stable_amd64 > /srv/CHROOT/etc/hostname root@host:~# mount -o bind /proc /srv/CHROOT/proc root@host:~# mount -o bind /sys /srv/CHROOT/sys root@host:~# mount -o bind /dev/pts /srv/CHROOT/dev/pts root@host:~# chroot /srv/CHROOT root@host:~# passwd --delete root stable_amd64:/# echo none / auto rw 0 0 > /etc/mtab stable_amd64:/# export LC_ALL=C LANGUAGE=C LANG=C stable_amd64:/# apt-get update stable_amd64:/# apt-get install dialog stable_amd64:/# apt-get dist-upgrade stable_amd64:/# apt-get install locales stable_amd64:/# dpkg-reconfigure locales # choose en_US.UTF-8 stable_amd64:/# echo "export LC_ALL=en_US.UTF-8 LANGUAGE=en_US.UTF-8 LANG=en_US.UTF-8" >> /etc/profile stable_amd64:/# export LC_ALL=en_US.UTF-8 LANGUAGE=en_US.UTF-8 LANG=en_US.UTF-8 stable_amd64:/# apt-get install binutils nano nmap psmisc lsof findutils grep less tar gzip bzip2 wget dnsutils module-init-tools iptables procps man mail mutt stable_amd64:/# apt-get clean stable_amd64:/# exit root@host:~# umount /srv/CHROOT/dev/pts root@host:~# umount /srv/CHROOT/sys root@host:~# umount /srv/CHROOT/proc