homehowtokbslinksaboutcontactprojectsmusic

Index > Help Tutorials > Create Ubuntu base image for RAM
create ubuntu base system (ubuntu 12.04 lts x86) setup the directory where our new system would be installed
rambox=/mini
debootstrap --arch i386 precise $rambox
copy time setting from local system to newly created base system
cp /etc/{timezone,localtime} $rambox/etc/
chroot to newly created base system
chroot $rambox
generate locals setting and setup timezone
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen; locale-gen en_US.UTF-8; update-locale LANG=en_US.UTF-8; dpkg-reconfigure -u tzdata
setup the hostname
echo "localhost" > /etc/hostname
for now setup the password for root user
passwd
optionally install some softwares, I like nano editor
apt-get install nano
setup root for auto login
cat << EOT >> etc/init/tty1.conf

# Auto login account 
exec /bin/login -f root < /dev/tty1 > /dev/tty1 2>&1
EOT
create init script
nano init
and paste the following in it
#!/bin/sh

# Mount all fstab entries
mount -av

# set and run the init
init=/sbin/init
exec ${init}
make above script excuable
chmod +x init
setup the interfaces and configure for dhcp
cat << EOT >> /etc/network/interfaces

# eth0
auto eth0
iface eth0 inet dhcp
EOT
exit the chroot session
exit
copy the modules
cp -fr /lib/modules/$(uname -r) $rambox/lib/modules/
setup $rambox/etc/fstab
cat << EOT >> $rambox/etc/fstab

devpts  /dev/pts  devpts  nosuid,noexec,gid=5,mode=0620  0 0
tmpfs   /dev/shm  tmpfs   nosuid,nodev,mode=0755  0 0
sysfs   /sys      sysfs   nosuid,nodev,noexec  0 0
proc    /proc     proc    nosuid,nodev,noexec  0 0
EOT
set the correct permissions of above file
chmod 0644 $rambox/etc/fstab
compress new image
cd $rambox; find . -print0 | sudo cpio --null -ov --format=newc | gzip -9 > ~/$rambox.cpio.gz
copy kernel from working ubuntu desktop/server
cp /boot/vmlinuz-$(uname -r) ~
copy this compressed image and kernel to tftp server's root and set the permissions
mkdir -p /tftpboot/$rambox; cp ~/{$rambox.cpio.gz,vmlinuz-$(uname -r)} /tftpboot/$rambox/; chmod 755 /tftpboot/$rambox/ -R
Now add the pxe option on tftp server for this new image to boot from
nano /tftpboot/pxelinux.cfg/default
and paste the following at the end
echo "" >> /tftboot/pxelinux.cfg/default
echo "default $rambox" >> /tftboot/pxelinux.cfg/default
echo "label $rambox" >> /tftboot/pxelinux.cfg/default
echo "kernel $rambox/vmlinuz-$(uname -r)" >> /tftboot/pxelinux.cfg/default
echo "append initrd=$rambox/$rambox.cpio.gz rw" >> /tftboot/pxelinux.cfg/default
default rambox
        label rambox
        kernel mini/vmlinuz-3.13.0-39-generic
        append initrd=mini/mini.cpio.gz rw
finally start the pxe client and see the magic.

cpio file management

make cpio archive file from ~/mnt,all in one line
find ~/mnt/. -print0 | cpio --null -ov --format=newc | gzip -9 > ~/file.cpio.gz
unzip and extract cpio archive file in ~/mnt folder unzip file.cpio.gz
gunzip ~/file.cpio.gz
make directory for mount
mkdir -p ~/mnt
change directory to ~/mnt
cd ~/mnt
now extract the content of file.cpio archive
cpio -idv < ~/file.cpio
or all in one line
gunzip ~/file.cpio.gz; mkdir -p ~/mnt; cd ~/mnt; cpio -idv < ~/file.cpio
Reference