Page 1 of 3 123 LastLast
Results 1 to 10 of 22

Thread: How to delete files/directories on Read-Only file system

  1. #1
    Join Date
    Apr 2006
    Beans
    1,740

    How to delete files/directories on Read-Only file system

    Hi folks,


    Ubuntu 7.10


    I have some files and directories on an USB flash pendrive. I can't delele them because on read-only filesystem.


    I tried;

    $ sudo mount -o remount,rw /mnt/maindir
    without result.


    If run;
    $ sudo mount -o remount,rw /dev/sdb1
    Code:
    mount: you must specify the filesystem type
    What filesystem I have to specify there?


    I don't expect running;
    Code:
    $ dd if=/dev/zero of=/dev/sdb1
    to erase the pendrive completely.


    Please shed me some light. TIA


    B.R.
    satimis

  2. #2
    Join Date
    Jun 2006
    Beans
    7,419
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: How to delete files/directories on Read-Only file system

    try

    sudo mkdir /media/usb

    sudo mount -t vfat -o rw /dev/sdb1 /media/usb

  3. #3
    Join Date
    Apr 2006
    Beans
    1,740

    Re: How to delete files/directories on Read-Only file system

    Quote Originally Posted by logos34 View Post
    try

    sudo mkdir /media/usb

    sudo mount -t vfat -o rw /dev/sdb1 /media/usb
    Hi logos34,


    Thanks for your advice.


    $ ls /media/
    Code:
    cdrom  cdrom0  floppy  floppy0  sdb1  sdb2

    $ sudo mount -t vfat -o rw /dev/sdb1 /media/sdb1/
    No complaint


    $ sudo rm -rf /media/sdb1/dir
    ......
    rm: cannot remove `/media/sdb1/dir': Read-only file system


    Still fails


    B.R.
    satimis

  4. #4
    Join Date
    May 2006
    Beans
    160
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: How to delete files/directories on Read-Only file system

    Might seem like a stupid question, but does your USB drive have a write-protect switch? You know, like SD cards and floppies?

  5. #5
    Join Date
    Apr 2006
    Beans
    1,740

    Re: How to delete files/directories on Read-Only file system

    Quote Originally Posted by fyo View Post
    Might seem like a stupid question, but does your USB drive have a write-protect switch? You know, like SD cards and floppies?
    Hi fyo,


    I can't find a hardware switch on the UBS Pendrive. Those data were copied on it about 1~2 hours ago.


    I ran;

    $ sudo mount /dev/sdb1 /mnt

    $ sudo mkdir /mnt/maindir

    $ sudo cp /path/to/files /mnt/maindir

    Warning popup saying coping the files as read only


    $ sudo cp -r /path/to/dir-a /mnt/maindir
    $ sudo cp -r /path/to/dir-b /mnt/maindir
    etc.


    I can remove all files copied on the pendrive. But I can't remove the directories together with their files.


    B.R.
    satimis

  6. #6
    Join Date
    May 2006
    Beans
    160
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: How to delete files/directories on Read-Only file system

    Quote Originally Posted by satimis View Post
    I can remove all files copied on the pendrive. But I can't remove the directories together with their files.
    Sounds strange. Try chmod'ing them 666. Yes, sudo should work already, but...

    Maybe also try mounting with sync and dirsync options?

    Yes, I'm just throwing stuff at the wall at this point and hoping something sticks.

  7. #7
    Join Date
    Jun 2007
    Location
    Neverland
    Beans
    894
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: How to delete files/directories on Read-Only file system

    Hi,

    You don't need comma after remount.
    Try without it, see if this helps.

    Then, try mounting it as FAT:

    Code:
    sudo mkdir /mnt/usb
    sudo mount -t vfat -o rw /dev/xxx /mnt/usb
    xxx is the usb device, which you can identify by typing:

    Code:
    sudo fdisk -l
    After that, switch to the usb device (by using cd) and see the permissions on the files and the directories by using ls -la. What do you get?

    Are you the owner? Are you using sticky bits?

    Dedoimedo
    Linux Systems Expert / Systems Programmer, LPIC-1, LPIC-2(WIP), GSEC, CCHD, CCHA
    http://www.dedoimedo.com - A place to learn a lot about a lot!

    Pangolin Review | Ringtail Review | Linux Games | My books

  8. #8
    Join Date
    Apr 2006
    Beans
    1,740

    Re: How to delete files/directories on Read-Only file system

    Quote Originally Posted by Dedoimedo View Post
    Hi,

    You don't need comma after remount.
    Try without it, see if this helps.

    Then, try mounting it as FAT:

    Code:
    sudo mkdir /mnt/usb
    sudo mount -t vfat -o rw /dev/xxx /mnt/usb
    xxx is the usb device, which you can identify by typing:

    Code:
    sudo fdisk -l
    After that, switch to the usb device (by using cd) and see the permissions on the files and the directories by using ls -la. What do you get?

    Are you the owner? Are you using sticky bits?
    Hi Dedoimedo,


    This USB pendrive looks quite strange to me. I got it in a conference as gift from a multi-nation software company. It has files on it introducing their products taking up 57M out of 1G.


    After mount it with;
    Code:
    $ sudo mount /dev/sdb1 /mnt
    (I found /dev/sdb1 by runnint "fdisk -l")

    I can copy files on it. They can be deleted later.


    If running
    Code:
    $ cp -r /path/to/dir-A /mnt/
    Directory including files can be copied on the pendrive. But they can't be deleted later.


    Then I followed logos34's advice trying to delete them but without result.


    Later I found on running;
    $ fdisk -l
    Code:
    Disk /dev/sda: 160.0 GB, 160041885696 bytes
    255 heads, 63 sectors/track, 19457 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    
    Disk /dev/sdb: 1056 MB, 1056702464 bytes
    33 heads, 62 sectors/track, 1008 cylinders
    Units = cylinders of 2046 * 512 = 1047552 bytes
    The partition table seems gone.


    Therefore I ran
    # fdisk /dev/sdb

    to repartition the drive and afterwards ran;

    # mkfs.ext2 -c /dev/sdb1
    it went though w/o complaint


    But I can't mount the pendrive

    $ sudo mount -t ext2 /dev/sdb1 /media/sdb1/
    Code:
    mount: wrong fs type, bad option, bad superblock on /dev/sdb1,
           missing codepage or other error
           In some cases useful info is found in syslog - try
           dmesg | tail  or so

    Then I ran
    Code:
    dmesg | tail

    It asked me to run "e2fsck /dev/sdb1"

    $ sudo e2fsck /dev/sdb1
    Code:
    ....
    Inode 421 has INDEX_FL flag set but is not a directory.
    Clear HTree index<y>? 
    ......
    It took long time to run without finish. Therefore I manually exited it by pressing [Ctrl]+c


    I don't know how to proceed further. Nor I know what mistake I have committed. Please advise.


    TIA


    B.R.
    satimis
    Last edited by satimis; July 15th, 2008 at 02:41 PM.

  9. #9
    Join Date
    Jun 2007
    Location
    Neverland
    Beans
    894
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: How to delete files/directories on Read-Only file system

    Hello,

    Could it be a U3 thingie?

    If so, you should download a U3 uninstaller (in Windows), remove the hidden partitions, reformat as fat32, then try this thing again.

    BTW, don't pause commands in mid-run - it's not healthy. What was the "long time?"

    Dedoimedo

    P.S. Try fdisk again ... Unmount first! Remove ALL partitions. Unplug. Plug. Create new partition. Unplug. Plug. Format partition. Mount. Try writing / deleting ...
    Linux Systems Expert / Systems Programmer, LPIC-1, LPIC-2(WIP), GSEC, CCHD, CCHA
    http://www.dedoimedo.com - A place to learn a lot about a lot!

    Pangolin Review | Ringtail Review | Linux Games | My books

  10. #10
    Join Date
    Apr 2006
    Beans
    1,740

    Re: How to delete files/directories on Read-Only file system

    Hi Dedoimedo,


    This is a very strange pendrive. Performed following test-

    Plug the pendrive


    # fdisk -l
    Code:
    Disk /dev/sda: 160.0 GB, 160041885696 bytes
    255 heads, 63 sectors/track, 19457 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *           1          31      248976   83  Linux
    /dev/sda2              32       19457   156039345    5  Extended
    /dev/sda5              32       19457   156039313+  8e  Linux LVM
    
    
    Disk /dev/sdb: 1056 MB, 1056702464 bytes
    33 heads, 62 sectors/track, 1008 cylinders
    Units = cylinders of 2046 * 512 = 1047552 bytes

    # fdisk /dev/sdb
    Code:
    Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
    Building a new DOS disklabel. 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)
    Code:
    Command (m for help): n
    Command action
       e   extended
       p   primary partition (1-4)
    p
    Partition number (1-4): 1
    First cylinder (1-1008, default 1): 
    Using default value 1
    Last cylinder or +size or +sizeM or +sizeK (1-1008, default 1008): 
    Using default value 1008
    
    Command (m for help): p
    
    Disk /dev/sdb: 1056 MB, 1056702464 bytes
    33 heads, 62 sectors/track, 1008 cylinders
    Units = cylinders of 2046 * 512 = 1047552 bytes
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sdb1               1        1008     1031153   83  Linux
    
    Command (m for help): w
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    Syncing disks.

    # fdisk -l
    Code:
    Disk /dev/sda: 160.0 GB, 160041885696 bytes
    255 heads, 63 sectors/track, 19457 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *           1          31      248976   83  Linux
    /dev/sda2              32       19457   156039345    5  Extended
    /dev/sda5              32       19457   156039313+  8e  Linux LVM
    
    Disk /dev/sdb: 1056 MB, 1056702464 bytes
    33 heads, 62 sectors/track, 1008 cylinders
    Units = cylinders of 2046 * 512 = 1047552 bytes
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sdb1               1        1008     1031153   83  Linux
    It seems OK now


    Unplug the pendrive. Re-plug it.


    # fdisk -l
    Code:
    Disk /dev/sda: 160.0 GB, 160041885696 bytes
    255 heads, 63 sectors/track, 19457 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *           1          31      248976   83  Linux
    /dev/sda2              32       19457   156039345    5  Extended
    /dev/sda5              32       19457   156039313+  8e  Linux LVM
    
    Disk /dev/sdb: 1056 MB, 1056702464 bytes
    33 heads, 62 sectors/track, 1008 cylinders
    Units = cylinders of 2046 * 512 = 1047552 bytes
    
    Disk /dev/sdb doesn't contain a valid partition table
    The partition table on the pendrive seems gone. I repeated the steps 3 times with the same result.


    If continue immediately after running "fdisk /dev/sdb"


    # mkfs -c /dev/sdb1
    Code:
    mke2fs 1.40-WIP (14-Nov-2006)
    Filesystem label=
    OS type: Linux
    Block size=4096 (log=2)
    Fragment size=4096 (log=2)
    129024 inodes, 257788 blocks
    12889 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=264241152
    8 block groups
    32768 blocks per group, 32768 fragments per group
    16128 inodes per group
    Superblock backups stored on blocks: 
            32768, 98304, 163840, 229376
    
    Checking for bad blocks (read-only test): done                                
    Writing inode tables: done                            
    Writing superblocks and filesystem accounting information: done
    
    This filesystem will be automatically checked every 39 mounts or
    180 days, whichever comes first.  Use tune2fs -c or -i to override.

    # fdisk -l
    Code:
    Disk /dev/sda: 160.0 GB, 160041885696 bytes
    255 heads, 63 sectors/track, 19457 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *           1          31      248976   83  Linux
    /dev/sda2              32       19457   156039345    5  Extended
    /dev/sda5              32       19457   156039313+  8e  Linux LVM
    
    Disk /dev/sdb: 1056 MB, 1056702464 bytes
    33 heads, 62 sectors/track, 1008 cylinders
    Units = cylinders of 2046 * 512 = 1047552 bytes
    
    Disk /dev/sdb doesn't contain a valid partition table

    The partition table also gone.


    Could it be a U3 thingie?

    If so, you should download a U3 uninstaller (in Windows), remove the hidden partitions, reformat as fat32, then try this thing again.
    I don't know. I suppose it would not be so complicate. The pendrive contains files for advertising.


    BTW, don't pause commands in mid-run - it's not healthy. What was the "long time?"
    Noted.

    On running "sudo ext2fsck /dev/sdb" I continue pressing [Enter] to accept <y> for >15 minutes. It seemed without end.


    B.R.
    satimis

Page 1 of 3 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •