介紹
losetup 是用來把 file mount 成 block device 的工具來,
我可應用在 mount dd 的 raw image
應用
查看有什麼東西在 mount 中:
# -a | --all
losetup -a
/dev/loop0: [fe02]:16465924 (/xen/domains/debian6/disk.img) /dev/loop1: [fe02]:16465923 (/xen/domains/debian6/swap.img) /dev/loop3: [fe00]:4554764 (/home/iso/CentOS-6.3-i386-minimal.iso) /dev/loop4: [fe02]:16465926 (/xen/domains/centos6/centos6.img)
詳細資料
losetup [-l]
NAME SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE DIO LOG-SEC /dev/loop0 0 0 0 0 /home/recovery_disk/sde.img 0 512
AUTOCLEAR
--detach 後但 device 仍是 actively 就會 flag and destroyed later
找到下一個可用的 loop device:
# -f | --find
# --show Display the name of the assigned loop device if the -f option
# -P, --partscan Force the kernel to scan the partition table on a newly created loop device.
losetup -f
/dev/loop2
建立 loop mount (image->block):
losetup /dev/loop0 /root/hdd.img
detach device
# -d, --detach
losetup -d /dev/loop0
其他功能:
-r, --read-only
-j, --associated file # show status of all loop devices associated with given file
Example
# loop device 放在中間 !!
losetup -r /dev/loop0 /mnt/vm/winxp/winxp-vio.raw
Kenerl modules
/etc/modules
loop
/etc/modprobe.conf
options loop max_loop=64
modprobe loop
所有 loop device 都是 major=7 的
loop0 b 7 0 loop1 b 7 1 loop2 b 7 2
建立: loop8
mknod -m 660 /dev/loop8 b 7 8
Mount Full HardDisk Image
一般而言, mount partition image 會比較容易
# mount partition image
losetup -r /dev/loop0 sdc2.img
# mount disk image
file winxp-vio.raw
winxp-vio.raw: x86 boot sector, Microsoft Windows XP MBR, Serial 0x2bc02bbf; partition 1: ID=0x7, active,
starthead 1, startsector 63, 41942977 sectors, code offset 0xc0
file win7-data.raw
win7-data.raw: x86 boot sector
找出 partition 的 start 位置
parted winxp-vio.raw
# 把 display unit 改成 byte
unit b <-- byte
Number Start End Size Type File system Flags
1 32256B 21474836479B 21474804224B primary ntfs boot
# mount partition
losetup -r -o 32256 /dev/loop0 winxp-vio.raw
-r, --read-only
-o offset # offset = "Start byte"
# 測試是否成功 mount 起
blkid /dev/loop0
/dev/loop0: LABEL="winxp" UUID="187040E87040CDE6" TYPE="ntfs"