Format USB with bad partition table (read-only fs) - unix

I have a USB drive that my Ubuntu machine can't format. I think the problem originated when I was using Rufus or UNetBootin inside a Windows VM and got a blue screen. There's no important data on there, I just want to be able to use it. It's probably not worth the trouble but I want to understand the problem in case it happens again. I tried all sorts of tools but none of them seems to be low-level enough to rewrite the partition table.
Here is the output of some of the tools I tried. As you can note, there is no sdb1 or any found partition because the table is unreadable. I can use a Windows host too if the only solution is by using some ".exe" but I'd rather use UNIX terminal tools if possible.
ls -l /dev/ | grep sdb
brw-rw---- 1 root disk 8, 16 Mar 26 10:57 sdb
sudo hdparm -r0 /dev/sdb
/dev/sdb:
setting readonly to 0 (off)
readonly = 0 (off)
sudo partprobe -s /dev/sdb
Warning: Unable to open /dev/sdb read-write (Read-only file system). /dev/sdb has been opened read-only.
Warning: Unable to open /dev/sdb read-write (Read-only file system). /dev/sdb has been opened read-only.
Warning: Unable to open /dev/sdb read-write (Read-only file system). /dev/sdb has been opened read-only.
/dev/sdb: msdos partitions
sudo gparted /dev/sdb
libparted : 3.2
Unable to open /dev/sdb read-write (Read-only file system). /dev/sdb has been opened read-only.
Unable to open /dev/sdb read-write (Read-only file system). /dev/sdb has been opened read-only.
Unable to open /dev/sdb read-write (Read-only file system). /dev/sdb has been opened read-only.
Unable to open /dev/sdb read-write (Read-only file system). /dev/sdb has been opened read-only.
/dev/sdb: unrecognised disk label
sudo fdisk -l /dev/sdb
Disk /dev/sdb: 15 GiB, 16106127360 bytes, 31457280 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
sudo partx -l /dev/sdb
partx: /dev/sdb: failed to read partition table
sudo partx -d /dev/sdb
partx: specified range <1:0> does not make sense
sudo fsck.fat -n /dev/sdb
fsck.fat 3.0.28 (2015-05-16)
Logical sector size (65535 bytes) is not a multiple of the physical sector size.
sudo blkid -pi /dev/sdb
DEVNAME=/dev/sdb
MINIMUM_IO_SIZE=512
PHYSICAL_SECTOR_SIZE=512
LOGICAL_SECTOR_SIZE=512
sudo wipefs -a /dev/sdb
wipefs: error: /dev/sdb: probing initialization failed: Read-only file system

Apparently the Startup Disk Creator on Ubuntu doesn't care what's on the drive at all. I suppose it always creates its own partition table. So I used it with an Ubuntu image, assuming it would fail and was greatly surprised. I then used GParted to have an empty FAT32 partition and now I can use my drive without any problem (except maybe with future formats). Oddly, GParted first thought my drive was 60GB and successfully created a partition table but failed creating a partition. After the error message, the size of the drive rightly showed 16GB so I created the partition successfully.

Faced same issue, unmount then format worked for me,
here assumes that /dev/sdb1 is where the my device is located at.
sudo umount /dev/sdb1
sudo mkdosfs -F 32 -I /dev/sdb1

Related

How to create and mount file for read and write as a HFS+ filesystem in linux?

I am trying to mount a file that will act as a read/write HFS+ filesystem. I am using arch linux based distro so I installed hfsprogs and hfsutils. In debian based distros hfsprogs should be enough.
I created a 8G file like this:
dd if=/dev/zero of=test.img bs=1024 count=0 seek=$[1000*8000]
Then I did the formatting:
mkfs.hfsplus -v TestImg test.img
After that when I try to mount the file I get:
mkdir /tmp/sun
sudo mount -t hfsplus -o loop,rw,offset=0 test.img /tmp/sun
mount: /tmp/sun: mount failed: Operation not permitted
Parted shows that offset it ok:
sudo parted -m test.img unit B print
1:0B:8191999999B:8192000000B:hfs+::;
I also tried to use fdisk with the file creating sun partition table but that did not help either. Can you help me please with creating HFS+ rw filesystem as a file?
I used loop device inappropriately.
The correct steps are:
Create file
dd if=/dev/zero of=test.img bs=100MB count=10 seek=$[10*8]
Create blocked device mapped to that file:
losetup -fP test.img
At this point blocked device /dev/loop0 got created.
Create filesystem:
mkfs.hfsplus test.img
Mount to your folder
mount -o rw,loop /dev/loop0 /tmp/loop_test

