mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-15 04:13:11 +00:00
Build: Remove grub from default build process
This removes grub and all the loopback device business from the default build process. Running grub takes about a second, and it turns out it's inconsistently packaged in different distributions, which has led to at least one confusing issue so far (grub-install vs grub2-install). Removing it from the basic path will make it easier for people to try Serenity out. There are now two scripts that can be used to build a disk image: 1. `build-image-grub.sh` - this will build an image suitable for writing to the IDE hard drive of a physical machine, complete with a partition table and bootloader. This can be run in qemu with the `qgrub` target for the `run` script. 2. `build-image-qemu.sh` - this is a simpler script which creates a bare filesystem image rather than a full MBR disk. Both of these call out to `build-root-filesystem.sh` to do most of the work setting up... the root filesystem. For completeness' sake, I've retained the `sync.sh` script as a simple forwarding to `build-image-qemu.sh`. This relies on the functionality from #194 and #195. #195 allows us to use `/dev/hda` as the root device when nothing else is specified, and #194 works around a strange feature of qemu that appends a space to the kernel command line.
This commit is contained in:
parent
0aa1f1c2d6
commit
e1c982e4db
87
Kernel/build-image-grub.sh
Executable file
87
Kernel/build-image-grub.sh
Executable file
|
@ -0,0 +1,87 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
die() {
|
||||
echo "die: $@"
|
||||
exit 1
|
||||
}
|
||||
|
||||
if [ $(id -u) != 0 ]; then
|
||||
die "this script needs to run as root"
|
||||
fi
|
||||
|
||||
grub=$(which grub-install 2>/dev/null) || true
|
||||
if [[ -z "$grub" ]]; then
|
||||
grub=$(which grub2-install 2>/dev/null) || true
|
||||
fi
|
||||
if [ -z "$grub" ]; then
|
||||
echo "can't find a grub-install or grub2-install binary, oh no"
|
||||
exit 1
|
||||
fi
|
||||
echo "using grub-install at ${grub}"
|
||||
|
||||
echo "setting up disk image..."
|
||||
dd if=/dev/zero of=_disk_image bs=1M count=${DISK_SIZE:-500} status=none || die "couldn't create disk image"
|
||||
chown 1000:1000 _disk_image || die "couldn't adjust permissions on disk image"
|
||||
echo "done"
|
||||
|
||||
echo -n "creating loopback device... "
|
||||
dev=$(losetup --find --partscan --show _disk_image)
|
||||
if [ -z $dev ]; then
|
||||
die "couldn't mount loopback device"
|
||||
fi
|
||||
echo "loopback device is at ${dev}"
|
||||
|
||||
cleanup() {
|
||||
if [ -d mnt ]; then
|
||||
echo -n "unmounting filesystem... "
|
||||
umount mnt || ( sleep 1 && sync && umount mnt )
|
||||
rm -rf mnt
|
||||
echo "done"
|
||||
fi
|
||||
|
||||
if [ -e ${dev} ]; then
|
||||
echo -n "cleaning up loopback device... "
|
||||
losetup -d ${dev}
|
||||
echo "done"
|
||||
fi
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
echo -n "creating partition table... "
|
||||
parted -s ${dev} mklabel msdos mkpart primary ext2 32k 100% -a minimal set 1 boot on || die "couldn't partition disk"
|
||||
echo "done"
|
||||
|
||||
echo -n "destroying old filesystem... "
|
||||
dd if=/dev/zero of=${dev}p1 bs=1M count=1 status=none || die "couldn't destroy old filesystem"
|
||||
echo "done"
|
||||
|
||||
echo -n "creating new filesystem... "
|
||||
mke2fs -q -I 128 ${dev}p1 || die "couldn't create filesystem"
|
||||
echo "done"
|
||||
|
||||
echo -n "mounting filesystem... "
|
||||
mkdir -p mnt
|
||||
mount ${dev}p1 mnt/ || die "couldn't mount filesystem"
|
||||
echo "done"
|
||||
|
||||
./build-root-filesystem.sh
|
||||
|
||||
echo -n "creating /boot... "
|
||||
mkdir -p mnt/boot
|
||||
echo "done"
|
||||
|
||||
echo "installing grub using $grub..."
|
||||
$grub --boot-directory=mnt/boot --target=i386-pc --modules="ext2 part_msdos" ${dev}
|
||||
|
||||
if [ -d mnt/boot/grub2 ]; then
|
||||
cp grub.cfg mnt/boot/grub2/grub.cfg
|
||||
else
|
||||
cp grub.cfg mnt/boot/grub/grub.cfg
|
||||
fi
|
||||
echo "done"
|
||||
|
||||
echo -n "installing kernel in /boot... "
|
||||
cp kernel mnt/boot
|
||||
echo "done"
|
38
Kernel/build-image-qemu.sh
Executable file
38
Kernel/build-image-qemu.sh
Executable file
|
@ -0,0 +1,38 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
die() {
|
||||
echo "die: $@"
|
||||
exit 1
|
||||
}
|
||||
|
||||
if [ $(id -u) != 0 ]; then
|
||||
die "this script needs to run as root"
|
||||
fi
|
||||
|
||||
echo "setting up disk image..."
|
||||
qemu-img create _disk_image ${DISK_SIZE:-500}m || die "couldn't create disk image"
|
||||
chown 1000:1000 _disk_image || die "couldn't adjust permissions on disk image"
|
||||
echo "done"
|
||||
|
||||
echo -n "creating new filesystem... "
|
||||
mke2fs -q -I 128 _disk_image || die "couldn't create filesystem"
|
||||
echo "done"
|
||||
|
||||
echo -n "mounting filesystem... "
|
||||
mkdir -p mnt
|
||||
mount _disk_image mnt/ || die "couldn't mount filesystem"
|
||||
echo "done"
|
||||
|
||||
cleanup() {
|
||||
if [ -d mnt ]; then
|
||||
echo -n "unmounting filesystem... "
|
||||
umount mnt || ( sleep 1 && sync && umount mnt )
|
||||
rm -rf mnt
|
||||
echo "done"
|
||||
fi
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
./build-root-filesystem.sh
|
98
Kernel/build-root-filesystem.sh
Executable file
98
Kernel/build-root-filesystem.sh
Executable file
|
@ -0,0 +1,98 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
die() {
|
||||
echo "die: $@"
|
||||
exit 1
|
||||
}
|
||||
|
||||
if [ $(id -u) != 0 ]; then
|
||||
die "this script needs to run as root"
|
||||
fi
|
||||
|
||||
echo -n "creating initial filesystem structure... "
|
||||
mkdir -p mnt/{bin,etc,proc,tmp}
|
||||
chmod 1777 mnt/tmp
|
||||
echo "done"
|
||||
|
||||
echo -n "setting up device nodes... "
|
||||
mkdir -p mnt/dev
|
||||
mkdir -p mnt/dev/pts
|
||||
mknod -m 666 mnt/dev/bxvga b 82 413
|
||||
mknod mnt/dev/tty0 c 4 0
|
||||
mknod mnt/dev/tty1 c 4 1
|
||||
mknod mnt/dev/tty2 c 4 2
|
||||
mknod mnt/dev/tty3 c 4 3
|
||||
mknod mnt/dev/random c 1 8
|
||||
mknod mnt/dev/null c 1 3
|
||||
mknod mnt/dev/zero c 1 5
|
||||
mknod mnt/dev/full c 1 7
|
||||
mknod -m 666 mnt/dev/debuglog c 1 18
|
||||
mknod mnt/dev/keyboard c 85 1
|
||||
mknod mnt/dev/psaux c 10 1
|
||||
mknod -m 666 mnt/dev/ptmx c 5 2
|
||||
ln -s /proc/self/fd/0 mnt/dev/stdin
|
||||
ln -s /proc/self/fd/1 mnt/dev/stdout
|
||||
ln -s /proc/self/fd/2 mnt/dev/stderr
|
||||
echo "done"
|
||||
|
||||
echo -n "installing base system... "
|
||||
cp -R ../Base/* mnt/
|
||||
cp -R ../Root/* mnt/
|
||||
cp kernel.map mnt/
|
||||
echo "done"
|
||||
|
||||
echo -n "installing users... "
|
||||
mkdir -p mnt/home/anon
|
||||
mkdir -p mnt/home/nona
|
||||
cp ../ReadMe.md mnt/home/anon/
|
||||
chown -R 100:100 mnt/home/anon
|
||||
chown -R 200:200 mnt/home/nona
|
||||
echo "done"
|
||||
|
||||
echo -n "installing userland... "
|
||||
find ../Userland/ -type f -executable -exec cp {} mnt/bin/ \;
|
||||
chmod 4755 mnt/bin/su
|
||||
echo "done"
|
||||
|
||||
echo -n "installing applications... "
|
||||
cp ../Applications/About/About mnt/bin/About
|
||||
cp ../Applications/Downloader/Downloader mnt/bin/Downloader
|
||||
cp ../Applications/FileManager/FileManager mnt/bin/FileManager
|
||||
cp ../Applications/FontEditor/FontEditor mnt/bin/FontEditor
|
||||
cp ../Applications/IRCClient/IRCClient mnt/bin/IRCClient
|
||||
cp ../Applications/Launcher/Launcher mnt/bin/Launcher
|
||||
cp ../Applications/ProcessManager/ProcessManager mnt/bin/ProcessManager
|
||||
cp ../Applications/Taskbar/Taskbar mnt/bin/Taskbar
|
||||
cp ../Applications/Terminal/Terminal mnt/bin/Terminal
|
||||
cp ../Applications/TextEditor/TextEditor mnt/bin/TextEditor
|
||||
cp ../Demos/HelloWorld/HelloWorld mnt/bin/HelloWorld
|
||||
cp ../Demos/RetroFetch/RetroFetch mnt/bin/RetroFetch
|
||||
cp ../Demos/WidgetGallery/WidgetGallery mnt/bin/WidgetGallery
|
||||
cp ../DevTools/VisualBuilder/VisualBuilder mnt/bin/VisualBuilder
|
||||
cp ../Games/Minesweeper/Minesweeper mnt/bin/Minesweeper
|
||||
cp ../Games/Snake/Snake mnt/bin/Snake
|
||||
cp ../Servers/LookupServer/LookupServer mnt/bin/LookupServer
|
||||
cp ../Servers/SystemServer/SystemServer mnt/bin/SystemServer
|
||||
cp ../Servers/WindowServer/WindowServer mnt/bin/WindowServer
|
||||
cp ../Shell/Shell mnt/bin/Shell
|
||||
echo "done"
|
||||
|
||||
echo -n "installing shortcuts... "
|
||||
ln -s Downloader mnt/bin/dl
|
||||
ln -s FileManager mnt/bin/fm
|
||||
ln -s HelloWorld mnt/bin/hw
|
||||
ln -s IRCClient mnt/bin/irc
|
||||
ln -s Minesweeper mnt/bin/ms
|
||||
ln -s Shell mnt/bin/sh
|
||||
ln -s Snake mnt/bin/sn
|
||||
ln -s Taskbar mnt/bin/tb
|
||||
ln -s VisualBuilder mnt/bin/vb
|
||||
ln -s WidgetGallery mnt/bin/wg
|
||||
echo "done"
|
||||
|
||||
# Run local sync script, if it exists
|
||||
if [ -f sync-local.sh ]; then
|
||||
sh sync-local.sh
|
||||
fi
|
15
Kernel/run
15
Kernel/run
|
@ -18,6 +18,7 @@ elif [ "$1" = "qn" ]; then
|
|||
-device VGA,vgamem_mb=64 \
|
||||
-debugcon stdio \
|
||||
-device e1000 \
|
||||
-kernel kernel \
|
||||
-hda _disk_image \
|
||||
-soundhw pcspk
|
||||
elif [ "$1" = "qtap" ]; then
|
||||
|
@ -30,6 +31,19 @@ elif [ "$1" = "qtap" ]; then
|
|||
-object filter-dump,id=hue,netdev=br0,file=e1000.pcap \
|
||||
-netdev tap,ifname=tap0,id=br0 \
|
||||
-device e1000,netdev=br0 \
|
||||
-kernel kernel \
|
||||
-hda _disk_image \
|
||||
-soundhw pcspk
|
||||
elif [ "$1" = "qgrub" ]; then
|
||||
# ./run qgrub: qemu with grub
|
||||
$SERENITY_QEMU_BIN -s -m $ram_size \
|
||||
$SERENITY_EXTRA_QEMU_ARGS \
|
||||
-d cpu_reset,guest_errors \
|
||||
-device VGA,vgamem_mb=64 \
|
||||
-debugcon stdio \
|
||||
-object filter-dump,id=hue,netdev=breh,file=e1000.pcap \
|
||||
-netdev user,id=breh,hostfwd=tcp:127.0.0.1:8888-192.168.5.2:8888 \
|
||||
-device e1000,netdev=breh \
|
||||
-hda _disk_image \
|
||||
-soundhw pcspk
|
||||
else
|
||||
|
@ -42,6 +56,7 @@ else
|
|||
-object filter-dump,id=hue,netdev=breh,file=e1000.pcap \
|
||||
-netdev user,id=breh,hostfwd=tcp:127.0.0.1:8888-192.168.5.2:8888 \
|
||||
-device e1000,netdev=breh \
|
||||
-kernel kernel \
|
||||
-hda _disk_image \
|
||||
-soundhw pcspk
|
||||
fi
|
||||
|
|
162
Kernel/sync.sh
162
Kernel/sync.sh
|
@ -1,163 +1,3 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
die() {
|
||||
echo "die: $@"
|
||||
exit 1
|
||||
}
|
||||
|
||||
if [ $(id -u) != 0 ]; then
|
||||
die "this script needs to run as root"
|
||||
fi
|
||||
|
||||
echo "setting up disk image..."
|
||||
if [ ! -f _disk_image ]; then
|
||||
echo "not found; creating a new one"
|
||||
dd if=/dev/zero of=_disk_image bs=1M count=${DISK_SIZE:-500} || die "couldn't create disk image"
|
||||
parted -s _disk_image mklabel msdos mkpart primary ext2 32k 100% -a minimal set 1 boot on || die "couldn't partition disk image"
|
||||
chown 1000:1000 _disk_image || die "couldn't adjust permissions on disk image"
|
||||
else
|
||||
echo "already exists, nothing to do"
|
||||
fi
|
||||
echo "done"
|
||||
|
||||
echo "checking for and removing old loopback devices..."
|
||||
losetup -j _disk_image | cut -d : -f 1 | while read old_dev; do
|
||||
echo "removing $dev"
|
||||
losetup -d ${old_dev}
|
||||
done
|
||||
echo "done"
|
||||
|
||||
echo -n "creating loopback device... "
|
||||
dev=$(losetup --find --partscan --show _disk_image)
|
||||
if [ -z $dev ]; then
|
||||
die "couldn't mount loopback device"
|
||||
fi
|
||||
echo "loopback device is at ${dev}"
|
||||
|
||||
echo -n "destroying old filesystem... "
|
||||
dd if=/dev/zero of=${dev}p1 bs=1M count=1 status=none
|
||||
echo "done"
|
||||
|
||||
echo -n "creating new filesystem... "
|
||||
mke2fs -q -I 128 ${dev}p1 || die "couldn't create filesystem"
|
||||
echo "done"
|
||||
|
||||
echo -n "mounting loopback device... "
|
||||
mkdir -p mnt
|
||||
mount ${dev}p1 mnt/ || die "couldn't mount loopback device"
|
||||
echo "done"
|
||||
|
||||
echo -n "creating initial filesystem structure... "
|
||||
mkdir -p mnt/{boot,bin,etc,proc,tmp}
|
||||
chmod 1777 mnt/tmp
|
||||
echo "done"
|
||||
|
||||
grub=$(which grub-install 2>/dev/null) || true
|
||||
if [[ -z "$grub" ]]; then
|
||||
grub=$(which grub2-install 2>/dev/null) || true
|
||||
fi
|
||||
if [ -z "$grub" ]; then
|
||||
echo "can't find a grub-install or grub2-install binary, oh no"
|
||||
exit 1
|
||||
fi
|
||||
echo "installing grub using $grub..."
|
||||
|
||||
$grub --boot-directory=mnt/boot --target=i386-pc --modules="ext2 part_msdos" ${dev}
|
||||
|
||||
if [ -d mnt/boot/grub2 ]; then
|
||||
cp grub.cfg mnt/boot/grub2/grub.cfg
|
||||
else
|
||||
cp grub.cfg mnt/boot/grub/grub.cfg
|
||||
fi
|
||||
|
||||
echo -n "setting up device nodes... "
|
||||
mkdir -p mnt/dev
|
||||
mkdir -p mnt/dev/pts
|
||||
mknod -m 666 mnt/dev/bxvga b 82 413
|
||||
mknod mnt/dev/tty0 c 4 0
|
||||
mknod mnt/dev/tty1 c 4 1
|
||||
mknod mnt/dev/tty2 c 4 2
|
||||
mknod mnt/dev/tty3 c 4 3
|
||||
mknod mnt/dev/random c 1 8
|
||||
mknod mnt/dev/null c 1 3
|
||||
mknod mnt/dev/zero c 1 5
|
||||
mknod mnt/dev/full c 1 7
|
||||
mknod -m 666 mnt/dev/debuglog c 1 18
|
||||
mknod mnt/dev/keyboard c 85 1
|
||||
mknod mnt/dev/psaux c 10 1
|
||||
mknod -m 666 mnt/dev/ptmx c 5 2
|
||||
ln -s /proc/self/fd/0 mnt/dev/stdin
|
||||
ln -s /proc/self/fd/1 mnt/dev/stdout
|
||||
ln -s /proc/self/fd/2 mnt/dev/stderr
|
||||
echo "done"
|
||||
|
||||
echo -n "installing base system... "
|
||||
cp -R ../Base/* mnt/
|
||||
cp -R ../Root/* mnt/
|
||||
cp kernel mnt/boot
|
||||
cp kernel.map mnt/
|
||||
echo "done"
|
||||
|
||||
echo -n "installing users... "
|
||||
mkdir -p mnt/home/anon
|
||||
mkdir -p mnt/home/nona
|
||||
cp ../ReadMe.md mnt/home/anon/
|
||||
chown -R 100:100 mnt/home/anon
|
||||
chown -R 200:200 mnt/home/nona
|
||||
echo "done"
|
||||
|
||||
echo -n "installing userland... "
|
||||
find ../Userland/ -type f -executable -exec cp {} mnt/bin/ \;
|
||||
chmod 4755 mnt/bin/su
|
||||
echo "done"
|
||||
|
||||
echo -n "installing applications... "
|
||||
cp ../Applications/About/About mnt/bin/About
|
||||
cp ../Applications/Downloader/Downloader mnt/bin/Downloader
|
||||
cp ../Applications/FileManager/FileManager mnt/bin/FileManager
|
||||
cp ../Applications/FontEditor/FontEditor mnt/bin/FontEditor
|
||||
cp ../Applications/IRCClient/IRCClient mnt/bin/IRCClient
|
||||
cp ../Applications/Launcher/Launcher mnt/bin/Launcher
|
||||
cp ../Applications/ProcessManager/ProcessManager mnt/bin/ProcessManager
|
||||
cp ../Applications/Taskbar/Taskbar mnt/bin/Taskbar
|
||||
cp ../Applications/Terminal/Terminal mnt/bin/Terminal
|
||||
cp ../Applications/TextEditor/TextEditor mnt/bin/TextEditor
|
||||
cp ../Demos/HelloWorld/HelloWorld mnt/bin/HelloWorld
|
||||
cp ../Demos/RetroFetch/RetroFetch mnt/bin/RetroFetch
|
||||
cp ../Demos/WidgetGallery/WidgetGallery mnt/bin/WidgetGallery
|
||||
cp ../DevTools/VisualBuilder/VisualBuilder mnt/bin/VisualBuilder
|
||||
cp ../Games/Minesweeper/Minesweeper mnt/bin/Minesweeper
|
||||
cp ../Games/Snake/Snake mnt/bin/Snake
|
||||
cp ../Servers/LookupServer/LookupServer mnt/bin/LookupServer
|
||||
cp ../Servers/SystemServer/SystemServer mnt/bin/SystemServer
|
||||
cp ../Servers/WindowServer/WindowServer mnt/bin/WindowServer
|
||||
cp ../Shell/Shell mnt/bin/Shell
|
||||
echo "done"
|
||||
|
||||
echo -n "installing shortcuts... "
|
||||
ln -s Downloader mnt/bin/dl
|
||||
ln -s FileManager mnt/bin/fm
|
||||
ln -s HelloWorld mnt/bin/hw
|
||||
ln -s IRCClient mnt/bin/irc
|
||||
ln -s Minesweeper mnt/bin/ms
|
||||
ln -s Shell mnt/bin/sh
|
||||
ln -s Snake mnt/bin/sn
|
||||
ln -s Taskbar mnt/bin/tb
|
||||
ln -s VisualBuilder mnt/bin/vb
|
||||
ln -s WidgetGallery mnt/bin/wg
|
||||
echo "done"
|
||||
|
||||
# Run local sync script, if it exists
|
||||
if [ -f sync-local.sh ]; then
|
||||
sh sync-local.sh
|
||||
fi
|
||||
|
||||
echo -n "unmounting filesystem... "
|
||||
umount mnt || ( sleep 1 && sync && umount mnt )
|
||||
echo "done"
|
||||
|
||||
echo -n "removing loopback device... "
|
||||
losetup -d ${dev}
|
||||
echo "done"
|
||||
./build-image-qemu.sh
|
||||
|
|
Loading…
Reference in a new issue