Getting a disk ready
Linux with fdisk
Indicate what partition table you are going to use MBR or GPT (recommended GPT)
sudo fdisk /dev/X #Initiates fdisk on selected disk device
sudo fdisk -l /dev/X #Lists basic info about device
lsblk #To list disks info and mountpoints
#Inside fdisk
o #Define MBR partition table
g #Defines GPT partition table
m #Prints help menu
Set partitions
p #Print the actual partition table
n #Add a new partition
#Inside new partition creator
+500M #Sets space of 500MB
+50G #Sets space of 50GB
v #Verify partition table
d #Delete a partition
w #Write changes
Assign a filesystem
sudo mkfs -t type -L LabelName /dev/X
mkfs.fat
mkfs.exfat
mkfs.ntfs
mkfs.ext4
sudo mkswap -L swapName /dev/X #Give a partition swap
sudo swapon /dev/X #Turn on swapfile
swapon --show #List swap files, size and location
sudo swapoff /swapfile #Turn off swapfile
Most popular types:
FAT32: compatible with almost everything, optimized for removable storage though has a limitation of 4GB for a single file.
mkfs.fat
exFAT: ExtendedFAT, evolution of FAT32, optimized for removable storage, practically no limit on file or partition size and full compatible with modern OS's though it may not be compatible with old ones.
mkfs.exfat
NTFS: designed by Microsoft, used on Windows, but is compatible with Linux thanks to drivers and is also useful for removable storage as it has great compatibility, great optimization and no size limitations like FAT32.
EXT4: the most recent versión of Extended Filesystem, native on Linux systems, best performance.
SWAP: special format file/partition that acts like an extensión of RAM, giving as much space as we want from the storage disk so if the RAM gets full the system uses it for creating new processes and it doesn't crash or stops working. But as it is in the disk connected by SATA or NVME maybe, not the RAM DIMM Module, its way more slow, so its best to avoid reaching that limit.
Mount the partition
mkdir /mnt/partitionMountpoint #Create directory(wherever you want, /mnt recommended by FHS) that will act as mount point ?Where we will have access to the insides of the partition
sudo mount /dev/X /mnt/partitionMountpoint #Mount the partition in the directory previously created
sudo umount /mnt/partitionMountpoint #Unmount the partition from the file system, it will still be on /dev/X
df -h #Lists mounted filesystems, where they are mounted and space usage
lsblk -f #Lists devices, if they are mounted and where, and filesystem format type
/etc/fstab
Configuration file that specifies what filesystems will be mounted and where at the boot of the system. Takes care of our root filesystem!
It's critical for system booting, so when editing take great care and make sure to have a backup copy! Malfunctioning fstab is no fun.
cp /etc/fstab /etc/fstab.bak
#Adding a new auto mount point
sudo blkid #List mounted points info and their UUID (Universal Unique Identifier), way more secure for naming a device in fstab and the standard
UUID=fsID /mnt/partitionMountpoint formatType defaults 0 2 #Line you need to add to the fstab !Be careful
sudo mount -a #Tries to mount all the filesystems mentioned in the fstab, you can reboot too
#Add swap to fstab
UUID=IDofSwapPartition none swap sw 0 0 #Mountpoint =none, as swap is a different type of storage used for virtual memory, so is not accesible in the traditional sense
sudo swapon -a #Activate swap on fstab
#Example: Mounts ntfs filesystem on /mnt/MoviesHDD with ReadOnly permissions
UUID=332fd7eb-a8be-431d-923b-bc6799628e78 /mnt/MoviesHDD ntfs defaults,ro 0 2
Windows with diskpart
Indicate what partition table you are going to use MBR or GPT (recommended GPT)
#On CMD
diskpart #Enter diskpart menu
disk list #List disks available
select disk n #Select the disk you want to edit !Be careful, we will delete all data!
clean #Deletes all data and partitions from a disk
convert gpt #Creates partition table GPT
convert mbr #Creates partition table MBR
detail disk #Shows detailed info on current selected disk
Set partitions
#With disk still selected
create partition primary #Takes all space available into 1 partition
create partition primary size=N #Creates a partition with N Megabytes
select partition N #Select the partition you want
detail partition #Shows detailed info on the current selected partition
Assign a filesystem
See most popular ones above.
filesystems #Shows current FS and available ones
format fs=x #Formats partition into X filesystem, available: NTFS, FAT, FAT32
format label=whatever #Formats partition again and places a label as a "name", if done first formats partition to NTFS by default
Mount the partition
select partition N #Select the partition you want to mount
assign letter=X #Mounts the partition in the specified letter:
Last updated