Capacity of pen drive shown is less than the actual

19,316

Solution 1

These instructions worked for me to reformat an 8GB USB flash drive that was made useless after I used dd to write a bootable iso file to the flash drive. I reformatted the flash drive to its original FAT32 format as follows:

  1. Remove all of your USB devices except for the 8GB USB flash drive that you want to reformat, so you won't get confused about the device name of the USB flash drive later on.

  2. List all the partitions.

     sudo fdisk -l
    

    Search the results of the command for output that looks like this:

     Disk /dev/sdc: 7864 MB, 7864320000 bytes
     30 heads, 33 sectors/track, 15515 cylinders, total 15360000 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: 0x00016288
    
        Device Boot      Start         End      Blocks   Id  System
     /dev/sdc1   *        2048    15359999     7678976    b  W95 FAT32
    

    If you see something like 7864 MB (8GB) in the output (see the example output above), then that is your 8GB USB flash drive. In this example it is called /dev/sdc. Now open the Disks application from the Dash and check again to make sure that the device name of your 8GB flash drive is the same as what you got from running the command: sudo fdisk -l.

  3. Create a partition table on the disk of type msdos, sometimes known as Master Boot Record (MBR).

     sudo parted /dev/sdc mklabel msdos
    

    In this example I used /dev/sdc for the name of the device which is what was found in the results of step 2. I can't stress strongly enough how important it is to verify the device name before running this step!

    Warning: If you type the wrong device name you may overwrite your operating system or another one of your partitions containing important personal files!!! So be careful and check the device name a second time. Open the Disks application and check the device name of your 8GB USB flash drive in Disks. It should be the same device name!!! Now check again! You don't want to accidentally type the wrong device name!

  4. Add an empty "primary" partition, which will hold a FAT filesystem later.

     sudo parted -a none /dev/sdc mkpart primary fat32 0 8192 
    

    Once again in this example I used /dev/sdc for the name of the device which is what was found in the results of step 2. The command specifies the start point (from 0 MB) to the end point (8192 MB). If the 8GB USB flash drive does not have the full 8192 MB space, parted will adjust it automatically. If the terminal returns a message that the start point can't start at 0 MB and you have to use some other small number close to 0 MB, type Y to accept this. Note the command is creating a single, primary partition on the whole disk.

    This newly created partition will have the ID /dev/sdc1. That is because the device name in this example is /dev/sdc and the 1 at the end is because it is the first partition on that device.

  5. Create a FAT filesystem on the /dev/sdc1 partition by formatting the partition.

     mkfs.vfat -n "8GB-USB" /dev/sdc1
    

    /dev/sdc1 is the partition ID from step 4. "8GB-USB" is the partition label, which can be your own choice of label, just enclose the label inside two double quote characters.

You now have a ready-to-use reformatted USB flash drive with an 8GB FAT partition.

Solution 2

General description of the problem

You can use dd to write raw data or clone an image file or an Ubuntu iso file to a USB drive. These data can be 'anything anywhere', and might confuse the partitioning tool, that you intend to use afterwards, because the tool expects a certain structure (partition table and file system).


Clone from an iso file to create a USB boot drive

When you clone an Ubuntu iso file to a USB drive, the USB drive will be a bootable live drive, that can be run to 'Try Ubuntu' or to install Ubuntu into an internal drive. dd is a cloning tool, when used as described in the original question. There are also other cloning tools, for example 'Disks' alias gnome-disks, the 'Ubuntu Startup Disk Creator' in Ubuntu 16.04 LTS and newer versions, 'mkusb' and 'Win32 Disk Imager'. USB drives that are cloned from iso files have the ISO9660 file system which is read-only. This is a feature of the system, that can be used on CD/DVD drives and it is inherited when cloned to USB drives.

Extract from an iso file to create a USB boot drive

There are other tools, that extract the files from an Ubuntu iso file to a file system in a USB drive. 'Unetbootin', 'LinuxLive' and 'Rufus' are extracting tools. 'mkusb' is an extracting tool, when it is creating a persistent live drive. An extracted system in a USB drive can be read-write.

