WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Refresh USB devices after partitioning  (Read 6388 times)

Offline bbenson

  • Newbie
  • *
  • Posts: 9
Refresh USB devices after partitioning
« 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

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11634
Re: Refresh USB devices after partitioning
« Reply #1 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

Offline bbenson

  • Newbie
  • *
  • Posts: 9
Re: Refresh USB devices after partitioning
« Reply #2 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.

Offline bbenson

  • Newbie
  • *
  • Posts: 9
Re: Refresh USB devices after partitioning
« Reply #3 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?

Offline gerald_clark

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 4254
Re: Refresh USB devices after partitioning
« Reply #4 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.

Offline bbenson

  • Newbie
  • *
  • Posts: 9
Re: Refresh USB devices after partitioning
« Reply #5 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?

Offline core-user

  • Full Member
  • ***
  • Posts: 192
  • Linux since 1999
Re: Refresh USB devices after partitioning
« Reply #6 on: February 27, 2015, 11:15:38 AM »
Filesystems will be on /dev/sdb1 or /dev/sdc1..... ;)
AMD, ARM, & Intel.

Offline bbenson

  • Newbie
  • *
  • Posts: 9
Re: Refresh USB devices after partitioning
« Reply #7 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?

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11044
Re: Refresh USB devices after partitioning
« Reply #8 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.
The only barriers that can stop you are the ones you create yourself.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11634
Re: Refresh USB devices after partitioning
« Reply #9 on: February 27, 2015, 11:53:02 AM »
Hi bbenson
Are you saying  rebuildfstab  works after unplugging/replugging your device?

Offline bbenson

  • Newbie
  • *
  • Posts: 9
Re: Refresh USB devices after partitioning
« Reply #10 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.
« Last Edit: February 27, 2015, 12:16:05 PM by bbenson »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11634
Re: Refresh USB devices after partitioning
« Reply #11 on: February 27, 2015, 12:17:51 PM »
Hi bbenson
From what I understand, rebuildfstab  also creates the mount points in  /mnt.

Offline gerald_clark

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 4254
Re: Refresh USB devices after partitioning
« Reply #12 on: February 27, 2015, 12:24:29 PM »
partprobe is part of the parted.tcz package.

Offline bbenson

  • Newbie
  • *
  • Posts: 9
Re: Refresh USB devices after partitioning
« Reply #13 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
« Last Edit: February 27, 2015, 12:45:38 PM by bbenson »

Offline bbenson

  • Newbie
  • *
  • Posts: 9
Re: Refresh USB devices after partitioning
« Reply #14 on: February 27, 2015, 12:42:22 PM »
Oh, and... a big thanks for everyone taking the time to respond and lend a hand.