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 04:58]
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>​
  
-When it comes to external drives, ​most operating systems deal with them in a very OS-specific ​way since many closed-source ​operating ​systems use their own custom formats. Linux is a lot more general, and permits ​you to use nearly anything, after a fashion, so usually hard drives problems arise because you need to get information //to// a closed source OS and that OS cannot read your drive, not the other way round.+Hard drives can broadly be classified as either internal or external. Internal ​drives ​tend to be easier to managebecause 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
  
-=====Mac Compatible=====+Here is a profile of your internal drive:
  
-If you have a drive that claims to be "Mac compatible"​ and you want to use it on both Linux and Mac OS, then it is probably formatted as **HFS+**. HFS+, in addition to being one of the least stable file systems on the market, is crafted intentionally to be incompatible with other systems; in order to write //to// HFS+ from Linux, you must disable journaling on the drive.+=====Internal Drives=====
  
-You can, howeverread //from// it without doing anything to the drive.+The drive inside your Linux computer is either an SSD or a traditional spinning disk drive, or you possibly are using both. Your drive(s) ​can be seen as one pool of available disk space by Linuxor conversely one drive can be seen as several differentartificially-separated disks even though it's actually one physical drives. Computers are able to perform this perceptual magick through "​partitions":​ imaginary boundaries that an OS agrees to respect as an (air-quotes) Different Disk than the rest of the drive (or, when disks actually ​//are// physically separate, ​the computer can see all of the disks as [air-quotes] One Big Drive).
  
-Disabling the journal on an HFS+ drive must be done from within Mac OSIf you do not have access to Mac OSthen you cannot write to the HFS+ drive**do not** attempt to write to the drive; you could do damage to the files.+There is nothing special about hard drives in terms of storage except that they are relatively fast and efficient in managing a lot of informationAbstractlythough, they are no different that, for instance, a tape archive (or a quarter-inch tape, or similar media). In fact, hard drives can be used directly as, basicallya tape drive.
  
-If you are stuck with a "Mac compatible"​ drive and want to use it as an active "​normal"​ drive in your studio, with full read and write capabilities,​ then your best bet is to copy all of the data off of the drive, [[#​format|re-format it]], and then copy the data back onto it.+<WRAP alert> 
 +Do not try this at home, you could possibly erase important ​data. 
 +</​WRAP>​
  
-If you require the drive to remain compatible with a Mac as well as Linux (andas a side benefitWindows), then use the [[#​udf|UDF]] format.+Assume we have attached a drive and it appears ​as ''/​dev/​sdx''​ on our computer. Raw data can be written to the drive without any formattingand independent of any file system:
  
-If these are not valid options for you, then use Mac OS to disable the journal on the driveMac OS may later re-activate the journal without notice, so you may have to do this often.+<​code>​ 
 +# echo '​Do ​not try this at home unless ​you really know what you are doing.
 +# echo "​hello"​ | dd of=/​dev/​sdx 
 +# head -c{1..5} /dev/sdx 
 +hello# 
 +</​code>​
  
-=====Windows Compatible=====+The data "​hello"​ was written as raw bytes on the drive. It was not written as a file, so if you plug the drive into another computer, it will not look like there is anything on the drive (if the computer even understands how to mount the drive), but the string "​hello"​ is still on the drive. It's just written as raw data.
  
-If you have a drive that claims ​to be "Windows compatible" and you want to use it on both Linux and Windows, then it is probably formatted as **NTFS** or **ExFAT**, with a small chance of it being **FAT32**+This is actually how data was stored for a very long time,but eventually the disadvantages became too much to bear and someone invented a "file system"​ which does exactly what its name suggests: it creates a //system// for managing //files//. With a file system, ​you don't need to know the exact byte count to retrieve your data off of hard drive; the drive itself remembers ​that for you. Rather than reading raw data, bytes 1 to 5, for the string ​"hello", we could instead just make a request to our drive for our "​hello"​ file, and no matter where that file was or how many times we have revised and added to it, the computer can quickly and easily find it on the drive and show it to us.
  
-None of these filesystems are particularly //good// but they are all well-supported by Linux (nothowever, by Mac OS).+Your Linux drive is running an open source file systemprobably either ''​ext4''​ or ''​jfs''​. These file systemsalthough open source and free for anyone (person or corporation) to use, the major closed source operating systems decline to include support for them. This means that the drives are recognised as being blank or simple "​un-readable" ​by another ​OS. It's advantageous to use the file systems nevertheless,​ because aside from being some of the most stable on the market, they have features that help Linux run efficiently.
  
-If you are stuck with "​Windows compatible" ​drive and want to use it as an active "​normal"​ drive in your studio, you probably canas is. There are several inconveniences that you may notice ​(file size limitations,​ permission issues), ​but as external ​drives ​go, everything should basically work as expected.+Once a drive has a file system, ​it can be mounted and used by your operating system. On Linuxwhen you attach a drive to your computer (internally or externally)the drive (upon detection) ​is assigned a node in the ''/​dev''​ directoryDrive nodes are dynamically created on an as-needed basis. Internal drives are assigned nodes as they are detected by the system, which is //usually// predictable after you notice ​the pattern ​but really it depends on the motherboard and which slots your drives ​are plugged into.
  
-A better option ​is to copy all of the data off the drive, re-format ​it as a [[#​udf|UDF]] file system, and put all of the data back on. UDF brings along with it several benefitsincluding Window and Mac compatibility,​ and elimination of the quirks of Window hard drive formats.+The first detected drive is assigned ''/​dev/​sda''​. The "​sd"​ prefix denotes ​the type of drive it is (actually it's historically inaccurate, but as a revisionist you can think of "​sd"​ meaning "Sata Disk"), and the "​a"​ is the first letter ​of many alphabets. That node represents ​the physical drive itself, which is different that what's //on// the driveIf a partition is found on that drive (most drives have at least one partition), then it gets a node ''/​dev/​sda1''​. If there is yet another partitionthen it would be assigned ''/​dev/​sda2''​.
  
-=====Linux Compatible=====+The second drive found gets ''/​dev/​sdb''​ and its partition ''/​dev/​sdb1'',​ and so on.
  
-If you are using a drive just on Linux systems (recommended,​ but not always possible), then you can keep your drives ​in a native Linux format. The only practical advantage of using a native Linux format on an external drive is that they happen to be very robust file systems. They are comparatively difficult to corrupt or break, they are fast, well-designed and maintained, case-sensitive,​ and have very few limitations in a pragmatic sense+These nodes only represent that drives are attached. They are not directories that you can open and view data in, they are metadata about your system.
  
-The immediate //​disadvantage//​ of using native formats for external ​drives ​on Linux is that none of them were really designed for external use. That ismost of them assume that the drive is **inside** the computer. This tends to not matter much until you start swapping ​drives ​with other Linux users or computers, at which point file permissions can become a problem.+The data on the drives ​is used by your Linux systemand internal ​drives ​are usually automatically mounted by Linux because those drives appear in the file ''/​etc/​fstab''​ as drives that are to be mounted upon boot.
  
-Permissions can be managed for external drives, but you have to be intentional and mindful of it. 
  
-A better option is to copy all of the data off the drive, re-format it as a [[#​udf|UDF]] file system, and put all of the data back on. UDF brings along with it several benefits, including Window and Mac compatibility,​ and elimination of the quirks of Window hard drive formats.+The take away points from this overview ​of your internal Linux drives are:
  
 +  * Use ''​ext4''​ or ''​jfs''​ or any Linux-native format for drives that are directly a part of your operating system to avoid unexpected results in how you OS works.
 +  * Drives get nodes in ''/​dev''​ based on when they were detected, and how many partitions exist on them.
 +  * Internal drives are automatically mounted by the system only if they are listed in ''/​etc/​fstab''​.
  
 +There is no quiz on this, but now you know.
  
-Hard drives are like blank tapes. They do not care what operating system you use them on, they do not care how you store data on them. You never have to worry that a drive, at least in terms of the hardware itself, will not work with one OS or another. You are the user, so you can format any drive to be a storage receptacle for your data. 
  
-The way drives store data is by putting bits into what is called a filesystem. What is a filesystem? Well, imagine that you have, for simplicity'​s sake, one word that you need to store on some device. That is a pretty simple requirement,​ so you could just write that word out on any device that accepts bits. You can actually do that; you can actually write data straight to a drive without ever formatting the drive for your computer. If you have a spare drive lying around without any data that you ever want to see again on it, you can try something like+====Formatting Internal Drives====
  
-# echo 'Heydo not actually try this at home unless you really know what you are doing.'+If you purchase an additional internal drive for your Linux computer, you probably should be using a Linux-native file system. There is probably no advantage in using a non-native file system, because it's an internal drive; other computers are not plugging into in asking to use data off of it (and if they are, they are doing so over your network, and TCP/IP makes basically everything universal).
  
-echo "​hello" ​dd of=/dev/sdx+(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!)
  
-# head -c{1..5/dev/sdx +{{anchor:​intformat}
-hello#+**To format an internal drive for use with Linux:**
  
-And that would write raw ascii data to that device. No filesystem, just raw bytes representing h-e-l-l-o.+<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.
  
-So let's say you did thatand then you add the word world to the driveagain as raw bytes.+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 youyou can investigate further:
  
-Now, we know that the word "​hello"​ starts at byte 0 and goes to byte 4, so if we ever need to read that word back from the drive, we can just ask the drive to give use whatever it has stored at byte 0 all the way to byte 5But what if we need to add to that word? what if you want to change it to "​salutations"?​ In that case, you would need to tell the drive to move some bytes around, which is ok until you realise that there is data after itso if you just start flipping bits to change "​hello"​ to "​salutations"​then you are overwriting the string "​world"​+<​code>​ 
 +$ mount | egrep '.*sd.*'​ 
 +/dev/sda2 on / type jfs (rw) 
 +/dev/sda1 on /boot type vfat (rw,fmask=177,dmask=077) 
 +/dev/sdb1 on /home type jfs (rw) 
 +</​code>​
  
-And what about when you JUST want the word "​world"​ without the "​hello"​ or "​salutations" ​in front of it? how do you tell the computer to go and retrieve that data? Sure you might remember right now that "​world"​ starts at byte 4 or 5 or whatever it was (or 9, depending on whether we changed the first word to "​salutations"​but what about a week from now? and obwiously this is just a simple example with two simple raw ascii strings. Imagine how stupid this would be with gigabytes of even moderately complex data.+In this example, there are two drives already ​in use by the system: one being used as the boot and system drive (''​sda''​)and another (''​sdb''​) used exclusively for the home directory.
  
-It starts ​to get really inefficient,​ really quickly, so the concept of filesystems were born. A filesystem is a method for keeping track of where one file ends and another begins, and also how and where data is written when changes are made, and where all that data is located when a user wants to open a file back up.+Compare that list to what the computer actually has attached:
  
-So when an OS asks you if you would like to format a drive, what it is really asking is whether you vould like to create a blank filesystem on your drive.+<​code>​ 
 +$ ls -1 /dev/sd* 
 +sda 
 +sda1 
 +sda2 
 +sdb 
 +sdb1 
 +sdc 
 +sdc1 
 +</​code>​
  
-Just one small catch: a filesystem needs to know where on a drive it is allowed to keep stuffThese boundaries are called partitions, and they are imaginary containers ​that live on a hard drive so that we can fill them up with a filesystem. +In this example, there is third drive not in use by the system, labelled ''​sdc''​. This is the new drive that needs formattingNotice ​that it does have a partition ​on it already, but that's only because most all drives purchased from modern computer store are pre-formatted,​ presumably ​so that users do not have to learn about formatting themselves.
-Partitions Explained+
  
-Partitions are much easier to explain than a filesystem. A partition is a like one of those drawer-separators that you might put in your shirt drawer to separate, say, the scary infoSec t-shirts from your cheeky-but-professional-enough geek t-shirts. It's a flimsy construct, probably just a piece of cardboard you ripped off the box that your new motherboard got shipped in, but it does its job and keeps things organised.+To prevent copy-paste errorsthis article uses the ''/​dev/​sdX''​ designation.
  
-Separating ​your shirts did not result ​in a new drawer coming into existancebut it serves basically the same purposeFor all intents and purposes, you have created two drawers from one.+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 inUsuallythe 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.//
  
-THat's what a partition is. You can take a drive, ​partition ​it once for really big drawer, partition ​it into two for two small drawers, three, four, whatever.+If you are unsure that you are targeting at the correct ​drive, ​mount it and have look at what's on it:
  
-All you really need to know is that for there to be a filesystem on a drive, there must be a partition first+<​code>​ 
-Format a Drive+$ su -c 'mount /dev/sdX1 /​mnt/​hd'​ 
 +$ cd /mnt/hd 
 +$ ls 
 +
 +.. 
 +Acme Drivers 
 +Acme Backup Pro Plus 
 +$ df -h /mnt/hd | awk '​{print $2}' 
 +Size 
 +2.8T 
 +</​code>​
  
-Most operating systems say "​format ​drive" meaning "put an empty filesystem ​on the drive" ​and disregard ​the need for a partition because they assume that users are incapable of understanding ​the concept of partitions. At this point, you are basically a hard drive genius by consumer tech standards because you dare acknowledge the existance of partitions and you even understand basically what a filesystem is for. Let's put your knowledge into practise and actually make a partition and a filesystem.+In this example, the drive is mounted at ''/​mnt/​hd''​ (pre-existing directory for quickly mounting drives ​on Slackware) and is shown to contain basically nothing, if we ignore ​the obligatory drivers ​and bloatware bundled by the vendor on the drive. ​
  
-There are three GUI applications Ʈoff the top of my head) that you can do use for thisGnome Disk UtilityGParted, and kvpm. For this post, the shell is easiest to convey, so we will use parted but feel free to check out the various GUI alternatives at some point if you prefer.+Confirming ​the size of the drive provides further reinforcementyes, this really ​is the 3TB drive you have purchased.
  
-    Firstyou need to know what your system is calling ​the drive that you want to format. Linux tracks any drive that you attach in the /dev directory. So to find out where on your system a drive lives once it has been plugged in, you can list that directory. Since formatting a drive is always risky business Ŕyou REALLY don't want to format the wrong drive by mistake), it's not a bad idea to get a before-and-after view.+With that settledunmount (with the ''​umount''​ [sic] command) ​the drive so that you can perform surgery ​on it:
  
-    So, without the drive plugged into your computer:+<​code>​ 
 +$ cd ~ 
 +$ su -c '​umount /​dev/​sdX*'​ 
 +</​code>​
  
-    ls /dev/sd?+Create a fresh partition table on the device. A partition table just tells a computer what kind of partition to look for when reading the drive. Operations like re-formatting entire drives justifiably require root permissions:​
  
-    And then plug your drive in, and repeat: The one that wasn't there before? that's your drive.+<​code>​ 
 +$ su 
 +# parted /dev/sdX mklabel gpt 
 +</​code>​
  
-    Let's sayfor the sake of this example, ​that the drive you plugged in got labelled /dev/sde. 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. On most laptops, the first driwe you plug in is going to come up as sdb because sda is the driwe inside your computerBut if you have another drive plugged in alreadyyou would get sdc. If you are using desktop with three drives in itthen you are looking at sdd for you first external, sde for your second, and so on.+Historically, the de facto partition label was ''​msdos''​ because ​that was (and still is) the most ubiquitous; msdos-style partitioning ​is universally recognisedFor drives larger than 2TB, a ''​gpt''​ partition label must be usedbecause ''​msdos''​ partition labels cannot scale to 2TB.
  
-    Just to make sure we can proceed to work on the driveunmount ​it. Unmounting a drive ensures that no data is being read from or written to that drive while you are doing surgery on it. You need to be root for all of this delicate stuff, so use either su or sudo bash to get to root prompt.+Very little actually rides on this, it's just a matter of whose identifier you want to useIt has nothing to do with how your data is secured ​or kept, it's just an identifier so that the computer knows what to look for when it mounts ​drive.
  
-    umount /dev/sde* 2> /dev/null+Next, find out how big your disk is:
  
-    First, create a partition table on the device. A partition table just tells a computer what kind of partition to look for when reading the drive.+<​code>​ 
 +# parted /dev/sdX print | grep Disk 
 +</​code>​
  
-    parted /dev/sde mklabel msdos+For the sake of this example, assume the drive is 2834020 MB (2.8TB) in size.
  
-    I am using a partition ​label msdos because ​that is the most ubiquitous. You can use another if you prefer, but msdos is sort of the lowest common denominator. If you have an EFI or UEFI computer, you could also use a gpt partition label. Very little actually rides on this, it's just a matter of whose identifier you want to use. It has nothing to do with how your data is secured or kept, it's just an identifier so that the computer knows what to look for when it mounts a drive.+Create ​a partition that spans the whole drive:
  
-    Next, find out how big your disk is.+<​code>​ 
 +# parted /dev/sdX mkpart primary 1 2834020 
 +</​code>​
  
-    parted /dev/sde print | grep Disk+This creates a partition that starts at the first megabyte (1) and spans all the way until the 2,834,020th megabyte. ​
  
-    For the sake of this examplelet'​s ​say you are using a thumb drive 8020MB (8GB) in size.+<WRAP important>​ 
 +Do not start your partition at the 0th megabyte or you will get the error ''​Warning:​ The resulting partition is not properly aligned for best performance''​. Start your partition at 1. You are sacrificing 1024 bytesbut it'​s ​worth it. 
 +</​WRAP>​
  
-    Create ​a partition ​that spans the whole drive.+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''​.
  
-    parted /dev/sde mkpart primary 1 8020+For a Linux native drive, use ''​ext4'':​
  
-    You probably see what we did here; we use parted to take the sde device and make a partition beginning at the first megabyte all the way until the 8020th megabyte. Do not start your partition at the 0th megabyte or you will get an optimisation error. Specifically,​ you will get the dreaded Warning: The resulting partition is not properly aligned for best performance. error, and you will spend the rest of your evening searching for a solution. This is the solution: do not start your partition at the 0th megabyte, but at 1.+<​code>​ 
 +# mkfs.ext4 -L penguindrive /dev/sdX1 
 +</​code>​
  
-    Now your drive has a partition, so you can drop a filesystem into it and move on with your life.+Or ''​jfs'':​
  
-    A partition is indicated by a number trailing the device locationSo in this case, the location of your new partition is /dev/sde1+<​code>​ 
 +# mkfs.jfs -L penguindrive ​/dev/sdX1 
 +</​code>​
  
-    For a Linux native ​drive, ​use Ext4:+The drive is now formatted. It's best to create a permanentstandard place for it on your system. Assuming that it is going to be used as extra storage space:
  
-    mkfs.ext4 -L penguin ​/dev/sde1+<​code>​ 
 +# mkdir /storage 
 +</code>
  
-    For a three-way compatible ​drive, ​use Wicrosoft's ExFat:+To make the drive automatically mountadd it to ''/​etc/​fstab''​. For example, to have it mount as extra storage at boot time, add a line like this:
  
-    mkfs.exfat -n penguin ​/dev/sde1 +<​code>​ 
-    ​Unplug the drive from the computer, and then plug it back in. It should mount on your desktop with the name "​penguin"​ and it is ready for use.+LABEL=penguindrive ​  /storage ​ jfs  rw  1 1 
 +</​code>​
  
-Understanding Unix Permissions+If you do not know the label of your drive, use ''​lsblk -f''​. If your drive has no label, then use the PARTUUID (use UUID if you partition is ''​msdos''​) instead:
  
-Unix filesystems are designed to govern who can or cannot see certain data. This is useful if you are sharing a computer with someone, even if just temporarily handing them a thumb drive with one file you want to share and other files you do not want to share. That works really well for a computer, but external drives wery often move from one person'​s computer to another; that's why they are external. We want them to be portable. Since a lot of new Linux users do not understand file permissions or user identity, it' a cammon problem for you to take a drive from one computer to another only to find that the computer will not allow you to use the files on the drive.+<​code>​ 
 +LABEL=penguindrive ​  /​storage ​ jfs  rw  1 1 
 +PARTUUID=7280201c-fc5d-40f2-a9b2-466611d3d49e /​storage ​ jfs  rw  0  2 
 +</​code>​
  
-The quick and dirty way to solve this is to switch to a root userwho has permission to see and use any file they please. At that point, you can grab a file, move it or cory it from the drive to your computer, open it, edit it, whatever you want. That, of course, only solves the issue for as long as you remain root, so really you want to change the ownership, and probably the permissions,​ of the file or directory so that it belongs to you, the user of this other computer.+And finallymount the drive by mounting all drives listed in ''/​etc/​fstab'':​
  
-$ whoami +<​code>​ 
-klaatu+mount -a 
 +</​code>​ 
 +</​WRAP>​
  
-$ groups 
-users power video audio netdev 
  
-# chown -R klaatu:​users /​path/​to/​file/​or/​directory+=====External Drives=====
  
-# chmod -R 755 /path/to/file/or/directory+External hard drives are more complex, but only because they tend to move around. You may not move it often, ​or you might literally have it on your keychain and take it everwhere with you. The bottom line is that external hard drives tend to visit not just one computer, indeed not even just one operating system, and as a multimedia artist, you are likely to have to deal with that frequently.
  
-With that, the file or directory (and all files within it) would become owned by klaatu and the users group. The user (klaatu) gets read, write, and execute permission, the group (useres) gets read and write, and anyone else also gets read and write. Done.+====Incoming Drives====
  
-Any file on Unix filesystem belongs ​to:+In this context, an "​incoming drives"​ is drive you do not own but need to work with. 
  
-    A useridentified by a User ID by the computer, but more often by a memorable username by us humans. +Good news: drives coming to you from clients or collaborators, more often than notare plug-and-play **for reading** on Linux
-    A group of usersidentified by a Group ID by the computer ​and a memorable group name by us humans. A group is an arbitrary label, or a "​tag"​ if you like, that we humans make up, and then add other users. If a user is a member of a group, then they inherit the privileges associated with that group.+
  
-So if I have a directory called foo, owned by klaatu and aliens, and foo has permissions set to allow the user (that'​s Klaatu in this case, because he is the user logged in looking at the folder, so the worldview is from his perspective) read write and execute this directory, then Klaatu will be free to enter foo and create new files within it. If the group only has permission to read foo, then all they can do really is list its contents. They will not be able to create ​new file in that location, but they are free to see the contents of the foo directory. If everyone else has no permissions,​ then users not in the aliens group will see that the directory foo exists, but not see inside of it. If they require access to foo, they would need to be added to the aliens group.+There are only a few caveats:
  
-The files and directories inside that directory, of course, have permissions of their ownSo maybe Klaatu can get into foo but if there is a file there belonging ​to someone else and to some other groupthen he would not have the same permissions. In other wordspermissions do not cascade or trickle-down. They are gateways through which users and groups of users must passOnce you are insidethat doesn't mean you can do whatever you want with onything you find there, because everything has gateway all its own.+  * Macs mostly use HFS+ formatted drivesHFS+ is a relatively volatile ​file system; it is rather prone to failure ​and corruption, but luckily tools to repair them tend to be pretty good. Even soit is safer to minimise contact with HFS+ drives; get the data you need from the drive, and disconnect it. 
 +  * Windows formats generally pose no issue; it is mostly all reverse-engineered by nowand so it's mostly ​matter of attaching the drive and reading data from it as you would any other drive.
  
-User and Group and Others each have a triad of permissions. The shorthand ​to determine ​permission set is to use really ​simple ​math: 4 for read, 2 for write, and 1 for eXecute. So if I say that a file has a permission level of 7 for klaatu, we know that he has read+write+eXecute permission. If he has only 6 then we know he only has read+write. If a group has 5, the only way to get that sum is to add read (4) + eXecute (1). And so on.+**Writing** ​to a foreign drive is less simple.
  
-A file's owner, ​or rootcan change a file's permissions with, as in the above command block, chmod.+**Mac Drives** 
 +<WRAP indent>​ 
 +HFS+ drives are crafted to be intentionally incompatible with other systems (the journal is not open source ​or even open spec); in order to write //to// HFS+ from Linuxyou **must** disable journaling on the drive first.
  
-So this might raise the question: if any file permission ​on drive handed to you can be overridden as long as you look at the files as root, why have permissions on an external drive at all? Well, you might not need permissions on an external ​drive, ​and you might feel perfectly safe just using FAT or ExFAT on portable media. I do not, because I don't trust FAT or ExFAT, but that might well be the solution for you.+Disabling ​the journal ​on an HFS+ drive must be done from within Mac OS. If you do not have access to Mac OSthen you cannot write to the HFS+ drive, ​**do not** attempt to write to the drive; ​you could do serious damage to the drive'​s file system.
  
-On the other hand, this file premission thing is about more than just privacy. It also serves as buffer against those annoying mistakes users can make, like accidentally deleting a file or moving a file instead of copying it or overwriting a file or accidentally leaving the nuclear launch codes on your thumb drive for anyone ​to see. Whatever. Yes, if someone has physical possession of the drive, they can get to your data (unless you encrypt it really welletcbut this post isn't about concealing data, it's about how to make it seamless to share data when you want to do so). Unix file permissions on a portable ​drive are not going to save you from thatbut it does act as a buffer against someone accidentally deleting your holiday photosor accidentally opening ​the nuclear launch codes, or accidentally opening up your cat photos only to realise that your cat really is cuter than theirs. So it's not a bad idea to play the Unix permissions game even on those portable drivesYou just have to understand how Unix sees users. +If you are stuck with "Mac compatible" ​drive and want to use it as an active "​normal" ​drive in your studiowith full read and write capabilitiesthen your best bet is to copy all of the data off of the drive, ​[[#​extformat|re-format ​it]]and then copy the data back onto it.
-Understanding Users and Groups+
  
-When you configure ​a Linux systemthe computer creates one user account, which we call root but the computer calls 0. Then you create yourself ​user accountand you give it a fancy name like klaatubut your computer sees you as or 1000You're also added to some default group, which gets a number too. +If you require the drive to remain compatible with Mac as well as Linux (andas side benefitWindows)then use the [[#​udf|UDF]] format.
-creating a user during the install process+
  
-This works out just fine for a single computer or a network of computers all networked together as you find in research facilities or VFX housesbut what happens with a portable drive is that you create files on it as user klaatu or (1000) and then walk the drive to another computer and give the thumb drive to a friend who just so happens to be 1001 and suddenly the computer insists that your friend is not allowed to use any of the files you are trying to hand overWorse yet, that other user, user 1001 could be you on that other computer, because maybe the other computer belongs to your lifePartnerFriendSpouse, so he or she has the user 1000 account and you got pushed over to the 1001 slot. Happens all the time, and it is absolutely maddening. To really rub it in, the computer tells you that the owner of the file is klaatu and yet it will not let you see the files, because what it really means is that user 1000 owns the files, but in trying to be helpful to the human brain, it is using the more human-memorable username rather than your User ID (UID).+If these are not valid options ​for you, then use Mac OS to disable the journal on the drive. ​Mac OS may later re-activate ​the journal without notice, so you may have to do this often. 
 +</​WRAP> ​
  
-There are a few ways to mitigate this annoyance. In the order of usefulness:+**Windows Drives**
  
-    This, above all else: Pick the same user ID every time.+<WRAP indent>​ 
 +Most Windows drive formats are well reverse-engineered at this point and can be both read from and written to without any special action taken on your part. 
 +</​WRAP>​
  
-    Yes, for something so important, most modern Linux distributions seem to not make a big deal about it. In fact, they hide it away, usually in an "​advanced"​ disclosure triangle or button. It is not advanced, it is the most basic method of identifying a user that a computer possesses. You see, for each user that gets created on a Unix system, the system assigns that user a number. So when I am configuring my computer and I create a user for myself and call it klaatu, the computer takes note of that very human-friendly name, but actually sees me as, say, 1000.+{{anchor:​udf}} 
 +=====UDF: ​the Universal Universal Disk Format===== ​
  
-    When I create ​a file, the user that owns that file really is 1000Not just any user who happens by claiming to be klaatu.+Partly as an answer to the problem of having no universally-accepted file system and partly out of the need for good file system, a few Standards groups came up with **UDF**, the Universal Disk FormatIt was mostly intended as the replacement for ISO-9660, and did become the official file system for CD-RW, DVD-RW, and Blu-Ray.
  
-    So, when you set up a profile for yourself, take a moment to click that "​advanced"​ button (or on Slackware, just proceed as usual) and assign yourself a custom user ID. Every single time, do that. And make your user ID the same on every single computer you own. This solves your problem. Done. Because every file you ever create will get THAT magic number assigned to it, and so you will always have access. It's really just that simple.+There are two significant disadvantages of UDF:
  
-    I advise choosing a rare user IDFor instanceLinux systems often start out user IDs at 1000, so picking something in that range can sometimes be inconvenient if you happen to be on system with other actual users, ​or with system that happens to use a block of numbers for something else. My usual UID is 6666, which is high enough that it is unlikely to collide with anything else. Pick your own, remember it, and use it.+  * Maximum volume size is 2TB (on hard drives). 
 +  * It does not use journalingmaking data recovery after crash or accidental unplugging ​little riskier.
  
-    Create a unique group for yourself, or join some common ones. Since the group permissions of a file and directory are recorded along with user information, it isn't a bad idea to make a group to which you can belong and call your own. Some systems create a special primary group for you, which has the same name as your username. It has a unique numberas well (its group ID or GID). The logic here is that now your data belongs to YOU and YOU. No one else on your computer gets to see it unless you invite them to your group and then grant that group permission to see a file or directory. It makes sense in some situations; it just depends on how you work. If your system ​creates such a group, then you can use that as your group; take a moment to make sure that it exists on all of your systemsand that it is your primary group.+It is open source, it can use UTF-8 filenames that are as long as 255 bytesfile sizes and file system ​sizes of 2TB. UDF does not bother with permissionsmaking ​it ideal for external drives.
  
-    If such a group does not exist, take over an existing group or create one for yourself. I used to make a new group for myself and anyone else on the same system with whom I needed to share data but then I got lazy and just started using an existing group. Of courseany given Unix configuration can change what groups exist and what GID they get, but common one I have noticed ​is the floppy group (GID 25). There are others, like dialout (20), and tape (26) which simply are not realistcally used on modern systems but have the advantage of existing anyway, and usually getting tho same GID (from what I have seen, anyway). So I just make floppy the primary group for all my users who need to access certain stores of data, and it works out. It generally benefits me at some point when fumbling with thumbdrives,​ because I know that I made the effort at install time to ensure all of my users (or myself an all machines) are members of the same group and therefore create and use data that gets stamped with that GID.+Since it was primarily intended ​for optical mediacreating ​UDF volume ​is different ​from formatting a drive for any other filesystem.
  
-    On drives that regularly get used on other computers, I keep a directory called 777 at the top of the drive. When I need to use the portable ​drive for inter-computer transfersI put the data I want to transfer in the 777 folderrun a quick chmod -R 777 on 777.+Slackermedia recommends ​the UDF format for any external ​drive that you intend ​to use with more than just your own computer. It 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 formatit ensures that the data that matters ​to you the most is always available to youregardless of what OS you happen to have on hand.
  
-    It's just a convenient place to have an always-public location that is separate from all my other "​real"​ data. 
  
-The UDF Alternative+====Formatting a Drive for UDF====
  
-Partly as an answer to the filesystem ​problema 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 ​filesystem ​for CD-RW, DVD-RW, and Blu-Ray.+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.
  
-The down side is that it does not use journalingmaking ​data recovery after a crash or accidental unplugging ​little riskier. It does not use partitions, but that is not usually an issue for an external drive.+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. 
  
-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).+<​code>​ 
 +# dd if=/​dev/​zero ​of=/dev/sdx bs=512 count=4096 
 +</​code>​
  
-Since it was primarily intended for optical media, creating a UDF volume ​is different from formatting a drive for any other filesystem.+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.+Create the filesystem ​so that it spans the entire drive:
  
-    To get rid of the existing partition on a drive, zero out the first 4096 bytes of the drive.+<​code>​ 
 +mkudffs --utf8 \ 
 +--blocksize=512 \ 
 +--udfrev=0x0201 \ 
 +--lvid="​penguindf"​ \ 
 +--vid="​penguindf"​ \ 
 +--media-type=hd \ 
 +/dev/sdx || echo "​failed"​ 
 +</​code>​
  
-    dd if=/​dev/​zero of=/dev/sdx bs=512 count=4096+Now you can mount and use the drive on any platform.
  
-    Note that the bytesize (bs) is not flexible. It must be 512.+{{anchor:​extformat}} 
 +====Formatting Drives on Linux====
  
-    Nextfind out the block count for your drives:+This section reiterates the usual steps in formatting a drivewith 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]].
  
-    $ df -i /dev/sdx 
-    Inodes ​  ​IUsed ​   IFree 
-    2040230 ​  ​619 ​   2039611 
  
-    Finally, create ​the filesystem so that it spans the entire ​drive.+<WRAP indent>​ 
 +**1.** Identify ​the drive's device node.
  
-    mkudffs --blocksize=512 \ +With the drive //unplugged// from the computer:
-    --udfrev=0x0201 \ +
-    --lvid="​myUdfDrive"​ \ +
-    --vid="​myUdfDrive"​ \ +
-    --media-type=hd --utf8 \ +
-    ​/dev/sdx || echo "​fail"​+
  
-Now you can mount and use the drive on any platform.+<​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}}]
  
-[EOF] 
  
  
 +<WRAP centeralign>​
 +<wrap fa>​[[dotdesktop|R]]</​wrap>​ <wrap fa>​[[start|S]]</​wrap>​ <wrap fa>​[[mimetypes|Q]]</​wrap>​
 +</​WRAP>​
  
-[[{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|]]