2 # Shell script to install Nameless to a disk.
4 BINARIES
=( boot
/x86
/mbr boot
/x86
/vbr-fat32 boot
/x86
/stage
3/LOADER.BIN kernel
/kernel.elf
)
8 if [ $user != "root" ]; then
9 echo nameless2disk needs to be run as root
!
15 for i
in "${BINARIES[@]}"; do
17 echo $i does not exist
, have you compiled Nameless?
24 # Ask the user are they sure they want to install.
26 echo About to
install Nameless to real disk
$target.
27 echo This will WIPE ALL DATA on
$target, type YES
if you want to
continue.
29 if [ $prompt != "YES" ]; then
34 echo OK
, installing Nameless to
$target.
35 echo Creating partition table on
$target...
37 # Create a partition table on the disk.
38 fdisk
$target <<- END > /dev/null
50 if ! [ $?
-eq 0 ]; then
51 echo An error occurred
!
54 # Create a FAT32 filesystem on the disk.
55 echo Formatting
$target...
56 mkfs.fat
-F 32 "$target"1
57 if ! [ $?
-eq 0 ]; then
58 echo An error occurred
!
61 # Write MBR and VBR to the disk.
62 # TODO: write VBR to the backup BPB as well?
63 echo Writing bootsectors to
$target...
64 dd 'if=boot/x86/mbr' "of=$target" 'bs=440' 'count=1'
65 if ! [ $?
-eq 0 ]; then
66 echo An error occurred
!
69 dd 'if=boot/x86/vbr-fat32' 'of='"$target"1 'bs=1' 'skip=90' 'seek=90'
70 if ! [ $?
-eq 0 ]; then
71 echo An error occurred
!
74 # Mount the partition and copy stage3 and kernel to it.
75 echo Copying files to
$target...
76 local mountpoint
=$
(mktemp
-d)
77 mount
"$target"1 $mountpoint
78 if ! [ $?
-eq 0 ]; then
79 echo An error occurred
!
82 cp boot
/x86
/stage
3/LOADER.BIN
$mountpoint/LOADER.BIN
83 cp kernel
/kernel.elf
$mountpoint/KERNEL.ELF
84 if ! [ $?
-eq 0 ]; then
85 echo An error occurred
!
88 # Unmount the partition and flush write cache to make sure the OS
89 # binaries have actually been written to the disk.
90 echo Unmounting
$target...
93 echo Flushing cache...
95 echo Nameless has been successfully installed to
$target!
99 # Check if all the required tools are installed.
100 [ -z $
(command -v fdisk
) ] && echo fdisk not found
, is util-linux installed?
&& exit 127
101 [ -z $
(command -v mkfs.fat
) ] && echo mkfs.fat not found
, is dosfstools installed?
&& exit 127
103 # Check for root privileges.
106 # Make sure that Nameless has been compiled.
109 # cd to the directory we're in.
110 cd $
(dirname $
(realpath
$0))
112 # For convenience, list all connected disks.
115 # Ask the user where to install.
116 echo -n "Choose the disk you want to install to: "
119 # If the target does not exist or is not a blkdev, exit.
120 [ -b $target ] ||
echo $target does not exist or is not a block device
! ||
exit 1