WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Why can't dd write to /dev/ram0 on Core Linux?  (Read 3247 times)

Offline holmessherlock

  • Newbie
  • *
  • Posts: 5
Why can't dd write to /dev/ram0 on Core Linux?
« on: July 05, 2018, 01:08:09 AM »
I created an ext2 file-system on `/dev/ram0` ramdisk, and mounted it at `/mnt/ram`.

Code: [Select]
mkdir /mnt/ram
mkext2fs /dev/ram0
sudo mount /dev/ram0 /mnt/ram -o rw

Reading from ramdisk with `dd` works.

Code: [Select]
dd if=/dev/ram0 bs=1 count=1

When I want to write the contents of the file `my_file` to ramdisk, it fails.

Code: [Select]
dd if=./my_file of=/dev/ram0 bs=1 count=1
0+0 records in
0+0 records out
0 bytes (0B) copied, 0.000913 seconds, 0B/s

However, just reading the file dumps its content on stdin.

Code: [Select]
dd if=./my_file bs=1 count=1

The permission on `/dev/ram0` shows rw permisssion for root.

Code: [Select]
ls -l /dev/ram0
brw-rw----   1  root   staff   1,   0   Jul   5   02:56   /dev/ram0

What does prevent dd from writing to `/dev/ram0`?

Offline polikuo

  • Hero Member
  • *****
  • Posts: 724
Re: Why can't dd write to /dev/ram0 on Core Linux?
« Reply #1 on: July 05, 2018, 01:30:47 AM »
TC use zswap to speed up swapping

You can disable it by adding boot code "nozswap"

See /etc/init.d/tc-config

Quote
if [ -n "$NOZSWAP" ]; then
   echo "${BLUE}Skipping compressed swap in ram as requested from the boot command line.${NORMAL}"
else
   modprobe -q zram
   modprobe -q zcache

   while [ ! -e /dev/zram0 ]; do usleep 50000; done
   grep MemFree /proc/meminfo | awk '{print $2/4 "K"}' > /sys/block/zram0/disksize

   mkswap /dev/zram0 >/dev/null 2>&1
   swapon /dev/zram0
   echo "/dev/zram0  swap         swap    defaults,noauto   0       0" >> /etc/fstab # Lets swapoff -a work
fi

Offline Pats

  • Sr. Member
  • ****
  • Posts: 322
Re: Why can't dd write to /dev/ram0 on Core Linux?
« Reply #2 on: July 05, 2018, 01:38:01 AM »
Quote
What does prevent dd from writing to `/dev/ram0`?

"sudo" is a very useful command !

Offline holmessherlock

  • Newbie
  • *
  • Posts: 5
Re: Why can't dd write to /dev/ram0 on Core Linux?
« Reply #3 on: July 05, 2018, 03:31:46 AM »
"sudo" is a very useful command !

I know, but not in this case. Already tried.


Offline holmessherlock

  • Newbie
  • *
  • Posts: 5
Re: Why can't dd write to /dev/ram0 on Core Linux?
« Reply #4 on: July 05, 2018, 03:35:23 AM »
TC use zswap to speed up swapping

Why will zwap prevent ramdisk write attempts?

Offline polikuo

  • Hero Member
  • *****
  • Posts: 724
Re: Why can't dd write to /dev/ram0 on Core Linux?
« Reply #5 on: July 05, 2018, 04:12:04 AM »
I don't see any problem even as a normal user ??? ?

/dev/ram*
Code: [Select]
tc@box:~$ ls -l /dev/ram*
lrwxrwxrwx    1 root     root             4 Feb 26 21:17 /dev/ram -> ram1
brw-rw----    1 root     staff       1,   0 Jul  5 15:56 /dev/ram0
brw-rw----    1 root     staff       1,   1 Jul  5 15:55 /dev/ram1
brw-rw----    1 root     staff       1,   2 Jul  5 14:56 /dev/ram2
brw-rw----    1 root     staff       1,   3 Jul  5 14:56 /dev/ram3
brw-rw----    1 root     staff       1,   4 Jul  5 14:56 /dev/ram4
brw-rw----    1 root     staff       1,   5 Jul  5 14:56 /dev/ram5
brw-rw----    1 root     staff       1,   6 Jul  5 14:56 /dev/ram6
brw-rw----    1 root     staff       1,   7 Jul  5 14:56 /dev/ram7

Read
Code: [Select]
tc@box:~$ dd if=/dev/ram0 of=/dev/null bs=512 count=1
1+0 records in
1+0 records out
512 bytes (512B) copied, 0.000050 seconds, 9.8MB/s
tc@box:~$ dd if=/dev/ram1 of=/dev/null bs=512 count=1
1+0 records in
1+0 records out
512 bytes (512B) copied, 0.000053 seconds, 9.2MB/s

