Partition, Format and Mount new disk in Debian
Find the disk
lonewanderer@debian:~
lsblklsblk
Note the name of the device, e.g. /dev/sdb
Create a partition
lonewanderer@debian:~
sudo fdisk /dev/sdbWelcome to fdisk (util-linux 2.39.3).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help):
- Create a new label by pressing
g - Enter
nfor a new partition. - Choose the size you want
- Save changes by pressing
w
Format the partition
lonewanderer@debian:~
sudo mkfs -t ext4 /dev/sdb1Mount the disk persistently
Create the folder where the new disk is going to be mounted:
lonewanderer@debian:~
sudo mkdir /mount-pathEdit /etc/fstab
# <file system> <mount point> <type> <options> <dump> <pass>
/dev/sdb1 /mount-path ext4 defaults 0 0
Test the mount:
lonewanderer@debian:~
sudo mount -aIf no errors, run
lonewanderer@debian:~
sudo systemctl daemon-reloadResize the partition
This should become its own article, but here we go:
Unmount the partition:
lonewanderer@debian:~
sudo umount /deb/sdb1Then follow the Guide on Stack Exchange
Enlarge the partition:
lonewanderer@debian:~
sudo fdisk -u /dev/sdbp to print the partition table, take note of the number, start, end, type of sda1.
Delete it: d
Recreate it using command n with same number (1), start and type but with a bigger end (taking care not to overlap with other partitions). Try to align things on a megabyte boundary that is for end, make it a multiple of 2048 minus 1. Change the type if needed with t (for partitions holding an extX or btrfs filesystem, the default of 83 is fine).
Then w to write and q to quit.
The partition table will have been modified but the kernel will not be able to take that into account as some partitions are mounted.
However, if in-use partitions were only enlarged, you should be able to force the kernel to take the new layout with:
lonewanderer@debian:~
sudo partx /dev/sdaIf that fails, you’ll need to reboot. The system should boot just fine.
Then, resize the filesystem so it spreads to the extent of the enlarged partition (might be located in /sbin):
lonewanderer@debian:~
sudo resize2fs /dev/sda1Which for ext4 will work just fine even on a live FS.