Make the USB drive read/write again

Persistent live drive

If you want to use the pendrive both to boot Ubuntu live and to store files, I suggest that you create a persistent live drive. This can be done in Windows with 'LinuxLive' and 'Unetbootin', and in Ubuntu with 'mkusb' and 'Unetbootin'. See the following links and links from them,

askubuntu.com/.../how-do-i-make-a-persistent-live-usb-of-ubuntu-...

www.linuxliveusb.com/

help.ubuntu.com/community/mkusb/persistent

unetbootin.github.io/

Restore the USB drive to a standard storage device

Otherwise you can restore the USB drive to a standard storage device with 'mkusb-dus'. The first megabyte of the drive is wiped and a new MSDOS partition table with a FAT32 file system is created automatically. This method works also when other tools are confused by some data.

enter image description here

See the following links and links from them,

help.ubuntu.com/community/mkusb

help.ubuntu.com/community/mkusb/wipe

Solution 3

If you write an file system image onto a medium, the file system won't know, how much space there actually is, so you'll be restricted to its original size, unless you extend it (if the file system type allows it).

Additionally, you probably used an image with a ISO 9660 file system, which doesn't support modification at all. If you want to create a bootable and writable USB drive, use tools like Startup Disk Creator.

Solution 4

Flash devices don't last forever. When they fail, they sometimes exhibit symptoms similar to what you're reporting. Although it's worth trying other suggestions here, there's a high probability that your device is simply dead and that you must replace it.

Share:
19,316

Related videos on Youtube

Pratik Singhal
Author by

Pratik Singhal

Updated on September 18, 2022

Comments

  • Pratik Singhal
    Pratik Singhal over 1 year

    I have a 8 GB pendrive. I used to write raw data into the pendrive (without creating filesystem) using the dd command.

    Today, when I inserted the pen drive, the I am unable to write anything on to it. When I open gparted it is showing the total space on the pen drive as 500 MB. I am unable to create a new partition table or a partition on the pen drive now.

    Here is the fdisk -l output.

    Disk /dev/sdb: 0 MB, 512000 bytes
    255 heads, 63 sectors/track, 0 cylinders, total 1000 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 4096 bytes
    I/O size (minimum/optimal): 4096 bytes / 4096 bytes
    Disk identifier: 0x00095df6
    

    What's wrong with the pen drive? How can I recover the lost space?

    Device Boot      Start         End      Blocks   Id  System
    

    When I open gnome-disks, it shows the total space as 8 GB but when I try to create a new partition using it, it shows the following error:

    Error creating partition on /dev/sdb: Command-line parted --align optimal --script "/dev/sdb" "mkpart primary ext2 1MiB 7969177599b"' exited with non-zero exit status 1: Error: The location 7969177599b is outside of the device /dev/sdb.
     (udisks-error-quark, 0)
    
    • psusi
      psusi about 9 years
      What does lsblk say about the drive?
    • Pratik Singhal
      Pratik Singhal about 9 years
      lsblk just recognizes the drive as it would recognize any other drive
    • psusi
      psusi about 9 years
      Yes, and how big does it say the drive is?
    • Pratik Singhal
      Pratik Singhal about 9 years
      It says the drive size is 7.4G
    • JonasCz
      JonasCz about 9 years
      What I did was overwrite it with dd with input from /dev/zero/, and then format it.
  • A. Kounovský
    A. Kounovský about 9 years
    Have you tried zeroing the first sector of the disk using sudo dd if=/dev/zero of=/dev/sdX bs=512 count=1 ?
  • Pratik Singhal
    Pratik Singhal about 9 years
    Yes, In fact I booted into windows created a new partition and it works fine on windows, tried mounting it on friends laptop (who uses ubuntu 14.04) it works fine , but not working on my laptop!
  • foladev
    foladev about 2 years
    This worked perfectly. Thanks.