6

I am using a script from http://www.angstrom-distribution.org/demo/beagleboard/ that uses mkfs.vfat and mkfs.e2fs to create 2 partitions on a sd card but I get

mkfs.vfat 3.0.12 (29 Oct 2011)
mkfs.vfat: unable to open /dev/sdg1: Device or resource busy

Edit: there's a problem with this script. As a workaround I used http://code.google.com/p/beagleboard/wiki/LinuxBootDiskFormat

The script is the following

#! /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

full output is:

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!

I've tried

sudo fuser -v /dev/sdg
sudo fuser -v /dev/sdg1
sudo fuser -v /dev/sdg2

but with no results. Thanks

5
  • What does mount | grep sdg say?
    – jippie
    Apr 23, 2012 at 20:47
  • It says nothing. No output.
    – gc5
    Apr 23, 2012 at 20:56
  • Does the device show up in ls -l /media ?
    – jippie
    Apr 23, 2012 at 21:02
  • No it doesn't mount, maybe because the partition table is corrupted or mkfs didn't end successfully
    – gc5
    Apr 23, 2012 at 21:08
  • I forgot to unmount the USB before deleting and creating a new partition on it. Only solution was to physically disconnect the USB and reconnect it. It then appeared as sdh instead of sdg after executing lsblk -f
    – gimmegimme
    Mar 2, 2023 at 15:38

2 Answers 2

4

Check that your LVM is not stealing the devices:

sudo dmsetup ls

If you see your devices there, simply remove them:

sudo dmsetup remove sdgX
1
  • I am sorry I am unable to test it; however I'll give an up vote to these answers, and accept this later. Thanks
    – gc5
    Jul 16, 2012 at 13:17
4

Pekka Nikander's answer did the trick for me.

The only issue is that you can't just "dmsetup remove sdgX". When the mkcard script repartitions, the LVM grabs them again. So, I ran the script once, and then reran it again after unstealing the devices and commenting out the partitioning sections in the script.

EDIT: I believe the part he commented out in mkcard.txt is the following lines:

if [ -x `which kpartx` ]; then
       kpartx -a ${DRIVE}
fi
2
  • Please comment or edit pekka's answer so I can accept it.
    – gc5
    Jul 16, 2012 at 13:17
  • Would love to, but I can't. There's no button to allow me to do so.
    – user77294
    Jul 24, 2012 at 6:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .