Skip to content

Commit d2d54da

Browse files
committed
working with hard drives
1 parent fa6b091 commit d2d54da

File tree

11 files changed

+146
-20
lines changed

11 files changed

+146
-20
lines changed

Diff for: README.md

-17
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,6 @@ Houses helpful concise information primarily about GNU/Linux, POSIX, and related
1313

1414
I started this a while ago. It is fairly incomplete but we'll see if it grows, not making promises yet.
1515

16-
# Todo
17-
## Mature
18-
* linux-fhs
19-
* package-managers_conda
20-
* package-managers_pacman+yay
21-
* package-managers_pip
22-
23-
## Started
24-
* networking
25-
* shell_bash
26-
* shell_posix
27-
* text-editors_vim
28-
29-
## Empty
30-
* text-editors_kakoune
31-
* shell_xonsh
32-
3316
# Guidelines and Structure
3417
## Topics
3518
Each directory is about a particular topic. Each topic may or may not have an associated general category. The naming convention is: '\<General Category\>_\<Specific Topic\>' or simply '\<Specific Topic\>' if there is no associated category. Dashes ('-') are used instead of spaces. If a Specific Topic has an underscore in its name, it is replaced by a dash ('wpa_supplicant' -> 'wpa-supplicant').

Diff for: filesystems/exfat/how.md

-1
This file was deleted.

Diff for: filesystems/exfat/how.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../mkfs/how.md

Diff for: filesystems/ext/how.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../mkfs/how.md

Diff for: filesystems/ext/what.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
# One Sentence
3+
The ext4 file system is a modern journalling filesystem that is usually the default
4+
choice on Linux.
5+
6+
# Background
7+
The ext4 filesystem is an improvement over ext3, which itself improves on ext2.
8+
The ext2 filesystem may be useful because it has native support on both FreeBSD
9+
and Linux. Other than this case, ext4 should generally be preferred.

Diff for: filesystems/fdisk/how.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
## Enter fdisk shell for device `<d>`
3+
`sudo fdisk /dev/<d>`
4+
5+
## List commands
6+
`fdisk> m`
7+
8+
## Delete Partition
9+
`fdisk> d`
10+
11+
## Create GPT Partition Table (Overwrites Existing)
12+
`fdisk> g`
13+
14+
## Create New Partition
15+
`fdisk> n`
16+
17+
## Print Partition Table
18+
`fdisk> p`
19+
20+
## Print Unpartitioned Space
21+
`fdisk> F`
22+
23+
## Print Partition Information
24+
`fdisk> i`
25+
26+
## Write and Quit
27+
`fdisk> w`
28+
29+
## Quit Without Saving
30+
`fdisk> q`

Diff for: filesystems/fdisk/what.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# One Sentence
2+
The `fdisk` tool lets you create and modify partition tables.
3+
4+
# Background
5+
See `linux/devices/drives` for background on how drives work in Linux.
6+
7+
The `fdisk` tool is a simple tool letting you create/delete partitions and create
8+
fresh partitions. Of course, you can also create fresh partition tables with it.
9+
The GNU `parted` tool can let you manipulate partitions _and_ filesystems,
10+
but I prefer using `fdisk` and `mkfs`.

Diff for: filesystems/mkfs/how.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
## Format Partition `<p>` (e.g. `sdb1`) to Filesystem `<fs>` (e.g. `ext2`, `ext4`, `exfat`, `ntfs`, etc)
3+
`$ sudo mkfs.<fs> /dev/<p>`
4+
5+
## Format Partition `<p>` to ext4
6+
`$ sudo mkfs.ext4 /dev/<p>`
7+
8+
## Format Partition `<p>` to ntfs
9+
`$ sudo mkfs.ntfs /dev/<p>`
10+

Diff for: filesystems/ntfs/how.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11

2-
## Change the label of an NTFS drive partition
3-
`$ sudo ntfslabel -f /dev/sdb1 NTFS128G-0`
2+
## Creating NTFS Filesystem at Partition
3+
See filesystem/mkfs/how.md hpage
4+
5+
## Change the label of an NTFS drive partition `<part>` to <label>
6+
`$ sudo ntfslabel -f /dev/<part> <label>`
47

Diff for: filesystems/zfs/what.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
# One Sentence
3+
The zfs filesystem is an advanced filesystem used natively by FreeBSD.
4+
5+
# Background
6+
The zfs filesystem is an influential filesystem that may be the most advanced
7+
free and open source file system available.

Diff for: langs/julia/how.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Julia
2+
3+
## Run a Shell Command (Create Cmd object and Run it)
4+
`run(<shell command>)`
5+

Diff for: linux/devices/drives/what.md

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# One Sentence
2+
In Linux, all drives are files.
3+
4+
# Background
5+
This section gives a working understanding of how hard drives work on Linux and basic
6+
information on how to prepare them. Use other hpages or manpages to understand
7+
how to use the commandline tools described here.
8+
9+
## How Hard Drives work in Linux
10+
### Device File
11+
Recall than in the Unix philosophy, everything is a file. Things may not _literally_
12+
be files, but the point is they should be able to act like them. To the extent they
13+
follow Unix, Linux and BSD thus also treat everything like files. In these operating
14+
systems, you have _file abstractions_ like _device files_ and _sockets_. Even though
15+
these aren't files in the traditional sense, they can be read from and written to,
16+
just like files.
17+
18+
When you plug in a hard drive in Linux, a _device file_ is created in the `/dev`
19+
directory. Usually the first hard drive is `/dev/sda`, second is `/dev/sdb`, and so on
20+
(but not necessarily). You can use the `lsblk` (list block devices) tool to print
21+
information on what _block devices_ are available.
22+
23+
### Block Device
24+
A hard drive is one example of a [block device](https://unix.stackexchange.com/questions/259193/what-is-a-block-device).
25+
A block device is basically something you can read from or write to in "blocks" instead of
26+
individual characters. It may mean something specific, but for a working understanding
27+
you can treat block device and hard drive as interchangeable. Note that you can have
28+
device files that don't point to block devices (`/dev/random` and `/dev/zero` are examples).
29+
30+
### Partition Tables and Partitions
31+
A hard drive has a partition table, partitions, and filesystems. A partition is basically
32+
a chunk of a block device. Partitions, like mathematical partitions, cannot overlap with
33+
each other. Other than logically dividing the hard drive into usable areas, the other
34+
job of the partition is to hold the filesystem. The filesystem is the interface for you
35+
to create, modify, and delete files.
36+
37+
A partition table is a single, low-level thing on the disk that describes all the partitions a
38+
disk has. So the first step to making a disk usable is to create and setup the partition
39+
table.
40+
41+
### MBR and GPT
42+
Two different protocols for partition tables are master boot record (MBR) and
43+
grand partition table (GPT). I don't know the difference between them, but basically
44+
they can each support different filesystems and features. MBR is the older one and
45+
GPT is the newer one. You usually want to use GPT unless you need to use MBR for some
46+
reason (using some kind of DOS drive).
47+
48+
### Filesystems
49+
To actually use a partition, it needs a filesytem. A filesystem is the interface
50+
that is used to manage files. Many filesystems exist, each with different features,
51+
for example `ext4` is commonly used on Linux and `zfs` is commonly used on FreeBSD.
52+
53+
## How to Use Drives
54+
### Creation
55+
The `fdisk` tool is a simple tool letting you create/delete partitions and create
56+
fresh partitions. Of course, you can also create fresh partition tables with it.
57+
Use `mkfs` to make new filesystems on partitions.
58+
59+
The GNU `parted` tool is another tool that can help you repartition a drive and
60+
create filesystems. I prefer using the separete `fdisk` and `mkfs` tools though.
61+
62+
### Mounting
63+
In order to use a partition, it has to be _mounted_ to the filesystem.
64+
Mounting is kind of like the docking procedure on a space ship. It's where
65+
the two systems "connect" and can then transfer things between them.
66+
Use the `mount` and `umount` commands to mount partitions to particular
67+
(empty) directories and also unmount them, respectively.
68+

0 commit comments

Comments
 (0)