Tiny Core Linux

General TC => Programming & Scripting - Unofficial => Topic started by: SvOlli on May 31, 2010, 09:35:34 AM

Title: Script to remaster with ntfs-3g included
Post by: SvOlli on May 31, 2010, 09:35:34 AM
Hello,

I've hacked a little script together for integrating ntfs-3g into the initrd. I'm using this to set up a system where I need to put the tce directory inside an ntfs-partition. It is intended to be used together with the grub4dos.tcz package, which includes everything needed to start Tiny Core Linux using the Windows Bootloader.

Code: [Select]
#!/bin/sh

if [ -f /opt/.tce_dir ]; then
  TCEDIR=$(cat /opt/.tce_dir)
else
  TCEDIR=/tmp/tce
fi

TMPDIR=/tmp/initrd.d
TCLOOP=/tmp/tcloop
TCENAMES="ntfs-3g"

installtcz()
{
for tce in $@;do
  if [ ! -d ${TCLOOP}/${tce} ]; then
    if [ ! -f ${TCEDIR}/optional/${tce}.tcz ]; then
      echo "downloading ${tce}"
      tce-load -w ${tce}
    fi
    echo "installing ${tce}"
    tce-load -i ${TCEDIR}/optional/${tce}.tcz
    if [ ! -d ${TCLOOP}/${tce} ]; then
      echo "${tce} seems to be installed, but not via loopback, forcing it."
      sudo mkdir -p ${TCLOOP}/${tce}
      sudo mount -o loop ${TCEDIR}/optional/${tce}.tcz ${TCLOOP}/${tce}
    fi
  fi

  echo "copying ${tce} to new initrd"
  (cd ${TCLOOP}/${tce} ; find * ! -type d | xargs tar cf -) |
    (cd ${TMPDIR};sudo tar xf -)
  touch ${TMPDIR}/usr/local/tce.installed/${tce}
done
}

if [ "$(id -u)" -eq 0 ]; then
  echo do not run as root, sudo will called when necessary
  exit 0
fi

if [ ! -f "${1}" ]; then
  echo "usage: ${0} initrd.gz [initrd_ntfs.gz]"
  exit 0
fi

sudo rm -rf ${TMPDIR}
sudo mkdir -p ${TMPDIR}

echo "unpacking initrd"
gzip -dc ${1} | (cd ${TMPDIR};sudo cpio -i)

echo "creating /usr/local/tce.installed"
sudo mkdir -p ${TMPDIR}/usr/local/tce.installed
sudo chown ${USER}:staff ${TMPDIR}/usr/local/tce.installed

installtcz ${TCENAMES}

sudo chroot ${TMPDIR} ldconfig
sudo sed -i 's/\$(blkid \$1)/$(blkid $1|sed s@TYPE=\\"ntfs\\"@TYPE=\\"ntfs-3g\\"@g)/' ${TMPDIR}/usr/sbin/fstype

ntfscpio="${2}"
[ -z "${ntfscpio}" ] && ntfscpio="tinycore+ntfs.gz"

echo "creating new initrd"
(cd ${TMPDIR};find .|sudo cpio -H newc -o) | gzip -9 > "${ntfscpio}"
[ -x /usr/local/bin/advdef ] && /usr/local/bin/advdef -z4 "${ntfscpio}"
(edit 1: bugfix in sed-script for patching fstype)
Title: Re: Script to remaster with ntfs-3g included
Post by: Xianwen Chen on June 29, 2010, 06:17:47 AM
Hello,

I've hacked a little script together for integrating ntfs-3g into the initrd. I'm using this to set up a system where I need to put the tce directory inside an ntfs-partition. It is intended to be used together with the grub4dos.tcz package, which includes everything needed to start Tiny Core Linux using the Windows Bootloader.

Code: [Select]
#!/bin/sh

if [ -f /opt/.tce_dir ]; then
  TCEDIR=$(cat /opt/.tce_dir)
else
  TCEDIR=/tmp/tce
fi

TMPDIR=/tmp/initrd.d
TCLOOP=/tmp/tcloop
TCENAMES="ntfs-3g"

installtcz()
{
for tce in $@;do
  if [ ! -d ${TCLOOP}/${tce} ]; then
    if [ ! -f ${TCEDIR}/optional/${tce}.tcz ]; then
      echo "downloading ${tce}"
      tce-load -w ${tce}
    fi
    echo "installing ${tce}"
    tce-load -i ${TCEDIR}/optional/${tce}.tcz
    if [ ! -d ${TCLOOP}/${tce} ]; then
      echo "${tce} seems to be installed, but not via loopback, forcing it."
      sudo mkdir -p ${TCLOOP}/${tce}
      sudo mount -o loop ${TCEDIR}/optional/${tce}.tcz ${TCLOOP}/${tce}
    fi
  fi

  echo "copying ${tce} to new initrd"
  (cd ${TCLOOP}/${tce} ; find * ! -type d | xargs tar cf -) |
    (cd ${TMPDIR};sudo tar xf -)
  touch ${TMPDIR}/usr/local/tce.installed/${tce}
done
}

if [ "$(id -u)" -eq 0 ]; then
  echo do not run as root, sudo will called when necessary
  exit 0
fi

if [ ! -f "${1}" ]; then
  echo "usage: ${0} initrd.gz [initrd_ntfs.gz]"
  exit 0
fi

sudo rm -rf ${TMPDIR}
sudo mkdir -p ${TMPDIR}

echo "unpacking initrd"
gzip -dc ${1} | (cd ${TMPDIR};sudo cpio -i)

echo "creating /usr/local/tce.installed"
sudo mkdir -p ${TMPDIR}/usr/local/tce.installed
sudo chown ${USER}:staff ${TMPDIR}/usr/local/tce.installed

installtcz ${TCENAMES}

sudo chroot ${TMPDIR} ldconfig
sudo sed -i 's/\$(blkid \$1)/$(blkid $1|sed s@TYPE=\\"ntfs\\"@TYPE=\\"ntfs-3g\\"@g)/' ${TMPDIR}/usr/sbin/fstype

ntfscpio="${2}"
[ -z "${ntfscpio}" ] && ntfscpio="tinycore+ntfs.gz"

echo "creating new initrd"
(cd ${TMPDIR};find .|sudo cpio -H newc -o) | gzip -9 > "${ntfscpio}"
[ -x /usr/local/bin/advdef ] && /usr/local/bin/advdef -z4 "${ntfscpio}"
(edit 1: bugfix in sed-script for patching fstype)

Dear SvOlli,

Thanks for sharing!

Best regards,

Xianwen
Title: Re: Script to remaster with ntfs-3g included
Post by: Xianwen Chen on July 19, 2010, 04:00:18 PM
Can this script be used for TC 3.0?
Title: Re: Script to remaster with ntfs-3g included
Post by: maro on July 19, 2010, 07:49:20 PM
I'm obviously not the author of the script (and have not used it myself) but after reading it I'm pretty sure that it should work with TC 3.0.

AFAICT it uses only one extension (i.e. 'ntfs-3g.tcz') which does exists in the 3.x repository and the rest is "just" a typical shell script using functionality BusyBox should supply. I would therefore encourage you to trial it out, or wait until SvOlli has had a chance to confirm my opinion.
Title: Re: Script to remaster with ntfs-3g included
Post by: SvOlli on July 19, 2010, 11:03:53 PM
@maro: your assumptions are all correct :)

@Xianwen Chen: I haven't tested it on 3.x yet, but I can't think of any cause why it shouldn't work. Just give it a try.

I'm also working on a script that remasters a tinycore iso with ntfs drivers that works on any Linux system. After that one is done, I'll double-check this script. So stay tuned. ;)
Title: Re: Script to remaster with ntfs-3g included
Post by: Ulysses_ on November 04, 2010, 04:03:05 PM
Beginner here, following instructions for installing TC inside a Windows system (http://www.tinycorelinux.com/wiki/GRUB4DOS). Copied the script into /root and made it executable with chmod a+x ntfs4tinycore.sh. Then copied tinycore.gz from the cdrom into the same directory /root.  Typing:

./ntfs4tinycore.sh tinycore.gz

it says "/bin/sh: ./ntfs4tinycore.sh: not found"

What am I doing wrong? ???

[fixurl]
Title: Re: Script to remaster with ntfs-3g included
Post by: maro on November 04, 2010, 04:20:28 PM
Ulysses_: I trust you call this command from the '/root' directory?

In my view there is no need to put such a script into '/root'. In particular you would need to be 'root' to copy a script there, but this script should not be executed as 'root' (at least that is what I saw when I took a quick glance over it). So that looks a bit like a recipe for trouble.

What I tend to do is to have such a script in the home directory of the $USER (e.g. 'tc'), and just call it directly (as the $USER)with sh script.sh. That way I don't have to worry about changing permissions or ownership.
Title: Re: Script to remaster with ntfs-3g included
Post by: SvOlli on November 04, 2010, 04:28:22 PM
[removed: see remaster/remix sticky]
Title: Re: Script to remaster with ntfs-3g included
Post by: theYinYeti on January 09, 2012, 02:00:46 PM
I can’t believe there is no “right” way to handle NTFS flash drives… it’s more and more common these days, with 16GB+ drives, and 4GB+ files!

Thank you very much SvOlli for your script, the only way I could achieve the result I sought  :)

Y.
Title: Re: Script to remaster with ntfs-3g included
Post by: roberts on January 09, 2012, 03:40:52 PM
If your boot loader can handle multiple initrds then we have
http://distro.ibiblio.org/tinycorelinux/4.x/x86/contrib/ntfs-3g.gz (http://distro.ibiblio.org/tinycorelinux/4.x/x86/contrib/ntfs-3g.gz)

Otherwise it is quite simple to use ezremaster and add the readily available extension ntfs-3g.tcz
into a single initrd.
Title: Re: Script to remaster with ntfs-3g included
Post by: gerald_clark on January 09, 2012, 03:53:07 PM
Or 'cat core.gz ntfs-3g.gz > mycore.gz'.
Title: Re: Script to remaster with ntfs-3g included
Post by: vinnie on January 10, 2012, 05:37:35 AM
Or 'cat core.gz ntfs-3g.gz > mycore.gz'.

 ??? this command assemble two .gz in a single?
Title: Re: Script to remaster with ntfs-3g included
Post by: Rich on January 10, 2012, 05:55:17 AM
Hi vinnie
No, it creates a file with the two .gz files back to back.
Title: Re: Script to remaster with ntfs-3g included
Post by: vinnie on January 10, 2012, 03:27:59 PM
so it was a mistake?  ???
Title: Re: Script to remaster with ntfs-3g included
Post by: gerald_clark on January 10, 2012, 03:32:27 PM
No, it was not a mistake.
Core.gz is a gzipped cpio archive of the root filesystem.
You can use cat to combine core.gz with another gzipped cpio archive and write it as a new file.
The bootloader will extract the one file that contains both gzipped cpio archives.