homehowtokbslinksaboutcontactprojectsmusic

Index > My Projects > osDeploy on Ubuntu 16 LTS
Contents
Install Package(s)
Download core and configure
Compress base system
PXE/iPXE Configuration
Cleanup
Auto login
Linux Support
NFS Server Setup
Customization
Disable IPv6
Scripts

Install Package(s)

apt install debootstrap
Go up

Download core and configure

osd=/osd; debootstrap --arch i386 xenial $osd
rm $osd/etc/{timezone,localtime}; cp /etc/{timezone,localtime} $osd/etc
echo "osd" > $osd/etc/hostname
update repo
cp /etc/apt/sources.list $osd/etc/apt
copy kernel
mkdir -pv $osd/lib/modules; cp -r /lib/modules/$(uname -r) $osd/lib/modules/
setup network interface for dhcp
cat << eot >> /etc/network/interfaces
auto enp0s3
iface enp0s3 inet dhcp
eot
chroot to osd
chroot $osd
Update dns setting if needed, you do not want 127.0.0.1 to be your dns server !
nano $osd/etc/resolvconf/resolv.conf.d/original

Autologin

setup auto logon for root
sed -i s,'ExecStart=-/sbin/agetty --noclear %I $TERM','ExecStart=-/sbin/agetty -a root --noclear %I $TERM',g /etc/systemd/system/getty.target.wants/getty\@tty1.service
update time settings
locale-gen en_US.UTF-8; update-locale LANG=en_US.UTF-8; dpkg-reconfigure -u tzdata
run update and upgrade if applicable
apt update; apt dist-upgrade
install packages
apt install pciutils dmidecode nano wget ssh partclone udpcast ntfs-3g nfs-common smartmontools dnsutils pigz chntpw wimtools
Go up

Compress base system

compress via gzip
cd $osd; find . -print0 | sudo cpio --null -ov --format=newc | gzip -9 > /var/www/html/ipxe/imgs/osd.gz
compress via xz compression method
cd $osd; find . -print0 | sudo cpio --null -ov --format=newc > /var/www/html/ipxe/imgs/osd; xz -zvf -9 -C crc32 /var/www/html/ipxe/imgs/osd
Go up

PXE/iPXE Configuration

TFTP setup for nfsboot copy current boot kernel
cp /boot/vmlinuz-$(uname -r) ~
Go up
create init script
cat << eot > init
#!/bin/sh
mkdir -p /dev/{,pts,ptmx}

# Mount file system in ram.
mount -a

init=/sbin/init
exec \${init}
eot
make init executable
chmod a+x init

Cleanup

apt autoremove; apt autoclean; apt clean
rm -rv /var/lib/apt/lists/*; rm -rv /var/log/*; rm -rv /usr/share/GeoIP
rm -rv /usr/share/man; rm -rv /usr/share/doc
rm -rv $osd/lib/modules/$(uname -r)/kernel/sound
rm -rv $osd/lib/modules/$(uname -r)/kernel/net/appletalk
rm -rv $osd/lib/modules/$(uname -r)/kernel/net/wireless
rm -rv $osd/lib/modules/$(uname -r)/kernel/net/bluetooth
rm -rv $osd/lib/modules/$(uname -r)/kernel/drivers/bluetooth
rm -rv $osd/lib/modules/$(uname -r)/kernel/drivers/net/wireless
rm -rv $osd/lib/modules/$(uname -r)/kernel/drivers/net/appletalk
rm -rv $osd/var/cache/debconf
Go up testing codes
wget http://archive.ubuntu.com/ubuntu/dists/xenial/main/installer-amd64/current/images/netboot/ubuntu-installer/amd64/linux -O /var/www/html/ipxe/krls/linux

wget http://archive.ubuntu.com/ubuntu/dists/xenial/main/installer-amd64/current/images/netboot/ubuntu-installer/amd64/initrd.gz -O /var/www/html/ipxe/imgs/initrd.gz

Linux Support

You can use sfdisk for this task, reference
save:
sfdisk -d /dev/sda > part_table
restore:
sfdisk /dev/sda < part_table
Go up

NFS Setup

Install packages
apt-get install nfs-kernel-server -y
Make images directory
mkdir -pv /images/dev
Set the permission
chmod 777 /images -R
Make /images as nfs share available to all machines
cat << eot >> /etc/exports

# osDeploy images
/images    *(rw,async,subtree_check)
eot
now export all nfs shares listed in /etc/exports
exportfs -av
or restart nfs server
/etc/init.d/nfs-kernel-server restart
mount -o nolock,proto=tcp $storage /images 2>/dev/null
Go up

Disable IPv6

cat << eot >> /etc/sysctl.conf

# disable ipv6
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
eot
Go up

Customization

get ip via profile
clear
echo -n "Getting IP, please wait...................."
dhclient 2>/dev/null
sleep 2
ip=`ifconfig | grep "Bcast" | awk '{print $2}' | cut -d ":" -f2`
echo "$ip"

Scripts

mount script at boot
cat << eot > /root/.mount
#!/bin/sh
\$(for var in \$(cat /proc/cmdline); do echo export \$var | grep =; done)
if [ -n "\${nfs}" ]
then
        mpt="/images"
        nfsroot="\${nfs}:\${shr}"
        mkdir -p \$mpt 2>/dev/null
        mount -o nolock,proto=tcp \$nfsroot \$mpt 2>/dev/null
fi

if [ -n "\${job}" ]
then
        . /images/.core/\${scr}
fi

eot
Go up

Get IP address, try 10 times
nano /root/.profile
and paste the following at the end


ip=`ifconfig | grep "Bcast" | awk '{print \$2}' | cut -d ":" -f2`
try=1
while [ -z "${ip}" -a "${try}" -le 10 ]
do
     clear
     echo -n "Try $try : Getting IP, please wait...................."
     dhclient 2>/dev/null
     sleep 4
     (( try++ ))
     ip=`ifconfig | grep "Bcast" | awk '{print \$2}' | cut -d ":" -f2`
     echo "${ip}"
done

if [ -n "${ip}" ]
then
. ~/.mount
fi