4

I created an Ubuntu live usb:

$ dd if=/path/to/ubuntu.iso of=/dev/sdb

I installed my distro. Now I want to turn my usb back for a normal storing use.

$ lsblk
sdb      8:16   1    15G  0 disk 
├─sdb1   8:17   1   1,4G  0 part  # Ubuntu is here
└─sdb2   8:18   1   2,3M  0 part  # Extra space I guess

$ sudo gdisk /dev/sdb
> p  # list patitions
Command (? for help): p
Disk /dev/sdb: 0 sectors, 0 bytes
Logical sector size: 512 bytes
Disk identifier (GUID): A9CA0E15-8539-47B8-9BD1-4942D18E789B
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 18446744073709551582
Partitions will be aligned on 2048-sector boundaries
Total free space is 0 sectors (0 bytes)

Number  Start (sector)    End (sector)  Size       Code  Name

As you can see, no partition are listed, and the disk is seen as empty.

Nonetheless I try to create a new one:

Command (? for help): n
Partition number (1-128, default 1): 
First sector (34-18446744073709551582, default = 2048) or {+-}size{KMGTP}: 
Last sector (2048-18446744073709551582, default = 18446744073709551582) or {+-}size{KMGTP}: 
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): 
Changed type of partition to 'Linux filesystem'

Then to write the changes:

Command (? for help): w
Caution! Secondary header was placed beyond the disk's limits! Moving the
header, but other problems may occur!
Warning! The claimed last usable sector is incorrect! Do you want to correct
this problem? (Y/N): Y
Have adjusted the second header and last usable sector value.

Problem: partition 1 is too big for the disk.
Aborting write operation!
Aborting write of new partition table.

So it does not work. What am I doing wrong? For the time being he usb sick still works as a live usb.


EDIT 1

ok before receiving answers I tried to format each partition:

$ sudo mkfs.ext4 /dev/sdb1
$ sudo mkfs.ext4 /dev/sdb2

Then I checked the partitions' id:

$ blkid /dev/sdb*
/dev/sdb1: UUID="eea83bc3-408b-4287-8c35-0cceeee837bb" TYPE="ext4" 
/dev/sdb2: UUID="1138f1f8-0840-44fe-bb89-935993ed83af" TYPE="ext4" 

Tried to use fdisk:

$ sudo fdisk /dev/sdb
fdisk: unable to read /dev/sdb: Invalid argument

Then I did as Alex Stragies advised to remove file signature:

$ dd if=/dev/zero of=/dev/sdb count=4 bs=1M

fdisk worked this time:

$ sudo fdisk /dev/sdb

I build a new msdos partition table:

> o  
Building a new DOS disklabel with disk identifier 0xb4151e51.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
You must set cylinders.
You can do this from the extra functions menu.

and saved the changes and exited fdisk:

>  w
The partition table has been altered!

Syncing disks.

Now when I check partitions in fdisk it tells me my the device has about 4MB instead of 16GB! My usb stick should have about 16GB

$ sudo fdisk /dev/sdb
> p
Disk /dev/sdb: 4 MB, 4194304 bytes
131 heads, 2 sectors/track, 31 cylinders, total 8192 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        8191        4095+  ee  GPT

Using gdisk:

$ sudo gdisk /dev/sdb
> p
Disk /dev/sdb: 8192 sectors, 4.0 MiB
Logical sector size: 512 bytes
Disk identifier (GUID): 5A262CEA-114A-4DF7-B2D3-99634D40398A
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 8158
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048            8158   3.0 MiB     8300  Linux filesystem

Whereas using lsblk it tells me the device has a capacity off 15GB and two volumes or 1,4G and 2,3M:

$ lsblck
sdb      8:16   1    15G  0 disk 
├─sdb1   8:17   1   1,4G  0 part 
└─sdb2   8:18   1   2,3M  0 part

What is going on? I am totally lost here


EDIT 2

I played a bit with dd's count and fdisk. I can go up to a count=2000 with dd to get 2GB copied:

$ dd if=/dev/zero of=/dev/sdb count=2000 bs=1M

but no more. If I specify count=3000, only 2GB will be copied.

To clarify things: I already had this issue three years ago and I gave up my former usb stick as I was told it was probably broken. I found it was bad luck as I also used it as an Ubuntu live usb stick before formatting it and having it broken. Now it happens today, under the same circumstances, with Ubuntu. Though I used it as an Arch Linux lie usb so many times before and reformatting it has never failed. I found on the internet other threads where users describe the same issue, related to making live usb stick (with Ubuntu). But no clear solution has been found, I read people advising about reformatting, creating new partition to unallocated space and such. Sureley someone has already experienced this issue and found a bullet proof solution no? Or is my usb stick lost for good?

  • have you tried with fdisk as well? – mazs Jun 12 '16 at 12:51
  • fdisk wont even do it: $ sudo fdisk /dev/sdb will output: fdisk: unable to read /dev/sdb: Invalid argument – kaligne Jun 12 '16 at 13:30
  • You should not have stopped after o. You should have continued with creating a new partition. Do partprobe, then dd ... count=12, then partprobe again, then proceed to fdisk with o, then n, p. – Alex Stragies Jun 12 '16 at 15:08
  • I used gdisk as fdisk told me there was a gpt partition table. I created new empty GUID partition table with gdisk using o. Created new partition for the full disk (4M). Then modprobe then I redidi the dd with count=12. Repeted the procedure and this time I could create a partition about 12M instead of 4M. How am I supposed to increase the dd's count? – kaligne Jun 12 '16 at 17:07
  • you can increase dd count with count=n and specify written block size with bs=1M for example (1 megaybte block size) – mazs Jun 12 '16 at 17:20
3

fdisk may not be able to open the device, because it sees a iso9660 filesystem.

this could be confirmed with blkid /dev/sdb*.

In Any case I would then probably try this:

  • dd if=/dev/zero of=/dev/sdb count=4 bs=1M This will remove any filesystem signature at the start
  • try fdisk /dev/sdb again
  • start with operation o (Create new MS-DOS partition table)

  • Then, add the partition, press n, then p, then several Enters to select maximum size. (Otherwise fdisk will create a small dummy partition)

  • Change the type of the partition with t, if desired

You need to make sure, your installation reliably detects block device changes, and refreshes the kernel map for that. If unsure, force with partprobe between dd and fdisk

  • removing the file signature seemed to work, I could open the device with fdisk. However now it tells me my device is about 4M, instead of 16GB ! I edited my question and I wrote in EDIT 1 all the steps I made. – kaligne Jun 12 '16 at 14:47
0

You could wipe the partitions from the usb pendrive with (run all the below commands as root) :

dd if=/dev/zero of=/dev/sdb bs=1M count=1000
sync

This would write 1Gb of zeroes starting from the beginning of sdb so that would definitely erase any partition information.
Then create a single partition with fdisk :

fdisk /dev/sdb
n
p
<enter> three times
w
partprobe
sync

Then check with lsblk partitions, and create a filesystem on the new partition with mkfs.ext4 /dev/sdb1.

  • I originally had an usb stick of 16GB. I can set dd' count up to 2000 to get 2GB copied, however dd wont copy more than that, even if I give a count=3000. Only 2GB will be copied. How is that so? – kaligne Jun 12 '16 at 18:02
  • what is the output of the lsusb ? do you see a pendrive of 16Gb ? or the output of hdparm -I /dev/sdb | grep "device size" ? – mazs Jun 12 '16 at 19:06
  • fdisk tells me I have successfuly created a 1955MB Linux file system partition in /dev/sdb1. lsblk tells me it detects a 15GB drive in /dev/sdb: sdb 8:16 1 15G 0 disk, but nothing about /dev/sdb1. I checked and could not find any /dev/sdb1 in my path. lsusb gives me outputs about BUS. Nothing about any usb stick. hdparm -I /dev/sdb outputs this failure message: /dev/sdb: HDIO_DRIVE_CMD(identify) failed: Inappropriate ioctl for device. – kaligne Jun 12 '16 at 19:39
  • after you created partition, did you execute partprobe and sync ? if lsblk sees the 16gb then you should be able to use it.....have you tried to unplug the stick and place it in another usb port ? – mazs Jun 12 '16 at 19:45
  • Yes I did fdisk o, n, w. Then partprobe && sync. I changed the usb stick to a different usb port. lsblk still lists it in dev/sdb. It's the only usb stick i plugged so there is no error about it. When I remove it, lsblk does not list /dev/sdb anymore. – kaligne Jun 12 '16 at 19:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.