WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Anyone using syslinux to chainload partition with TinyCore-7.2.iso dd'ed to it?  (Read 2538 times)

Offline KsWoodsMan

  • Newbie
  • *
  • Posts: 6
I'm REALLY liking TinyCore 7.2 and have a project in mind for it.
What I'm trying to do is partition an 8GB usb thumbdrive with 4 partitions.
As reported by # fdisk -l /dev/sdx , the C/H/S is 7890/64/32. I have confirmed the location of the partitions by mounting the disk with the correct offsets fed to mount and losetup respectively.

The first partition is the lions share of the disk and is formatted to Fat32. Windows sees this one and will read/write to it without fail.
The second part is the 16MB image of TinyCore-7.2.iso dd'ed directly to /dev/sdx2.
The third partition is 200+ MB and formatted to ext3 for my tce directory.
The 4th partition is 32MB and formatted to fat16. It has syslinux on it and will currently boot without issues. I can install TC and/or a kernel and alternate initrd to it , adding their configuration to  /dev/sdx4/boot/syslinux and it's golden, ( it works ).

What I'm running into is, I want to boot TC from the partition with the iso written to it. I ALSO want those files to be READ ONLY to prevent mucking about in the fs.
Writing it directly to the disk doesn't work well for me. It boot fine . It is quick to load and everything gets found correctly. BUT it grabs the whole disk.
Yes, I could move the beginning of the 1 partition on the .iso to something other than 0 or the first hdd sector to something with a multiple of 4 to match the 2048 byte sector size on the .iso's format. ? But then windows  doesn't see the Fat/NTFS formatted partition set aside for it.

Way back when, it was a trivial matter to write a bootsector that pointed to whatever partition your linux installation was on and have ntldr boot your Linux partition/install from the NT boot.ini file.

I'm trying to accomplish this same thing having syslinux/chain.c32 chainload a .bss file with the 2nd partition (TC.iso) marked active.

I have tried using the  original boot sector with it's isolinux code intact using fdisk to point it to the correct offset, dd'ing it out to /mnt/sdx/boot/syslinux/TinyCore.bss .
On both the 512 byte boot sector file in /boot/syslinux and the mbr located at the beginning of the partition I've tried several combinations.

 I've left the original and unmolested MBR from the iso on the partition.
I've zeroed the original on the partition from byte 0 to 440.
I've zeroed the original on the partition from byte 446 to 510 clearing the partition table.
I've zeroed the original on the partition completely from byte 0 to 512.
Ive played with each combination AND manipulating the partition tables on the written partition to point to that  location, the next sector, the 4th, 8th, 16th & 32nd sector on the partition.  Each attemp has also had that  location marked active as well as not marked active.

You ask , Why not use a different boot loader ?!
Simple. Syslinux only requires it to be installed once. From there changing the configuration files is a trivial matter. Changes can be done with any text editor  including  cat and echo. It doesn't require updating  or even having syslinux installed in the  OS editing it.

Am I missing something with chain.c32 in the syntax ?
LABEL tc-iso
KERNEL /boot/syslinux/chain.c32
APPEND /boot/TinyCore.bss

« Last Edit: April 06, 2017, 11:58:08 AM by KsWoodsMan »

Offline KsWoodsMan

  • Newbie
  • *
  • Posts: 6
I found a GOOD work-around for what I want.

I dd'ed the hybrid iso TinyCore-7.2.iso to my /dev/sdx with
dd if=$(path_to_isos)/TinyCore/TinyCore-7.2.iso bs=128K of=/dev/sdx oflag=direct
and to clear the partition table
dd bs=1 count=64 if=/dev/zero of=/dev/sdx seek=446
This left the isolinux code in the first 440 bytes of the MBR as well as the disk label from offset 440 - 446, the partition record and the MBR identifier in the last 2 bytes

To set the first data sector on the HDD to sector 4, give it the remainder of the first 16 cylinders, mark it as a hidden partition and to set it active ( bootable),
Using sfdisk from a command prompt in KNOPPIX I issued

