Is it possible to create partitions via Terminal in a live session?

Chat about Linux in general
Forum rules
Do not post support questions here. Before you post read the forum rules. Topics in this forum are automatically closed 6 months after creation.
Matthew_Wai
Level 5
Level 5
Posts: 522
Joined: Sun Jun 07, 2015 10:42 am
Location: China

Is it possible to create partitions via Terminal in a live session?

Post by Matthew_Wai »

After some time, I may have to clean install Windows and a Linux distro on an HDD because the HDD currently in use could fail later according to this thread: https://www.linuxquestions.org/question ... 175721400/

I have "Mint 21 Cinnamon 64-bit.iso" on a Ventoy device. Is it possible to create partitions via Terminal in a live session? I can create partitions via Command Prompt on Windows PE, but I am interested to know whether it is possible on Linux.
Last edited by LockBot on Mon Jul 31, 2023 10:00 pm, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
I have Windows, UnionTech OS, and Linux Mint on the same HDD.
rene
Level 20
Level 20
Posts: 12212
Joined: Sun Mar 27, 2016 6:58 pm

Re: Is it possible to create partitions via Terminal in a live session?

Post by rene »

Of course. The Live/Installer USB is a complete system and includes all normal Linux command-line based partitioning tools such as gdisk, fdisk, sfdisk, probably cfdisk, parted -- and graphical ones such as gparted and the installer's own partitioning tool.
Matthew_Wai
Level 5
Level 5
Posts: 522
Joined: Sun Jun 07, 2015 10:42 am
Location: China

Re: Is it possible to create partitions via Terminal in a live session?

Post by Matthew_Wai »

rene wrote: Tue Jan 31, 2023 5:10 am gdisk, fdisk, sfdisk, probably cfdisk, parted
Which one would you recommend if I want to do the following things?

1. Delete all partitions from the HDD.
2. Convert the HDD into a GPT disk.
3. Create a 71-GB NTFS partition for Windows.
4. Create an 82-GB Ext4 partition for Linux.
5. Create an NTFS data partition occupying all of the remaining space.
I have Windows, UnionTech OS, and Linux Mint on the same HDD.
User avatar
londoner
Level 2
Level 2
Posts: 66
Joined: Sun Oct 13, 2019 7:03 pm
Location: South Africa

Re: Is it possible to create partitions via Terminal in a live session?

Post by londoner »

Gparted is probably easiest for a new user. It is available in the menu on the live USB under Administration.
https://gparted.org/display-doc.php?name=help-manual
I strongly suggest you install Windows first before Linux.
Boot from from your live USB and create the partitions.
Install Windows, then reboot from Live USB and install Linux Mint.
User avatar
kc1di
Level 18
Level 18
Posts: 8181
Joined: Mon Sep 08, 2008 8:44 pm
Location: Maine USA

Re: Is it possible to create partitions via Terminal in a live session?

Post by kc1di »

I would use gparted my self.
But have used fdisk in the past you'll have to learn it's system though. May not be intuitive to new users.
Good luck.
Last edited by kc1di on Tue Jan 31, 2023 8:55 am, edited 1 time in total.
Easy tips : https://easylinuxtipsproject.blogspot.com/ Pjotr's Great Linux projects page.
Linux Mint Installation Guide: http://linuxmint-installation-guide.rea ... en/latest/
Registered Linux User #462608
Matthew_Wai
Level 5
Level 5
Posts: 522
Joined: Sun Jun 07, 2015 10:42 am
Location: China

Re: Is it possible to create partitions via Terminal in a live session?

Post by Matthew_Wai »

londoner wrote: Tue Jan 31, 2023 7:55 amGparted is probably easiest for a new user.
The easiest way for me is using DiskPart, a command-line tool, on Windows PE. I want to do the same via a command-line tool on Linux.
I have Windows, UnionTech OS, and Linux Mint on the same HDD.
rene
Level 20
Level 20
Posts: 12212
Joined: Sun Mar 27, 2016 6:58 pm

Re: Is it possible to create partitions via Terminal in a live session?

Post by rene »

parted likely comes closest; plain gdisk or fdisk (former specifically for GPT partitioning, latter for either) is fine as well. But note: Linux is not Windows, and the tools are different.

There's also the question as to why you want to partition manually in the first place: both Mint's and Windows' installer are perfectly capably of partitioning...
Last edited by rene on Tue Jan 31, 2023 9:12 am, edited 1 time in total.
User avatar
kc1di
Level 18
Level 18
Posts: 8181
Joined: Mon Sep 08, 2008 8:44 pm
Location: Maine USA

Re: Is it possible to create partitions via Terminal in a live session?

Post by kc1di »

This page gives a brief rundown on a few partition mangers. some GUI some command line.
https://itsfoss.com/partition-managers-linux/

I would ask you the same question as above, why do you want to manually partition your drive? Mint installer has a manual setting called something else that is more that capable of partitioning the disk for you.
Easy tips : https://easylinuxtipsproject.blogspot.com/ Pjotr's Great Linux projects page.
Linux Mint Installation Guide: http://linuxmint-installation-guide.rea ... en/latest/
Registered Linux User #462608
User avatar
AndyMH
Level 21
Level 21
Posts: 13760
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: Is it possible to create partitions via Terminal in a live session?

Post by AndyMH »

Matthew_Wai wrote: Tue Jan 31, 2023 6:58 am [1. Delete all partitions from the HDD.
2. Convert the HDD into a GPT disk.
3. Create a 71-GB NTFS partition for Windows.
4. Create an 82-GB Ext4 partition for Linux.
5. Create an NTFS data partition occupying all of the remaining space.
gparted is by far the easiest tool to use. In addition to the above you will need an EFI partition, format fat32, size 100MB and set the flags esp and boot - assuming you are booting UEFI.

From memory win wants to create three partitions, MS reserved, win C: and a recovery partition.
Thinkcentre M720Q - LM21.3 cinnamon, 4 x T430 - LM21.3 cinnamon, Homebrew desktop i5-8400+GTX1080 Cinnamon 19.0
linux-rox
Level 10
Level 10
Posts: 3334
Joined: Sun Jul 19, 2020 9:17 pm

Re: Is it possible to create partitions via Terminal in a live session?

Post by linux-rox »

Be aware, there's another step you didn't ask about: create file system. Terminal tools for that include mkfs.ext4 and mkdosfs. An internet search on those two should get your started. Or search for linux make file system.

By the way, for dual boot, I'd say you want a 200 MB EFI partition. And if it's not a UEFI computer, you need a BIOS boot partition for GPT.
Matthew_Wai
Level 5
Level 5
Posts: 522
Joined: Sun Jun 07, 2015 10:42 am
Location: China

Re: Is it possible to create partitions via Terminal in a live session?

Post by Matthew_Wai »

rene wrote: Tue Jan 31, 2023 8:54 am both Mint's and Windows' installer are perfectly capably of partitioning...
kc1di wrote: Tue Jan 31, 2023 9:00 am Mint installer has a manual setting called something else that is more that capable of partitioning the disk for you.
I am sorry to say that I do not intend to install Mint.
I have Windows, UnionTech OS, and Linux Mint on the same HDD.
rene
Level 20
Level 20
Posts: 12212
Joined: Sun Mar 27, 2016 6:58 pm

Re: Is it possible to create partitions via Terminal in a live session?

Post by rene »

I shall in that case take the fact that you still asked on a Mint forum to be a compliment for said Mint forum.
Matthew_Wai
Level 5
Level 5
Posts: 522
Joined: Sun Jun 07, 2015 10:42 am
Location: China

Re: Is it possible to create partitions via Terminal in a live session?

Post by Matthew_Wai »

"Mint 21 Cinnamon 64-bit.iso" is a very useful tool although I will not use the installer.
I have Windows, UnionTech OS, and Linux Mint on the same HDD.
User avatar
kc1di
Level 18
Level 18
Posts: 8181
Joined: Mon Sep 08, 2008 8:44 pm
Location: Maine USA

Re: Is it possible to create partitions via Terminal in a live session?

Post by kc1di »

Matthew_Wai wrote: Wed Feb 01, 2023 2:22 amI am sorry to say that I do not intend to install Mint.
And I'm sorry to here that. Which Distro will you be using?
Last edited by SMG on Fri Feb 03, 2023 10:39 am, edited 1 time in total.
Reason: Removed extra quote tag to fix quote attribution.
Easy tips : https://easylinuxtipsproject.blogspot.com/ Pjotr's Great Linux projects page.
Linux Mint Installation Guide: http://linuxmint-installation-guide.rea ... en/latest/
Registered Linux User #462608
Matthew_Wai
Level 5
Level 5
Posts: 522
Joined: Sun Jun 07, 2015 10:42 am
Location: China

Re: Is it possible to create partitions via Terminal in a live session?

Post by Matthew_Wai »

kc1di wrote: Wed Feb 01, 2023 7:36 am Which Distro will you be using?
UnionTech OS
I have Windows, UnionTech OS, and Linux Mint on the same HDD.
User avatar
kc1di
Level 18
Level 18
Posts: 8181
Joined: Mon Sep 08, 2008 8:44 pm
Location: Maine USA

Re: Is it possible to create partitions via Terminal in a live session?

Post by kc1di »

Matthew_Wai wrote: Wed Feb 01, 2023 7:46 am
kc1di wrote: Wed Feb 01, 2023 7:36 am Which Distro will you be using?
UnionTech OS
And what is the OS based upon? since obviously it's and in house build.
Easy tips : https://easylinuxtipsproject.blogspot.com/ Pjotr's Great Linux projects page.
Linux Mint Installation Guide: http://linuxmint-installation-guide.rea ... en/latest/
Registered Linux User #462608
Matthew_Wai
Level 5
Level 5
Posts: 522
Joined: Sun Jun 07, 2015 10:42 am
Location: China

Re: Is it possible to create partitions via Terminal in a live session?

Post by Matthew_Wai »

kc1di wrote: Wed Feb 01, 2023 9:23 amAnd what is the OS based upon? since obviously it's and in house build.
See: https://www.linuxadictos.com/en/uos-la- ... ndows.html
I have Windows, UnionTech OS, and Linux Mint on the same HDD.
linux-rox
Level 10
Level 10
Posts: 3334
Joined: Sun Jul 19, 2020 9:17 pm

Re: Is it possible to create partitions via Terminal in a live session?

Post by linux-rox »

That explains the thread. Last time I looked at Deepin, it didn't support live session boot. OTOH, the installer did have a partitioning tool.

Edit: Out of curiosity, took a look at the current stable version, 20.8. Still no live session. Test the scenario where set up partitions in a Mint live session, then install Deepin to them. Worked fine as far as I can tell (did test in a VM). No live session is a big deal, though, IMHO. How does one do repairs?

Note: I did partition setup with GParted, because that's what I always use. GP uses the same command line tools as discussed above, so those should work just as well.
Last edited by linux-rox on Wed Feb 01, 2023 3:45 pm, edited 1 time in total.
User avatar
kc1di
Level 18
Level 18
Posts: 8181
Joined: Mon Sep 08, 2008 8:44 pm
Location: Maine USA

Re: Is it possible to create partitions via Terminal in a live session?

Post by kc1di »

linux-rox wrote: Wed Feb 01, 2023 12:54 pm That explains the thread. Last time I looked at Deepin, it didn't support live session boot. OTOH, the installer did have a partitioning tool.
yep explains a lot :)
Easy tips : https://easylinuxtipsproject.blogspot.com/ Pjotr's Great Linux projects page.
Linux Mint Installation Guide: http://linuxmint-installation-guide.rea ... en/latest/
Registered Linux User #462608
Matthew_Wai
Level 5
Level 5
Posts: 522
Joined: Sun Jun 07, 2015 10:42 am
Location: China

