使用linux访问hd.img文件

来源:互联网 发布:德语网络课 编辑:程序博客网 时间:2024/06/05 14:35

#!/bin/bash
#Key Words:linux0.11 bochs harddisk bash
#mount hdimg name:hdimage-devel
#mount point:/mnt/initrd
hdimg=hdimage-devel
mpoint=/mnt/initrd

if [ "$1" == "mount" ]
then

    #mount hdimg
    echo "$1 START"
    sudo losetup /dev/loop1 "$hdimg" && /
    sudo fdisk /dev/loop1 && /
    sudo losetup -d /dev/loop1 && /

    
    #Command (m for help): x

    #Expert command (m for help): p

    #Disk /dev/loop1: 16 heads, 38 sectors, 410 cylinders

    #Nr AF  Hd Sec  Cyl  Hd Sec  Cyl     Start      Size ID
    # 1 00   0   3    0  15  38  203          2     124030 81
    # 2 00   0   1  204  15  38  407     124032     124032 81
    # 3 00   0   0    0   0   0    0          0          0 00
    # 4 00   0   0    0   0   0    0          0          0 00
    #2*512
    sudo losetup -o 1024 /dev/loop1
$hdimg && /
    sudo mount -t minix /dev/loop1 "$mpoint"
    echo "$1 END"

elif [ "$1" == "umount" ]
then

    #umount hdimg
    echo "$1 START"
    sudo umount /dev/loop1 && /
    sudo losetup -d /dev/loop1
    echo "$1 END"
else
    echo "Usage ./hd.sh [mount|umount]"
fi