4 ms·
Does the third command really work as intended? sudo cat ubuntu-14.04-desktop-amd64.dmg >> /dev/sda1 I believe this will attempt to write data after the o
by vog 11y ago
Does the third command really work as intended?
sudo cat ubuntu-14.04-desktop-amd64.dmg >> /dev/sda1
I believe this will attempt to write data after the of the the block device, which almost by defintion will fail.
However, I often do the following, which works pretty well:
sudo cat ubuntu-14.04-desktop-amd64.dmg > /dev/sda1
- acranox 11y agoThe redirection will happen in your shell, but the command will be called inside the shell invoked by sudo. So that won't work either unless you have write privs to the block device, but if that were the case, you probably didn't need sudo to read the dmg file. So this will likely fail for a reason other than the one you pointed out.
- vive-la-liberte 11y agoCorrect. In these kinds of situations I usually do sudo sh -c 'blah blah blah >> file' but I don't like it when I have to do that.
- deleted 11y ago[deleted]
- laumars 11y agoA better way to write files as root is to pipe the output into `tee`. eg: blah blah blah | sudo tee -a file This will do the appending as per your example. If you want to write to the file like people are doing with the Ubuntu image then just drop the append (-a) flag: cat ubuntu-14.04-desktop-amd64.dmg | sudo tee /dev/sda1 Though obviously the `dd` utility is still a better way of writing disk images than any of the above.
- cnvogel 11y ago'>>' will cause O_APPEND to be specified as flags when opening "/dev/sda". I'm pretty sure this flag is ignored on block devices as it's obviously useless. fd = open("/dev/sda", O_WRONLY|O_CREAT|O_NOCTTY|O_APPEND, 0644); pos = lseek(fd, 0, SEEK_CUR); -> pos = 0 http://hastebin.com/abuhiwivoz.pl http://hastebin.com/abuhiwivoz.pl # tmp sudo ./open_sda Current position after open: 0 Current position after seek to end: 128035676160
- Sir_Cmpwn 11y agoBetter: cat ubuntu-14.04-desktop-amd64.dmg | sudo tee /dev/sda1
- laumars 11y agoI know you meant to use the pipe instead of redirection, but it might be worth updating your comment for the benefit of others who are less command line literate :)
- Sir_Cmpwn 11y agoWhoops, fixed.
- nilved 11y agoBest: sudo tee /dev/sda < ubuntu-14.04-desktop-amd64.dmg
- pedrocr 11y agoYou better redirect tee to /dev/null otherwise your terminal is going to print out that whole file.
- orik 11y agoif you used cat, could potentially something escape and run in your userspace?