Getting a disk ready

Linux with fdisk

  1. 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
 

MBR (Master Boot Record): old structure, used with BIOS, legacy mode, for old OS's, used for maximum compatibility. Allows only maximum of 3 primary partitions and 1 extended that can be filled with logical partitions, but only the primaries can be booteable and partitions can be of maximum 2TB.

(Windows 7 32bits and below only function with MBR)

GPT(GUID Partition Table): new structure, used with UEFI in modern computers. Can hold up to 128 primary partitions with practically unlimited space. Also easier to recover in case of corruption and more secure. Preferable unless you are working with specific old systems.

(Windows Vista 64bits and above requieres GPT with UEFI)

  1. 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
  1. 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
  • 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.

  1. 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      

Options (fourth field) [standard defaults]: defaults parameter includes standard configuration options for easy use of the filesystem, like:

  • rw: Being able to read-write

  • dev: Allows to use devices

  • auto: Allows auto-mount on system start

  • nouser: Prohibits normal users to mount or dismount the filesystem

  • exec: Allows to execute binaries in the filesystem

Dump (fifth field) [standard 0]: not commonly used today, usually skipped (0), if "1" the filesystem is included in the backup process Pass (sixth field) [Others standard 2) [fsck order]: order in which filesystem checks are done at boot time, root filesystem should have 1, then it after it finishes it goes to 2 for less important filesystems, if 0 the filesystem is not checked (not recommended!)

Windows with diskpart

  1. 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

MBR (Master Boot Record): old structure, used with BIOS, legacy mode, for old OS's, used for maximum compatibility. Allows only maximum of 3 primary partitions and 1 extended that can be filled with logical partitions, but only the primaries can be booteable and partitions can be of maximum 2TB.

(Windows 7 32bits and below only function with MBR)

GPT(GUID Partition Table): new structure, used with UEFI with modern computers. Can hold up to 128 primary partitions with practically unlimited space. Also easier to recover in case of corruption and more secure.

(Windows Vista 64bits and above requieres GPT with UEFI)

  1. 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
  1. 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
  1. 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