我正在使用来自的脚本http://www.angstrom-distribution.org/demo/beagleboard/使用 mkfs.vfat 和 mkfs.e2fs 在 SD 卡上创建 2 个分区,但我得到了
mkfs.vfat 3.0.12 (29 Oct 2011)
mkfs.vfat: unable to open /dev/sdg1: Device or resource busy
编辑:这个脚本有问题。为了解决这个问题,我使用了http://code.google.com/p/beagleboard/wiki/LinuxBootDiskFormat
脚本如下
#! /bin/sh
# mkcard.sh v0.5
# (c) Copyright 2009 Graeme Gregory <[email protected]>
# Licensed under terms of GPLv2
#
# Parts of the procudure base on the work of Denys Dmytriyenko
# http://wiki.omap.com/index.php/MMC_Boot_Format
export LC_ALL=C
if [ $# -ne 1 ]; then
echo "Usage: $0 <drive>"
exit 1;
fi
DRIVE=$1
dd if=/dev/zero of=$DRIVE bs=1024 count=1024
SIZE=`fdisk -l $DRIVE | grep Disk | grep bytes | awk '{print $5}'`
echo DISK SIZE - $SIZE bytes
CYLINDERS=`echo $SIZE/255/63/512 | bc`
echo CYLINDERS - $CYLINDERS
{
echo ,9,0x0C,*
echo ,,,-
} | sfdisk -D -H 255 -S 63 -C $CYLINDERS $DRIVE
sleep 1
if [ -x `which kpartx` ]; then
kpartx -a ${DRIVE}
fi
# handle various device names.
# note something like fdisk -l /dev/loop0 | egrep -E '^/dev' | cut -d' ' -f1
# won't work due to https://bugzilla.redhat.com/show_bug.cgi?id=649572
PARTITION1=${DRIVE}1
if [ ! -b ${PARTITION1} ]; then
PARTITION1=${DRIVE}p1
fi
DRIVE_NAME=`basename $DRIVE`
DEV_DIR=`dirname $DRIVE`
if [ ! -b ${PARTITION1} ]; then
PARTITION1=$DEV_DIR/mapper/${DRIVE_NAME}p1
fi
PARTITION2=${DRIVE}2
if [ ! -b ${PARTITION2} ]; then
PARTITION2=${DRIVE}p2
fi
if [ ! -b ${PARTITION2} ]; then
PARTITION2=$DEV_DIR/mapper/${DRIVE_NAME}p2
fi
# now make partitions.
if [ -b ${PARTITION1} ]; then
umount ${PARTITION1}
mkfs.vfat -F 32 -n "boot" ${PARTITION1}
else
echo "Cant find boot partition in /dev"
fi
if [ -b ${PARITION2} ]; then
umount ${PARTITION2}
mke2fs -j -L "Angstrom" ${PARTITION2}
else
echo "Cant find rootfs partition in /dev"
fi
完整输出为:
1024+0 records in
1024+0 records out
1048576 bytes (1.0 MB) copied, 0.356157 s, 2.9 MB/s
Disk /dev/sdg doesn't contain a valid partition table
DISK SIZE - 7948206080 bytes
CYLINDERS - 966
Checking that no-one is using this disk right now ...
OK
Disk /dev/sdg: 966 cylinders, 255 heads, 63 sectors/track
sfdisk: ERROR: sector 0 does not have an msdos signature
/dev/sdg: unrecognized partition table type
Old situation:
No partitions found
New situation:
Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0
Device Boot Start End #cyls #blocks Id System
/dev/sdg1 * 0+ 8 9- 72261 c W95 FAT32 (LBA)
/dev/sdg2 9 965 957 7687102+ 83 Linux
/dev/sdg3 0 - 0 0 0 Empty
/dev/sdg4 0 - 0 0 0 Empty
Successfully wrote the new partition table
Re-reading the partition table ...
If you created or changed a DOS partition, /dev/foo7, say, then use dd(1)
to zero the first 512 bytes: dd if=/dev/zero of=/dev/foo7 bs=512 count=1
(See fdisk(8).)
umount: /dev/sdg1: not mounted
mkfs.vfat 3.0.12 (29 Oct 2011)
mkfs.vfat: unable to open /dev/sdg1: Device or resource busy
umount: /dev/sdg2: not mounted
mke2fs 1.42 (29-Nov-2011)
/dev/sdg2 is apparently in use by the system; will not make a filesystem here!
我试过了
sudo fuser -v /dev/sdg
sudo fuser -v /dev/sdg1
sudo fuser -v /dev/sdg2
但没有结果。谢谢
答案1
检查你的 LVM 没有窃取设备:
sudo dmsetup ls
如果您在那里看到您的设备,只需将其删除:
sudo dmsetup remove sdgX
答案2
Pekka Nikander 的回答对我很有帮助。
唯一的问题是你不能直接“dmsetup remove sdgX”。当 mkcard 脚本重新分区时,LVM 会抓取它们再次。因此,我运行了一次脚本,然后在取消窃取设备并注释掉脚本中的分区部分后再次重新运行它。
编辑:我相信他在 mkcard.txt 中注释掉的部分是以下几行:
if [ -x `which kpartx` ]; then
kpartx -a ${DRIVE}
fi