2019-02-12 12:03:25 +01:00
|
|
|
#=----------------------------------------------------------------------------=#
|
|
|
|
# GNU GPL OS/K #
|
|
|
|
# #
|
|
|
|
# Desc: OS/K image maker script #
|
|
|
|
# #
|
|
|
|
# #
|
|
|
|
# Copyright © 2018-2019 The OS/K Team #
|
|
|
|
# #
|
|
|
|
# This file is part of OS/K. #
|
|
|
|
# #
|
|
|
|
# OS/K is free software: you can redistribute it and/or modify #
|
|
|
|
# it under the terms of the GNU General Public License as published by #
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or #
|
|
|
|
# any later version. #
|
|
|
|
# #
|
|
|
|
# OS/K is distributed in the hope that it will be useful, #
|
|
|
|
# but WITHOUT ANY WARRANTY# without even the implied warranty of #
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
|
|
|
# GNU General Public License for more details. #
|
|
|
|
# #
|
|
|
|
# You should have received a copy of the GNU General Public License #
|
|
|
|
# along with OS/K. If not, see <https://www.gnu.org/licenses/>. #
|
|
|
|
#=----------------------------------------------------------------------------=#
|
|
|
|
|
2019-02-15 15:47:56 +01:00
|
|
|
#Color codes
|
|
|
|
CL='\033[0;32m'
|
|
|
|
CL2='\033[1;36m'
|
|
|
|
CL3='\033[0m'
|
|
|
|
NC='\033[1;37m'
|
|
|
|
|
|
|
|
set -e #exit if error
|
|
|
|
|
2019-02-12 12:03:25 +01:00
|
|
|
## Create the image
|
2019-02-15 15:47:56 +01:00
|
|
|
echo ${CL2}[create_disk.sh]${NC} Creating image... \(dd\)${CL3}
|
2019-03-24 00:14:41 +01:00
|
|
|
dd if=/dev/zero of=$1 bs=512 count=131072 status=progress
|
2019-11-11 18:32:22 +01:00
|
|
|
|
2019-02-12 12:03:25 +01:00
|
|
|
## Partition the image
|
2019-11-11 18:32:22 +01:00
|
|
|
echo ${CL2}[create_disk.sh]${NC} Partitionning image... \(parted\)${CL3}
|
2019-11-25 23:13:22 +01:00
|
|
|
sudo parted --script $1 mktable msdos mkpart primary 2048s 100% set 1 boot on
|
2019-11-18 23:28:44 +01:00
|
|
|
|
|
|
|
## Mount
|
|
|
|
echo ${CL2}[create_disk.sh]${NC} Mount image... \(losetup\)${CL3}
|
2019-11-22 15:38:29 +01:00
|
|
|
lpblock=$(sudo losetup -f)
|
2019-11-18 23:28:44 +01:00
|
|
|
sudo losetup $lpblock $1 -o 1048576
|
|
|
|
echo ${CL2}[create_disk.sh]${NC} Sync image... \(sync\)${CL3}
|
|
|
|
sync
|
2019-11-11 18:32:22 +01:00
|
|
|
|
|
|
|
## Format
|
|
|
|
echo ${CL2}[create_disk.sh]${NC} Formatting image... \(mkdosfs\)${CL3}
|
2019-11-18 23:28:44 +01:00
|
|
|
sudo mkdosfs -F32 -f 2 $lpblock
|
|
|
|
echo ${CL2}[create_disk.sh]${NC} Sync image... \(sync\)${CL3}
|
|
|
|
sync
|
|
|
|
|
|
|
|
## Detach
|
|
|
|
echo ${CL2}[create_disk.sh]${NC} Unmount image... \(udisksctl\)${CL3}
|
|
|
|
sudo losetup -d $lpblock
|
2019-02-12 12:03:25 +01:00
|
|
|
|
2019-11-18 23:28:44 +01:00
|
|
|
## Mount
|
|
|
|
echo ${CL2}[create_disk.sh]${NC} Mount image... \(losetup\)${CL3}
|
2019-11-22 15:38:29 +01:00
|
|
|
lpblock=$(sudo losetup -f)
|
2019-11-18 23:28:44 +01:00
|
|
|
sudo losetup $lpblock $1 -o 1048576
|
2019-11-22 15:38:29 +01:00
|
|
|
lpblockbase=$(sudo losetup -f)
|
2019-11-18 23:28:44 +01:00
|
|
|
sudo losetup $lpblockbase $1
|
|
|
|
sudo udisksctl mount -b $lpblock --no-user-interaction
|
2019-02-12 12:03:25 +01:00
|
|
|
|
2019-11-18 23:28:44 +01:00
|
|
|
## Sync
|
2019-11-11 18:32:22 +01:00
|
|
|
echo ${CL2}[create_disk.sh]${NC} Sync image... \(sync\)${CL3}
|
|
|
|
sync
|
2019-02-12 12:03:25 +01:00
|
|
|
|
2019-11-18 23:28:44 +01:00
|
|
|
# Get the mountpoint
|
2019-11-13 22:21:56 +01:00
|
|
|
mountpoint=$(udisksctl info -b $lpblock | grep MountPoint | cut -d ':' -f 2 | sed 's/ //g')
|
|
|
|
|
|
|
|
if [ -z $mountpoint ];
|
|
|
|
then
|
|
|
|
echo Impossible to mount the image $mountpoint. Fatal error !
|
|
|
|
return 13
|
|
|
|
fi
|
|
|
|
|
2019-11-18 23:28:44 +01:00
|
|
|
## Install Grub
|
|
|
|
echo ${CL2}[create_disk.sh]${NC} Install grub into $lpblockbase as $mountpoint... \(grub-install\)${CL3}
|
2019-02-12 12:03:25 +01:00
|
|
|
|
2019-11-18 23:28:44 +01:00
|
|
|
sudo grub-install --force --target=i386-pc --root-directory=$mountpoint --boot-directory=$mountpoint/boot --no-floppy --modules="part_msdos biosdisk fat multiboot configfile" $lpblockbase
|
2019-02-12 12:03:25 +01:00
|
|
|
|
2019-11-18 23:28:44 +01:00
|
|
|
## Sync
|
2019-02-15 15:47:56 +01:00
|
|
|
echo ${CL2}[create_disk.sh]${NC} Sync image... \(sync\)${CL3}
|
2019-02-12 12:03:25 +01:00
|
|
|
sync
|
|
|
|
|
2019-11-18 23:28:44 +01:00
|
|
|
## Unmount
|
2019-11-11 18:32:22 +01:00
|
|
|
echo ${CL2}[create_disk.sh]${NC} Unmount image... \(udisksctl\)${CL3}
|
2019-11-18 23:28:44 +01:00
|
|
|
sudo udisksctl unmount --no-user-interaction -b $lpblock
|
|
|
|
sudo losetup -d $lpblock
|
|
|
|
sudo losetup -d $lpblockbase
|
2019-10-10 11:35:44 +02:00
|
|
|
|
2019-11-13 22:21:56 +01:00
|
|
|
echo ${CL2}[create_disk.sh]${CL} Terminated without error.${CL3}
|