Re: Is it possible to create partitions via Terminal in a live session?

Post by Matthew_Wai »

I booted my PC into a live session, deleted everything from a USB drive, and created three new partitions as shown below:

Code: Select all

To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

mint@mint:~$ lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
loop0    7:0    0   2.1G  1 loop /rofs
sda      8:0    0 465.8G  0 disk 
├─sda1   8:1    0   100M  0 part 
├─sda2   8:2    0    16M  0 part 
├─sda3   8:3    0  70.4G  0 part 
├─sda4   8:4    0   499M  0 part 
├─sda5   8:5    0     2G  0 part [SWAP]
├─sda6   8:6    0    78G  0 part 
└─sda8   8:8    0 314.8G  0 part 
sdb      8:16   1    60G  0 disk 
├─sdb1   8:17   1    60G  0 part 
└─sdb2   8:18   1    32M  0 part /media/mint/Linux Mint 21 Cinnamon 64-bit
sdc      8:32   1  28.9G  0 disk 
├─sdc1   8:33   1  20.9G  0 part /media/mint/EXTRA
└─sdc2   8:34   1     8G  0 part /media/mint/Windows ISO
sdd      8:48   1  57.3G  0 disk 
├─sdd1   8:49   1   8.3G  0 part 
└─sdd2   8:50   1    49G  0 part 
sde      8:64   1   7.2G  0 disk 
└─sde1   8:65   1   7.2G  0 part /media/mint/DEVICE
sdf      8:80   1     0B  0 disk 
sr0     11:0    1  1024M  0 rom  
mint@mint:~$ sudo gdisk /dev/sdd
GPT fdisk (gdisk) version 1.0.8