sfdisk -N 4 -u S /dev/sdx
4  32764  17  *
y

 I was amused when sfdisk gave some warnings pertaining to DOS
<ignored>... eh blah blah .. zero the first sector ... blah blah . </ignored>
This starts the 4th partition at offset 2048 or the 4th 512 Byte sector. It gives it the remainder of the 16 cylinders or sectors 4 through 32768 for a size of 32764 sectors for the iso9660 fs. Partition #4 can be mounted as an iso that is read only. It is also set active to be bootable and is not visible to most applications in Windows.

This satisfied booting from the iso. It doesn't try to grab the entire usb disk anymore when accessing /mnt/sd?/cde. Now it finds cde at /mnt/sdx4/cde and I can mount and umount the rest of the partitions without hassle.

While back in TC-7.2 , using fdisk from there I was able to create 2 more partitions at /dev/sdx1 and /dev/sdx3
Partition1 was the next  so many cylinders leaving room for a small partition at the end.
This satisfied Windows that it was now the first partition on the disk and it was happy . It can read and write to it.
My portable files can be transferred to and from there and they are good to go.

The last partition is for a tce directory and have a bit of room for any mydata.tcz or stray executables and scripts. And Now it is good too.

After creating filesystems on the device partitions. I can now boot freely between TC-7.2 on the usb stick and Windows on the internal HDD. Windows can do what it wants with the large partition there and those files are available to me when I need them.

When I need TC, I have a much more powerful command set at my finger tips , it's there.
If I just want to  carry some files with me between computers or to a computer off the grid  I have them with me on the same stick.

If someone starts mucking about deleting/editing files in the Fat32 partition They haven't really gone away. Just hiding waiting for photorec to  get them back.

The trickiest part was to write back an isolinux.cfg file to the ro isofs located on the usbstick.
But hexdump and dd are friends of mine and were up to the task to cure that woe of mine.
After trimming the descriptions a bit , 1445 bytes was enough room to add consoleblank=0 multivt and waitusb=15 to core-w.

:D Life IS Good ! :D
« Last Edit: April 06, 2017, 03:01:18 PM by KsWoodsMan »

Offline KsWoodsMan

  • Newbie
  • *
  • Posts: 6
Well .....
It was almost like I wanted but close enough.

I didn't inject or remove a sector in the original iso or offset my start point for /dev/sdx4 by 1+- depending on whether I injected or  omitted a blank sector from near the beginning. It still sees the whole disk as an iso9660 fs. Which means it still grabs the entire disk blocking any other mount attempts to the rest of the partitions.

one of these days, I'll get around to running
dd  bs=512 skip=1 if=/dev/sdx4 of=/dev/sdx4

and then
sfdisk -N 4 /dev/sdx
3 32765 17 *
y

That should take care of things.

That will still give me 2 sectors between the MBR and the first allocated partition to keep a backup of the altered and the original MBR.

Offline polikuo

  • Hero Member
  • *****
  • Posts: 714
The first partition is the lions share of the disk and is formatted to Fat32. Windows sees this one and will read/write to it without fail.
The second part is the 16MB image of TinyCore-7.2.iso dd'ed directly to /dev/sdx2.
The third partition is 200+ MB and formatted to ext3 for my tce directory.
The 4th partition is 32MB and formatted to fat16. It has syslinux on it and will currently boot without issues. I can install TC and/or a kernel and alternate initrd to it , adding their configuration to  /dev/sdx4/boot/syslinux and it's golden, ( it works ).

What I'm running into is, I want to boot TC from the partition with the iso written to it. I ALSO want those files to be READ ONLY to prevent mucking about in the fs.
If I were you, I would format my disk like this:
Partition 1 fat32/ntfs big partition for M$ (with a M$ bootable image if I feel like to)
Partition 2 partition for tce directory, syslinux, tinycore CD
Partition 3 (optional) swap partition

