Cdebootstrap

From campisano.org
Jump to navigation Jump to search

From Debian

# 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