Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
drives [2015/07/14 21:46]
slackermedia
drives [2021/06/03 19:48] (current)
Line 1: Line 1:
-[[{arrowp.png|border:​0;​background:​none;​width:​0;​display:​inline-block;​position:​absolute;​top:​0;​left:​0;​}dotdesktop|]]+======Hard Drives and Linux======
  
-[[{arrown.png|border:​0;​background:​none;​width:​0;​display:​inline-block;​position:​absolute;​top:​0;​margin-left:​2.5em;​}mimetypes|]]+Linux does hard drives astonishingly wellSo well, in fact, that most hard drive rescue services default to Linux because its toolset is so rich.
  
-======Hard Drives and Linux======+<WRAP info> 
 +**TL;DR** \\ 
 +If you do not want to go into hard drive forensics for a living, you may be most interested in: 
 +\\ 
 +  * [[#​kvpm|kvpm]],​ a graphical hard drive manager 
 +  * [[#​udf|udf]],​ a truly universal format that you should use for external drives under 2TB in size 
 +</​WRAP>​
  
 Hard drives can broadly be classified as either internal or external. Internal drives tend to be easier to manage, because they are not portable; they are integrated in some way with your operating system, even if it is just extra storage space that you use on an as-needed basis. ​ Hard drives can broadly be classified as either internal or external. Internal drives tend to be easier to manage, because they are not portable; they are integrated in some way with your operating system, even if it is just extra storage space that you use on an as-needed basis. ​
Line 60: Line 66:
 (The possible exception here is that you are getting a large drive that you want to use as shared storage space between a drive running Linux and a drive running some other OS. This is not recommended,​ but if you do this, then treat the drive as an [[#​udf|external drive]]. Slackermedia does not support this, because the other OS adds a significant variable to how your data is being managed, so you are, respectfully,​ on your own!) (The possible exception here is that you are getting a large drive that you want to use as shared storage space between a drive running Linux and a drive running some other OS. This is not recommended,​ but if you do this, then treat the drive as an [[#​udf|external drive]]. Slackermedia does not support this, because the other OS adds a significant variable to how your data is being managed, so you are, respectfully,​ on your own!)
  
 +{{anchor:​intformat}}
 **To format an internal drive for use with Linux:** **To format an internal drive for use with Linux:**
  
 <WRAP indent> <WRAP indent>
-Determine the device node of the drive you are going to format by first seeing what drives are already part of your system:+Determine the device node of the drive you are going to format by first seeing what drives are already part of your system
 + 
 +Use the ''​lsblk''​ command to view all block devices (hard drives) attached to your computer. If the ''​lsblk''​ command is not clear to you, or you want to double-check what it tells you, you can investigate further:
  
 <​code>​ <​code>​
Line 88: Line 97:
  
 In this example, there is a third drive not in use by the system, labelled ''​sdc''​. This is the new drive that needs formatting. Notice that it does have a partition on it already, but that's only because most all drives purchased from a modern computer store are pre-formatted,​ presumably so that users do not have to learn about formatting themselves. In this example, there is a third drive not in use by the system, labelled ''​sdc''​. This is the new drive that needs formatting. Notice that it does have a partition on it already, but that's only because most all drives purchased from a modern computer store are pre-formatted,​ presumably so that users do not have to learn about formatting themselves.
 +
 +To prevent copy-paste errors, this article uses the ''/​dev/​sdX''​ designation.
  
 Keep in mind that your drive in real life could be anything from ''​sdb''​ to ''​sdz'',​ depending on how many actual drives you have plugged in. Usually, the first drive you plug in is going to come up as ''​sdb''​ because ''​sda''​ is the drive running your computer, but be aware of your actual setup and use your head. //You do not want to format the wrong drive.// Keep in mind that your drive in real life could be anything from ''​sdb''​ to ''​sdz'',​ depending on how many actual drives you have plugged in. Usually, the first drive you plug in is going to come up as ''​sdb''​ because ''​sda''​ is the drive running your computer, but be aware of your actual setup and use your head. //You do not want to format the wrong drive.//
Line 94: Line 105:
  
 <​code>​ <​code>​
-$ su -c 'mount /dev/sdc1 /​mnt/​hd'​+$ su -c 'mount /dev/sdX1 /​mnt/​hd'​
 $ cd /mnt/hd $ cd /mnt/hd
 $ ls $ ls
Line 114: Line 125:
 <​code>​ <​code>​
 $ cd ~ $ cd ~
-$ su -c '​umount /dev/sdc*'+$ su -c '​umount /dev/sdX*'
 </​code>​ </​code>​
  
Line 121: Line 132:
 <​code>​ <​code>​
 $ su $ su
-# parted /dev/sdc mklabel gpt+# parted /dev/sdX mklabel gpt
 </​code>​ </​code>​
  
Line 131: Line 142:
  
 <​code>​ <​code>​
-# parted /dev/sdc print | grep Disk+# parted /dev/sdX print | grep Disk
 </​code>​ </​code>​
  
Line 139: Line 150:
  
 <​code>​ <​code>​
-# parted /dev/sdc mkpart primary 1 2834020+# parted /dev/sdX mkpart primary 1 2834020
 </​code>​ </​code>​
  
Line 148: Line 159:
 </​WRAP>​ </​WRAP>​
  
-Now the drive has a partition; all it needs now is a file system. Remember, a partition is indicated by a number trailing the device node. In this example, the location of your new partition is ''/​dev/​sdc1''​.+Now the drive has a partition; all it needs now is a file system. Remember, a partition is indicated by a number trailing the device node. In this example, the location of your new partition is ''/​dev/​sdX1''​.
  
 For a Linux native drive, use ''​ext4'':​ For a Linux native drive, use ''​ext4'':​
  
 <​code>​ <​code>​
-# mkfs.ext4 -L penguindrive /dev/sdc1+# mkfs.ext4 -L penguindrive /dev/sdX1
 </​code>​ </​code>​
  
Line 159: Line 170:
  
 <​code>​ <​code>​
-# mkfs.jfs -L penguindrive /dev/sdc1+# mkfs.jfs -L penguindrive /dev/sdX1
 </​code>​ </​code>​
  
Line 181: Line 192:
 </​code>​ </​code>​
  
-Now mount the drive by mounting all drives listed in ''/​etc/​fstab'':​+And finally, ​mount the drive by mounting all drives listed in ''/​etc/​fstab'':​
  
 <​code>​ <​code>​
-mount /storage+mount -a
 </​code>​ </​code>​
 </​WRAP>​ </​WRAP>​
Line 230: Line 241:
 Partly as an answer to the problem of having no universally-accepted file system and partly out of the need for a good file system, a few Standards groups came up with **UDF**, the Universal Disk Format. It was mostly intended as the replacement for ISO-9660, and did become the official file system for CD-RW, DVD-RW, and Blu-Ray. Partly as an answer to the problem of having no universally-accepted file system and partly out of the need for a good file system, a few Standards groups came up with **UDF**, the Universal Disk Format. It was mostly intended as the replacement for ISO-9660, and did become the official file system for CD-RW, DVD-RW, and Blu-Ray.
  
-The down side is that it does not use journaling, making data recovery after a crash or accidental unplugging a little riskier. It does not use partitions, but that is not usually an issue for an external drive.+There are two significant disadvantages of UDF:
  
-The good news is that it is open source, can use UTF-8 filenames that are as long as 255 bytes, file sizes and filesystem ​sizes of 2TB. Like FAT, UDF does not bother with permissions,​ making it ideal for external drives ​on Unix. At the very worst, even considering some of the features left out of UDF, it is a better and more flexible option than FAT, and has no patent issues to contend with (Micrososft sometimes sues companies for using random features in FAT).+  * Maximum volume size is 2TB (on hard drives). 
 +  * It does not use journaling, making data recovery after a crash or accidental unplugging a little riskier. 
 + 
 +It is open source, ​it can use UTF-8 filenames that are as long as 255 bytes, file sizes and file system ​sizes of 2TB. UDF does not bother with permissions,​ making it ideal for external drives.
  
 Since it was primarily intended for optical media, creating a UDF volume is different from formatting a drive for any other filesystem. Since it was primarily intended for optical media, creating a UDF volume is different from formatting a drive for any other filesystem.
  
-    The drive being formatted must have no partitions on itThis is entirely unlike any other filesystem, but it is necessary for some operating systems ​to accurately detect ​the UDF filesystem.+Slackermedia recommends the UDF format for any external ​drive that you intend to use with more than just your own computerIt avoids both file permission frustration and file size limitations, but maintains all the other UNIX features that one would expect from a drive. It works well on thumbdrives as well as tradition drives. By being a universal format, ​it ensures that the data that matters ​to you the most is always available to you, regardless of what OS you happen to have on hand.
  
-    To get rid of the existing partition on a drive, zero out the first 4096 bytes of the drive. 
  
-    dd if=/dev/zero of=/dev/sdx bs=512 count=4096+====Formatting a Drive for UDF====
  
-    Note that the bytesize (bs) is not flexible. It must be 512.+The drive being formatted ​must have no partitions on it. This is entirely unlike any other filesystem, but it is necessary for some operating systems to accurately detect the UDF filesystem.
  
-    Nextfind out the block count for your drives:+To get rid of the existing partition on a drivezero out the first 4096 bytes of the drive. This effectivel **erases all of the data on the drive** so you should be doing this only on an empty drive or a drive with data on it that you do not wish to use. 
  
-    $ df -i /dev/sdx +<​code>​ 
-    ​Inodes ​  ​IUsed ​   IFree +# dd if=/​dev/​zero of=/​dev/​sdx ​bs=512 count=4096 
-    2040230 ​  ​619 ​   2039611+</​code>​
  
-    Finally, create the filesystem so that it spans the entire drive.+Note that the bytesize (bs) is not flexible. It must be 512.
  
-    ​mkudffs --blocksize=512 \ +Create the filesystem so that it spans the entire drive: 
-    --udfrev=0x0201 \ + 
-    --lvid="​myUdfDrive" \ +<​code>​ 
-    --vid="​myUdfDrive" \ +mkudffs ​--utf8 \ 
-    --media-type=hd ​--utf8 ​+--blocksize=512 \ 
-    /dev/sdx || echo "fail"+--udfrev=0x0201 \ 
 +--lvid="​penguindf" \ 
 +--vid="​penguindf" \ 
 +--media-type=hd \ 
 +/dev/sdx || echo "failed" 
 +</​code>​
  
 Now you can mount and use the drive on any platform. Now you can mount and use the drive on any platform.
  
-[EOF]+{{anchor:​extformat}} 
 +====Formatting Drives on Linux====
  
 +This section reiterates the usual steps in formatting a drive, with an emphasis on external drives (read the section on [[#​intformat|formatting internal drives]] if you are adding a drive to you computer internally). If you are formatting to UDF (you probably should be), read the section on [[#​udf|UDF]].
  
  
-[[{arrown.png|border:0;​background:none;width:0;display:inline-block;float:right;}mimetypes|]][[{arrowp.png|border:​0;​background:​none;​width:​0;​float:​right;}dotdesktop|]]+<WRAP indent>​ 
 +**1.** Identify the drive'​s device node. 
 + 
 +With the drive //​unplugged//​ from the computer: 
 + 
 +<​code>​ 
 +# ls /dev/sd* 
 +sda  sda1  sdb  sdb1 
 +</​code>​ 
 + 
 +Then plug the drive in and do the same command again: 
 + 
 +<​code>​ 
 +# ls /dev/sd* 
 +sda  sda1  sdb  sdb1  sdc  sdc1 
 +</​code>​ 
 + 
 +The new node is the drive you have just attached. 
 + 
 +**2.** Unmount the drive. 
 + 
 +It probably isn't mounted, but just in case... 
 + 
 +<​code>​ 
 +# umount /dev/sdX* 
 +</​code>​ 
 + 
 +**3.** Create a fresh partition table: 
 + 
 +<WRAP important>​ 
 +From this point on, the device ''​sdx''​ (a rare drive node, since it would require you to have 23 drives attached to your computer) is used to protect people from copying and pasting commands and unintentionally erasing a real drive. Replace ''​sdx''​ with the actual label of your target drive. 
 +</​WRAP>​ 
 + 
 +<​code>​ 
 +# parted /dev/sdx mklabel msdos 
 +</​code>​ 
 + 
 +Or, for drives lager than 2TB: 
 + 
 +<​code>​ 
 +# parted /dev/sdx mklabel gpt 
 +</​code>​ 
 + 
 +**4.** Get the drive size: 
 + 
 +<​code>​ 
 +# parted /dev/sdx unit MB print | grep Disk 
 +Disk /dev/sdx: 63417MB 
 +Disk Flags: 
 +</​code>​ 
 + 
 +**5.** Create a partition spanning from 1 MB to the last available MB (which you will have gotten from the ''​parted print''​ command): 
 + 
 +<​code>​ 
 +# parted /dev/sdx mkpart primary 1 63417 
 +</​code>​ 
 + 
 +**6.** Put a file system on the partition you just created. 
 + 
 +<​code>​ 
 +# mkfs.jfs ​-L rockhopper /dev/sdx 
 +</​code>​ 
 + 
 +Or for an ''​ext4''​ file system (more common across Linuxes) 
 + 
 +<​code>​ 
 +# mkfs.ext4 -L rockhopper /dev/sdx 
 +</​code>​ 
 + 
 +Also consider using [[#​udf|UDF]] for drives under 2TB. 
 + 
 +**7.** Unplug the drive and plug it back in. 
 + 
 +</​WRAP>​ 
 + 
 +{{anchor:kvpm}
 +====KVPM Volume and Partition Manager==== 
 + 
 +[[https://​sourceforge.net/​projects/​kvpm/​|KVPM]] is a graphical interface to the ''​parted''​ command and some related hard drive tools. 
 + 
 +Install KVPM from [[http://​slackbuilds.org]] 
 + 
 +Launch **kvpm** from the **K Menu**. 
 + 
 +Once kvpm has launched, look at the list of drives for one that matches your drive in size and vendor. For safety purposes, you should **not** have any other external drives plugged into your computer at this point, so only the internal hard drive(s) and you target drive should be visible. 
 + 
 +Right-click on your target drive and choose **Add disk partition**. 
 + 
 +Accept the default options so that you are using all available space on the drive. 
 + 
 +[{kvpm_part.png | Create a partition on a drive.}}] 
 + 
 +One the new partition appears, ​right-click on the partition inside the drive and choose **Filesystem operations** → **Make filesystem**. 
 + 
 +[{{ kvpm_mkfs.png | Create a filesystem in the partition on your drive. ​}}] 
 + 
 +Use the filesystem type of your choice, give the drive a name (or "​label"​),​ and click **OK**. 
 + 
 +[{{ kvpm_fs.png | Name your drive and set it loose. }}] 
 + 
 + 
 + 
 +<WRAP centeralign>​ 
 +<wrap fa>[[dotdesktop|R]]</​wrap>​ <wrap fa>​[[start|S]]</​wrap>​ <wrap fa>​[[mimetypes|Q]]</​wrap>​ 
 +</​WRAP>​