qnx6 fs cannot be mounted read/write, standard hd

I am running Neutrino 6.4.0 with an attached standard 2.5" , 250GB Toshiba hard disk with 6 pre-existing qnx6 partitions. All of them can be mounted read-only; however, I cannot mount any of those as read/write. For instance:
mount -r -t qnx6 /dev/hd1t77.3 /home/p3
works fine, while
mount -t qnx6 /dev/hd1t77.3 /home/p3
returns the following:
mount: Can't mount /home/p3 (type qnx6)
mount: Possible reason: Read-only file system
I have even tried different sync options (-o sync=ignore , and -o sync=optional), to no avail.
Interestingly, I have created an additional partition on the same disk using mkqnx6fs /dev/hd1t77.6 , and that partition CAN be mounted read/write
My question is, what might be causing the existing partitions to be read-only, and is there any way to make them read-write?
Your system defines partitions as qnx4 (t77). Probably you should try mount it with qnx4 type. See official help for details.

setting up rsync on a centOS on gcloud - error #ERROR: chdir failed

I'm a complete noob in all gcloud
I was trying to setup an rsync module to have a sharecenter box do backup on a set schedule, which I was able to do on o centOS with digital ocean but somehow I can't get the same thing setup on a centOS vm instance in gcloud
here are my settings and all info I was able to gather about the issue I'm having
==================
my /etc/rsyncd.conf
motd file = /etc/rsyncd.motd
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
[moodleic]
path = /home/FranciscoCortes/backups
comment = backup module for moodle backup files folder defined in path
read only = no
list = yes
uid = nobody
gid = nobody
auth users = FranciscoCortes
secrets file = /etc/rsyncd.secrets
use chroot = no
hosts allow = *
==================
the path actualy exist
[FranciscoCortes#centos6 backups] cd /home/FranciscoCortes/backups/
[FranciscoCortes#centos6 backups]
================
the module exist
[FranciscoCortes#centos6 ~]$ rsync -va rsync://FranciscoCortes#localhost/
moodleic backup module for moodle backup files folder defined in path
================
the permissions on the folder seem ok
[FranciscoCortes#centos6 ~]$ ls -l
total 8
drwxrwxr-x. 2 FranciscoCortes FranciscoCortes 4096 Jan 7 21:37 backups
================
sudo netstat -tulpn
tcp 0 0 :::873 :::* LISTEN 17096/xinetd
================
cat /etc/services | grep rsync
rsync 873/tcp # rsync
rsync 873/udp # rsync
================
but the error I get is this
[FranciscoCortes#centos6 ~]$ rsync -va rsync://FranciscoCortes#localhost/moodleic/
Password:
#ERROR: chdir failed
rsync error: error starting client-server protocol (code 5) at main.c(1503) [receiver=3.0.6]
================
the rsync error log shows this
2015/01/09 01:21:20 [16987] unable to bind any inbound sockets on port 873
2015/01/09 01:21:20 [16987] rsync error: error in socket IO (code 10) at socket.c(541) [receiver=3.0.6]
2015/01/09 01:25:37 [17118] connect from localhost (::1)
2015/01/09 01:25:48 [17118] rsync: chdir /home/FranciscoCortes/backups failed
: Permission denied (13)
================
I've tried to set the uid and gid the same as the user authorized on the secrets file which is already the owner of the folder in the path so I'm not sure why I would get the permission denied.
I'm I missing something??
Any help is appreciated.
I think it could be caused by SELinux.
I'd set it to permissive and try a test run.
You can disable it temporarily with this command setenforce 0.
Sincerely,
Paolo

Mounting VMDK disk image

I have a single vmware disk image file with vmdk extension
I am trying to mount this and explore all of the partitions (including hidden ones).
I've tried to follow several guides, such as : http://forums.opensuse.org/showthread.php/469942-mounting-virtual-box-machine-images-host
I'm able to mount the image using vdfuse
vdfuse -w -f windows.vmdk /mnt/
After this I can see one partition and an entire disk exposed
# ll /mnt/
total 41942016
-r-------- 1 te users 21474836480 Feb 28 14:16 EntireDisk
-r-------- 1 te users 1569718272 Feb 28 14:16 Partition1
Continuing with the guide I try to mount either EntireDisk or Partition1 using
mount -o loop,ro /mnt/Partition1 mnt2/
But that gives me the error 'mount: you must specify a filesystem type'
In trying to find the correct type I tried
dd if=/mnt/EntireDisk | file -
which outputs a ton of information but of note is:
/dev/stdin: x86 boot sector; partition 1: ....... FATs ....
So i tired to mount as a vfat but that gave me
mount: wrong fs type, bad option, bad superblock ...etc
What am I doing wrong?
For newer Linux systems, you can use guestmount to mount the third partition within a VMDK image:
guestmount -a xyz.vmdk -m /dev/sda3 --ro /mnt/vmdk
Alternatively, to autodetect and mount an image (less reliable), you can try:
guestmount -a xyz.vmdk -i --ro /mnt/vmdk
Do note that the flag --ro simply mounts the image as read-only; to mount the image as read-write, just replace it with the flag --rw.
Installation
guestmount is contained in following packages per distro:
Ubuntu: libguestfs-tools
OpenSuse: guestfs-tools
CentOS / Fedora: libguestfs-tools-c
Troubleshooting
error: could not create appliance through libvirt
$ guestmount -a file.vmdk -i --ro /mnt/guest
libguestfs: error: could not create appliance through libvirt.
Try running qemu directly without libvirt using this environment variable:
export LIBGUESTFS_BACKEND=direct
Original error from libvirt: Cannot access backing file '/path/to/file.vmdk' of storage file '/tmp/libguestfssF6WKX/overlay1.qcow2' (as uid:107, gid:107): Permission denied [code=38 int1=13]
Solution: use LIBGUESTFS_BACKEND=direct, as suggested:
LIBGUESTFS_BACKEND=direct guestmount -a file.vmdk -i --ro /mnt/guest
fusermount: user has no write access to mountpoint
LIBGUESTFS_BACKEND=direct guestmount -a file.vmdk -i --ro /mnt/guest/
fusermount: user has no write access to mountpoint /mnt/guest
libguestfs: error: fuse_mount failed: /mnt/guest/, see error messages above
Solution: use sudo, or change file permissions on the mountpoint
You can also use qemu:
For .vdi disks
sudo modprobe nbd
sudo qemu-nbd -c /dev/nbd1 ./linux_box/VM/image.vdi
if they are not installed, you can install them (issuing this command in Ubuntu)
sudo apt install qemu-utils
and then mount it with:
mount /dev/nbd1p1 /mnt
For .vmdk disks
sudo modprobe nbd
sudo qemu-nbd -r -c /dev/nbd1 ./linux_box/VM/image.vmdk
notice that I use the option -r, that's because VMDK version 3 must be read only to be able to be mounted by qemu
and then I mount it with
mount /dev/nbd1p1 /mnt
I use nbd1, because nbd0 sometimes gives: 'mount: special device /dev/nbd0p1 does not exist'
For .ova disks
tar -tf image.ova
tar -xvf image.ova
The above will extract the .vmdk disk and then mount it.
Install affuse, then mount using it.
affuse /path/file.vmdk /mnt/vmdk
The raw disk image is now found under /mnt/vmdk.
Check its sector size:
fdisk -l /mnt/vmdk/file.vmdk.raw
# example
Disk file.vmdk.raw: 20 GiB, 21474836480 bytes, 41943040 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
Disklabel type: dos
Disk identifier: 0x000da525
Device Boot Start End Sectors Size Id Type
/mnt/vmdk/file.vmdk.raw1 * 2048 41943039 41940992 20G 83 Linux
Multiply sector size and start sector. In the example it would be 2048*512:
echo '2048*512' | bc
1048576
Mount the raw file using that offset:
mount -o ro,loop,offset=1048576 /mnt/vmdk/file.raw /mnt/vmdisk
The disk should now be mounted and readable on /mnt/vmdisk.
Here is an answer from commandlinefu.com that worked for me:
kpartx -av <image-flat.vmdk>; mount -o /dev/mapper/loop0p1 /mnt/vmdk
You can also activate LVM volumes in the image by running
vgchange -a y
and then you can mount the LV inside the image.
To unmount the image, umount the partition/LV, deactivate the VG for the image
vgchange -a n <volume_group>
then run
kpartx -dv <image-flad.vmdk>
to remove the partition mappings.
You can take a look in this article for a download link for VMware Virtual Disk Development Kit (VDDK). Once downloaded and installed:
vmware-mount -p path_to_vmdk will show the partitions inside the VMDK file. For example:
Nr Start Size Type Id Sytem
-- ---------- ---------- ---- -- ------------------------
1 2048 461371392 BIOS 83 Linux
Then just do:
sudo vmware-mount path_to_vmdk 1 /mnt/mount_point
I tried guestmount, but it is very, very slow. Underneath it creates a virtual machine, uses KVM and so on. Crazy stuff, slow as hell.
Have you got the software package for ntfs?
Try
apt-get install ntfs-3g
on debian based systems.

riak-admin fails on osx 10.8.5

I'm trying to install riak on my OSX 10.8.5, but when using the command riak-admin test it always fail. I can't find a solution for it!
Also using sudo riak-admin test doesn't help it.
I have installed riak(1.4.2) through brew.
>riak start
!!!!
!!!! WARNING: ulimit -n is 256; 4096 is the recommended minimum.
!!!!
>riak ping
pong
>riak-admin test
Failed to write test value: {error,timeout}%
I have installed riak(1.4.2) precompiled tarball using wget
>curl -O http://s3.amazonaws.com/downloads.basho.com/riak/1.4/1.4.2/osx/10.8/riak-1.4.2-OSX-x86_64.tar.gz
>tar xzvf riak-1.4.2-osx-x86_64.tar.gz
>cd riak-1.4.2
>bin/riak start
!!!!
!!!! WARNING: ulimit -n is 256; 4096 is the recommended minimum.
!!!!
>bin/riak ping
pong
>bin/riak-admin test
Failed to write test value: {error,timeout}%
I have install riak(1.4.1) precompiled tarball using wget
>curl -O http://s3.amazonaws.com/downloads.basho.com/riak/1.4/1.4.1/osx/10.8/riak-1.4.1-OSX-x86_64.tar.gz
>tar xzvf riak-1.4.1-osx-x86_64.tar.gz
>cd riak-1.4.1
>bin/riak start
!!!!
!!!! WARNING: ulimit -n is 256; 4096 is the recommended minimum.
!!!!
>bin/riak ping
pong
>bin/riak-admin test
Failed to read test value: {error,{insufficient_vnodes,0,need,1}}%
Solution
Following this procedure http://docs.basho.com/riak/... solved my issue.
It has to do with the Open Files Limit on mac OSX.
Before
To check the current limits on your Mac OS X system, run:
>launchctl limit maxfiles
maxfiles 256 unlimited
Edit (or create) /etc/launchd.conf
Edit (or create) /etc/launchd.conf and increase the limits. Add lines
that look like the following (using values appropriate to your
environment):
limit maxfiles 16384 32768
Restart the system
Save the file, and restart the system for the new limits to take
effect. After restarting, verify the new limits with the launchctl
limit command:
>launchctl limit maxfiles
maxfiles 16384 32768

Resources