Is there a command for the apple terminal to brute force a wipe of everything including all partitions, master boot records, and data on a usb flash drive?
Just a little information about the situation:
I just got a stick from a friend which seems to be damaged but it isnt a physical defect. I guess he just removed the stick while formatting or so.
I already tried to repartition, reformat and erase the stick with the Mac Disc Utility and I tried to format it on windows. Nothing of it worked, so I decided to use terminal for it (im just getting used to terminal/bash, so im a complete newbie at this) and tried the commands (all with sudo and diskutil in front of them ofc) repairDisk, reformat, partitionDisk, eraseDisk or zeroDisk, but nothing worked. Im getting this error message now: Error: -69759: Securely erasing data to prevent recovery failed
Underlying error: 5: POSIX reports: Input/output error
So my final thought is now that I have to clean everything from this drive as it seems there is something broken on a very low level and i would assume that completely wiping it will result in my diskutil to install a complete new partition scheme and everything on the drive so it will eventually start working again..
Thank you all in advance!
Screenshots:
Try this in Terminal if you are CERTAIN it is disk3:
sudo dd if=/dev/zero of=/dev/rdisk3 bs=65536 count=1000
If it says the disk is busy, make it un-busy!
sudo diskutil unmountDisk /dev/disk3
First, check what disk# your usb is (to be certain) in a terminal:
sudo diskUtil list
then
sudo dd if=/dev/urandom of=/dev/<your_usb_disk_here> bs=1m
If you get busy error and/or if the usb is in use elsewhere, stop what you are doing there and unmount it first as Mark Setchell said
sudo diskutil unmountDisk /dev/<your_usb_disk_here>
If you get a funky name from using bootcamp assistant or something, and you cannot get dd or even Disk Utility to wipe it for some reason, like "permission" problem, use:
diskutil eraseVolume HFS+ NAME <your_usb_disk_here>
Note that the last arg is not e.g. /dev/disk2 , but just the last part, disk2
Related
usually creating RAM disks works with the following commands
hdid -nomount ram://<blocksize>
Returns e.g. /dev/disk2
Then I would format the disk, with say
newfs_hfs /dev/disk2
followed by mounting it:
mount -t hfs /dev/disk2 /some/mount/target
This procedure doesn't seem to work with APFS. I'm on High Sierra beta 9. The mount command doesn't output any error, but the path is not mounted.
In my case, after the hdid command finished, newfs_apfs -i /dev/disk2 yields
nx_kernel_mount:1364: checkpoint search: largest xid 1, best xid 1 # 1
nx_kernel_mount:1422: sanity checking all nx state... please be patient.
spaceman_metazone_init:278: no metazone for device 0, of size 209715200 bytes, block_size 4096
apfs_newfs:18075: FS will NOT be encrypted.
When I then enter mount -t apfs /dev/disk2 /some/target/path then the mount commands seems to work for 2 seconds, doesn't give any output and the mount was NOT succesful.
Can anyone tell me how to actually make a APFS RAM disk s.t. it works? :p
PS: I've also tried something like diskutil partitionDisk /dev/disk2 GPT APFS myvolumename 0b which does mount the volume to /Volumes/myvolumename but creates yet another disk (disk3 in this case) which seems odd to me!
#Glyph provided the best answer in a comment to the accepted answer, but it deserves its own answer:
diskutil partitionDisk $(hdiutil attach -nomount ram://$((2048*sizeInMB))) 1 GPTFormat APFS 'Ramdisk' '100%'
Change sizeInMB to your desired size.
I've updated Glyph's answer to simplify the volume name a little.
Found a solution:
hdid -nomount ram://<blocksize>
diskutil erasedisk <format> <diskname> <output path of previous hdid command>
where <format> is taken from diskutil listFilesystems from the "Personality" column. Yes, it seems weird to me too that you may have to quote this parameter, e.g. when specifying case-sensitive variants, but oh well...
<blocksize> is 2048 * desired size in megabytes
The last command formats the RAM disk and mounts it to /Volumes/<diskname>
It seems to be the case that when now entering diskutil list that you will see two new disks, the one hdid created, and a synthesized one.
To destroy the RAM disk again, call diskutil eject <output path of previous hdid command>, e.g. diskutil eject /dev/disk2
This will do all the work for you, unmounting the /Volumes/<diskname> path and destroy the two disks, releasing your memory.
Keep in mind that the minimum/maximum values for <blocksize> depend on the chosen <format>. Also, <diskname> cannot always be chosen arbitrarily. Exemplary, FAT32 requires it to consist of upper-case letters!
Cheers!
Also, info to delete/destroy the RAM disk needs to be corrected. ramdisk will be created at path /Volumes/'ramdisk', so the command is:
diskutil eject /Volumes/'ramdisk'
Good evening everyone! I have been working on this for sometime, but can't figure it out. I am simply trying to get the working bootcode of a bootloader installed on an attached media, but can't figure this out!!! I have tried grub legacy, lilo, and grub2... The host system has it's drive listed as /dev/sda* and the target attached media is listed as /dev/sdb* and is mounted to /mnt/target.
With grub legacy, I was attempting to work with another media (/dev/sdc*, /mnt/source) that already had it installed and tried dirty hacks like:
dd if=/mnt/source/boot/grub/stage1 of=/dev/sdb bs=446 count=1
dd if=/mnt/source/boot/grub/stage2 of=/dev/sdb bs=512 seek=1
This will actually boot into a grub interface where you can enter things like:
root (hd0,0)
setup (hd0)
I get no error messages, but grub will boot to garbage on the screen and then stop.
With lilo, I actually had the package installed and tried to setup (after creating a lilo.conf):
default=Test1
timeout=10
compact
prompt
lba32
backup=/mnt/target/boot/lilo/MBR.hda.990428
map=/mnt/target/boot/lilo/map
install=/mnt/target/boot/lilo/boot.b
image=/mnt/target/boot/vmlinuz
label=Test1
append="quiet ... settime"
initrd=/mnt/target/boot/ramdisks/working.gz
And then from the prompt execute the following:
$ lilo -C /mnt/target/boot/lilo/lilo.conf -b /dev/sdb
Warning: /dev/sdb is not on the first disk
Fatal: Sorry, don't know how to handle device 0x0701
With grub2, I tried something like:
grub-mkconfig -o /mnt/target/boot/grub/grub.cfg
Generating grub.cfg ...
Found linux image: /boot/vmlinuz-3.11.0-12-generic
Found initrd image: /boot/initrd.img-3.11.0-12-generic
Found memtest86+ image: /boot/memtest86+.bin
No volume groups found
done
I couldn't even get the above to generate a grub.cfg correctly or in the right spot so I gave up on this one... The entries listed above are for the host system, not the target system.
I can provide any additional information that you guys need to help resolve this problem.
-UPDATE-
After working with the media a bit longer, I decided to run an 'fdisk -l' and was presented with the following info:
Partition 1 has different physical/logical beginnings (non-Linux?):
phys(0,32,33) logical(0,37,14)
Partition 1 has different physical/logical endings:
phys(62,53,55) logical(336,27,19)
I should also note that when I try to mount the partition I always get a message that states:
EXT4-fs (sdb1): couldn't mount as ext3 due to feature incompatibilities
Not sure if that is just specific to busybox, or if that is related to the fdisk output. Anyhow, I don't know if the fdisk info is indicating that there may be a problem with the disk geometry that could be causing all these bootloaders to not work.
First stage boot sector code for grub legacy is in "stage1", for grub(2) in "boot.img". Fist stage code contains the address of next stage to be loaded on same disk.
On some other disk the address of next stage to be loaded could be (and is maybe) different.
I think using chroot and grub-install would be a better way to go.
See Grub2/Installing.
As for disk/partition structure:
dd if=/mnt/source/boot/grub/stage2 of=/dev/sdb bs=512 seek=1
maybe has overwritten partition table in MBR of sdb.
So, this should apparently be really simple, but had trouble finding any good answers online.
I have a mounted external usb hard drive.
I would like to unmount it, using bash. (Essentially I'm just looking for the equivalent bash command for right clicking on my external hard drive in nautilus and selecting 'unmount')
How can I achieve this?
Searching for "Unmount Hard Drive Terminal" yields http://ubuntuforums.org/showthread.php?t=842698.
russlar provides a solution:
open terminal, and run df -h. this will tell you all the hard drives mounted. then, run sudo umount /dev/<something>, where <something> is the name of the hard drive that you want to unmount.
I set the HOME variable in /etc/launchd.conf using the following line: setenv HOME /Users/student
Now the machine wont boot at startup. I tried holding shift at startup but safe mode doesn't seem to be working. I tried holding cmd+s on startup and got into single user mode. I was able to bring up the /etc/launchd.conf file but I can not save/overwrite the existing file due to permission issues.
Is there some way to reset this file from single user mode or other to fix this? I'm open to other approaches as well. I am not a unix/linux power user by any means, fyi :)
Thank you in advance.
I'll give you two options, but first a warning: both of these involve using the command line to undo the damage, and if you do it wrong there's a possibility you'll make it even worse. A backup would've been a good idea, but it's a little late for that (well, actually, there are still ways to do it, but they also involve a risk of getting it wrong...). So whatever your do, be careful.
Option 1: use single-user mode (Command-S at startup). This will leave you running as root, which means you are not subject to normal file permissions; after remounting the startup disk for write access (mount -uw /) you should not get permissions errors. You said this didn't work; the most likely thing is that you mistyped the command (I see this happen a lot -- people either leave out the "/", or the space between "-uw" and "/"). Hint: if the mount command prints anything (other than the prompt for the next command) you typed it wrong. If that still doesn't do it, check the file's flags and metadata with ls -leO# /etc/launchd.conf and report the results.
Option 2: use recovery mode (Command-R at startup). This boots from a small hidden partition with a minimal copy of OS X. In recovery mode, pull down the Utilities menu and choose Terminal. This is actually a fair bit like single-user mode, except that the normal startup disk won't be /, it'll be /Volumes/Macintosh HD (or whatever it's named), and it'll already be mounted for write access. Since there's (probably) a space in the volume name, you'll have to quote or escape it:
$ cd "/Volumes/Macintosh HD"
$ mv launchd.conf launchd.conf-disabled
I have a shell script that mounts an smb share. It works perfectly on all macs with every OS revision except 10.7.5
The offending command is simply:
mount -t smbfs -o nobrowse //test:test#servername/sharename /my/mnt/point
When I attempt this command on a 10.7.5 mac, it fails either with a "broken pipe" or "authentication failed" error. However, it works fine on macs running 10.7.4, 10.6, 10.8 etc.
Can anyone successfully use this command on 10.7.5?
Is there any alternative way of achieving this, or troubleshooting exactly why this error is happening? I'm running out of ideas!
Since feature requests to mark a comment as an answer remain declined, I copy the above solution here.
Thanks for the replies. The problem was two fold: firstly, for some reason you cannot run this command as root in 10.7.5, and secondly you cannot mount outisde of /Volumes. Strangely this seems to work in all other OS revisions. I have worked around this problem by mounting my share in /Volumes and then creating a sym link to the desired mount point:
mkdir -p /Volumes/share
sudo -u localadminuser mount -t smbfs -o nobrowse //user:pass#server/share /Volumes/share
ln -s /Volumes/share /location/that/I/prefer/to/mnt
I hope this helps someone out. No idea why 10.7.5 changes this. – BSUK
There are many reasons why the mount will not work. Some of the reasons include:
Time between server and client being too different
Workgroup name not specified on the mac
Local hostname uses non-latin characters
Encryption is too strict between the mac and the server
To solve the time; set the time.
I've seen broken pipe/authentication errors most often when you don't use a workgroup name for the connection. A connection string looking like generally works better than one without any workgroup:
//WORKGROUP;user:50000#192.168.2.1/Share
... assuming that the 50000 is the password for the user user should allow the connection. Generally, you just need to have a string before the semi-colon, it can read anything; it just needs to be there.
To solve the local hostname issue click on an interface, choose advanced go to the WINS tab and make sure that the name doesn't have any foreign characters there.
If the encryption is too strict, you will need to edit the nsmb.conf. I have a set of lines looking like:
[server1]
minauth=none
for an ancient BSD server which cannot deal with encrypted passwords. You can have this in either an /etc/nsmb.conf or ~/Library/Preferences/nsmb.conf file.
This may not address your issue, but it may help you in trying to proceed.
Unfortunately, saying it works on box x and not on box y doesn't really help, as there could be any arbitrary configuration difference between them.