Skip to content

Instantly share code, notes, and snippets.

@drucko
Forked from icopitg-fh/fdisk.in
Created December 30, 2015 11:33
Show Gist options
  • Save drucko/4f6ef28aaa1b7dfec6a3 to your computer and use it in GitHub Desktop.
Save drucko/4f6ef28aaa1b7dfec6a3 to your computer and use it in GitHub Desktop.
Buildroot image install script. We use syslinux to boot the system. fdisk.in file is a necessary include that automates the creation of our partitions.
d
1
d
2
d
3
d
4
n
p
1
+4M
a
1
t
6
n
p
2
w
#!/bin/sh
INSTALL_ROOT=/mnt
DEV_NODE=0
if [ "$1" = "/dev/hda" ] || [ "$1" = "/dev/hdb" ] || [ "$1" = "/dev/hdc" ] || [ "$1" = "/dev/hdd" ] || [ "$1" = "/dev/sda" ] || [ "$1" = "/dev/sdb" ] || [ "$1" = "/dev/sdc" ] || [ "$1" = "/dev/sdd" ]; then
DEV_NODE=1
fi
# Display usage information if parameter is empty
if [ "$DEV_NODE" = "0" ]; then
echo
echo "Usage: $0 DEVICE"
echo
echo " DEVICE=/dev/hd[a-d] -> install X-Linux on to hard disk"
echo " DEVICE=/dev/sd[a-d] -> install X-Linux on to USB mass storage"
echo
echo " Ex: $0 /dev/hdc"
echo " $0 /dev/sda"
echo
exit 0
fi
echo
if [ "$DEV_NODE" = "1" ]; then
echo Install Production Environment onto $1
echo
# Delete all partitions on target
# Create a single FAT16 partition
echo Create Paritions
fdisk $1 < ./fdisk.in > /dev/null
# Format the partition
# Install syslinux
echo Format "$1"1
mkdosfs "$1"1 > /dev/null 2>&1
syslinux -i "$1"1
# Add syslinux configuation file
echo Install Bootloader
mount "$1"1 $INSTALL_ROOT
echo "DEFAULT linux" > $INSTALL_ROOT/syslinux.cfg
echo "LABEL linux" >> $INSTALL_ROOT/syslinux.cfg
echo "KERNEL bzimage" >> $INSTALL_ROOT/syslinux.cfg
echo "APPEND root=/dev/sda2 quiet console=tty1 console=ttyS0,115200n8" >> $INSTALL_ROOT/syslinux.cfg
# Copy the file system image
echo Install Kernel Image
cp output/images/bzImage $INSTALL_ROOT/bzImage
umount $INSTALL_ROOT
echo Format "$1"2
mke2fs "$1"2 > /dev/null 2>&1
echo Install Root Filesystem
mount "$1"2 $INSTALL_ROOT
tar xf output/images/rootfs.tar -C $INSTALL_ROOT
umount $INSTALL_ROOT
echo Installation finished!
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment