WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Script to remaster with ntfs-3g included  (Read 12754 times)

Offline SvOlli

  • Full Member
  • ***
  • Posts: 193
  • Linux Developer
Script to remaster with ntfs-3g included
« 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)
« Last Edit: June 01, 2010, 01:17:57 PM by SvOlli »

Offline Xianwen Chen

  • Full Member
  • ***
  • Posts: 142
Re: Script to remaster with ntfs-3g included
« Reply #1 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

Offline Xianwen Chen

  • Full Member
  • ***
  • Posts: 142
Re: Script to remaster with ntfs-3g included
« Reply #2 on: July 19, 2010, 04:00:18 PM »
Can this script be used for TC 3.0?

Offline maro

  • Hero Member
  • *****
  • Posts: 1228
Re: Script to remaster with ntfs-3g included
« Reply #3 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.

Offline SvOlli

  • Full Member
  • ***
  • Posts: 193
  • Linux Developer
Re: Script to remaster with ntfs-3g included
« Reply #4 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. ;)

Offline Ulysses_

  • Full Member
  • ***
  • Posts: 232
Re: Script to remaster with ntfs-3g included
« Reply #5 on: November 04, 2010, 04:03:05 PM »
Beginner here, following instructions for installing TC inside a Windows system. 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]
« Last Edit: November 05, 2010, 12:59:00 PM by ^thehatsrule^ »

Offline maro

  • Hero Member
  • *****
  • Posts: 1228
Re: Script to remaster with ntfs-3g included
« Reply #6 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.

Offline SvOlli

  • Full Member
  • ***
  • Posts: 193
  • Linux Developer
Re: Script to remaster with ntfs-3g included
« Reply #7 on: November 04, 2010, 04:28:22 PM »
[removed: see remaster/remix sticky]
« Last Edit: November 05, 2010, 12:57:42 PM by ^thehatsrule^ »

Offline theYinYeti

  • Full Member
  • ***
  • Posts: 177
    • YetI web site
Re: Script to remaster with ntfs-3g included
« Reply #8 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.

Offline roberts

  • Administrator
  • Hero Member
  • *****
  • Posts: 7361
  • Founder Emeritus
Re: Script to remaster with ntfs-3g included
« Reply #9 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

Otherwise it is quite simple to use ezremaster and add the readily available extension ntfs-3g.tcz
into a single initrd.
10+ Years Contributing to Linux Open Source Projects.

Offline gerald_clark

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 4254
Re: Script to remaster with ntfs-3g included
« Reply #10 on: January 09, 2012, 03:53:07 PM »
Or 'cat core.gz ntfs-3g.gz > mycore.gz'.

Offline vinnie

  • Hero Member
  • *****
  • Posts: 1187
  • HandMace informatic works
Re: Script to remaster with ntfs-3g included
« Reply #11 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?

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11178
Re: Script to remaster with ntfs-3g included
« Reply #12 on: January 10, 2012, 05:55:17 AM »
Hi vinnie
No, it creates a file with the two .gz files back to back.

Offline vinnie

  • Hero Member
  • *****
  • Posts: 1187
  • HandMace informatic works
Re: Script to remaster with ntfs-3g included
« Reply #13 on: January 10, 2012, 03:27:59 PM »
so it was a mistake?  ???

Offline gerald_clark

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 4254
Re: Script to remaster with ntfs-3g included
« Reply #14 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.