[THE 1st TIME] Disk partitioning pt.2 - fdisk

Forum rules
Share your brain ;)
machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

[THE 1st TIME] Disk partitioning pt.2 - fdisk

Unread post by machinebacon » 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:

Code: Select all

bbq@grill:~ sudo fdisk
Usage: fdisk [OPTION]... [DEVICE]
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.

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
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:

Code: Select all

sudo blkid -o list
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

Code: Select all

/dev/sda5           ext4        WORK         /             7dd68644-0f72-434e-b5fc-8381f0424f91
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:

Code: Select all

sudo fdisk /dev/sda
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

Code: Select all

sudo mke2fs -t ext4 /dev/sda5
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 :)
..gnutella..

User avatar
elixir
Weight Watcher
Posts: 357
Joined: Fri Feb 21, 2014 8:25 am

Re: [THE 1st TIME] Disk partitioning pt.2 - fdisk

Unread post by elixir » Sat Mar 01, 2014 9:34 pm

So after reading pt. 1 and pt. 2. It is to my understanding that after full partitioning the 3 main /dev/sda's (/, swap, and /home). We can then go into the system and create logical partitions, such as /documents, inside of our /home partition. Do I have the correct idea?
Out of the corner of your eye you spot him... Shia LaBeouf.

https://www.youtube.com/watch?v=o0u4M6vppCI

User avatar
wuxmedia
Grasshopper
Posts: 6445
Joined: Wed Oct 17, 2012 11:32 am
Location: Back in Blighty
Contact:

Re: [THE 1st TIME] Disk partitioning pt.2 - fdisk

Unread post by wuxmedia » Sat Mar 01, 2014 9:59 pm

Hmm, I guess so.
I'm lazy, so I just have a big /dev/sda10 which has all my documents and such in a big mess.
If you can do it, it would make more work after to get them all mounted in fstab at boot.
if you had 5 dirs, that were partitions (/dev/sda6-11, say; docs, vidz, pr0n, mp3s, pix. each one of those would have to have a fstab entry.
Totally possible, bit too much like hard work for me 8)
if you mount just one /dev/sdaX then all those dirs would be inside it already.
"Seek, and Ye shall find"
"Github | Chooons | Site"

User avatar
elixir
Weight Watcher
Posts: 357
Joined: Fri Feb 21, 2014 8:25 am

Re: [THE 1st TIME] Disk partitioning pt.2 - fdisk

Unread post by elixir » Sat Mar 01, 2014 10:31 pm

Haha:D I can make these partitions after the system is installed though correct?

For example I can do

Code: Select all

sudo fdisk /dev/sda3
(say that is my /home partition)

And then create a new logical partition inside of it such as /dev/sda4 and have that be documents and so on?
Out of the corner of your eye you spot him... Shia LaBeouf.

https://www.youtube.com/watch?v=o0u4M6vppCI

User avatar
wuxmedia
Grasshopper
Posts: 6445
Joined: Wed Oct 17, 2012 11:32 am
Location: Back in Blighty
Contact:

Re: [THE 1st TIME] Disk partitioning pt.2 - fdisk

Unread post by wuxmedia » Sat Mar 01, 2014 10:33 pm

I guess, as long as they aren't too full, I wouldn't put anything on it you want to keep, just to be on the safe side.
"Seek, and Ye shall find"
"Github | Chooons | Site"

User avatar
elixir
Weight Watcher
Posts: 357
Joined: Fri Feb 21, 2014 8:25 am

Re: [THE 1st TIME] Disk partitioning pt.2 - fdisk

Unread post by elixir » Sat Mar 01, 2014 10:34 pm

Ok thank you. I will do some trial and error xD
Out of the corner of your eye you spot him... Shia LaBeouf.

https://www.youtube.com/watch?v=o0u4M6vppCI

User avatar
dkeg
Configurator
Posts: 3782
Joined: Sun Nov 18, 2012 9:23 pm
Location: Mid-Atlantic Grill

Re: [THE 1st TIME] Disk partitioning pt.2 - fdisk

Unread post by dkeg » Sun Mar 02, 2014 1:21 am

I actually just recently did this type of setup. I have my /dev/sda2 which is now labeled 'data'. On this I have a media directory for music, videos, etc. I also installed and set up 'Copy' here as well. Pointless to have this for each spin. All my documents really are in various cloud solutions for various reasons. I have not yet, but will set up the partition to mount in fstab.

This type of setup for sure makes for cleaner spin configs on different partitions, plus makes life much simpler

Work hard; Complain less

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: [THE 1st TIME] Disk partitioning pt.2 - fdisk

Unread post by machinebacon » Sun Mar 02, 2014 2:34 am

@LXR: In the optimal case it looks like this: we have a drive of (say) 100 GB (taking a round number now).

CASE 1: PRIMARY PARTITIONS ONLY (max 4)
We create a partition on which we install our Linux, including its own /home folder (not partition), and give it 20GB (which is absolutely enough, I run most of my partitions with between 5 and 15 GB -- the 5GB ones are for quick tests, the 15GB ones if I plan to do some bootstrapping on it). If you want to use a /swap partition, give it 2GB. More than this is actually bullshit. So we have 78GB left over. Now you give, for example, 58GB for a /my_shared_files partition. This is our third partition so far, and we have still 20GB unpartitioned space. As long as you do not plan to add more than one 'own' (primary) partition, we can keep it this way. This is the preferred choice for a more 'static' setup

CASE 2: Logical partitions
We create a primary partition that spans over the whole drive (100GB), and then create containers (logical partitions) in sizes like, for example: /dev/sda1 = 100GB = whole drive, /dev/sda5 = 15GB = our main Linux install, /dev/sda6 = 10GB = our distrohopping install, /dev/sda7 = 35GB = our porn/documents, /dev/sda8 = 18 GB = testing Gentoo, /dev/sda2 = 2GB = /swap. The remaining part we _could_ leave unpartitioned, in case we want to add another new Linux, or want to move around stuff and resize something (careful!).

I hope this answers the question. Remember: never manipulate mounted partitions. Also remember, in Case #2: it is much easier (and most of the time _only_ possible) to manipulate this setup from a live session. This has to do with the order of partitions, so just simply keep a 'rescue stick' at hand (something that has gparted for convenience)
..gnutella..

User avatar
elixir
Weight Watcher
Posts: 357
Joined: Fri Feb 21, 2014 8:25 am

Re: [THE 1st TIME] Disk partitioning pt.2 - fdisk

Unread post by elixir » Sun Mar 02, 2014 7:38 am

Thank you for this. If I understand this correctly, on the part where you said "58GB for a /my_shared_files partition" that is a partition that will share all of my files between all distros I add to it?
Out of the corner of your eye you spot him... Shia LaBeouf.

https://www.youtube.com/watch?v=o0u4M6vppCI

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: [THE 1st TIME] Disk partitioning pt.2 - fdisk

Unread post by machinebacon » Sun Mar 02, 2014 8:23 am

Yes, this is the partition that stores files that are independent of the OS you use, for example music. To use this partition and to make it mount automatically, you would use an entry in fstab. Let's imagine, the partition /dev/sda6 (of course an ext4 partition) stores all your music and photos (as in ~/Music ~/Photos ~/Porn). In the OS you would do a sudo nano /etc/fstab and add this line:

Code: Select all

/dev/sda6 /media/my_files ext4 defaults 0 0
Then you make a sudo mount -a and you'll find /media/my_files/Music, /media/my_files/Photos and so on.

If you use one of the newer BBQ releases, you can also run sudo mkmnt, this does it for you more or less automatically.
..gnutella..

User avatar
elixir
Weight Watcher
Posts: 357
Joined: Fri Feb 21, 2014 8:25 am

Re: [THE 1st TIME] Disk partitioning pt.2 - fdisk

Unread post by elixir » Sun Mar 02, 2014 9:30 am

Awesome, repartition went well. I have 20GB for /, 2GB for swap, and 78GB for all files. Only problem is I am entering

Code: Select all

/dev/sda6 /media/my_files ext4 defaults 0 0
and I keep getting the error

Code: Select all

elixir@bbq:~$ sudo mount -a
mount: wrong fs type, bad option, bad superblock on /dev/sda3,
       missing codepage or helper program, or other error
       In some cases useful info is found in syslog - try
       dmesg | tail  or so
Checked out the sudo mkmnt. Currently looking for answers.
Out of the corner of your eye you spot him... Shia LaBeouf.

https://www.youtube.com/watch?v=o0u4M6vppCI

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: [THE 1st TIME] Disk partitioning pt.2 - fdisk

Unread post by machinebacon » Sun Mar 02, 2014 11:06 am

what does sudo blkid -o list and sudo fdisk -l and cat /etc/fstab show? Of course you need to adjust the paths (/dev/sdaX and /media/XXX)
..gnutella..

User avatar
elixir
Weight Watcher
Posts: 357
Joined: Fri Feb 21, 2014 8:25 am

Re: [THE 1st TIME] Disk partitioning pt.2 - fdisk

Unread post by elixir » Sun Mar 02, 2014 6:36 pm

Code: Select all

elixir@bbq:~$ sudo blkid -o list
device                            fs_type      label         mount point                           UUID
---------------------------------------------------------------------------------------------------------------------------------------
/dev/sda1                         ext4                       /                                     e251d795-ae69-47a6-b93c-7ba25971f9bd

Code: Select all

elixir@bbq:~$ sudo fdisk -l

Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders, total 1953525168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x00099b9a

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *          63    39070079    19535008+  83  Linux
Partition 1 does not start on physical sector boundary.
/dev/sda2        39070080    42973874     1951897+  82  Linux swap / Solaris
/dev/sda3        42973875   195318269    76172197+  83  Linux
Partition 3 does not start on physical sector boundary.

Code: Select all

elixir@bbq:~$ cat /etc/fstab
proc		/proc		proc	defaults	0	0
/swapfile	swap		swap	defaults	0	0
/dev/sda1	/		ext4	defaults,noatime	0	1
/dev/sda3	/media/files	ext4	defaults	0	0
I was checking online, and something said about formatting it with sudo e2fsck and I seemed to get the same error.
Now I see something that says "parted /dev/sdc print' to get the real partitions since the fdisk listing is going to be wrong" going to check that out.
Out of the corner of your eye you spot him... Shia LaBeouf.

https://www.youtube.com/watch?v=o0u4M6vppCI

User avatar
elixir
Weight Watcher
Posts: 357
Joined: Fri Feb 21, 2014 8:25 am

Re: [THE 1st TIME] Disk partitioning pt.2 - fdisk

Unread post by elixir » Sun Mar 02, 2014 7:06 pm

Hey I just fixed it by reconfiguring it to ext4 with the code.

Code: Select all

sudo mke2fs -t ext4 /dev/sda3
It mounted and now says it is mounted on /media/files :)
When I umount it my files disappear and when I mount they are back again so everything is working nicely.
Thank you for your help! :)
Out of the corner of your eye you spot him... Shia LaBeouf.

https://www.youtube.com/watch?v=o0u4M6vppCI

User avatar
wuxmedia
Grasshopper
Posts: 6445
Joined: Wed Oct 17, 2012 11:32 am
Location: Back in Blighty
Contact:

Re: [THE 1st TIME] Disk partitioning pt.2 - fdisk

Unread post by wuxmedia » Sun Mar 02, 2014 7:16 pm

good work elixir!
"Seek, and Ye shall find"
"Github | Chooons | Site"

User avatar
dkeg
Configurator
Posts: 3782
Joined: Sun Nov 18, 2012 9:23 pm
Location: Mid-Atlantic Grill

Re: [THE 1st TIME] Disk partitioning pt.2 - fdisk

Unread post by dkeg » Thu Oct 22, 2015 1:49 am

elixir wrote:Hey I just fixed it by reconfiguring it to ext4 with the code.

Code: Select all

sudo mke2fs -t ext4 /dev/sda3
It mounted and now says it is mounted on /media/files :)
When I umount it my files disappear and when I mount they are back again so everything is working nicely.
Thank you for your help! :)
I just took full advantage of this. Thank you!

Work hard; Complain less

sPacE gàN
Saltimbocca-Roller
Posts: 16
Joined: Wed Oct 28, 2015 3:41 am

Re: [THE 1st TIME] Disk partitioning pt.2 - fdisk

Unread post by sPacE gàN » Tue Nov 10, 2015 3:47 am

I used sudo mkmnt and it works like a charm; guides you through setup and automatically mounts on startup. Lovely

Post Reply