2023-06-02 18:40:24 +03:00
|
|
|
#!/bin/bash
|
2023-02-04 23:46:11 +02:00
|
|
|
set -e
|
|
|
|
|
|
|
|
DISK_SIZE=$[50 * 1024 * 1024]
|
|
|
|
MOUNT_DIR=/mnt
|
|
|
|
|
2023-04-02 04:07:27 +03:00
|
|
|
dd if=/dev/zero of=$DISK_IMAGE_PATH bs=512 count=$[$DISK_SIZE / 512] > /dev/null
|
2023-02-04 23:46:11 +02:00
|
|
|
|
2023-04-02 04:07:27 +03:00
|
|
|
sed -e 's/\s*\([-\+[:alnum:]]*\).*/\1/' << EOF | fdisk $DISK_IMAGE_PATH > /dev/null
|
2023-02-04 23:46:11 +02:00
|
|
|
g # gpt
|
|
|
|
n # new partition
|
|
|
|
1 # partition number 1
|
|
|
|
# default (from the beginning of the disk)
|
|
|
|
+1MiB # bios boot partiton size
|
2023-03-19 05:51:25 +02:00
|
|
|
n # new partition
|
|
|
|
3 # partition number 3
|
|
|
|
# default (right after bios boot partition)
|
|
|
|
+10Mib# partition size
|
2023-02-04 23:46:11 +02:00
|
|
|
n # new partition
|
|
|
|
2 # partition number 2
|
|
|
|
# default (right after bios boot partition)
|
|
|
|
# default (to the end of disk)
|
|
|
|
t # set type
|
|
|
|
1 # ... of partition 1
|
|
|
|
4 # bios boot partition
|
|
|
|
t # set type
|
|
|
|
2 # ... of partition 2
|
|
|
|
20 # Linux filesystem
|
2023-03-30 16:37:53 +03:00
|
|
|
t # set type
|
|
|
|
3 # ... of partition 3
|
|
|
|
20 # Linux filesystem
|
2023-02-04 23:46:11 +02:00
|
|
|
w # write changes
|
|
|
|
EOF
|
|
|
|
|
2023-04-02 04:07:27 +03:00
|
|
|
LOOP_DEV=$(sudo losetup -f --show $DISK_IMAGE_PATH)
|
2023-02-04 23:46:11 +02:00
|
|
|
sudo partprobe $LOOP_DEV
|
|
|
|
|
|
|
|
PARTITION1=${LOOP_DEV}p1
|
|
|
|
PARTITION2=${LOOP_DEV}p2
|
2023-03-19 05:51:25 +02:00
|
|
|
PARTITION3=${LOOP_DEV}p3
|
2023-02-04 23:46:11 +02:00
|
|
|
|
2023-04-02 04:07:27 +03:00
|
|
|
sudo mkfs.ext2 $PARTITION3 > /dev/null
|
2023-03-27 01:11:17 +03:00
|
|
|
sudo mount $PARTITION3 $MOUNT_DIR
|
2023-04-02 04:07:27 +03:00
|
|
|
echo 'hello' | sudo tee ${MOUNT_DIR}/hello.txt > /dev/null
|
2023-03-27 01:11:17 +03:00
|
|
|
sudo umount $MOUNT_DIR
|
|
|
|
|
2023-04-02 04:07:27 +03:00
|
|
|
sudo mkfs.ext2 $PARTITION2 > /dev/null
|
2023-02-04 23:46:11 +02:00
|
|
|
|
|
|
|
sudo mount $PARTITION2 $MOUNT_DIR
|
|
|
|
|
2023-02-22 22:29:31 +02:00
|
|
|
sudo cp -r ${SYSROOT}/* ${MOUNT_DIR}/
|
2023-02-04 23:46:11 +02:00
|
|
|
|
2023-04-02 04:07:27 +03:00
|
|
|
sudo grub-install --no-floppy --target=i386-pc --modules="normal ext2 multiboot" --boot-directory=${MOUNT_DIR}/boot $LOOP_DEV > /dev/null
|
2023-02-04 23:46:11 +02:00
|
|
|
|
|
|
|
sudo umount $MOUNT_DIR
|
2023-03-19 05:51:25 +02:00
|
|
|
|
2023-02-04 23:46:11 +02:00
|
|
|
sudo losetup -d $LOOP_DEV
|