Tiny Core Linux
Tiny Core Base => TCB Talk => Topic started by: danielibarnes on July 11, 2009, 01: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:
--- 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
-
Thanks for sharing. I will incorporate for v2.2 next rc.
-
Unless I'm missing something, the patch above would add two fstab entries for /dev/tcvd?
-
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.
-
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?
-
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
-
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.
-
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.
-
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.
-
(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.