WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: tcvd boot parameter  (Read 3983 times)

Offline danielibarnes

  • Hero Member
  • *****
  • Posts: 548
tcvd boot parameter
« on: July 11, 2009, 04:59:55 PM »
I'd like to propose an additional feature for the tcvd= boot parameter.

My virtual HDD is not a simple ext2 loopback image. Because I use it as a virtual HD with QEMU, it has a partition table with three partitions: 1 is shared data, 2 is 1.x-specific extensions and backup, and 3 is 2.x specific extensions and backup. The current implementation of the option does not handle partitions.

I modified the /etc/init.d/tc-config to allow a syntax in the form of tcvd=tcvd.img:n where n is the partition number. In my case, I can boot 1.x with "tcvd=tcvd.img:2 tce=tcvd restore=tcvd" and 2.x with "tcvd=tcvd.img:3 tce=tcvd restore=tcvd."

Does this sound like a useful feature for 2.2? I am including my diff on the 2.1 tinycore.gz below:
Code: [Select]
--- old/etc/init.d/tc-config    Sat Jul 11 14:30:23 2009
+++ new/etc/init.d/tc-config    Sat Jul 11 14:29:42 2009
@@ -330,4 +330,6 @@
 if [ -n "$TCVD" ]; then
   wait $fstab_pid
+  TCVDP="${TCVD#*:}"
+  TCVD="${TCVD%:*}"
   TCVD="${TCVD#/}"
   TCVD="${TCVD#dev/}"
@@ -346,4 +348,9 @@
        ln -sf "$MOUNTPOINT"/"$TCVD_LOOPFILE" /dev/tcvd
-        printf "/dev/tcvd \t/mnt/tcvd \text2\tloop\t0 0 #Added by TC\n" >> /etc/fstab
+       if [ -n "$TCVDP" ]; then
+         TCVDO=$(/sbin/fdisk -l -u /dev/tcvd | grep /dev/tcvd$TCVDP | awk '{print $2}' | head -1)
+         [ -n "$TCVDO" ] && TCVD_OFFSET=,offset=$(( 512 * $TCVDO ))
+       fi
+       printf "/dev/tcvd\t/mnt/tcvd\text2\tloop%s\t0 0 #Added by TC\n" "$TCVD_OFFSET" >> /etc/fstab
        sync
      fi

Note that incorrect use where n is omitted as in "tcvd=tcvd.img:" or where n is a non-existent partition should not cause errors or an invalid entry in fstab.

Thanks,
Daniel
« Last Edit: July 11, 2009, 06:41:13 PM by danielibarnes »

Offline roberts

  • Retired Admins
  • Hero Member
  • *****
  • Posts: 7361
  • Founder Emeritus
Re: tcvd boot parameter
« Reply #1 on: July 11, 2009, 05:33:35 PM »
Thanks for sharing.  I will incorporate for v2.2 next rc.
10+ Years Contributing to Linux Open Source Projects.

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11044
Re: tcvd boot parameter
« Reply #2 on: July 11, 2009, 05:35:20 PM »
Unless I'm missing something, the patch above would add two fstab entries for /dev/tcvd?
The only barriers that can stop you are the ones you create yourself.

Offline danielibarnes

  • Hero Member
  • *****
  • Posts: 548
Re: tcvd boot parameter
« Reply #3 on: July 11, 2009, 06:43:20 PM »
Unless I'm missing something, the patch above would add two fstab entries for /dev/tcvd?

Sorry, that was a typo. I fixed it. There was a missing "-" at the front of the first printf.

Offline roberts

  • Retired Admins
  • Hero Member
  • *****
  • Posts: 7361
  • Founder Emeritus
Re: tcvd boot parameter
« Reply #4 on: July 11, 2009, 07:06:36 PM »
Daniel, I need to test this code before I include it. Not being a Qemu user, and being lazy, what are the options, I assume, to qemu-img to make partitions on .img file?
10+ Years Contributing to Linux Open Source Projects.

Offline danielibarnes

  • Hero Member
  • *****
  • Posts: 548
Re: tcvd boot parameter
« Reply #5 on: July 11, 2009, 10:59:48 PM »
Daniel, I need to test this code before I include it. Not being a Qemu user, and being lazy, what are the options, I assume, to qemu-img to make partitions on .img file?

The qemu-img app cannot create partitions, only the image file. I typically create the partitions and format them within qemu, but you can use fdisk like so:

# fdisk -C $(( $(stat -c %s tcvd.img) / 255 / 63 / 512 )) tcvd.img

My partition table looks like this:

Disk tcvd.img: 0 MB, 0 bytes
255 heads, 63 sectors/track, 114 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks  Id System
tcvd.img1               1          38      305203+ 83 Linux
tcvd.img2              39          76      305235  83 Linux
tcvd.img3              77         114      305235  83 Linux

The next question is, how do you format a partition? Outside of qemu, you can use losetup. First, display the partition table with sectors:

# fdisk -l -u -C $(( $(stat -c %s tcvd.img) / 512 )) tcvd.img

Disk tcvd.img: 0 MB, 0 bytes
255 heads, 63 sectors/track, 1843200 cylinders, total 0 sectors
Units = sectors of 1 * 512 = 512 bytes

   Device Boot      Start         End      Blocks  Id System
tcvd.img1              63      610469      305203+ 83 Linux
tcvd.img2          610470     1220939      305235  83 Linux
tcvd.img3         1220940     1831409      305235  83 Linux

Then use a few calculations to setup the loop device:

# OFFSET=$((512 * $START))
# SIZE=$((512 * $END - $OFFSET))
# losetup --offset $OFFSET --sizelimit $SIZE --find tcvd.img

where $START and $END are the start and end columns for a particular partition, like 610470 and 1220939 for the second partition. Use mke2fs on the loop device like a normal partition.

EDIT: Corrected error
« Last Edit: July 12, 2009, 09:18:50 AM by danielibarnes »

Offline roberts

  • Retired Admins
  • Hero Member
  • *****
  • Posts: 7361
  • Founder Emeritus
Re: tcvd boot parameter
« Reply #6 on: July 12, 2009, 12:58:30 AM »
Sorry, what started out as a simple mod to tc-config, seemingly depends on a rather esoteric procedure. Do you really feel that the community would benefit from having to perform such?

It would appear that the same result could be achieved by simply using directories on the virtual hard drive.
10+ Years Contributing to Linux Open Source Projects.

Offline danielibarnes

  • Hero Member
  • *****
  • Posts: 548
Re: tcvd boot parameter
« Reply #7 on: July 12, 2009, 08:54:38 AM »
Working with partitions in a loopback file outside of qemu is definitely difficult (as evidenced by the subtle error in my instructions above). I always do it within qemu where it is the same as a regular HDD.

I have the image on a usb flash drive which I run with qemu and boot natively. I created the partitions out of habit, and so I created the special syntax without thinking there might be a more obvious solution. I can use "tcvd=tcvd.img tce=tcvd/tce1 restore=tcvd/restore1" when booting natively and "tce=hda/tce1 restore=hda/restore1" within qemu.

I think maybe I was trying to make it more difficult than it needs to be. I'll just put it all in a single ext2 loopback file to keep it simple.

Offline roberts

  • Retired Admins
  • Hero Member
  • *****
  • Posts: 7361
  • Founder Emeritus
Re: tcvd boot parameter
« Reply #8 on: July 12, 2009, 10:29:46 AM »
Note too that you can simplify your boot options by moving mydata.tgz into the tce directory and then dropping the restore boot option as the system will use the tce boot option to find your backup.
10+ Years Contributing to Linux Open Source Projects.

Offline yooka

  • Newbie
  • *
  • Posts: 1
Re: tcvd boot parameter
« Reply #9 on: August 21, 2009, 11:45:33 AM »
(Hi there - my first post   :) )

I found just using qemu-img to create a 'simple' image results in a 1-partition
image with an mbr at the start. This is incompatible with the tcvd= boot code
because the loop mount does'nt expect the mbr to be there.

This means instead of using qemu-img, it is better to create the img in tc
using dd and then formatting it to ext2. Then it's both bootable as tcvd
and qemulator.