Register
It is currently Sat Dec 20, 2014 7:11 am

slax's bash installer


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Tue Sep 12, 2006 12:50 pm   
User avatar

Joined: Tue May 17, 2005 12:55 am
Posts: 86
Location: Big Easy, Louisiana
ok, as a group we need to fix this script so that it formats the partition. I was quite surprised when I installed slax yesterday, rebooted into slax on the hd. Then rebooted to fix my mbr so i could load suse too. After fixing the mbr and rebooting and choosing slax to check my grub settings, edubuntu loaded :o seems that the installer doesn't format the partition :o

So here is the script.

Code:
coastie@foxhole:~/Slax> cat make_disk.sh
#!/bin/bash
# Batch file to create bootable SLAX disk
# usage: make_disk.sh /dev/sda1 # (must be the partition)
# WARNING! boot sector of the device will be OVERWRITTEN!
# author: Tomas M. <http://www.linux-live.org>

if [ "$1" = "" ]; then
  echo "usage: $0 partition_device"
  echo "example: $0 /dev/sda1"
  exit 1
fi

PART="$1"
BOOT="`echo \"$PART\" | sed -r \"s/[0-9]+\\\$//\"`"

TMPDIR=/mnt/makedisk_mount$$
echo "Mounting $PART to $TMPDIR..."
mkdir -p $TMPDIR
mount "$PART" $TMPDIR
if [ $? -ne 0 ]; then exit 1; fi

echo "Copying files..."
cp -a ./* "$TMPDIR"
if [ $? -ne 0 ]; then exit 1; fi
sync

echo "Setting up boot sector in $BOOT..."
echo "boot=$BOOT
compact
lba32
vga=769
prompt
timeout=20
install=text

image=$TMPDIR/boot/vmlinuz
initrd=$TMPDIR/boot/initrd.gz
label=slax
root=/dev/ram0
append=\"max_loop=255 init=linuxrc load_ramdisk=1 prompt_ramdisk=0 ramdisk_size=4444\"
read-write
" >$TMPDIR/lilo.conf
lilo -C $TMPDIR/lilo.conf -m $TMPDIR/lilo.map -s $TMPDIR/origmbr 2>&1 | grep -vi warning
if [ $? -ne 0 ]; then exit 1; fi

umount $TMPDIR
rmdir $TMPDIR
echo "Successfully installed in $1"


This script is a little beyond my capabilities with bash at the present time :o .


Top
 Profile YIM  
 PostPosted: Wed Sep 13, 2006 8:08 am   

Joined: Wed Sep 06, 2006 12:19 pm
Posts: 54
Location: Covington, WA
coastie wrote:
ok, as a group we need to fix this script so that it formats the partition. I was quite surprised when I installed slax yesterday, rebooted into slax on the hd. Then rebooted to fix my mbr so i could load suse too. After fixing the mbr and rebooting and choosing slax to check my grub settings, edubuntu loaded :o seems that the installer doesn't format the partition :o

...



From a quick look at the script, it merely mounts a chosen partition, copies files to it, and installs a lilo bootloader to the mbr of the partition's disk to allow booting into the new slax install............This also saves the original mbr as "/origmbr" in the root of the slax filesystem.........

There is no formatting done here...........I'm not familiar with slax, per se, but I am intimately familiar with Slackware and the Slackware installer does allow you to format the partition.......But it seems that you should format beforehand, while in the slax livecd and then install........

Having said that :D , it would be trivial to add formatting capability to the install script by checking for a second argument on the command line, such as 'make_disk.sh /dev/sda1 reiserfs'......

By adding a check, along with a case statement, you could have formatting done, like so:
Code:
if [ "$2" ];then
    case $2 in
        reiserfs)   mkreiserfs $PART
        ;;
        ext3)       mke2fs -j $PART
        ;;
        ext2)       mke2fs $PART
        ;;
        jfs)        jfs_mkfs $PART
        ;;
        xfs)        mkfs.xfs $PART
        ;;
        *)          echo "'$2' is not recognised as a Linux partition"
                    exit 1
        ;;
    esac
fi


Combine that with the script and it would look something like this (note - I surrounded the additions with triple asterisks (***))
Code:
#!/bin/bash
# Batch file to create bootable SLAX disk
# usage: make_disk.sh /dev/sda1 # (must be the partition)
# WARNING! boot sector of the device will be OVERWRITTEN!
# author: Tomas M. <http://www.linux-live.org>

if [ "$1" = "" ]; then
  echo "usage: $0 partition_device ***[filesystem_type]***"
  echo "example: $0 /dev/sda1 ***reiserfs***"
  exit 1
fi

PART="$1"
***FSTYPE="$2"***
BOOT="$(sed -r "s/[0-9]+$//" <<<$PART)"
TMPDIR=/mnt/makedisk_mount$$

***
if [ "$FSTYPE" ];then
    echo "Formatting the partition..."
    case $FSTYPE in
        reiserfs)   mkreiserfs $PART
        ;;
        ext3)       mke2fs -j $PART
        ;;
        ext2)       mke2fs $PART
        ;;
        jfs)        jfs_mkfs $PART
        ;;
        xfs)        mkfs.xfs $PART
        ;;
        *)          echo "'$FSTYPE' is not recognised as a Linux partition"
                    exit 1
        ;;
    esac
fi
***

echo "Mounting $PART to $TMPDIR..."
mkdir -p $TMPDIR
mount "$PART" $TMPDIR  ||  exit 1

echo "Copying files..."
cp -a ./* "$TMPDIR"  ||  exit 1
sync

echo "Setting up boot sector in $BOOT..."
cat<<_LCFG_ >$TMPDIR/lilo.conf
boot=$BOOT
compact
lba32
vga=769
prompt
timeout=20
install=text

image=$TMPDIR/boot/vmlinuz
  initrd=$TMPDIR/boot/initrd.gz
  label=slax
  root=/dev/ram0
  append="max_loop=255 init=linuxrc load_ramdisk=1 prompt_ramdisk=0 ramdisk_size=4444"
  read-write
_LCFG_

lilo -C $TMPDIR/lilo.conf -m $TMPDIR/lilo.map -s $TMPDIR/origmbr 2>&1 | grep -vi warning
test $? -ne 0  &&  exit 1

umount $TMPDIR
rmdir $TMPDIR
echo "Successfully installed in $1"

You will need to interact with the formatting utility to go ahead with the formatting job..........This could be automated, but that would be a bad idea, IMO, in case you mistyped the partition to install on.... :shock:

As a side note, I streamlined the script a bit, by removing some "useless use of commands"...... ;)


HTH :-)
---thegeekster


Top
 Profile  
 PostPosted: Thu Sep 14, 2006 6:20 am   
User avatar

Joined: Tue May 17, 2005 12:55 am
Posts: 86
Location: Big Easy, Louisiana
thanks, though I didn't write this one, it comes with the slax live cd.


Top
 Profile YIM  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP