mkfs.vfat: não é possível abrir / dev / sdg1: dispositivo ou recurso ocupado

5

Estou usando um script do link que usa mkfs.vfat e mkfs.e2fs para criar duas partições em um cartão SD, mas eu recebo

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

Edit: há um problema com este script. Como solução alternativa, usei o link

O script é o seguinte

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

a saída completa é:

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!

Eu tentei

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

mas sem resultados. Obrigado

    
por gc5 23.04.2012 / 22:20

2 respostas

5

Verifique se o seu LVM não rouba os dispositivos:

sudo dmsetup ls

Se você vir seus dispositivos lá, basta removê-los:

sudo dmsetup remove sdgX
    
por Pekka Nikander 03.07.2012 / 09:42
4

A resposta de Pekka Nikander fez o truque para mim.

O único problema é que você não pode apenas "remover o dmsetup do sdgX". Quando as repartições do script mkcard, o LVM as pega novamente . Então, eu corri o script uma vez e, em seguida, reran novamente depois de unstealing os dispositivos e comentando as seções de particionamento no script.

EDIT: Eu acredito que a parte que ele comentou no mkcard.txt é as seguintes linhas:

if [ -x 'which kpartx' ]; then
       kpartx -a ${DRIVE}
fi
    
por user77294 16.07.2012 / 08:57

Tags