Announcement

Collapse
No announcement yet.

Noob ownership question - copying from usb drive sdb1 to sda6

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Noob ownership question - copying from usb drive sdb1 to sda6

    Still new to Linux. And I have an ownership question.

    I have an ext4 partition sda6 on which I'd like to store media files and such. It is owned by root. There is nothing on this partition at the moment.

    The media files are stored on a USB drive, sdb1. It is owned by User.

    Is it advisable to change the owner of sda6 to User?

    if not, why not?

    #2
    Short answer is sure, go ahead.

    Some terminology discussion;
    "sda6" is a partition and as such, has no actual ownership. A partition is nothing more than a divider to separate drive space.
    "ext4" is a file system format (or type). The file system is applied to the partition, thus allowing access to the drive space to store files.
    File systems are mounted to define where they are accessed,
    "ownership" and permissions are applied to the files and folders and in some ways to the file system, not directly to the entire partition.
    So you wouldn't actually change the ownership of the partition, you would mount it in a way that would allow you access as a user. Terminology is very important in my opinion because it allows us to be clear and specific. For example, there are some file systems that don't require partitions so one could confuse the details. I nit-pick this area often because it's sort of my area and I want there to be no mistakes because when you're messing about with file systems and drive partitions it's easy to lose everything with a minor slip-up. OK, off the soap box (for now ).

    How you go about this depends on your needs, but since we know we have a fixed (not removable) device, the "normal" way to mount this is using the /etc/fstab file. Since mounting requires root level access, all mounts are initially owned by root even if you mount to a folder owned by you. After mounting the first time, you can change ownership of the mount to you and it will stick.

    Lets assume you want this mounted at every boot. Since it's for you I recommend mounting in your home folder somewhere. Start by opening a terminal (konsole). Then, for example if your username is bob:

    mkdir /home/bob/storage
    sudo mount /dev/sda6 /home/bob/storage
    sudo chown bob:bob /home/bob/storage

    Now you have mounted it in your home under "storage" and you "own" it. The ownership will be remembered from now on.

    To this mounted each time you boot you need to add it to fstab. First step is to find the UUID of the file system on /dev/sda6. You can use the device name or file system label to mount, but UUIDs are considered the best way. This will show you the UUID:

    lsblk |grep sda6 | awk '{ print $4 }'

    It will look something like this:

    8f0691df-074c-4b0b-ad38-d993d17fef67

    Copy it (highlight and select copy) and then edit fstab using kate or kwrite;

    kate /etc/fstab

    Add this line to fstab;

    UUID=8f0691df-074c-4b0b-ad38-d993d17fef67 /home/bob/storage ext4 defaults,user 0 0

    and save it. The "user" option will allow you to mount and unmount it without being root. If you add "noauto" to the options, it would not be mounted at boot but you could mount it manually without using sudo.

    #Note that you need to leave a blank line at the end of fstab (a final carriage return) - many if not most Linux files will want a final carriage return at the end. It's a good habit just to do it everywhere.

    There are other ways to do this, but this is the standard way fixed devices are handled.


    Another tip; Since you're using EXT4 you should be aware that EXT4 reserves 5% of it's space for "root" use. This is to protect you from locking the file system if it gets 100% full and helps reduce the chance of massive fragmentation that would slow file system access considerably. However, 5% is excessive unless it's a very small partition. Try this to see how many blocks are saved;

    sudo tune2fs -l /dev/sda6 |grep 'Reserved block count'

    also do;

    df -h

    to see how much free space. Then to change it;

    sudo tune2fs -m1 /dev/sda6

    "m1" sets it at one percent. Or you can use zero, whatever. Then re-run the two above commands and look at the difference. My EXT4 partition I use for virtual machines is 363GB in size. Changing the default of 5% to 1% gave me about 15GB more free space.
    Last edited by oshunluvr; Feb 12, 2019, 01:22 PM.

    Please Read Me

    Comment


      #3
      Thank you once again oshunluvr!

      I agree with you about terminology and thank you for the clarification. I still have to translate to/from Windows-speak.

      I have done as you said. I won't be able to test against the usb device till later. But I'm hopeful.

      There are couple of things I had to do differently than you said,
      lsblk didn't get the UUID. I used blkid.
      I had to add it fstab before mounting.

      Comment


        #4
        Originally posted by TwoFistedJustice View Post
        lsblk didn't get the UUID. I used blkid.
        Yeah, lsblk only shows the UUID of mounted devices.

        Originally posted by TwoFistedJustice View Post
        I had to add it fstab before mounting.
        You can mount manually without fstab like this:

        sudo mount -o user /dev/sda6 /home/bob/storage

        Good to know if you run into mounting problems down the road. Mounting from the command line will expose error messages and warnings, etc. Just entering "mount" with nothing else will list all your current mounts and their options in use.

        Please Read Me

        Comment

        Working...
        X