On Fri, May 01, 2009 at 12:25:44AM +0200, Dennis J. wrote:
On 05/01/2009 12:11 AM, Richard W.M. Jones wrote:
> On Thu, Apr 30, 2009 at 10:39:37PM +0100, Richard W.M. Jones wrote:
>> I haven't tried it, but it's possibly something you can do from
>> libguestfs, or if not, it's something that we could add to libguestfs.
>
> OK, I just added grub-install to libguestfs:
>
>
http://git.et.redhat.com/?p=libguestfs.git;a=commitdiff;h=b55bf8158f0b7f6...
>
> (Make sure you have a back up of your guest image before experimenting
> with this ...)
Looking at that patch wouldn't specifying /dev/sda as device actually
overwrite the physical boot sector on the host system rather than the one
in the image?
Or does libguestfs manipulate the device table so that access to /dev/sda
get automatically gets re-routed to access the image instead?
Neither. libguestfs boots a mini virtual machine, so /dev/sda really
is the right device all along.
Example usage:
$ guestfish
Welcome to guestfish, the libguestfs filesystem interactive shell for
editing virtual machine filesystems.
Type: 'help' for help with commands
'quit' to quit the shell
<fs> alloc /tmp/test 100M
<fs> run
qemu: loading initrd (0x157fd37 bytes) at 0x000000000f470000
<fs> sfdisk /dev/sda 0 0 0 ,
<fs> list-partitions
/dev/sda1
<fs> mkfs ext2 /dev/sda1
<fs> mount /dev/sda1 /
<fs> ll /
total 13
drwxr-xr-x 3 root root 1024 Apr 30 18:28 .
drwxr-xr-x 19 root root 0 Apr 30 18:27 ..
drwx------ 2 root root 12288 Apr 30 18:28 lost+found
<fs> grub-install / /dev/sda
<fs> ll /boot/grub/
total 236
drwxr-xr-x 2 root root 1024 Apr 30 18:28 .
drwxr-xr-x 3 root root 1024 Apr 30 18:28 ..
-rw-r--r-- 1 root root 30 Apr 30 18:28 device.map
-rw-r--r-- 1 root root 11736 Apr 30 18:28 e2fs_stage1_5
-rw-r--r-- 1 root root 11512 Apr 30 18:28 fat_stage1_5
-rw-r--r-- 1 root root 10744 Apr 30 18:28 ffs_stage1_5
-rw-r--r-- 1 root root 10736 Apr 30 18:28 iso9660_stage1_5
-rw-r--r-- 1 root root 12328 Apr 30 18:28 jfs_stage1_5
-rw-r--r-- 1 root root 10968 Apr 30 18:28 minix_stage1_5
-rw-r--r-- 1 root root 13360 Apr 30 18:28 reiserfs_stage1_5
-rw-r--r-- 1 root root 512 Apr 30 18:28 stage1
-rw-r--r-- 1 root root 111020 Apr 30 18:28 stage2
-rw-r--r-- 1 root root 11008 Apr 30 18:28 ufs2_stage1_5
-rw-r--r-- 1 root root 10344 Apr 30 18:28 vstafs_stage1_5
-rw-r--r-- 1 root root 12984 Apr 30 18:28 xfs_stage1_5
<fs> exit
$ ll /tmp/test
-rw-rw-r--. 1 rjones rjones 104857600 2009-04-30 23:28 /tmp/test
$ file /tmp/test
/tmp/test: x86 boot sector; GRand Unified Bootloader, stage1 version 0x3, 1st sector
stage2 0x25003, GRUB version 0.94; partition 1: ID=0x83, starthead 0, startsector 1,
192779 sectors, extended partition table (last)\011, code offset 0x48
Note that this does not require root privileges.
Rich.
--
Richard Jones, Emerging Technologies, Red Hat
http://et.redhat.com/~rjones
New in Fedora 11: Fedora Windows cross-compiler. Compile Windows
programs, test, and build Windows installers. Over 70 libraries supprt'd
http://fedoraproject.org/wiki/MinGW http://www.annexia.org/fedora_mingw