Forum › Forums › New users › New Users and General Questions › [SOLVED] How to mount logical drives from terminal?
Tagged: fstab, manual mount, mount, mtab, umount, unmount, X-mount.mkdir
- This topic has 11 replies, 5 voices, and was last updated May 4-1:18 am by dugin.
-
AuthorPosts
-
May 3, 2022 at 1:56 pm #82566Member
dugin
I would like to know how to mount my [internal] logical drives from terminal, without using a file manager to mount the directory in /media, so that there is a green dot on the directory icon, that is, such that the contents of the directory are viewable and operable from terminal. If I run the mount command from terminal as root, the green dot on the logical drive does not illuminate, the drive is not accessible, and paradoxically, cli returns that the device is already mounted (or busy).
- This topic was modified 1 year ago by dugin.
- This topic was modified 1 year ago by dugin.
- This topic was modified 1 year ago by dugin.
May 3, 2022 at 2:23 pm #82569MemberRobin
::(Hint: Please note, you can activate the automount feature in antiX, allowing to let mount a pluggable external drive automatically the moment it was plugged. No need to manually mounting drives at all if you don’t want. Internal drives you can get mounted by the antiX boot option mount=all at start time automatically)
The default way to mount something from terminal is to use the mount command.
In case there is an entry in fstab file describing the mount already it is enough to call it by e.g.
sudo mount /dev/sda7which will mount it to the correct predetermined place already.
But you can also mount it explicitly to any other empty folder in your file system (which you then call mountpoint) as well:
mkdir $HOME/my-special-test-mount sudo mount /dev/sda7 $HOME/my-special-test-mountwhich will mount it to this folder in your home directory, even when your device is mounted already to one or more other mountpoints. Make sure to unmount them all properly before unplugging the device, otherwise you will see data loss. (most recent versions of unplugdrive tool (0.90 on antiX 19 and 0.93 on antiX 21) will handle this unmounting task properly for you)
You can also create manually a folder in /media (or /media/<user>)
sudo mkdir /media/my-special-test-mount sudo mount /dev/sda7 /media/my-special-test-mountBut be aware, writing to this folder might conflict with automatically mounted devices in this folders. Make sure not to use names here already occupied.
Whether the file manager of your choice will show the mounted devices with green dots I can’t tell you, some of them keep their own specific registry or rules to decide whether a device is to be displayed as mounted or not, and in case you do this manually, they possibly won’t notice it.
Further reading: in a console window type the command
man mountWindows is like a submarine. Open a window and serious problems will start.
May 3, 2022 at 2:33 pm #82572MemberPPC
::Edit: Robin typed faster than me 🙂 :
I assume, from your previous posts that you are refereeing to how Rox filer File Manager displays mounted partitions…
0- antix menu > Terminal
1- Create the folder where you want the partition to be mounted. It could be anywhere, in your case, you want it to be in the /media folder… In my antiX 19 the full path is /media/[user_name] so, try this:
cd /media/$USER
mkdir mydiskIn this example, you create a folder called “mydisk”. Assuming your username is “dugin”, it will be in /media/dugin/mydisk
2- Once the folder where it partition will be mounted already exists, you have only to mount the partition you want to access. For example, “sdc1”:
sudo mount /dev/sdc1 /media/dugin/mydisk
If you open rox filer and enter the media/dugin folder, you should see a “green dot” warning that the mount point “mydisk” is mounted…
Note: you can use only a single command to create the mount point and mount the drive. Example:
sudo mkdir -p /media/$USER/mydisk; sudo mount /dev/sdc1 /media/$USER/mydisk3- To unmount your partition from the terminal:
sudo umount /media/dugin/mydisk- This reply was modified 1 year ago by PPC.
- This reply was modified 1 year ago by PPC.
- This reply was modified 1 year ago by PPC.
May 3, 2022 at 3:22 pm #82581Memberdugin
::Sorry, my query pertains to internal logical drives, and I will edit my OP to specify that. I want to accomplish with terminal exactly what a file manager does when I click the (internal) logical drive icon in /media to mount it, using Rox.
- This reply was modified 1 year ago by dugin.
May 3, 2022 at 3:29 pm #82583MemberPPC
::my query pertains to internal logical drives
That is exactly what the commands both answers you got allow you to do. Just use the name of the partition you want to mount instead of “sda7” on Robin’s example and “sdc1” in my example.
P.
Edit: so you don’t get confused- you can name the mount point exactly the same name as the partition you want to access has:
In my example, for partition sdc1:
sudo mkdir -p /media/$USER/mydisk; sudo mount /dev/sdc1 /media/$USER/mydiskYou can simply replace “mydisk” with the same name the partition has, using this command:
sudo mkdir -p /media/$USER/sdc1; sudo mount /dev/sdc1 /media/$USER/sdc1
If your partition appears in Rox directly inside the /media folder (and not inside /media/[your_user_name] ), you can shorten the mountpoint’s path. Ex:
sudo mkdir -p /media/sdc1; sudo mount /dev/sdc1 /media/sdc1
Note: the first part of the command (before the “;”) is to make sure the folder used as mount point always exists. If it exists, you can use only the “sudo mount…” part of the command
- This reply was modified 1 year ago by PPC.
- This reply was modified 1 year ago by PPC.
- This reply was modified 1 year ago by PPC.
May 3, 2022 at 3:55 pm #82589Memberdugin
::I’m not getting it, but if I must create a folder to mount the drive, where is the folder that Rox creates, assuming that Rox is doing what I have to do?
May 3, 2022 at 4:03 pm #82590MemberPPC
::@dugin – we are trying to help you, answering your questions as well as we can – you got answers to your questions- how to mount a logical drive/partition, from the terminal – now you want an explanation of how a file manager mounts a drive/partition?…
… I almost said “RTFM”, but here is my last try, on this thread: probably rox creates a folder with the same name as your partition and then mounts it?… Or like Robin said “In case there is an entry in fstab file describing the mount already it is enough to call it”
What does that have to do with your initial question? Follow the advice given to you, or not, it’s up to you…Bye,
P.
- This reply was modified 1 year ago by PPC.
May 3, 2022 at 4:16 pm #82593Memberdugin
May 3, 2022 at 6:25 pm #82602MemberRobin
::I’m not getting it, but if I must create a folder to mount the drive, where is the folder that Rox creates, assuming that Rox is doing what I have to do?
PPC is correct. Also ROX (or any other filemanager or any other helper tool for mounting) needs to create a folder (usually in /media or /media/<username>) itself, before being able to mount something to this place. After unmounting most filemanagers or helper tools will remove this empty folder again they have created, since it is no longer needed.
After manually mounting a device to /media/<user>/<mountpoint> (by using console command) it will get displayed in Roxfiler correctly with the green dot. So everything is fine. Maybe you need to refresh the Rox filer window to see the change, same goes after unmounting.
Try:
sudo cp /etc/fstab /etc/fstab.bak sudo leafpad /etc/fstabAdd the line:
/dev/sda7 /media/<username>/sda7-test ext3 noauto,exec,usersMake sure to replace sda7 by your actual device name of the partition you want to mount. Also make sure to replace ext3 by the actual file system type of your device. And finally replace <username> by your actual username. (without brackets).
Don’t use blanks in path and filename, this would make necessary quoting, while we want to have things easy in the beginning.
Watch carefully not to touch anything else found in this file.
Make sure there is a blank line in the end of the file still after your editing.Save and close the file.
Now enter
sudo mount /dev/sda7You will get an error message, since the target folder is missing.
So let’s create it and see what happens
sudo mkdir /media/<username>/sda7-testMake sure the path and filename matches what you have used in fstab file before.
Check the folder, you can see it’s actually empty and a default folder.Now again try to mount manually:
sudo mount /dev/sda7This time your device, the partition, will get mounted properly.
It gets mounted to the target folder you have preset in /etc/fstab file.Check in Rox filer, the green dot is present now. (don’t forget to refresh to make it appear). Then, enter the folder, now you’ll find all contents of your mounted partition in there. The contents are not actually copied in this place, but the complete filesystem of your device is mounted to this empty folder. Now this folder is a mountpoint. After unmounting it will be a simple empty folder again.
Also you can use
mount
to see on console it is actually mounted, it should be the last entry in the list.And you can check the mtab file for your new mounted device:
cat /etc/mtabAlso here it’s the last entry probably.
So let’s unmount the thing.
sudo umount /media/<username>/sda7-testDon’t use umount /dev/sda7 here, since this might be ambigious in case the device was mounted to other mountpoints before already. And watch for the spelling, the command is actually umount, not unmount.
Now check in Roxfiler for the green dot. (click the refresh button first…) There should be a grey dot now instead.
Please don’t forget to remove the testing line from your fstab file you have added in the beginning (you also could restore the file from the backup copy fstab.bak you have created).
Once you have made absolutely sure you have properly unmounted the device from the mountpoint you have created (double check this! The folder is supposed to be empty now) you can safely delete this empty folder which was used as a mountpoint before. Using Rox you are to use explicitly the open without mounting option from context menu, otherwise Rox will remount it automatically, similar for any other file manager. Be extremely carefully here, if you don’t make absolutely sure your device is unmounted properly from the folder you might easily delete its complete content this way!
That’s most of the magic behind mounting and unmounting. Sure, there are special options still to be used for specific file systems (fat, ntfs, nfs …) or for seamless remounting with different mount flags set (change from rw to r, from noexec to exec and vice versa). But once you’ve got the basic functionality of this mount command you’ll get these details easily from checking the options described in man mount.
You might wonder, at system startup and also when plugging a device you don’t need to manually mount anything, and also no need to care for creating all the needed folders to take the mounts before. This is true, since there are system services caring for the automatic folder creation in these specific situations. Just like file managers do handle this automatically when you let mount them a device on their own. Btw, the mount command has an extra command line option (X-mount.mkdir) to create the folder itself if needed.
Windows is like a submarine. Open a window and serious problems will start.
May 3, 2022 at 6:39 pm #82603Moderator
Brian Masinick
::@Robin: Very clear, well written suggestion. Nothing ambiguous (at least to me) about anything you’ve written.
Are there any remaining questions now?
--
Brian MasinickMay 3, 2022 at 8:36 pm #82605Moderator
christophe
::That’s all excellent advice above.
Just an added thought: The automount feature (when a new device is inserted) mounting from a live-usb will make a directory like
/media/demo/USB-DATA
And mount the device there. Is that throwing you off?
And as Robin noted, if they device is already plugged in at boot up, it will show as
/media/USB-DATA
(Or whatever the volume label may be).
Does that make sense?And if you want it always mounted at a different location, edit your fstab file.
confirmed antiX frugaler, since 2019
May 4, 2022 at 1:18 am #82613Memberdugin
-
AuthorPosts
- You must be logged in to reply to this topic.