-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_img.sh
executable file
·56 lines (42 loc) · 1.7 KB
/
create_img.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
#!/bin/bash
set -x
#trap read debug
# Create the actual disk image - 20MB
dd if=/dev/zero of=organix.img count=20 bs=1048576
# Make the partition table, partition and set it bootable.
parted --script organix.img mklabel msdos mkpart p ext2 1 20 set 1 boot on
# Map the partitions from the image file
kpartx -a organix.img
# sleep a sec, wait for kpartx to create the device nodes
sleep 1
# Make an ext2 filesystem on the first partition.
mkfs.ext2 /dev/mapper/loop0p1
# Make the mount-point
mkdir -p /mnt/organix
mkdir -p /mnt/organix/boot
# Mount the filesystem via loopback
mount /dev/mapper/loop0p1 /mnt/organix
# Create a device map for grub
echo "(hd0) /dev/loop0" > /mnt/organix/device.map
# Use grub2-install to actually install Grub. The options are:
# * No floppy polling.
# * Use the device map we generated in the previous step.
# * Include the basic set of modules we need in the Grub image.
# * Install grub into the filesystem at our loopback mountpoint.
# * Install the MBR to the loopback device itself.
grub-install --no-floppy \
--grub-mkdevicemap=/mnt/organix/device.map \
--modules="biosdisk part_msdos ext2 configfile normal multiboot"\
--root-directory=/mnt/organix \
--boot-directory=/mnt/organix/boot \
/dev/loop0
# Copy the grub config file
cp -r grub/* /mnt/organix/boot/grub
# Copy the kernel to boot on
cp -r src/kernel /mnt/organix/boot
# Copy the init ramdisk
cp -r initrd.img /mnt/organix/boot
# Unmount the loopback
umount /mnt/organix
# Unmap the image
kpartx -d organix.img