Tiny Core Linux

Tiny Core Base => TCB Q&A Forum => Topic started by: bbenson on February 26, 2015, 08:18:43 PM

Title: Refresh USB devices after partitioning
Post by: bbenson on February 26, 2015, 08:18:43 PM
Hi folks, this is my first post here and I am a first time user running Tiny Core installed to a VirtualBox VM.

I ran into a problem while writing a script that will format a USB mounted SD card with four partitions, and then copy files over to each of the partitions.

I'm doing the following in a sh script:

Code: [Select]

dd if=/dev/zero of=$DEVICE bs=1024 count=1024

{
echo ,9,0x0c,*
echo ,$(expr $CYLINDERS / 4),,-
echo ,$(expr $CYLINDERS / 4),,-
echo ,,0x0c,-
} | sfdisk -D -H 255 -S 63 -C $CYLINDERS $DEVICE

# creates four partitions
mkfs.vfat -F 32 -n boot ${DEVICE}1
mkfs.ext4 -L rootfs ${DEVICE}2
mkfs.ext4 -L userdata ${DEVICE}3
mkfs.vfat -F 32 -n other ${DEVICE}4

mount ${DEVICE}1
cp ~/files/* /mnt/$MOUNT
umount ${DEVICE}1


This gives the error
mount: can't find /dev/sdb1 in /etc/fstab

cp also says that there's no space left on the device.

I know this approach works on other distros, and I'm thinking maybe in this case fstab isn't being updated before I try to mount the new partitions. I searched for hours and can't really find what I'm looking for.

So I guess my question is, how can I refresh or regenerate fstab so that I can mount newly created partitions?

Many thanks in advance,
Bruce
Title: Re: Refresh USB devices after partitioning
Post by: Rich on February 26, 2015, 10:15:29 PM
Hi bbenson
Quote
So I guess my question is, how can I refresh or regenerate fstab so that I can mount newly created partitions?
You could try:
Code: [Select]
sudo rebuildfstab
Title: Re: Refresh USB devices after partitioning
Post by: bbenson on February 27, 2015, 08:38:55 AM
You could try:
Code: [Select]
sudo rebuildfstab

Thank you for the reply, Rich. I did try that after finding rebuildfstab listed in the udev rules for USB devices. It doesn't seem to be picking up the changes to the device. When I run the script, the USB device (/dev/sdb) disappears completely from fstab. rebuildfstab doesn't seem to do anything to bring it back.
Title: Re: Refresh USB devices after partitioning
Post by: bbenson on February 27, 2015, 10:25:18 AM
I'm finding this is happening when I just plug a USB device in normally as well. dmesg will say that there is a SCSI removable disk attached to /dev/sdc, but then it doesn't show up in fstab. Where is the disconnect here?
Title: Re: Refresh USB devices after partitioning
Post by: gerald_clark on February 27, 2015, 10:30:47 AM
fstab will not show sdb or sdc.
It only shows partitions that have filesystems on them, not the raw devices.
Title: Re: Refresh USB devices after partitioning
Post by: bbenson on February 27, 2015, 10:55:26 AM
fstab will not show sdb or sdc.
It only shows partitions that have filesystems on them, not the raw devices.

Isn't mkfs building the file systems?
Title: Re: Refresh USB devices after partitioning
Post by: core-user on February 27, 2015, 11:15:38 AM
Filesystems will be on /dev/sdb1 or /dev/sdc1..... ;)
Title: Re: Refresh USB devices after partitioning
Post by: bbenson on February 27, 2015, 11:19:50 AM
Filesystems will be on /dev/sdb1 or /dev/sdc1..... ;)

I agree. They should show up as enumerations on the base name, sdb or sdc. But they don't. Not unless I disconnect the device and connect it again. How can I manually jog the device bus so that TinyCore will pick up the newly written file systems on the device?
Title: Re: Refresh USB devices after partitioning
Post by: curaga on February 27, 2015, 11:49:31 AM
The util-linux partx tool is for this purpose, though at least fdisk also does it by itself. Curious that sfdisk does not.
Title: Re: Refresh USB devices after partitioning
Post by: Rich on February 27, 2015, 11:53:02 AM
Hi bbenson
Are you saying  rebuildfstab  works after unplugging/replugging your device?
Title: Re: Refresh USB devices after partitioning
Post by: bbenson on February 27, 2015, 12:04:22 PM
Hi bbenson
Are you saying  rebuildfstab  works after unplugging/replugging your device?


rebuildfstab seems to be unnecessary after I detach/reattach the device. The file systems will show up with no added effort on my part.
Title: Re: Refresh USB devices after partitioning
Post by: Rich on February 27, 2015, 12:17:51 PM
Hi bbenson
From what I understand, rebuildfstab  also creates the mount points in  /mnt.
Title: Re: Refresh USB devices after partitioning
Post by: gerald_clark on February 27, 2015, 12:24:29 PM
partprobe is part of the parted.tcz package.
Title: Re: Refresh USB devices after partitioning
Post by: bbenson on February 27, 2015, 12:40:40 PM
I tried partprobe and did not have any luck, but that might be a different issue.

I disconnected the device and reconnected it, and the file systems did not show up this time (sdb was not listed in blkid, mount, or sfdisk -l).

dmesg reports:

Code: [Select]
usb 1-1: new high-speed USB device number 12 using ehci-pci
usb 1-1: device descriptor read/all, error -110
usb 1-1: new high-speed USB device number 13 using ehci-pci
usb 1-1: device descriptor read/all, error -110
usb 1-1: new high-speed USB device number 14 using ehci-pci
usb 1-1: unable to read config index 0 descriptor/start: -110
usb 1-1: can't read configurations, error -110
usb 1-1: new high-speed USB device number 15 using ehci-pci
usb 1-1: unable to read config index 0 descriptor/start: -110
usb 1-1: can't read configurations, error -110
usb usb1-port1: unable to enumerate USB device

I have an Ubuntu VM running side-by-side with TinyCore, and Ubuntu can find the four filesystems and read and write to them every time, so it doesn't seem to be the card.

The fact that the file systems were showing up before and not now makes me think the problem is with TinyCore, or possibly with my expectations of how a removable media device should behave on an OS that isn't Ubuntu.

Edit: When I reboot the machine the file systems show up like normal: sdb1, sdb2, sdb3, sdb4
Title: Re: Refresh USB devices after partitioning
Post by: bbenson on February 27, 2015, 12:42:22 PM
Oh, and... a big thanks for everyone taking the time to respond and lend a hand.
Title: Re: Refresh USB devices after partitioning
Post by: gerald_clark on February 27, 2015, 12:43:29 PM
Looks like a failed USB drive.
Title: Re: Refresh USB devices after partitioning
Post by: Rich on February 27, 2015, 12:58:25 PM
Hi gerald_clark
Actually he's using an SD card. Is there anything special or different maybe driver wise verses a thumb drive?
Title: Re: Refresh USB devices after partitioning
Post by: gerald_clark on February 27, 2015, 01:02:48 PM
Yes, but connected via USB.
It could be the card reader or the card, or the card being improperly removed and inserted in a connected card reader.
Title: Re: Refresh USB devices after partitioning
Post by: bbenson on February 27, 2015, 01:16:36 PM
I do not believe the USB device has failed, for the following reasons:


And yes, this is an SD card which is connected through a USB card reader. No special drivers are being used on either VM.
Title: Re: Refresh USB devices after partitioning
Post by: Rich on February 27, 2015, 01:24:50 PM
Hi bbenson
What happens if you try it on bare metal, take the VM out of the equation?