FYI.
Install extlinux on partition 2.
Copy Tiny-Core-iso to your syslinux/extlinux/boot directory (depends on how you install it)
Copy memdisk to boot the iso file (easier to upgrade)
(See http://www.syslinux.org/wiki/index.php?title=MEMDISK)
Rename the tce directory and modify the syslinux.cfg/extlinux.conf to prevent tiny core iso to load the directory.
For example:
Code: [Select]
mv tce tceusb
vi extlinux.conf
APPEND tce=UUID="your-partition-uuid"/tceusb ...

Quote
Am I missing something with chain.c32 in the syntax ?
LABEL tc-iso
KERNEL /boot/syslinux/chain.c32
APPEND /boot/TinyCore.bss
I guess you are using syslinux 4.x
If you move forward to 6.0.3
You need to change this
KERNEL /boot/syslinux/chain.c32
to
COM32 /boot/syslinux/chain.c32
and add libcom32.c32, libutil.c32 to your syslinux directory
http://www.syslinux.org/wiki/index.php?title=Library_modules
I'm not sure with the "TinyCore.bss" thing though.

P.S.
M$ load the first readable partition and assign letter to it.
i.e. the fat32/ntfs big partition does not necessarily have to be the first on your USB.  ;)

Offline KsWoodsMan

  • Newbie
  • *
  • Posts: 6
As i turns out the iso can be mounted at offset 0 , 2048 and 4096. I was wrong about that earlier but moving forward..
@Polikuo , I did end up doing something like you suggested with the partitioning scheme. I mentioned that earlier ( I thought ).

Trimming a sector out between the MBR and the data portion of the iso didn't help. The partition was still mountable but booting the thumb drive failed.  Trimming another didn't make it get  better. So I started over as described below.
 
First I dd'ed the hybrid iso TinyCore-7.2. iso to /dev/sdx (again).

The first partition entry started on sector 0 and was 32768 sectors in size.
This wasn't going to work for Windows. It would see a raw 16MB disk and couldn't read from or write to it without formatting the partition.
 
With a pre-GPT version of sfdisk , I changed the 1st entry to the 4th in the MBR. The 4th entry is now sector 4 - 32767 .type 17 and it is active.
 
The first entry now starts on sector 32768 and extends to near the end of the disk and set to type 0b.
The second entry is approx 200 MB ext3 and takes up the remainder of the disk.
The third entry is blank. No swap on flash media.
The fourth entry is still the first 16MB of the disk starting at sector 4 , type 17 and active.

It will boot from it as expected. The (4th) partition (entry) with the iso written to it is read only.
I do have a tce directory on the 2nd partition (entry) at the end of the disk.
The first partition entry works  under windows. I have written to it a few time, formatted it and viewed it in DiskManagement console. It shows the layout as it is on the disk and doesn't try switching the order or arrangement.

I took the looong way to get to a simple solution. I'mma just stop there. 

Offline KsWoodsMan

  • Newbie
  • *
  • Posts: 6
I did figure out why booting failed after trimming blank space from the  beginning of the iso/hdd .
It turns out that isolinux in the mbr is expecting its bin file to be at a certain offset. Trimming the iso moved it's location and brought things to a screeching halt.

Anyone else remember rebooting to see " Li " on their monitor after a corrupted disk mishap or a failed attempt at a new installation ?

Yup ,  that takes me back.  [cheers] 

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 10960
FYI, I think a simpler solution would have been two partitions, the first fat32 for windows, the second ext2 for linux. You would then have marked the boot core files immutable, which makes them read-only even to root. This would protect them from accidental writes just as well as a read-only FS in a separate partition, and the risk of raw writes corrupting things is the same for both solutions.
The only barriers that can stop you are the ones you create yourself.

Offline KsWoodsMan

  • Newbie
  • *
  • Posts: 6
@Curaga , That partitioning scheme is similar to what I've ended up with. I took the scenic  route getting there was all.

I hadn't considered using chattr to set any file attributes to immutable.
I had considered using GPT tables and setting the attributes of an entire partition to read only with gdisk. This would keep me from errantly destroying the partition or writing to a filesystem mounted there. That is, as long as the OS recognizes and respects GPT entries.

Thanks Everyone.