Creating a SKI disk image

Create the disk

Your disk size is based on the formula  size = ((SIZE_IN_MB * 1024 * 1024) - 512) / 512  ; i.e. the total size of the disk in 512 byte sectors, minus a boot sector.

Once you know how big you want the image, create it with dd as such, where count is the size you previous worked out (example below is for 1GB == 1024MB)

[root@localhost]/nue/var/ski-disks# dd of=adisk if=/dev/zero bs=512 count=2097151
2097151+0 records out
[root@localhost]/nue/var/ski-disks# ls -l
...
-rw-r--r--    1 root     root     1073741312 Apr  8 14:39 adisk
...

Once done, format the disk as ext2

[root@localhost]/nue/var/ski-disks# /sbin/mke2fs ./adisk
mke2fs 1.32 (09-Nov-2002)
./adisk is not a block special device.
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
131072 inodes, 262143 blocks
13107 blocks (5.00%) reserved for the super user
First data block=0
8 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376

Writing inode tables: done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 30 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

Put in room for a boot sector

Add in some space in your image for your boot sector, and output it to a file called 'sd[letter]' where letter is the next disk letter. By default, this file goes in  /nue/var/ski-disks/ and gets linked from /var/ski-disks. Make sure it has world read/write permissions (you don't have to -- but if you use ski as a normal user later and forget to give rw permissions to the world group it will probably not find the disk).

[root@localhost]/nue/var/ski-disks# dd of=bootsector if=/dev/zero count=1 bs=512
1+0 records in
1+0 records out
[root@localhost]/nue/var/ski-disks# cat bootsector adisk > sdc
[root@localhost]/nue/var/ski-disks# ln -s sdc /var/ski-disks/sdc
[root@localhost]/nue/var/ski-disks# chmod a+wr sdc

Add what you want to the disk

Mount the disk locally, copy files to it, unmount.

[root@localhost]/nue/var/ski-disks# mount -t ext2 -oloop,offset=512 sdc /mnt/other
[root@localhost]/nue/var/ski-disks# touch /mnt/other/hello
[root@localhost]/nue/var/ski-disks# umount /mnt/other

You can also use debootstrap to create a complete Debian root environment, as an alternative to the RedHat root disk that comes with Ski.

Start x/ski

Start ski (or xski) and watch the kernel output to make sure it finds your new disk

SCSI device sdc: 2097152 512-byte hdwr sectors (1074 MB)
sdc: cache data unavailable
sdc: assuming drive cache: write through
 sdc: unknown partition table
Attached scsi disk sdc at scsi0, channel 0, id 2, lun 0

Create a partition table

To create the partition table you need to work out the geometry of your virtual drive. There are three concepts

Imagine the heads reading the disk as heads do. There may be many platters in a hard disk, both sides of which can be read, so each side needs it's own head. Cylinders are basically tracks, but extended down three dimensionally to form a cylinder with the disk platter below it. Sectors are how many sectors are in each cylinder. The total size of a disk is  disk size =  heads * cylinders * (sectors per cylinder) * 512  (512 is the size of a sector in bytes).

Disk partitions *must* start on cylinder boundaries, so we need to spoof the geometry to be able to read the partition on the disk. The easiest way is to imagine there is only one 512 byte sector per cylinder, but we have *lots* of cylinders (you could also do this with less cylinders but more heads, but there is a hard limit of 256 heads, so this would limit the size of our disk). The number of cylinders you need is derived from above, assuming we use the most number of heads we can

 cylinders = disk size / heads (256) / 512 / 1 

e.g. for our 1GB disk it is  1024 * 1024 * 1024 / 256 / 512 = 8192 cylinders 

use fdisk on the disk image to write the partition table. Go into the extended menu to setup your geometry, then just create a single partition the whole size of the disk using the defaults.

bash-2.04# fdisk /dev/sdc
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklab
el
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.


Command (m for help): x

Expert command (m for help): c
Number of cylinders (1-131071, default 1024): 8192

The number of cylinders for this disk is set to 8192.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Expert command (m for help): s
Number of sectors (1-63, default 32): 1
Warning: setting sector offset for DOS compatiblity

Expert command (m for help): h
Number of heads (1-256, default 64): 256

Expert command (m for help): r

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-8192, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-8192, default 8192):
Using default value 8192

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: If you have created or modified any DOS 6.x
partitions, please see the fdisk manual page for additional
information.
Syncing disks.

Mount the disk

Now you can mount and use the disk in the ski emulator!

bash-2.04# mount /dev/sdc1 /mnt
bash-2.04# cd /mnt
bash-2.04# ls
hello  lost+found
bash-2.04# cd
bash-2.04# umount /mnt

Notes

IA64wiki: skidiskimage (last edited 2005-02-14 01:31:53 by brahms)

Gelato@UNSW is sponsored by
the University of New South Wales National ICT Australia The Gelato Federation Hewlett-Packard Company Australian Research Council
Please contact us with any questions or comments.