I have tried deleting the read-only partition in both fdisk and gdisk. (I don't care if it screws up the partition table - I can always redo it once it lets me.) I have also tried using fdisk to just make a new partition table and the same with gdisk. In both cases, I cannot write the changes to disk.
For whatever it is worth, I think my efforts have rendered the USB stick entirely unusable. I seem to have managed to destroy the partition I could write files to but not the other one. So I'm left with a read-only 512M USB key with a read-only 4.5M partition containing 2 files which total 58% of that 4.5M. Of course, I can't change the partition table or add a further partition or create a file system because, guess what? Everything is now read-only!
Fdisk Unable To Write Dev Sda Bad File Descriptor
I later managed to reformat the larger partition in Fedora and Fedora now sees it as existing again. I made the file system etc. But the partition map remains corrupt so I certainly wouldn't trust it with actual files. I get errors about file descriptors, mismatches etc. etc.
Same things happened to me right now... I wanted to format my USB stick for USB-ZIP compatibility to be able to boot on an old PC. I used an utility from the syslinux package, called "mkdiskimage". This create a ZIP drive-like disk geometry on the USB stick, modifying the cylinder, head, and sector numbers. Now the USB stick still doesn't boot, but additionally I am unable to revert it from this state to the original. I tried to fill it with zeros (dd if=/dev/zero of=/dev/sdc) but only the first 14 MB was writeable from the 512 MB. Fdisk also doesn't work, when I delete the partition and want write the changes to the disk, it says it is read only. Now I must use some windows utility to make it work again.
Disk /dev/sdc doesn't contain a valid partition tablestephan@solaris:$ sudo fdisk /dev/sdcDevice contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabelBuilding a new DOS disklabel. Changes will remain in memory only,until you decide to write them. After that, of course, the previouscontent won't be recoverable.
So I did reboot. And to my surprise, I was still able to see my files on the FAT partition!Nautilus reporting disk as vfat type. Was even able to open a small text file (although my bigger .pdf doesnot seems to wish to open).But fdisk -l or fdisk /dev/sdb followed by p command both show linux partition:paul@Arcturus:$ fdisk -l /dev/sdb
/dev/sdb1: ***** FILE SYSTEM WAS MODIFIED *****/dev/sdb1: 246122/61054976 files (1.1% non-contiguous), 39505694/244190390 blocksError writing block 1 (Attempt to write block from filesystem resulted in shortwrite). Ignore error? yes
1. sudo fdisk -lDisk /dev/sda: 16.1 GB, 16139354112 bytes255 heads, 63 sectors/track, 1962 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x0001e4f8Device Boot/dev/sda1*/dev/sda2/dev/sda5/ SolarisStart118341834End183419631963Blocks1472409610342411034240Id83582SystemLinuxExtendedLinux swapDisk /dev/sdb: 4103 MB, 4103937024 bytes127 heads, 62 sectors/track, 1017 cylindersUnits = cylinders of 7874 * 512 = 4031488 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x000a62cbDevice Boot/dev/sdb1*(LBA)ubuntu@ubuntu:$Start1End1017Blocks4003898Idc2.sudo fsck.ext4 -v /dev/sda1e2fsck 1.41.14 (22-Dec-2010)/dev/sda1: recovering journalfsck.ext4: unable to set superblock flags on /dev/sda13.sudo mke2fs -n /dev/sda1mke2fs 1.41.14 (22-Dec-2010)Filesystem label=OS type: LinuxBlock size=4096 (log=2)Fragment size=4096 (log=2)Stride=0 blocks, Stripe width=0 blocks920272 inodes, 3681024 blocks184051 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=3770679296113 block groups32768 blocks per group, 32768 fragments per groupSystemW95 FAT328144 inodes per groupSuperblock backups stored on blocks:32768, 98304, 163840, 229376, 294912, 819200, 884736,1605632, 26542084.sudo e2fsck -b 32768 /dev/sda1e2fsck 1.41.14 (22-Dec-2010)Superblock needs_recovery flag is clear, but journal has data.Recovery flag not set in backup superblock, so running journalanyway./dev/sda1: recovering journalSuperblock needs_recovery flag is clear, but journal has data.Recovery flag not set in backup superblock, so running journalanyway.e2fsck: unable to set superblock flags on /dev/sda1ubuntu@ubuntu:$
-o to output the badblocks list to the file ./badblocks.list, -w for thewrite operation, -s to show progress, -v to be verbose, -b 4096 for theblocksize of 4K and -c 16 to test 16 blocks at once (default is 64).
This will mount the above folders in RAM, with a respectable max size (otherwiseyour ram fills up). The noatime option means that the access time of a file isnot updated, saving a lot of writes as well. You should also add the noatimeoption to your other partitions, for example on a standard Raspbian:
# dumpe2fs -h /dev/sdb[root@sss ]# dumpe2fs -h /dev/sdbdumpe2fs 1.42.9 (28-Dec-2013)Filesystem volume name:Last mounted on:Filesystem UUID:d6cd4d1a-c69f-4e81-8e7a-ed6cf0be68dbFilesystem magic number:0xEF53Filesystem revision #:1 (dynamic)Filesystem features:has_journal ext_attr resize_inode dir_index filetype needs_recovery extent 64bit flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isizeFilesystem flags:signed_directory_hashDefault mount options:user_xattr aclFilesystem state:cleanErrors behavior:ContinueFilesystem OS type:LinuxInode count:720896Block count:2883584Reserved block count:144179Free blocks:2795308Free inodes:720885First block:0Block size:4096Fragment size:4096Group descriptor size:64Reserved GDT blocks:1024Blocks per group:32768Fragments per group:32768Inodes per group:8192Inode blocks per group:512Flex block group size:16Filesystem created:Wed Dec 20 02:33:43 2017Last mount time:Wed Dec 20 02:34:40 2017Last write time:Wed Dec 20 02:34:40 2017Mount count:1Maximum mount count:-1Last checked:Wed Dec 20 02:33:43 2017Check interval:0Lifetime writes:132 MBReserved blocks uid:0 (user root)Reserved blocks gid:0 (group root)First inode:11Inode size:256Required extra isize:28Desired extra isize:28Journal inode:8Default directory hash:half_md4Directory Hash Seed: c577c1b0-aaa9-4d27-b5e6-54bd5b9540d1Journal backup: inode blocksJournal features: journal_64bitJournal size: 128MJournal length: 32768Journal sequence: 0x00000002Journal start: 1
When either dd or ddpt are given these options with suitablearguments, they will copy (IBS * COUNT) bytes from thebeginning of IFILE to the beginning of OFILE. Note thedifferent defaults for 'if=' and 'of=' between dd and ddpt; whiledefaulting to stdin and stdout may be more in keeping with a Unixfilter type command, in practice the filter syntax is not used muchfor ddpt. The author feels no default for 'if=' and /dev/null(or the Windows equivalent: NUL) for'of=' are more useful and safer.ddpt differs from dd asfollows. An IFILE of "-" is interpreted as stdin; anOFILE of "-" is interpreted as stdout while an OFILEof "." is interpreted as /dev/null.[dd interprets input and output file names of "-"literally; dd interprets an output file of "." as thecurrent directory and will not accept it.] By default the ddptutility does not truncate the OFILE before starting the copy(the dd command does if it is a regular file). ddpt has a'oflag=trunc' option (or 'conv=trunc' option) that will truncate theOFILE before starting the copy. For output block devices(including those accessed via the pt interface) ddpt writes integralmultiples of OBS bytes to the OFILE so it does not dopartial writes, ignoring them in the case of the last copy segment.For regular output files (including fifos and stdout) ddpt can dopartial writes (e.g. the last write is not a multiple of OBSbytes) to OFILE. Note that since regular OFILEs are nottruncated by default the length of OFILE may end up largerthan the length of IFILE.If the 'count=' option isnot given then an attempt is made to determine the remaining blocksin the file, device or partition. If the input file is stdin and nocount is given then a copy will continue until an EOF is detected onthe input stream (or something else goes wrong). If the 'count='option is not given then the remaining blocks on both the input andoutput files are determined (if possible) and if both are found thenthe minimum of the two counts is used. The 'skip=' option forIFILE and the 'seek=' option for OFILE are taken intoaccount when calculating the remaining number of blocks in a file,device or partition.If the 'count=' option is given thenno further checks regarding the remaining length of IFILE andOFILE are done and the ddpt will attempt to copy that numberof blocks. The 'count=0' option is valid and all the normalpreparations are made including opening files but no copy takesplace. Hence the 'count=0' option can be used to check that thesyntax is in order and that the files are present (see the "Verbose"section below).Other dd options also supported by ddpt: 2ff7e9595c
Comments