Hi,
May be this is well-known issue, but...
Problem description:
After building LFS, I want to check it, debug startup scripts,
check configs, etc.
Solution:
QEMU hard disc image; image accessible from host system
(not in time QEMU use it!), to copy/edit files on image from host system.
---------------------------
#!/bin/bash
#
# Create disc image for QEMU with bootable LFS
# Require ~1.2G of host system disc space
#
. ./LFS.sh
IMG_NAME=$LFS_BUILD/test.img
# Create QEMU image in raw format
# here: 63*16*2400*512 = 1238630400 = 1209600K
# note, that for QEMU max sectors 63, max heads 16, max cylinders 16383
qemu-img create -f raw $IMG_NAME 1209600 || exit 1
# Fill image by 0
losetup /dev/loop0 $IMG_NAME || exit 1
dd if=/dev/zero of=/dev/loop0 bs=1k count=1209600
losetup -d /dev/loop0
# Make two partitions on image
sfdisk -H 16 -S 63 -C 2400 $IMG_NAME <<EOF
unit: sectors
build/test.img1 : start= 63, size= 2015937, Id=83, bootable
build/test.img2 : start= 2016000, size= 403200, Id=82
build/test.img3 : start= 0, size= 0, Id= 0
build/test.img4 : start= 0, size= 0, Id= 0
EOF
# Make EXT3 filesystem on first partition of image
losetup -o 32256 /dev/loop0 $IMG_NAME || exit 1
mkfs -t ext3 -T small /dev/loop0 || exit 1
# Mount first partition of image on host system
mount /dev/loop0 /mnt || exit 1
# Copy grub's files to image; create bootable 'floppy' (need only once, during
writing MBR)
mkdir -p /mnt/boot/grub
cp $LFS/boot/grub/stage1 $LFS/boot/grub/stage2 $LFS/boot/grub/e2fs_stage1_5
/mnt/boot/grub/
cat $LFS/boot/grub/stage1 $LFS/boot/grub/stage2 > $LFS_BUILD/grubboot.img
cat > /mnt/boot/grub/menu.lst <<EOF
default 0
timeout 30
root (hd0,0)
title linux-2.6.24.5
kernel (hd0,0)/boot/linux-2.6.24.5 root=/dev/hda1
EOF
# Copy LFS to image
(cd $LFS; tar cf - bin boot etc home lib media mnt opt proc root sbin srv tmp
usr var ) | \
(cd /mnt; tar xf - )
# Create some devices for LFS
mkdir -p /mnt/{dev,proc,sys}
mknod -m 600 /mnt/dev/console c 5 1
mknod -m 666 /mnt/dev/null c 1 3
# Unmount guest image from host system
umount /mnt
losetup -d /dev/loop0
#
# Write grub into MBR of image:
#
# qemu -hda $IMG_NAME -hdachs 2400,16,63 -fda $LFS_BUILD/grubboot.img -boot a
#
# grub> root (hd0,0)
# Filesystem type is ext2fs, partition type 0x83
#
# grub> setup (hd0)
# Checking if "/boot/grub/stage1" exists... yes
# Checking if "/boot/grub/stage2" exists... yes
# Checking if "/boot/grub/e2fs_stage1_5" exists... yes
# Running "embed /boot/grub/e2fs_stage1_5 (hd0)"... 15 sectors are embedded.
succeeded
# Running "install /boot/grub/stage1 (hd0) (hd0)1+15 p
(hd0,0)/boot/grub/stage2/boot/grub/menu.lst"... succeeded.
# Done.
#
# Quit by pressing ^C q in the shell from which you launched qemu,
# or Ctrl-Alt-2 quit in QEMU window.
#
#
# Now start LFS-based system on image:
#
# qemu -hda $IMG_NAME -hdachs 2400,16,63 -boot c
#
#
# If you see something like
#
# ...: attempt to access beyond end of device
# hda1: rw=32, want=2097176, limit=2088387
# EXT3-fs error ... unable to read inode block - inode=120578, block=262146
#
# then, probably, you miss dd if=/dev/zero of=/dev/loop0 bs=1k count=1209600
#
--
- ptr
--
http://linuxfromscratch.org/mailman/listinfo/lfs-dev
FAQ: http://www.linuxfromscratch.org/faq/
Unsubscribe: See the above information page