1
0
Fork 0
mirror of https://github.com/pygos/build.git synced 2024-11-16 16:37:10 +01:00
build/cfg/alix/genimage.sh
David Oberhollenzer dbbb1889f4 Initial commit
Signed-off-by: David Oberhollenzer <david.oberhollenzer@tele2.at>
2018-01-29 10:17:30 +01:00

58 lines
986 B
Bash
Executable file

#!/bin/sh
set -u -e -x
FILE=$1
MOUNTED=0
LOOPATTACHED=0
function do_cleanup() {
[ $MOUNTED -ne 0 ] && umount /tmp/mnt.$$
[ $LOOPATTACHED -ne 0 ] && losetup -d ${LODEV}
rmdir /tmp/mnt.$$
}
trap do_cleanup ERR INT
cd `dirname $0`
truncate -s 1G $FILE
parted --script $FILE \
"mklabel msdos" \
"mkpart primary fat32 1M 256M" \
"mkpart primary btrfs 256M 100%" \
"set 1 boot on"
LODEV=$(losetup -f)
losetup -P ${LODEV} ${FILE}
LOOPATTACHED=1
mkfs.vfat ${LODEV}p1
mkfs.btrfs -f ${LODEV}p2
mkdir /tmp/mnt.$$
mount -t vfat ${LODEV}p1 /tmp/mnt.$$
MOUNTED=1
syslinux --install ${LODEV}p1
cp syslinux.cfg /tmp/mnt.$$/syslinux.cfg
cp ROOTFSFILE /tmp/mnt.$$/
cp KERNELFILE /tmp/mnt.$$/
umount /tmp/mnt.$$
MOUNTED=0
mount -t btrfs ${LODEV}p2 /tmp/mnt.$$
MOUNTED=1
mkdir /tmp/mnt.$$/etc /tmp/mnt.$$/etc_work
mkdir /tmp/mnt.$$/var_lib /tmp/mnt.$$/var_lib_work
umount /tmp/mnt.$$
MOUNTED=0
losetup -d ${LODEV}
LOOPATTACHED=0
dd if=mbr.bin of=$FILE conv=notrunc
rmdir /tmp/mnt.$$