Linux/Hard Drive Management: Difference between revisions
Brodriguez (talk | contribs) (Correct ordering of commands) |
Brodriguez (talk | contribs) (Split page into sections) |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
Various commands and tools to manage disks in Linux. | Various commands and tools to manage disks in Linux. | ||
== General == | == General == | ||
Line 11: | Line 12: | ||
This should output a string, which you can directly compare to the string on the website. If they match, then the file is valid with no errors. | This should output a string, which you can directly compare to the string on the website. If they match, then the file is valid with no errors. | ||
== File Management == | == File Management == | ||
Line 48: | Line 50: | ||
=== NTFS Partitions === | === NTFS Partitions === | ||
ntsflabel /dev/<partition> <label_name> | ntsflabel /dev/<partition> <label_name> | ||
== Mounting a Samba Network Share == | == Mounting a Samba Network Share == | ||
{{ Warn | The following method saves password credentials to a file, and is only secure if no one else has {{ ic | sudo/root}} access on the machine. }} | |||
First install the required packages: | First install the required packages: | ||
sudo apt update | sudo apt update | ||
sudo apt install cifs-utils | sudo apt install cifs-utils | ||
=== Create Mount Location === | |||
Next, create your local mount directory. This can be anywhere, technically. But for organizational practices, it's standard to mount "permanent" drive locations (such as this) under the <code>/mnt</code> folder of your Linux install. In this example, we'll call it <code>network_share</code>, but you can call it whatever you like. | Next, create your local mount directory. This can be anywhere, technically. But for organizational practices, it's standard to mount "permanent" drive locations (such as this) under the <code>/mnt</code> folder of your Linux install. In this example, we'll call it <code>network_share</code>, but you can call it whatever you like. | ||
sudo mkdir /mnt/network_share | sudo mkdir /mnt/network_share | ||
sudo chmod 777 /mnt/network_share | sudo chmod 777 /mnt/network_share | ||
=== Set Drive Credentials === | |||
We need a way to access credentials for this drive. To do this, we create a file that holds our credentials, and then limit permissions to the root user to make it secure. This makes it so no other users can see this unless they have sudo access (But at that point, anyone that has sudo access to this system can already see any file they want, if they desire). | We need a way to access credentials for this drive. To do this, we create a file that holds our credentials, and then limit permissions to the root user to make it secure. This makes it so no other users can see this unless they have sudo access (But at that point, anyone that has sudo access to this system can already see any file they want, if they desire). | ||
Line 71: | Line 77: | ||
sudo chmod 400 /etc/sambapasswords/network_share | sudo chmod 400 /etc/sambapasswords/network_share | ||
=== Create Auto-mount Command === | |||
Now we add the command to automatically mount this drive on computer startup. This is done by editing your fstab file with <code>sudo nano /etc/fstab</code>. In this file, add the following lines: | Now we add the command to automatically mount this drive on computer startup. This is done by editing your fstab file with <code>sudo nano /etc/fstab</code>. In this file, add the following lines: | ||
{ note | You'll need to replace <code>network_location</code> with the proper location to your network storage drive. Also, if you used different values in the above steps (credential file location, mount folder name, etc), then replace the corresponding value in this line.} | {{ note | You'll need to replace <code>network_location</code> with the proper location to your network storage drive. Also, if you used different values in the above steps (credential file location, mount folder name, etc), then replace the corresponding value in this line.}} | ||
//<network_location> /mnt/network_share cifs credentials=/etc/sambapasswords/network_share,user 0 0 | //<network_location> /mnt/network_share cifs credentials=/etc/sambapasswords/network_share,user 0 0 | ||
Line 79: | Line 85: | ||
sudo mount -a | sudo mount -a | ||
{ warn | If you get an error at this stage, either correct it or comment out the line you added to your fstab before restarting your computer. Errors in your fstab file on restart generally cause ubuntu to not boot into normal mode, which is annoying to deal with.} | {{ warn | If you get an error at this stage, either correct it or comment out the line you added to your fstab before restarting your computer. Errors in your fstab file on restart generally cause ubuntu to not boot into normal mode, which is annoying to deal with.}} | ||
If you got an error, then it likely displays in the command output and should be corrected before restarting your machine. | If you got an error, then it likely displays in the command output and should be corrected before restarting your machine. | ||
If you get no output, then it likely mounted correctly. Congratulations! You can verify by opening your <code>/mnt/network_share</code> folder and checking that it has the files you expect. | If you get no output, then it likely mounted correctly. Congratulations! You can verify by opening your <code>/mnt/network_share</code> folder and checking that it has the files you expect. |
Latest revision as of 12:53, 26 May 2020
Various commands and tools to manage disks in Linux.
General
GUI Hard Drive Management:
- Use the
gparted
program.
Verifying a download against a hash:
Some large files (particularly iso/img files, such as for an OS install) will have an associated SHA256 string on the website download page.
To verify your download had no errors, you can run the command:
sha256sum <file_location>
This should output a string, which you can directly compare to the string on the website. If they match, then the file is valid with no errors.
File Management
Copying Files
Copy Files Locally:
dd if=<input_location> of=<output_location> status=progress conv=fsync
Copy Files Over a Network:
rsync -avh <input_location> <output_location>
Note that input/output locations can be a local file path or a network path. If it's a network path, then it takes the format of:
<username>@<network_location>:<input_or_output_location>
Sym Links
ln -s <location_of_original_file_or_folder> <location_of_sym_link>
In this case, the <location_of_sym_link>
will point to <location_of_original_file_or_folder>
.
View General Drive Info
For a simple overview, use:
lsblk
For more detail, use:
sudo fdisk -l
Change Label of Drive
The drive label is generally what an OS will automatically name the drive, upon mounting.
Thus, it can be useful to give your drive labels meaningful names.
For the following commands:
<partition>
corresponds to the partition name (ex, sda1, sdb2, etc).<label_name>
corresponds to the new label you wish to give the drive.
Ext Partitions
e2label /dev/<partition> <label_name>
NTFS Partitions
ntsflabel /dev/<partition> <label_name>
sudo/root
access on the machine. First install the required packages:
sudo apt update sudo apt install cifs-utils
Create Mount Location
Next, create your local mount directory. This can be anywhere, technically. But for organizational practices, it's standard to mount "permanent" drive locations (such as this) under the /mnt
folder of your Linux install. In this example, we'll call it network_share
, but you can call it whatever you like.
sudo mkdir /mnt/network_share sudo chmod 777 /mnt/network_share
Set Drive Credentials
We need a way to access credentials for this drive. To do this, we create a file that holds our credentials, and then limit permissions to the root user to make it secure. This makes it so no other users can see this unless they have sudo access (But at that point, anyone that has sudo access to this system can already see any file they want, if they desire).
We create this file under /etc/sambapasswords
, and name the file the same as our mount folder name. But again, technically this file can be called whatever you want, and stored in any location you wish, as long as you're consistent.
sudo mkdir /etc/sambapasswords sudo nano /etc/sambapasswords/network_share
At this point, we're editing our credential file. Add the credentials via the two following lines, where you enter your network connection credentials instead of leaving it blank (no spaces).
username= password=
Set permissions on the file so that no unauthorized users can read it.
sudo chmod 400 /etc/sambapasswords/network_share
Create Auto-mount Command
Now we add the command to automatically mount this drive on computer startup. This is done by editing your fstab file with sudo nano /etc/fstab
. In this file, add the following lines:
network_location
with the proper location to your network storage drive. Also, if you used different values in the above steps (credential file location, mount folder name, etc), then replace the corresponding value in this line.//<network_location> /mnt/network_share cifs credentials=/etc/sambapasswords/network_share,user 0 0
Save the changes to your fstab file and exit. At this point, you should be done. You can test that it works by running
sudo mount -a
If you got an error, then it likely displays in the command output and should be corrected before restarting your machine.
If you get no output, then it likely mounted correctly. Congratulations! You can verify by opening your /mnt/network_share
folder and checking that it has the files you expect.