[THE 1st TIME] Disk partitioning pt.2 - fdisk
Posted: Tue Feb 25, 2014 4:58 am
Let's get to the scary part: partitioning a disk with terminal applications. What do we have?
There is a tool called fdisk, which is a real terminal program without any graphical user interface. It needs to be called as root (just like all other of these more serious applications). Let's see what it can do:
Okay, so it needs an option and we have to tell it which drive we want to work on. We can list our partition table, with the option -l.
We see that there are two disks attached, one is /dev/sda with a size of 160GB and 16 partitions, and on the bottom there is /dev/sdb with sharp 2GB, looks like a USB stick to me ;) It has actually another partition embedded, called sdb1p1, this happens when you 'dd' an ISO file onto a drive. And you get a similar output when you prepare to install one of our lite releases from a live session. You do not want to manipulate a mounted partition when using fdisk or any of the other tools! So, make sure that you have no mounted partitions on the device you want to manipulate:
should show (not mounted) for the drive /dev/sda if you are in a live session, and it should only show the the mount point '/' for the partition you work on when you run an installed session. Remember, do not manipulate a mounted partition. So if you see something like
do not use the following tools to manipulate /dev/sda5.
So fdisk can show us the position and size of the partitions, and we can do all serious operations with it: resizing, moving, copying and creating partitions. And we can delete them, too. Probably not what we want. Let's start it with an interactive command mode:
It requires you to enter single letters + [Enter]. We first check the list and [p]rint the table. This is the same output like above, the big list of drives and partitions. Let's say we want to add a new partition to our (not yet fully partitioned) drive: press [n] for [n]ew partition. You can there add a [l]ogical or [p]rimary partition. Logical means, it is a inside of another partition (good for distrohoppers). In general it is a good idea to have at least one huge primary partition: you can put many logical ones inside. All of these numbers will be given automatically, so you don't need to bother. You can give a size to the newly created partition. If you decide not to create anything here because you want to escape: press Ctrl-c to cancel the operation.
Before you completely quit fdisk, you want to [w]rite the new partition table to the disk. Remember that it will probably (!) not be updated in mtab yet, so you will need to reboot to see changes.
fdisk is powerful but not for first-timers. I recommend to play around with it inside a virtual environment, like Virtualbox. Create a virtual machine with 10 GB, and install Spring (or any netinstall Linux distro), and play around with fdisk to get comfortable with it. Once you understand how logical and primary partitions work, and how you can resize them non-destructively, you will use fdisk over gparted :)
A little addition for your convenience: you might want to create a filesystem on the partition, for example an ext4, using mke2fs
BTW I do not take any responsibility for wiped drives and partitions. Please, read the last paragraph again and make your first steps in a virtualbox :)
There is a tool called fdisk, which is a real terminal program without any graphical user interface. It needs to be called as root (just like all other of these more serious applications). Let's see what it can do:
Code: Select all
bbq@grill:~ sudo fdisk
Usage: fdisk [OPTION]... [DEVICE]
Code: Select all
Disk /dev/sda: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders, total 312581808 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000d41f5
Device Boot Start End Blocks Id System
/dev/sda1 4094 242511871 121253889 5 Extended
/dev/sda2 254035968 291146117 18555075 83 Linux
/dev/sda3 291147776 301387775 5120000 83 Linux
/dev/sda4 * 301387776 312580095 5596160 83 Linux
/dev/sda5 4096 10244095 5120000 83 Linux
/dev/sda6 10246144 14342143 2048000 82 Linux swap / Solaris
/dev/sda7 14344192 25720831 5688320 83 Linux
/dev/sda8 25722880 38010879 6144000 83 Linux
/dev/sda9 38012928 52348927 7168000 83 Linux
/dev/sda10 52350976 71929855 9789440 83 Linux
/dev/sda11 71931904 92616703 10342400 83 Linux
/dev/sda12 92616705 107851078 7617187 83 Linux
/dev/sda13 107853824 142612479 17379328 83 Linux
/dev/sda14 142614528 185620479 21502976 83 Linux
/dev/sda15 185620543 231133183 22756320+ 83 Linux
/dev/sda16 231135232 242511871 5688320 83 Linux
Disk /dev/sdb: 1973 MB, 1973419008 bytes
64 heads, 32 sectors/track, 1881 cylinders, total 3854334 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x2b8b8fd1
Device Boot Start End Blocks Id System
/dev/sdb1 * 0 620543 310272 17 Hidden HPFS/NTFS
Disk /dev/sdb1: 317 MB, 317718528 bytes
64 heads, 32 sectors/track, 303 cylinders, total 620544 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x2b8b8fd1
Device Boot Start End Blocks Id System
/dev/sdb1p1 * 0 620543 310272 17 Hidden HPFS/NTFS
Code: Select all
sudo blkid -o list
Code: Select all
/dev/sda5 ext4 WORK / 7dd68644-0f72-434e-b5fc-8381f0424f91
So fdisk can show us the position and size of the partitions, and we can do all serious operations with it: resizing, moving, copying and creating partitions. And we can delete them, too. Probably not what we want. Let's start it with an interactive command mode:
Code: Select all
sudo fdisk /dev/sda
Before you completely quit fdisk, you want to [w]rite the new partition table to the disk. Remember that it will probably (!) not be updated in mtab yet, so you will need to reboot to see changes.
fdisk is powerful but not for first-timers. I recommend to play around with it inside a virtual environment, like Virtualbox. Create a virtual machine with 10 GB, and install Spring (or any netinstall Linux distro), and play around with fdisk to get comfortable with it. Once you understand how logical and primary partitions work, and how you can resize them non-destructively, you will use fdisk over gparted :)
A little addition for your convenience: you might want to create a filesystem on the partition, for example an ext4, using mke2fs
Code: Select all
sudo mke2fs -t ext4 /dev/sda5