Differences
This shows you the differences between two versions of the page.
Previous revision | |||
— | linux:shell_commands:fdisk [2025/04/09 12:42] (current) – Update speed tplecko | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Create partitions using CLI on linux ====== | ||
+ | First and foremost: | ||
+ | **!! WARNING !!** | ||
+ | |||
+ | These commands are EXAMPLES. DELETING partitions, MODIFYING and FORMATTING filesystems destroys data and/or may prevent your machine from booting. | ||
+ | |||
+ | To quickly set up a drive up as a single ext4 partition... | ||
+ | View detected devices of class " | ||
+ | <code shell> | ||
+ | View existing partition table(s) | ||
+ | <code shell> | ||
+ | Edit the partition table for my chosen device (in this case, " | ||
+ | <code shell> | ||
+ | Within FDISK, press: | ||
+ | < | ||
+ | d ...to delete the current partition | ||
+ | n ...to create a new partition | ||
+ | p ...to specify it as a PRIMARY partition | ||
+ | 1 ...to set it as the 1ST primary partition | ||
+ | w ...to write the changes. | ||
+ | </ | ||
+ | Display the new partition table: | ||
+ | <code shell> | ||
+ | Format the new partition' | ||
+ | <code shell> | ||
+ | Create a new directory where the new drive will mount into: | ||
+ | <code shell> | ||
+ | mkdir /storage | ||
+ | mount /dev/sdx1 /storage | ||
+ | </ | ||
+ | |||
+ | TUNING | ||
+ | Remove reserved blocks (i.e. set to 0%), since this drive is just for user data | ||
+ | <code shell> | ||
+ | Since server is on UPS, Set write-back so apps don't wait for actual disk writes | ||
+ | <code shell> | ||
+ | Mount at boot up using /etc/fstab and also set write-back policy | ||
+ | <code shell>vi / | ||
+ | Find (or add) the relevant line in fstab for your drive. Parameters in fstab are separated by white space, for example the drive described above might appear as: | ||
+ | <code shell>/ | ||
+ | * The first parameter identifies the partition (either by /dev/ or a long UUID); | ||
+ | * The second parameter is the path the partition will be mounted to; | ||
+ | * Third is the filesystem type; | ||
+ | * The fourth parameter contains the options; | ||
+ | * Fifth is the dump schedule for backups; and, | ||
+ | * The sixth parameter is pass-number (used to control fsck order). | ||
+ | Change the options (4th parameter) to: | ||
+ | <code shell> | ||
+ | Reboot to check that everything went well. | ||
+ | Remember these commands are destructive! Have backups and be careful! | ||
+ | |||
+ | |||
+ | <code bash Speedy> | ||
+ | su@fs:~$ lsblk | ||
+ | NAME | ||
+ | loop0 7:0 0 55.4M 1 loop / | ||
+ | loop1 7:1 0 55.4M 1 loop / | ||
+ | loop2 7:2 0 44.4M 1 loop / | ||
+ | loop3 7:3 0 91.9M 1 loop / | ||
+ | loop4 7:4 0 63.7M 1 loop / | ||
+ | loop5 7:5 0 44.5M 1 loop / | ||
+ | loop6 7:6 0 63.8M 1 loop / | ||
+ | loop7 7:7 0 91.9M 1 loop / | ||
+ | sda 8:0 0 | ||
+ | ├─sda1 | ||
+ | └─sda2 | ||
+ | sdb 8:16 | ||
+ | └─sdb1 | ||
+ | sdc 8:32 | ||
+ | └─sdc1 | ||
+ | sr0 | ||
+ | su@fs:~$ sudo mkfs -t ext4 /dev/sdc1 | ||
+ | |||
+ | $ fdisk /dev/sdc | ||
+ | n | ||
+ | w | ||
+ | |||
+ | su@fs:~$ mkfs -t ext4 /dev/sdc1 | ||
+ | $ blkid | ||
+ | /dev/sda1: UUID=" | ||
+ | /dev/sda2: UUID=" | ||
+ | /dev/sdb1: UUID=" | ||
+ | /dev/loop0: TYPE=" | ||
+ | /dev/loop1: TYPE=" | ||
+ | /dev/loop2: TYPE=" | ||
+ | /dev/loop3: TYPE=" | ||
+ | /dev/loop4: TYPE=" | ||
+ | /dev/loop5: TYPE=" | ||
+ | /dev/loop6: TYPE=" | ||
+ | /dev/loop7: TYPE=" | ||
+ | /dev/sdc1: UUID=" | ||
+ | |||
+ | su@fs:~$ vim /etc/fstab | ||
+ | / | ||
+ | |||
+ | su@fs:~$ mount -a | ||
+ | </ |