The protective MBR's 0xEE partition is oversized! Auto-repairing.

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help): h
b	back up GPT data to a file
c	change a partition's name
d	delete a partition
i	show detailed information on a partition
l	list known partition types
n	add a new partition
o	create a new empty GUID partition table (GPT)
p	print the partition table
q	quit without saving changes
r	recovery and transformation options (experts only)
s	sort partitions
t	change a partition's type code
v	verify disk
w	write table to disk and exit
x	extra functionality (experts only)
?	print this menu

Command (? for help): p
Disk /dev/sdd: 120176640 sectors, 57.3 GiB
Model:  SanDisk 3.2Gen1
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): D1702AFA-A0DA-46F5-9E40-968373EA14D6
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 120176606
Partitions will be aligned on 2048-sector boundaries
Total free space is 4029 sectors (2.0 MiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048        17410047   8.3 GiB     0700  Basic data partition
   2        17410048       120174591   49.0 GiB    0700  Basic data partition

Command (? for help): o
This option deletes all partitions and creates a new protective MBR.
Proceed? (Y/N): y

Command (? for help): p
Disk /dev/sdd: 120176640 sectors, 57.3 GiB
Model:  SanDisk 3.2Gen1
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): 3CEFD13F-0469-4156-8706-C287B5893E78
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 120176606
Partitions will be aligned on 2048-sector boundaries
Total free space is 120176573 sectors (57.3 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name

Command (? for help): n
Partition number (1-128, default 1): 1
First sector (34-120176606, default = 2048) or {+-}size{KMGTP}: 
Last sector (2048-120176606, default = 120176606) or {+-}size{KMGTP}: +7G
Current type is 8300 (Linux filesystem)
Hex code or GUID (L to show codes, Enter = 8300): 
Changed type of partition to 'Linux filesystem'

Command (? for help): c
Using 1
Enter name: Windows

Command (? for help): p
Disk /dev/sdd: 120176640 sectors, 57.3 GiB
Model:  SanDisk 3.2Gen1
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): 3CEFD13F-0469-4156-8706-C287B5893E78
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 120176606
Partitions will be aligned on 2048-sector boundaries
Total free space is 105496509 sectors (50.3 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048        14682111   7.0 GiB     8300  Windows

Command (? for help): n
Partition number (2-128, default 2): 2
First sector (34-120176606, default = 14682112) or {+-}size{KMGTP}: 
Last sector (14682112-120176606, default = 120176606) or {+-}size{KMGTP}: +8G
Current type is 8300 (Linux filesystem)
Hex code or GUID (L to show codes, Enter = 8300): 
Changed type of partition to 'Linux filesystem'

Command (? for help): c
Partition number (1-2): 2
Enter name: Linux

Command (? for help): p
Disk /dev/sdd: 120176640 sectors, 57.3 GiB
Model:  SanDisk 3.2Gen1
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): 3CEFD13F-0469-4156-8706-C287B5893E78
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 120176606
Partitions will be aligned on 2048-sector boundaries
Total free space is 88719293 sectors (42.3 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048        14682111   7.0 GiB     8300  Windows
   2        14682112        31459327   8.0 GiB     8300  Linux

Command (? for help): n
Partition number (3-128, default 3): 3
First sector (34-120176606, default = 31459328) or {+-}size{KMGTP}: 
Last sector (31459328-120176606, default = 120176606) or {+-}size{KMGTP}: 
Current type is 8300 (Linux filesystem)
Hex code or GUID (L to show codes, Enter = 8300): 
Changed type of partition to 'Linux filesystem'

Command (? for help): c
Partition number (1-3): 3
Enter name: My_files

Command (? for help): p
Disk /dev/sdd: 120176640 sectors, 57.3 GiB
Model:  SanDisk 3.2Gen1
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): 3CEFD13F-0469-4156-8706-C287B5893E78
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 120176606
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048        14682111   7.0 GiB     8300  Windows
   2        14682112        31459327   8.0 GiB     8300  Linux
   3        31459328       120176606   42.3 GiB    8300  My_files

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sdd.
The operation has completed successfully.
mint@mint:~$ lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
loop0    7:0    0   2.1G  1 loop /rofs
sda      8:0    0 465.8G  0 disk 
├─sda1   8:1    0   100M  0 part 
├─sda2   8:2    0    16M  0 part 
├─sda3   8:3    0  70.4G  0 part 
├─sda4   8:4    0   499M  0 part 
├─sda5   8:5    0     2G  0 part [SWAP]
├─sda6   8:6    0    78G  0 part 
└─sda8   8:8    0 314.8G  0 part 
sdb      8:16   1    60G  0 disk 
├─sdb1   8:17   1    60G  0 part 
└─sdb2   8:18   1    32M  0 part /media/mint/Linux Mint 21 Cinnamon 64-bit
sdc      8:32   1  28.9G  0 disk 
├─sdc1   8:33   1  20.9G  0 part /media/mint/EXTRA
└─sdc2   8:34   1     8G  0 part /media/mint/Windows ISO
sdd      8:48   1  57.3G  0 disk 
├─sdd1   8:49   1     7G  0 part 
├─sdd2   8:50   1     8G  0 part 
└─sdd3   8:51   1  42.3G  0 part 
sde      8:64   1   7.2G  0 disk 
└─sde1   8:65   1   7.2G  0 part /media/mint/DEVICE
sdf      8:80   1     0B  0 disk 
sr0     11:0    1  1024M  0 rom  
mint@mint:~$ sudo mkfs.ntfs -Q -L "Data2" /dev/sdd3
Cluster size has been automatically set to 4096 bytes.
Creating NTFS volume structures.
mkntfs completed successfully. Have a nice day.
mint@mint:~$ sudo blkid /dev/sdd*
/dev/sdd: PTUUID="3cefd13f-0469-4156-8706-c287b5893e78" PTTYPE="gpt"
/dev/sdd1: PARTLABEL="Windows" PARTUUID="fa1a8bd1-4321-4053-898a-650f789e73b1"
/dev/sdd2: PARTLABEL="Linux" PARTUUID="76fa8686-42bd-4432-8836-5f9aa0f82edb"
/dev/sdd3: LABEL="Data2" BLOCK_SIZE="512" UUID="068EE39E1A4F3BE8" TYPE="ntfs" PARTLABEL="My_files" PARTUUID="d427d7f6-1772-44c3-a052-ef2b00d3833a"
mint@mint:~$
It was only a test on the USB drive. I intend to use the same commands on a hard drive when the present one fails. I think the unformatted "Windows" partition, i.e. /dev/sdd1: PARTLABEL="Windows", will be recognized by Windows Setup, which will then create the necessary partitions, including a reserved partition, an EFI partition, a recovery partition, and an NTFS partition.
I have Windows, UnionTech OS, and Linux Mint on the same HDD.
Locked

Return to “Chat about Linux”