Write /dev/zero
Code: [Select]
tc@box:~$ dd if=/dev/zero of=/dev/ram0 bs=512 count=1
1+0 records in
1+0 records out
512 bytes (512B) copied, 0.000062 seconds, 7.9MB/s
tc@box:~$ dd if=/dev/zero of=/dev/ram1 bs=512 count=1
1+0 records in
1+0 records out
512 bytes (512B) copied, 0.000060 seconds, 8.1MB/s
tc@box:~$ head -c 512 /dev/ram0 | hexdump
0000000 0000 0000 0000 0000 0000 0000 0000 0000
*
0000200
tc@box:~$ head -c 512 /dev/ram1 | hexdump
0000000 0000 0000 0000 0000 0000 0000 0000 0000
*
0000200

Write random data
Code: [Select]
tc@box:~$ dd if=/dev/sdb of=/dev/ram0 bs=512 count=1
1+0 records in
1+0 records out
512 bytes (512B) copied, 0.027136 seconds, 18.4KB/s
tc@box:~$ head -c 512 /dev/ram0 | hexdump
0000000 c033 8efa 8ed8 bcd0 7c00 e689 5706 c08e
0000010 fcfb 00bf b906 0100 a5f3 1fea 0006 5200
0000020 b452 bb41 55aa c931 f630 cdf9 7213 8113
0000030 55fb 75aa d10d 73e9 6609 06c7 068d 42b4
0000040 15eb b45a cd08 8313 3fe1 0f51 c6b6 f740
0000050 52e1 6650 c031 9966 66e8 e800 0135 694d
0000060 7373 6e69 2067 706f 7265 7461 6e69 2067
0000070 7973 7473 6d65 0d2e 660a 6660 d231 00bb
0000080 667c 6652 0650 6a53 6a01 8910 66e6 36f7
0000090 7bf4 e4c0 8806 88e1 92c5 36f6 7bf8 c688
00000a0 e108 b841 0201 168a 7bfa 13cd 648d 6610
00000b0 c361 c4e8 beff 7dbe bebf b907 0020 a5f3
00000c0 66c3 8960 bbe5 07be 04b9 3100 53c0 f651
00000d0 8007 0374 8940 83de 10c3 f3e2 7448 795b
00000e0 5939 8a5b 0447 0f3c 0674 7f24 053c 2275
00000f0 8b66 0847 8b66 1456 0166 66d0 d221 0375
0000100 8966 e8c2 ffac 0372 b6e8 66ff 468b e81c
0000110 ffa0 c383 e210 66cc c361 76e8 4d00 6c75
0000120 6974 6c70 2065 6361 6974 6576 7020 7261
0000130 6974 6974 6e6f 2e73 0a0d 8b66 0844 0366
0000140 1c46 8966 0844 30e8 72ff 6627 3e81 7c00
0000150 4658 4253 0975 8366 04c0 1ce8 72ff 8113
0000160 fe3e 557d 0faa f285 bcfe 7bfa 5f5a fa07
0000170 e4ff 1ee8 4f00 6570 6172 6974 676e 7320
0000180 7379 6574 206d 6f6c 6461 6520 7272 726f
0000190 0d2e 5e0a b4ac 8a0e 623e b304 cd07 3c10
00001a0 750a cdf1 f418 fdeb 0000 0000 0000 0000
00001b0 0000 0000 0000 0000 7cb4 b4d8 0000 0100
00001c0 0001 fe07 ffff 003f 0000 a14e 0bb4 fe00
00001d0 ffff fe0f ffff 318d 0c35 1ab4 2e03 fe80
00001e0 ffff fe83 ffff a18d 0bb4 9621 0059 fe00
00001f0 ffff fe82 ffff 37ae 0c0e f9df 0026 aa55
0000200

Offline holmessherlock

  • Newbie
  • *
  • Posts: 5
Re: Why can't dd write to /dev/ram0 on Core Linux?
« Reply #6 on: July 05, 2018, 04:27:36 AM »
I don't see any problem even as a normal user ??? ?

I have no clue what's going on, because as you can see



Can you try using the skip parameter once?


Offline Pats

  • Sr. Member
  • ****
  • Posts: 322
Re: Why can't dd write to /dev/ram0 on Core Linux?
« Reply #7 on: July 05, 2018, 04:55:52 AM »
Normal way of RAM disk :

Quote
sudo mkdir /tmp/ramdisk
sudo chmod 777 /tmp/ramdisk
sudo mount -t tmpfs -o size=1024m myramdisk /tmp/ramdisk


To test write speed :
Quote
sudo dd if=/dev/zero of=/tmp/ramdisk/zero bs=4k count=10000

 To test read speed, run:
Quote
sudo dd if=/tmp/ramdisk/zero of=/dev/null bs=4k count=10000

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11044
Re: Why can't dd write to /dev/ram0 on Core Linux?
« Reply #8 on: July 05, 2018, 12:57:23 PM »
Do read dd's man page... skip means skip that many input blocks. Your input file is 1 byte long, you can't exactly skip 292kb into it.
The only barriers that can stop you are the ones you create yourself.

Offline holmessherlock

  • Newbie
  • *
  • Posts: 5
Re: Why can't dd write to /dev/ram0 on Core Linux?
« Reply #9 on: July 05, 2018, 11:23:07 PM »
Do read dd's man page... skip means skip that many input blocks. Your input file is 1 byte long, you can't exactly skip 292kb into it.

Oops, thanks for catching it. It will be `seek` instead of `skip`