Skip to content

Instantly share code, notes, and snippets.

@jof
Last active December 16, 2015 06:38
Show Gist options
  • Save jof/5392476 to your computer and use it in GitHub Desktop.
Save jof/5392476 to your computer and use it in GitHub Desktop.
Userland Debian chroot
#!/bin/bash
debian_release=squeeze
rhel_major=6
epel_release_rpm="epel-release-6-8.noarch.rpm"
chroot=/debian
mkdir -p $chroot
_machine=`uname -m`
wget -O /tmp/$epel_release_rpm http://mirrors.kernel.org/fedora-epel/${rhel_major}/${_machine}/$epel_release_rpm
rpm -i /tmp/$epel_release_rpm
if [ "$?" -ne 0 ]; then
echo "Failed to install EPEL." >2
exit 1
fi
yum install -y debootstrap
if [ "$?" -ne 0 ]; then
echo "Failed to install debootstrap." >2
exit 1
fi
if [ "$_machine" = 'x86_64' ]; then
debian_machine=amd64
else
debian_machine=i386
fi
debootstrap --arch $debian_machine squeeze $chroot http://mirrors.kernel.org/debian
if [ "$?" -ne 0 ]; then
echo "Failed to debootstrap" >&2
exit 1
fi
# Mount special FSes
_proc_mount_line="proc ${chroot}/proc proc defaults 0 0"
_sysfs_mount_line="sysfs ${chroot}/sys sysfs defaults 0 0"
_devpts_mount_line="devpts ${chroot}/dev/pts devpts gid=5,mode=620 0 0"
grep "$_proc_mount_line" /etc/fstab
if [ "$?" -ne 0 ]; then
echo $_proc_mount_line >> /etc/fstab
fi
grep "$_sysfs_mount_line" /etc/fstab
if [ "$?" -ne 0 ]; then
echo $_sysfs_mount_line >> /etc/fstab
fi
grep "$_devpts_mount_line" /etc/fstab
if [ "$?" -ne 0 ]; then
echo $_devpts_mount_line >> /etc/fstab
fi
cp /proc/mounts ${chroot}/etc/mtab
for file in /etc/hosts /etc/resolv.conf /etc/passwd /etc/shadow /etc/sudoers; do
rm -f ${chroot}${file}
ln $file ${chroot}${file}
done
mount -a
mount -o bind /lib/modules ${chroot}/lib/modules
# WTF. Yahoo bash is in /usr/local/bin/bash
mkdir -p ${chroot}/usr/local/bin
chroot $chroot ln -s /bin/bash /usr/local/bin/bash
# Copy homes
rsync -a /home/ /debian/home/
# Re-number RHEL SSHD to TCP/222
echo "Port 222" >> /etc/ssh/sshd_config
/etc/init.d/sshd restart
chroot $chroot apt-get update
chroot $chroot apt-get install --yes openssh-server sudo
echo YAY
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment