WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Core LVM installation, without any files on non-LVM volume (bootloader exluded)  (Read 6025 times)

Offline cowboyenvy

  • Newbie
  • *
  • Posts: 17
So, ive been struggling a bit but finally manged to accomplish what I wanted to do,

Install Core / TinyCore / Core Plus to an LVM parition without storing any files outside that LVM

My goal was to add tinycore to an existing LVM VG  without touching any of the MSDOS partitions

I am posting in hopes that if others wish to complete a similiar installation they can find this thread and perhaps save themselves some time and headache.

I wish to configure my tinycore linux to resided on an LVM volume keeping kernel vmlinux core.gz and initrd all on a single lvm

The following is an INCOMPLETE sh script, it will not do everything for you, and you will have to manually edit several variables etc, but it should serve in lue of a how to.



Code: [Select]
#!/bin/sh
# Partial installation script for installing Tiny Core Linux onto an LVM
# By CowboyEnvy (C) 2017, GNU General Public License version 2
#
# This is given as is without warranty and it is currently INCOMPLETE!
#
# The Goal is to create a standalone LVM installation of Tiny Core Linux
# on an LVM parition without needing an external source for pretce drivers
# This could be done either by remastering the core.gz or creating a second
# initrd image and merging the two at boot time
#
# I have opted for the second option as it seems a little more elegant and
# portable across multiple iterations of TinyCoreLinux
#
# I have attempted to make it is safe as possible and do some error checking
# However it is provided as is and may completly erase your disk if you are not
# Careful
#
# The following script is incomplete and is not completely automatic there
# are several things you will have to do on your own
#
# The Variables are currently hard coded and you will need to modify them
# to reflect the values you wish to use
#
# The you do not already have a Volume group you wish to add TinyCoreLinux
# to you will need create both a physical volume and a volume group before
# you can create a logical volume for tiny fore linux
#
# A Physical volume is either a GPT or MSDOS mbr partition of type 8e you
# can manually create one using fdisk PHYSICAL_DEVICE
#
# Once you have a Physical Volume you will need to initalize it
# you can do so by executing the following command
# sudo pvcreate DEVICE_PARITION
#
# The remaining Steps are documented in the remaining script, please read
# the script completely before proceeding

CORE_PV_PART=/dev/sda3
CORE_LV_SIZE=5g
CORE_VG_NAME=LVM
CORE_LV_NAME=TinyCoreLinux
CORE_LVM_VOLUME=/dev/mapper/$CORE_VG_NAME-$CORE_LV_NAME
CORE_MOUNT_PATH=/mnt/TinyCoreLinux
CORE_TCE_DIR=/etc/sysconfig/tcedir
CORE_SOURCE_DIR=/mnt/sda4/CorePlus-8.0
CORE_DESTINATION_DIR=/mnt/TinyCoreLinux/CorePlus-8.0
CLEAN=TRUE

##
## Mark logical volumes active so they can be used by tinycore
## Once marked active they will be automatically mapped by tinycorelinux
## they may also have /mnt directories created for them
##

[ -b $CORE_LVM_VOLUME ] || sudo vgchange -ay

##
## Once you have a physical device you will need to create a Volume Group
## the Volume group can be extended across multple partitions and disk
## However for simplicity the basic configuarion is a single partition
## uncomment the following line at your own risk, or execute the command
##
## sudo vgcreate $CORE_VG_NAME $CORE_PV_PART

##
## The following command will check to see if there is a mapper device already
## loaded and if it is not found will attempt to create your Logical Volume
##

[ -b CORE_LVM_VOLUME ] || sudo lvcreate -n $CORE_LV_NAME -L $CORE_LV_SIZE $CORE_VG_NAME

##
## Load required TCE extensions to complete install
## We will need LVM2.tcz as well ad advcomp to complete the initrd build process
##

[ -f /usr/local/tce.installed/lvm2 ] || tce-load -iw lvm2.tcz
[ -f /usr/local/tce.installed/advcomp ] || tce-load -iw advcomp

##
## The next step is to create the file system on the LV, we can do so by executing the
## following command, it should promp before overwriting and existing file system
## however it has been commented out for additional safety
##

## mkfs.ext4 $CORE_LVM_VOLUME

##
## a Little Cleanup for testing
## the following short block of code was added only for testing purposes and I'm not even sure
## how good it is at doing that
##

[ $CLEAN ] && [ -d $CORE_DESTINATION_DIR ] && sudo rm -rf $CORE_DESTINATION_DIR && echo Removing tree $CORE_DESTINATION_DIR
[ $CLEAN ] && [ -d $CORE_MOUNT_PATH ] && sudo umount $CORE_MOUNT_PATH >& /dev/null && umount $CORE_MOUNT_PATH
[ $CLEAN ] && [ -d $CORE_MOUNT_PATH ] && sudo rm -R $CORE_MOUNT_PATH && rm $CORE_MOUNT_PATH
[ $CLEAN ] && [ -d /tmp/lvm2 ] && rm -r /tmp/lvm2* && echo removed temporary files


##
## Create Know Directory to work with and mount the files system
## it just seems easier to create a specific mount instead of trying to figure
## how to identify which /mnt/dm-# directory to use
##
## Also create the base tce structure

sudo mkdir $CORE_MOUNT_PATH
sudo mount $CORE_LVM_VOLUME $CORE_MOUNT_PATH
[ -d $CORE_DESTINATION_DIR ] || sudo mkdir $CORE_DESTINATION_DIR $CORE_DESTINATION_DIR/tce
sudo chown -R $USER:staff $CORE_DESTINATION_DIR

##
## Copy Core files and extensions to new LVM volume
## I'm trying to get everything here, it's probably over kill
##

[ -d $CORE_SOURCE_DIR/boot ] && cp -r $CORE_SOURCE_DIR/boot $CORE_DESTINATION_DIR
[ -d $CORE_SOURCE_DIR/tce ] && for file in `ls $CORE_SOURCE_DIR/tce` ; do cp -R $CORE_SOURCE_DIR/tce/$file $CORE_DESTINATION_DIR/tce ; done
[ -d $CORE_SOURCE_DIR/cde ] && for file in `ls $CORE_SOURCE_DIR/cde` ; do cp -R $CORE_SOURCE_DIR/cde/$file $CORE_DESTINATION_DIR/tce ; done
[ -d /tmp/tce ] && for file in `ls /tmp/tce` ; do cp -R /tmp/tce/$file $CORE_DESTINATION_DIR/tce ; done
[ -d $CORE_TCE_DIR/ ] && for file in `ls $CORE_TCE_DIR` ; do cp -R $CORE_TCE_DIR/$file $CORE_DESTINATION_DIR/tce ; done

##
## Create RAM pretce Directory structure for building the initrd
## include the tcz and well as md5.txt and .dep files
## This should copy lvm2.tcz and all it's dependencies
##

[ -d /tmp/lvm2 ] || mkdir /tmp/lvm2 /tmp/lvm2/tmp /tmp/lvm2/tmp/tce /tmp/lvm2/tmp/tce/optional
cd $CORE_DESTINATION_DIR/tce/optional ; cp `ls glib2* libdevmapper* libffi* liblvm2* lvm2* ncurses* raid-dm-4.8.17-tinycore* readline* udev-lib*` /tmp/lvm2/tmp/tce/optional/

##
## you will need lvm2.tcz and it's dep (including .dep files)
## you need an onboot.lst to tell core what files to load
## you will also need onpre.sh as an executable file to run a script
## to activate your Logical Volumes
##
     
cd /tmp/lvm2/
echo  "#!/bin/sh " > tmp/onpre.sh
echo "vgchange -ay ; wait 2" >> tmp/onpre.sh
chmod 755 /tmp/lvm2/tmp/onpre.sh
echo "lvm2.tcz" > tmp/tce/onboot.lst

##
## This is a standard build process for building initrd images,
## We are only creating an appending file to extend core.gz
## you will need both core.gz and lvm2.gz to boot your system
## The process can be modified slightly to create a single core-lvm2.gz initrd
##


sudo find | sudo cpio -o -H newc | gzip -11 > ../lvm2.gz
advdef -z4 ../lvm2.gz
sudo cp ../lvm2.gz $CORE_DESTINATION_DIR/boot/

echo "You will need the following UUID to configure your bootloader"
blkid -s UUID $CORE_LVM_VOLUME

##
## good luck!
##


The Following is a menu entry in my ubuntu's /boot/grub/custom.cfg

Code: [Select]
### Begin /boot/grub/custom.cfg

menuentry 'CorePlus-8.0 LVM-TinyCoreLinux' --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-e6aad561-7648-48d5-a1e4-9f69a2743f45' {
recordfail
gfxmode $linux_gfx_mode
insmod lvm
insmod gzio
if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
insmod part_msdos
insmod ext2
set root='LVM-TinyCoreLinux'
search --no-floppy --fs-uuid --set=root 8759877d-2726-4124-b4a4-752503dc0f31
linux /CorePlus-8.0/boot/vmlinuz pretce=RAM home=UUID="8759877d-2726-4124-b4a4-752503dc0f31" opt=UUID="8759877d-2726-4124-b4a4-752503dc0f31" loglevel=3 showapps tce=UUID="8759877d-2726-4124-b4a4-752503dc0f31"/CorePlus-8.0/tce
initrd /CorePlus-8.0/boot/core.gz /CorePlus-8.0/boot/lvm2.gz
}

Note the UUID and initrd references

Good luck I hope it helps

Offline cowboyenvy

  • Newbie
  • *
  • Posts: 17
So while adding all the comments/documentation to the script I ended up reordering a couple of things inside the script, the following should correct the issues.

I seem to be unable to edit the original post so a reply will have to suffice.

Code: [Select]
#!/bin/sh
# Partial installation script for installing Tiny Core Linux onto an LVM
# Created and tested on Core Plus 8.0 x86
# By CowboyEnvy (C) 2017, GNU General Public License version 2
#
# This is given as is without warranty and it is currently INCOMPLETE!
#
# The Goal is to create a standalone LVM installation of Tiny Core Linux
# on an LVM parition without needing an external source for pretce drivers
# This could be done either by remastering the core.gz or creating a second
# initrd image and merging the two at boot time
#
# I have opted for the second option as it seems a little more elegant and
# portable across multiple iterations of TinyCoreLinux
#
# I have attempted to make it is safe as possible and do some error checking
# However it is provided as is and may completly erase your disk if you are not
# Careful
#
# The following script is incomplete and is not completely automatic there
# are several things you will have to do on your own
#
# The Variables are currently hard coded and you will need to modify them
# to reflect the values you wish to use
#
# The remaining Steps are documented in the script, please read the script
# completely before proceeding

CORE_PV_PART=/dev/sda3
CORE_LV_SIZE=5g
CORE_VG_NAME=LVM
CORE_LV_NAME=TinyCoreLinux
CORE_LVM_VOLUME=/dev/mapper/$CORE_VG_NAME-$CORE_LV_NAME
CORE_MOUNT_PATH=/mnt/TinyCoreLinux
CORE_TCE_DIR=/etc/sysconfig/tcedir
CORE_SOURCE_DIR=/mnt/sda4/CorePlus-8.0
CORE_DESTINATION_DIR=/mnt/TinyCoreLinux/CorePlus-8.0
CLEAN=TRUE

##
## Load required TCE extensions to complete install
## We will need LVM2.tcz as well ad advcomp to complete the initrd build process
##

[ -f /usr/local/tce.installed/lvm2 ] || tce-load -iw lvm2.tcz
[ -f /usr/local/tce.installed/advcomp ] || tce-load -iw advcomp

## The you do not already have a Volume group you wish to add TinyCoreLinux
## to you will need create both a physical volume and a volume group before
## you can create a logical volume for tiny fore linux
##
## A Physical volume is either a GPT or MSDOS mbr partition of type 8e you
## can manually create one using fdisk PHYSICAL_DEVICE
##
## Once you have a Physical Volume you will need to initalize it
## you can do so by executing the following command
##
## sudo pvcreate DEVICE_PARITION
##

##
## Mark logical volumes active so they can be used by tinycore
## Once marked active they will be automatically mapped by tinycorelinux
## they may also have /mnt directories created for them
##

[ -b $CORE_LVM_VOLUME ] || sudo vgchange -ay

##
## Once you have a physical device you will need to create a Volume Group
## the Volume group can be extended across multple partitions and disk
## However for simplicity the basic configuarion is a single partition
## uncomment the following line at your own risk, or execute the command
##
## sudo vgcreate $CORE_VG_NAME $CORE_PV_PART

##
## The following command will check to see if there is a mapper device already
## loaded and if it is not found will attempt to create your Logical Volume
##

[ -b CORE_LVM_VOLUME ] || sudo lvcreate -n $CORE_LV_NAME -L $CORE_LV_SIZE $CORE_VG_NAME

##
## The next step is to create the file system on the LV, we can do so by executing the
## following command, it should promp before overwriting and existing file system
## however it has been commented out for additional safety
##

## mkfs.ext4 $CORE_LVM_VOLUME

##
## a Little Cleanup for testing
## the following short block of code was added only for testing purposes and I'm not even sure
## how good it is at doing that
##

[ $CLEAN ] && [ -d $CORE_DESTINATION_DIR ] && sudo rm -rf $CORE_DESTINATION_DIR && echo Removing tree $CORE_DESTINATION_DIR
[ $CLEAN ] && [ -d $CORE_MOUNT_PATH ] && sudo umount $CORE_MOUNT_PATH >& /dev/null && umount $CORE_MOUNT_PATH
[ $CLEAN ] && [ -d $CORE_MOUNT_PATH ] && sudo rm -R $CORE_MOUNT_PATH && rm $CORE_MOUNT_PATH
[ $CLEAN ] && [ -d /tmp/lvm2 ] && rm -r /tmp/lvm2* && echo removed temporary files


##
## Create Know Directory to work with and mount the files system
## it just seems easier to create a specific mount instead of trying to figure
## how to identify which /mnt/dm-# directory to use
##
## Also create the base tce structure

sudo mkdir $CORE_MOUNT_PATH
sudo mount $CORE_LVM_VOLUME $CORE_MOUNT_PATH
[ -d $CORE_DESTINATION_DIR ] || sudo mkdir $CORE_DESTINATION_DIR $CORE_DESTINATION_DIR/tce
sudo chown -R $USER:staff $CORE_DESTINATION_DIR

##
## Copy Core files and extensions to new LVM volume
## I'm trying to get everything here, it's probably over kill
##

[ -d $CORE_SOURCE_DIR/boot ] && cp -r $CORE_SOURCE_DIR/boot $CORE_DESTINATION_DIR
[ -d $CORE_SOURCE_DIR/tce ] && for file in `ls $CORE_SOURCE_DIR/tce` ; do cp -R $CORE_SOURCE_DIR/tce/$file $CORE_DESTINATION_DIR/tce ; done
[ -d $CORE_SOURCE_DIR/cde ] && for file in `ls $CORE_SOURCE_DIR/cde` ; do cp -R $CORE_SOURCE_DIR/cde/$file $CORE_DESTINATION_DIR/tce ; done
[ -d /tmp/tce ] && for file in `ls /tmp/tce` ; do cp -R /tmp/tce/$file $CORE_DESTINATION_DIR/tce ; done
[ -d $CORE_TCE_DIR/ ] && for file in `ls $CORE_TCE_DIR` ; do cp -R $CORE_TCE_DIR/$file $CORE_DESTINATION_DIR/tce ; done

##
## Create RAM pretce Directory structure for building the initrd
## include the tcz and well as md5.txt and .dep files
## This should copy lvm2.tcz and all it's dependencies
##

[ -d /tmp/lvm2 ] || mkdir /tmp/lvm2 /tmp/lvm2/tmp /tmp/lvm2/tmp/tce /tmp/lvm2/tmp/tce/optional
cd $CORE_DESTINATION_DIR/tce/optional ; cp `ls glib2* libdevmapper* libffi* liblvm2* lvm2* ncurses* raid-dm-4.8.17-tinycore* readline* udev-lib*` /tmp/lvm2/tmp/tce/optional/

##
## you will need lvm2.tcz and it's dep (including .dep files)
## you need an onboot.lst to tell core what files to load
## you will also need onpre.sh as an executable file to run a script
## to activate your Logical Volumes
##
     
cd /tmp/lvm2/
echo  "#!/bin/sh " > tmp/onpre.sh
echo "vgchange -ay ; wait 2" >> tmp/onpre.sh
chmod 755 /tmp/lvm2/tmp/onpre.sh
echo "lvm2.tcz" > tmp/tce/onboot.lst

##
## This is a standard build process for building initrd images,
## We are only creating an appending file to extend core.gz
## you will need both core.gz and lvm2.gz to boot your system
## The process can be modified slightly to create a single core-lvm2.gz initrd
##


sudo find | sudo cpio -o -H newc | gzip -11 > ../lvm2.gz
advdef -z4 ../lvm2.gz
sudo cp ../lvm2.gz $CORE_DESTINATION_DIR/boot/

echo "You will need the following UUID to configure your bootloader"
blkid -s UUID $CORE_LVM_VOLUME

##
## good luck!
##


Offline cowboyenvy

  • Newbie
  • *
  • Posts: 17
So I ended up following the rabbit for a while longer; the following is a continuation of the idea of an installation script but is still not complete and should be consider alpha

comments on code etc are welcome, so are bug reports and error checking especially if you can tell me where I went wrong on something.

This is first ever attempt at this kind of script and as of yet it is not done nor feature complete but I need a bit of a respite from it, but it may be helpful to others, and someone might want to polish it out and finish it before I get around to working on it again.

Code: [Select]
#!/bin/sh
#
# Partial installation script for installing Tiny Core Linux onto an LVM
# Created and tested on Core Plus 8.0 x86
# By CowboyEnvy (C) 2017, GNU General Public License version 2
#
# This is given as is without warranty and it is currently INCOMPLETE!
#
# The Goal is to create a standalone LVM installation of Tiny Core Linux
# on an LVM parition without needing an external source for pretce drivers
# This could be done either by remastering the core.gz or creating a second
# initrd image and merging the two at boot time
#
# I have opted for the second option as it seems a little more elegant and
# portable across multiple iterations of TinyCoreLinux
#
# I have attempted to make it is safe as possible and do some error checking
# However it is provided as is and may completely erase your disk even if you are
# Careful
#
# The following script is incomplete and is not completely automatic there
# are several things you will have to do on your own
#
# The remaining Steps are documented in the script, please read the script
# completely before proceeding

echo ""
echo "+-----------------------------------------------------------------------"
echo "| `basename $0` 0.0.2a (c) 2017 by CowBoyEnvy GNU License ver 2.0 "
echo "+-----------------------------------------------------------------------"
echo ""

# Here we check all the command line parameters.

echo "Checking paramaters ..."
for i in $*; do
case $i in
*=*)
case $i in
pv*) PV_PART=${i#*=} ;;
lv*) LV_NAME=${i#*=} ;;
vg*) VG_NAME=${i#*=} ;;
src*) SOURCE_DIR=${i#*=} ;;
tce*) TCE_DIR=${i#*=} ;;
dest*) DESTINATION_DIR=${i#*=} ;;
mount*) MOUNT_PATH=${i#*=} ;;
kernel*) KERNEL_VER=${i#*=} ;;
temp*) TEMP=${i#*=} ;;
size*) LV_SIZE=${i#*=} ;;
esac
;;
*)
case $i in
--install) INSTALL=true ;;
--pause) PAUSE=true ;;
--force) FORCE="-f" ;;
--vgcreate) VGCREATE_=true ;;
--pvcreate) PVCREATE=true ;;
--base) BASE=true ;;
--remaster) REMASTER=true ;;
--format) FORMAT=true ;;
--clean) CLEAN=true ;;
--build) BUIlD=true ;;
--help)  HELP=true ;;
esac
;;
esac
done

PAUSE=true ; #placed here for debugging

##
## Sanity Check
##

## check/set default values

echo "Setting some defaults ..."
[ -z $KERNEL_VER ] && KERNEL_VER=`uname -r` && echo `uname -r`
[ $INSTALL ] && [ -z $DESTINATION_DIR ] && DESTINATION_DIR=/TinyCore
[ $INSTALL ] && [ -z $MOUNT_PATH ] && [ $LV_NAME ] && MOUNT_PATH=/mnt/$LVM_LV_NAME
[ $MOUNT_PATH ] && [ $DESTINATION_DIR ] && DESTINATION_PATH=$MOUNT_PATH/$DESTINATION_DIR
[ -z $TEMP ] && TEMP=/tmp/lvm2

echo "Kernel : $KERNEL_VER"
echo "Desination dir : $DESTINATION_DIR"
echo "Mount Path : $MOUNT_PATH"

## [ $VG_NAME ] && [ $LV_NAME ] && [ $PV_PART ]

[ $PAUSE ] && echo "Parse: Physical Volume, Volume Group, Volume Name"

if [ $VG_NAME ] && [ $LV_NAME ] && [ $PV_PART ] && [ $PV_PART ] && [ -b $PV_PART ] ; then
LVM_DM_BLK=/dev/mapper/$VG_NAME-$LV_NAME
echo "Physical Volume: $PV_PART"
echo "Volume Group   : $VG_NAME"
echo "Logical Volume : $LV_NAME"
echo "Device Mapper  : $LVM_DM_BLK"
elif [ $VG_NAME ] && [ $LV_NAME ] && [ $PV_PART ] ; then
echo "$PV_PART is not a valid block device"
exit
elif [ $VG_NAME ] && [ $LV_NAME ] ; then
LVM_DM_BLK=/dev/mapper/$VG_NAME-$LV_NAME
echo -n "Volume Group   : $VG_NAME"
sudo vgdisplay | grep -q "VG Name *$VG_NAME" && echo "EXISTS!" || echo ""
echo -n "Logical Volume : $LV_NAME"
sudo lvdisplay | grep -q "lv Name *$LV_NAME" && echo "EXISTS!" || echo ""
echo "Device Mapper  : $LVM_DM_BLK"
elif [ $PV_PART ] ; then
[ $VG_NAME ] || echo "Volume Group not specified!"
[ $LV_NAME ] || echo "Logical Volume not specified!"
echo "Syntax error: Physical Volume , Volume Group and Logical Volume must be specified together!"
echo "see $0 --help for more details"
exit
elif [ $VG_NAME ] || [ $LV_NAME ]; then
[ $VG_NAME ] || echo "Volume Group not specified!"
[ $LV_NAME ] || echo "Logical Volume not specified!"
echo "Syntax error: Volume Group and Logical Volume must be specified together!"
echo "see $0 --help for more details"
exit
else
echo ""
fi

[ $SOURCE_DIR ] && KERNEL=`find $SOURCE_DIR/boot/ -regex ".*/vmlinuz.*"`
[ $SOURCE_DIR ] && INITRD=`find $SOURCE_DIR/boot/ -regex ".*/core.*gz"`

if [ $SOURCE_DIR ]; then
if [ -f $KERNEL ] && [ -f $INITRD ]; then
echo "source : $SOURCE_DIR"
echo "Kernel : $KERNEL "
echo "initrd : $INITRD "
elif [ -d $SOURCE_DIR/boot ]; then
echo "source : $SOURCE_DIR"
[ -z $KERNEL ] && echo "Kernel         : NOT FOUND! $KERNEL"
[ -z $INITRD ] && echo "initrd         : NOT FOUND! $INITRD"
exit
elif [ -f $SOURCE_DIR ] || [ -b $SOURCE_DIR ]; then
echo "source : $SOURCE_DIR , is not a valid directory"
exit
else
echo "$SOURCE_DIR : Does not contain a boot directory!!"
exit
fi
elif [ -z $SOURCE_DIR ] && [ -z $INSTALL ] ; then
echo "No Source Specified ... skipping installation"
fi

if [ $TCE_DIR ] && [ -f $TCE_DIR/optional/lvm2.tcz ] ; then
echo "tce source: $TCE_DIR"
elif [ -z $TCE_DIR ]; then
if [ $SOURE_DIR ] && [ -f $SOURCE_DIR/tce/optional/lvm2.tcz ]; then
TCE_DIR=$SOURCE_DIR/tce
echo "tce source: $TCE_DIR"
elif [ $SOURE_DIR ] && [ -f $SOURCE_DIR/cde/optional/lvm2.tcz ]; then
TCE_DIR=$SOURCE_DIR/cde
echo "cde source: $TCE_DIR"
elif [ -z $TCE_DIR ] && [ -d /etc/sysconfig/tcedir ]; then
TCE_DIR=/etc/sysconfig/tcedir
echo "tce dfault: $TCE_DIR"
else
echo "No Valid TCE/CDE source located."
echo "Please specify a valid TCE/cde location with tce=TCE_SOURCE"
exit
fi
elif [ -f $TCE_DIR/optional/lvm2 ]; then
echo "tce source: $TCE_DIR"
elif [ -d $TCE_DIR/optional ]; then
echo "tce source: $TCE_DIR : lvm2.tcz NOT found!"
exit
elif [ -d $TCE_DIR ]; then
echo "tce source: $TCE_DIR/optional is not a valid directory"
exit
else
echo "tce source: $TCE_DIR is not a valid directory"
exit
fi

[ $MOUNT_PATH ] && mount | grep -qE "^/dev/.+$MOUNT_PATH.+[(]rw," && MOUNT_RW=true || MOUNT_RW=
[ -b $LVM_DM_BLK ] && NO_DM_BLK= || NO_DM_BLK=true

if [ $CLEAN ] && [ $MOUNT_RW ]; then
[ -$TEMP ] && [ -d $TEMP ] && rm -r $TEMP && echo "... Removing Temporary Files ... $TEMP"
[ $DESTINATION_PATH ] && [ -d $DESTINATION_PATH ] && sudo rm -rf `ls $DESTINATION_PATH` && echo " ... Removing directory tree ... $DESTINATION_PATH "
[ $MOUNT_PATH ] && [ -d $MOUNT_PATH ] && sudo umount $MOUNT_PATH >& /dev/null && echo $MOUNT_PATH
[ $MOUNT_PATH ] && [ -d $MOUNT_PATH ] && sudo rm -r $MOUNT_PATH
elif [ $CLEAN ] && [ $NO_DM_BLK ]; then
echo " ... $LVM_DM_BLK does not exist ... cleaning temp files"
[ $TEMP ] && [ -d $TEMP ] && rm -rf $TEMP && echo "... Removing Temporary Files ... $TEMP"
[ $MOUNT_PATH ] && [ -d $MOUNT_PATH ] && sudo rm -r $MOUNT_PATH
elif [ $CLEAN ] && [ -d $TEMP ]; then
[ $TEMP ] &&  [ -d $TEMP ] && rm -rf $TEMP && echo "... Removing Temporary Files ... $TEMP"
[ $MOUNT_PATH ] && [ -d $MOUNT_PATH ] && sudo rm -r $MOUNT_PATH
fi

[ $CLEAN ] && [ $PAUSE ] && echo "Press <ENTER> to continue" && read junk

if [ $MOUNT_PATH ] && [ -d MOUNT_PATH ] && [ -z FORCE ]; then
echo "$MOUNT_PATH , is an exsiting directory"
echo "Please do one of the following three options"
echo "Specify a new directory to be used"
echo "use --force to proceed anyway and overwrite destination files"
echo "use --force and --clean to remove the directory and it's children before proceeding"
exit
elif [ $MOUNT_PATH ] && [ -d `echo "$MOUNT_PATH" | sed 's|\(.*\)/.*|\1|' ` ]; then
echo -n "Mount path : $MOUNT_PATH"
echo " ... Parent Directory Found "
echo "$MOUNT_PATH" | sed 's|\(.*\)/.*|\1|'
[ -d $MOUNT_PATH ] || mkdir $MOUNT_PATH
fi

if [ $TEMP ] && [ -d $TEMP ] && [ -z $FORCE ]; then
echo "$TEMP , is an exsiting directory"
echo "Please do one of the folow three options"
echo "Specify a new directory to be used"
echo "use --force to proceed anyway and overwrite destination files"
echo "use -clean to remove the directory and it's children before proceeding"
exit
elif [ -d `echo "$TEMP" | sed 's|\(.*\)/.*|\1|' ` ] ; then
echo -n "Temp folder : $TEMP"
echo " ... Parent Directory Found "
echo "$TEMP" | sed 's|\(.*\)/.*|\1|'
[ $TEMP ] || mkdir $TEMP
fi

echo DESTINATION_PATH=$DESTINATION_PATH
echo LV_SIZE=$LV_SIZE
 
##
## Load required TCE extensions to complete install
## We will need LVM2.tcz as well as advcomp to complete the initrd build process
##

[ -f /usr/local/tce.installed/lvm2 ] || tce-load -iw lvm2.tcz
[ -f /usr/local/tce.installed/advcomp ] || tce-load -iw advcomp

##
## you will need lvm2.tcz and it's dep (including .dep files)
## you need an onboot.lst to tell core what files to load
## you will also need onpre.sh as an executable file to run a script
## to activate your Logical Volumes
##

if [ $TEMP ] ; then
## Build the pretce directory structure if it does not exist

[ -d $TEMP ] || mkdir $TEMP
[ -d $TEMP/tmp ] || mkdir $TEMP/tmp
[ -d $TEMP/tmp/tce ] || mkdir $TEMP/tmp/tce
[ -d $TEMP/tmp/tce/optional ] || mkdir $TEMP/tmp/tce/optional

## Transfer all needed tcz .dep and md5.txt files
cd $TCE_DIR/optional ; cp `ls glib2* libdevmapper* libffi* liblvm2* lvm2* ncurses* raid-dm-* readline* udev-lib*` $TEMP/tmp/tce/optional/
cd $TEMP ; echo $PWD
! [ -f tmp/onpre.sh ] && echo  "#!/bin/sh " > tmp/onpre.sh
echo "vgchange -ay ; wait 2" >> tmp/onpre.sh
chmod 755 $TEMP/tmp/onpre.sh
! [ -f tmp/onpre.sh ] && echo "lvm2.tcz" > tmp/tce/onboot.lst
[ -f tmp/onpre.sh ] && echo "lvm2.tcz" >> tmp/tce/onboot.lst
##
## This is a standard build process for building initrd images,
## We are only creating an appending file to extend core.gz
## you will need both core.gz and lvm2.gz to boot your system
## The process can be modified slightly to create a single core-lvm2.gz initrd
##

sudo find | sudo cpio -o -H newc | gzip -11 > ../lvm2.gz
advdef -z4 ../lvm2.gz
fi

## Then if  you do not already have a Volume group you wish to add
## TinyCoreLinux to you will need to create both a physical volume
## and a volume group before you can create a logical volume for
## Tiny Core Linux
##
## A Physical volume is either a GPT or MSDOS mbr partition of
## type 8e you can manually create one using fdisk PHYSICAL_DEVICE
##
## Once you have a Physical Volume you will need to initalize it
## you can do so by executing the following command
##

if [ $PVCREATE ] && [ $FORCE ] && [ -b $PV_PART ] && [ $VG_NAME ] && [ $LV_NAME ]; then
echo ""
echo "The next Step will initialize a PV, erasing information on that parition"
echo "Assuming you have entered:"
echo
echo "$0 --pvcreate --force pv=PHYSICAL_DEVICE vg=VOLUME_GROUP lv=LOGICAL_VOLUME"
echo
echo "it might just be simpler to type sudo pvcreate PHYSICAL_DEVICE"
echo "or press ctrl+c to terminate the script"
echo "Press <ENTER> to continue" && read junk
echo sudo pvcreate $PV_PART
fi

## It might be easier just to type:
## sudo pvcreate PHYSICAL_DEVICE

##
## Mark logical volumes active so they can be used by tinycore
## Once marked active they will be automatically mapped by Tiny Core
## Linux they may also have /mnt directories created for them
##

if [ $LVM_DM_BLK ]; then
echo "Checking for $LVM_DM_BLK ..."
[ -b $LVM_DM_BLK ] || sudo vgchange -ay
[ $PAUSE ] && echo "Press <ENTER> to continue" && read junk
fi


##
## Once you have a physical device you will need to create a Volume Group
## the Volume group can be extended across multple partitions and disk
## However for simplicity the basic configuarion is a single partition
## uncomment the following line at your own risk, or execute the command
##
## sudo vgcreate $VG_NAME $PV_PART

if ! `sudo vgdisplay | grep -qe "  VG Name.*$VG_NAME"` && [ -b $PV_PART ] && [ $VGCREATE ] ; then
[ $LV_SIZE ] && echo sudo lvcreate -n $LV_NAME -L $LV_SIZE $VG_NAME
[ $PAUSE ] && echo "Press <ENTER> to continue" && read junk
fi

##
## The following command will check to see if there is a mapper device already
## loaded and if it is not found will attempt to create your Logical Volume
##
if ! `sudo lvdisplay | grep -qe "  LV Name.*$LV_NAME"` && `sudo vgdisplay | grep -qe "  VG Name.*$VG_NAME"`; then
[ $LV_SIZE ] && echo sudo lvcreate -n $LV_NAME -L $LV_SIZE $VG_NAME
[ $PAUSE ] && echo "Press <ENTER> to continue" && read junk
FORMAT=true
fi

##
## The next step is to create the file system on the LV, we can do so by executing the
## following command, it should promp before overwriting and existing file system
## however it has been commented out for additional safety
##

[ FORMAT ] && mkfs.ext4 $LVM_DM_BLK

##
## Create Know Directory to work with and mount the files system
## it just seems easier to create a specific mount instead of trying to figure
## how to identify which /mnt/dm-# directory to use
##
## Also create the base tce structure
[ $PAUSE ] && echo "Press <ENTER> to continue" && read junk

! [ -d $MOUNT_PATH ] && [ $MOUNT_PATH ] sudo mkdir $MOUNT_PATH && echo " ... Creating Mount Path $MOUNT_PATH"
! `mount | grep -qe ".*$MOUNT_PATH.*"` && [ $LVM_DM_BLK ] && sudo mount $LVM_DM_BLK $MOUNT_PATH && echo "Mounting : $LVM_DM_BLK : $MOUNT_PATH"
! [ -d $DESTINATION_PATH ] && `mount | grep -qe ".*$MOUNT_PATH.*"` && sudo mkdir $DESTINATION_PATH $DESTINATION_PATH/tce

##
## Copy Core files and extensions to new LVM volume
## I'm trying to get everything here, it's probably over kill
##

if [ DESTINATION_DIR ] && [ -d $DESTINATION_PATH ] && `mount | grep -qe ".*$MOUNT_PATH.*"` ; then
sudo chown -R $USER:staff $DESTINATION_PATH
[ -d $SOURCE_DIR/boot ] && cp -rf $SOURCE_DIR/boot $DESTINATION_PATH
[ -d $SOURCE_DIR/tce ] && for file in `ls $SOURCE_DIR/tce` ; do cp -Rf $SOURCE_DIR/tce/$file $DESTINATION_PATH/tce ; done
[ -d $SOURCE_DIR/cde ] && for file in `ls $SOURCE_DIR/cde` ; do cp -Rf $SOURCE_DIR/cde/$file $DESTINATION_PATH/tce ; done
[ -d /tmp/tce ] && for file in `ls /tmp/tce` ; do cp -Rf /tmp/tce/$file $DESTINATION_PATH/tce ; done

[ $PAUSE ] && echo "Press <ENTER> to continue" && read junk
sudo cp ../lvm2.gz $DESTINATION_PATH/boot/
fi


echo "You will need the following UUID to configure your bootloader"
blkid -s UUID $LVM_DM_BLK

##
## good luck!
##


Offline giroro

  • Newbie
  • *
  • Posts: 1
thx for your sharing! I follow your idea and able to boot tinycore from lvm now


Sent from my iPhone using Tapatalk