-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·73 lines (49 loc) · 1.99 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# /bin/bash
BUILD_DIR="."
MOUNT_DIR="/mnt/out0"
BOOTLOADER_DIR="src/boot"
DISK_NAME="disk.img"
DISK_IMG_SIZE="100MB"
if [ -f "disk.img" ] ; then
sudo rm -rf "disk.img"
fi
echo "$(tput setaf 3)Creating a 100MB disk image... $(tput sgr0)"
# create a 100 MB disk image
dd if=/dev/zero of=${BUILD_DIR}/${DISK_NAME} seek=${DISK_IMG_SIZE} count=1k bs=1
echo "$(tput setaf 3)Setting up loop device... $(tput sgr0)"
# setup loopback device and reserve it for this process
outlo=`sudo losetup -f --show ${BUILD_DIR}/${DISK_NAME}`
echo "$(tput setaf 3)We are using '${outlo}' as our loop device now $(tput sgr0)"
# create MSDOS table for the disk
sudo parted ${outlo} mklabel msdos
# add a new primary partition starting from 32k to the end
sudo parted ${outlo} mkpart primary ext2 32k 100% -a minimal
# set the partition as active/bootable
sudo parted ${outlo} set 1 boot on
# create a new block device (/dev/loopXp1)
sudo partx -a ${outlo}
# format the partition with ext2
sudo mke2fs ${outlo}p1
# create a temporary mount point
sudo mkdir -p ${MOUNT_DIR}
# mount the block device with the new filesystem to the mount point we created
sudo mount -t ext2 ${outlo}p1 ${MOUNT_DIR}
# create a new directory for grub2 files
sudo mkdir -p ${MOUNT_DIR}/boot/grub
# copy grub configurations
sudo cp ${BOOTLOADER_DIR}/grub.cfg ${MOUNT_DIR}/boot/grub/
echo "$(tput setaf 3)Installing the boot loader... $(tput sgr0)"
# install the grub bootloader
sudo grub-install --boot-directory=${MOUNT_DIR}/boot/ --modules="ext2 part_msdos" ${outlo}
echo "$(tput setaf 3)Copying kernel to the disk $(tput sgr0)"
cp kernel.bin ${MOUNT_DIR}/boot/kernel-701
echo "$(tput setaf 3)Sleeping for 2 seconds... $(tput sgr0)"
sleep 2
echo "$(tput setaf 3)Unmount and remove the mount point... $(tput sgr0)"
# remove this if you need to modify something inside the disk image
sudo umount ${MOUNT_DIR}
sudo partx -d ${outlo}p1
sudo losetup -d ${outlo}
rm -rf ${MOUNT_DIR}
echo "$(tput setaf 3)Everything is done now with success! $(tput sgr0)"
return 0