Sudo echo "/mnt/4GB.swap swap swap defaults 0 0" >> /etc/fstab: permission denied

Started the Getting Started with AI course on a jetson Nano. in the setup portion there is the changing the swap file size. The last line is the above where I get “permission denied” yes using sudo and have tried changing permissions with chmod 600 /etc/fstab.

No idea what to do next…


What do you see from this command?
ls -l /usr/bin/sudo

It should look something like this:
-rwsr-xr-x 1 root root 149080 Jan 19 07:36 /usr/bin/sudo*

If you are missing the “sticky bit” (the “s” of “rwsr”), then you generated your filesystem incorrectly, likely using NTFS as the basis during flash with SDKM and would need to flash again using a Linux filesystem (ext4) for flash. If this is already correct, then something much more odd is going on.

This is the entire cmd chain:

# Disable ZRAM:
sudo systemctl disable nvzramconfig

# Create 4GB swap file
sudo fallocate -l 4G /mnt/4GB.swap
sudo chmod 600 /mnt/4GB.swap
sudo mkswap /mnt/4GB.swap

# Append the following line to /etc/fstab
sudo echo "/mnt/4GB.swap swap swap defaults 0 0" >> /etc/fstab

permission denied again, didn't bother rebooting...

after the mkswap cmd this was the result:
mkswap: /mnt/4GB.swap: warning: wiping old swap signature.
Setting up swapspace version 1, size = 4 GiB (4294963200 bytes)
no label, UUID=0e316c07-2c50-45f8-b5b9-e1c15d1b02ba
appreciate your help!!!

aaaarg! forgot to mention, ran your suggestions and had the identical result with the exception my time was 09:30

on the nvzramconfig cmd the message was it did not exist since I have tried this so many times…

We really need to know what the permissions are for the “sudo” command. If you type “which sudo”, then it should show the location (which is highly likely to be “/usr/bin/sudo”). If the permissions are wrong, then you cannot succeed. We need to verify that (A) the partition type where the command exists is ext4 (try “lsblk -f” and examine the filesystem type for the one which contains “/etc/fstab”), and (B) the sudo command itself has the sticky bit set. I did just realize that this must be at least partially ok if any sudo command succeeded, so also provide the permissions of the fstab file: “ls -l /etc/fstab”.

FYI, fstab should not have any special restrictions to it other than needing root authority. If none of the above shows what is going on, then perhaps the filesystem as a whole is read-only, but we can look at that after verifying the (A) sudo sticky bit, (B) filesystem type is ext4, and (C) the fstab file itself does not have anything unusual going on with it.

So, since I was having so many glitches did a clean install. Current config OOTB;
gary@gary-desktop:~$ free -m
total used free shared buff/cache available
Mem: 3956 1747 1456 62 752 2095
Swap: 1978 0 1978
gary@gary-desktop:~$ which sudo
gary@gary-desktop:~$ lsblk -f
loop0 vfat L4T-README 1234-ABCD
├─mmcblk0p1 ext4 ff2880cc-1a99-40bd-88c1-5cdc86fe9eed /
zram0 [SWAP]
zram1 [SWAP]
zram2 [SWAP]
zram3 [SWAP]
gary@gary-desktop:~$ ls -l /etc/fstab
-rw-r–r-- 1 root root 474 Feb 19 21:19 /etc/fstab

And again, thanks for all your help, I’ll hunt for your posts and learn alot.

For the “/usr/bin/sudo” command, what are the permissions of the command?
ls -l /usr/bin/sudo
…there should be a sticky bit set.

The filesystem is correct, I see it is ext4. Did this install work?

Gave up on changing the swap file size. thanks for your help!!

Now that you mention this being a swap file (it should have been obvious from your earlier information) I am thinking there is one other possible simple solution: If the file is in use, then it can’t be modified. You’d have to run sudo swapoff on the particular swap file. Then it should be available, and you could run sudo swapon for that file.

Hi LinuxDev,
I think i am running in to the same thing as the topicstarter, (newby i am) its in the start of the dli coarse, were the advise u to enlarge the swap memory to 4gb,
when i try to walk the path they instruct to do i also get an : permission denied.

sudo echo "/mnt/4GB.swap swap swap defaults 0 0" >> /etc/fstab

this then returns in :
bash: /etc/fstab: permission denied

I am not sure what could be wrong. (other than not having the permision :-))

(Found the missing information for completing this step in the training, not shure if it’s part of the course or not? It is presented in the videoclip)

What do you see from “ls -l /etc/fstab”? What do you see from “cat /etc/fstab”?

Another possibility: “sudo” might end up being applied to the echo, but not to the redirect. To test this theory, first use “sudo -s” on a line all by itself to drop into a root shell. Then run the echo command, but do not use sudo in the echo command…you are already root. If this works, then you can type “exit” to stop using root permissions and revert back to your regular user.

Yes u are correct.
the course hands out the propper information, but it could be to much, and there is a small bit of information missing in the written part underneath the youtube video clip. if one simply copy/paste this information (or wants to go to fast) the error of the topic starter is popping-up. i did it, and it was quite rewarding when i managed it :-) but one has to pay attention how to complete this step. (not sure if i give a way to much info for this course, if they meant it like this?) Greets Danny