Sample Header Ad - 728x90

Unix & Linux Stack Exchange

Q&A for users of Linux, FreeBSD and other Unix-like operating systems

Latest Questions

2 votes
1 answers
5392 views
sfdisk doesn't work anymore?
I updated my OS to Ubuntu GNOME 15.10 but now I have a huge issue : sfdisk doesn't work! I really need it to build partitions on my SD cards for an embedded Linux but it seems that the options changed. How to do to keep it working? Here is the script I use : CARD_DEV=$1 unset LANG umount ${CARD_DEV}...
I updated my OS to Ubuntu GNOME 15.10 but now I have a huge issue : sfdisk doesn't work! I really need it to build partitions on my SD cards for an embedded Linux but it seems that the options changed. How to do to keep it working? Here is the script I use : CARD_DEV=$1 unset LANG umount ${CARD_DEV}* >& /dev/null if [ -b "$CARD_DEV" ] ; then echo "*************** Formatting SD card... ***************" dd if=/dev/zero of=$CARD_DEV bs=1024 count=1024 SIZE=fdisk -l $CARD_DEV | grep Disk | awk '{print $5}' echo DISK SIZE - $SIZE bytes CYLINDERS=echo $SIZE/255/63/512 | bc echo CYLINDERS - $CYLINDERS { echo 1,9,0x0C,* echo 10,,,- } | sfdisk -D -H 255 -S 63 -C $CYLINDERS $CARD_DEV mkfs.vfat -F 32 -n "boot" ${CARD_DEV}1 mke2fs -j -L "filesystem" ${CARD_DEV}2 fi And I get : sfdisk: invalid option -- 'D' sfdisk [options] [[-N] ] sfdisk [options] Display or manipulate a disk partition table. Commands: -A, --activate [ ...] list or set bootable MBR partitions -d, --dump dump partition table (usable for later input) -g, --show-geometry [ ...] list geometry of all or specified devices -l, --list [ ...] list partitions of each device -s, --show-size [ ...] list sizes of all or specified devices -T, --list-types print the recognized types (see -X) -V, --verify test whether partitions seem correct --part-label [] print or change partition label --part-type [] print or change partition type --part-uuid [] print or change partition uuid --part-attrs [] print or change partition attributes device (usually disk) path partition number partition type, GUID for GPT, hex for MBR Options: -a, --append append partitions to existing partition table -b, --backup backup partition table sectors (see -O) --bytes print SIZE in bytes rather than in human readable format -f, --force disable all consistency checking --color[=] colorize output (auto, always or never) colors disabled by default -N, --partno specify partition number -n, --no-act do everything except write to device --no-reread do not check whether the device is in use -O, --backup-file override default backup file name -o, --output output columns -q, --quiet suppress extra info messages -X, --label specify label type (dos, gpt, ...) -Y, --label-nested specify nested label type (dos, bsd) -L, --Linux deprecated, only for backward compatibility -u, --unit S deprecated, only sector unit is supported -h, --help display this help and exit -v, --version output version information and exit Available columns (for -o): gpt: Device Start End Sectors Size Type Type-UUID Attrs Name UUID dos: Device Start End Sectors Cylinders Size Type Id Attrs Boot End-C/H/S Start-C/H/S bsd: Slice Start End Sectors Cylinders Size Type Bsize Cpg Fsize sgi: Device Start End Sectors Cylinders Size Type Id Attrs sun: Device Start End Sectors Cylinders Size Type Id Flags For more details see sfdisk(8). Version: sfdisk from util-linux 2.26.2
didil (331 rep)
Nov 10, 2015, 02:10 PM • Last activity: Jun 2, 2025, 09:05 PM
7 votes
1 answers
13447 views
Move a partition to the right using command line tools
I have a partition, say 190 GB, followed by 100 GB of unpartitioned disk free space. I want to move this partition 100GB "to the right" (towards a higher sector number), so that the free unpartitioned free space would then be on the left of it. This partition cannot just be copied carelessly, becaus...
I have a partition, say 190 GB, followed by 100 GB of unpartitioned disk free space. I want to move this partition 100GB "to the right" (towards a higher sector number), so that the free unpartitioned free space would then be on the left of it. This partition cannot just be copied carelessly, because: - it contains encrypted data that must be preserved (on the block level), - there is an overlap between the old and new position of the partition. I know GParted should be able to handle this. However I would like to do it myself with command line tools. I know sfdisk has something like this to move partition 100M to the right:
-sh
echo '+100M,' | sfdisk --move-data /dev/sdc -N 1
I'd like to know 2 things: - **If I was to move data manually, using tools like dd (or others), how would I do that?** I believe the end of the partition must be copied before the start of it, like a backward read-and-copy (of course, I would also need to edit the GPT partition table). - If I want to use sfdisk, how can I use it so that I shift by a very precise sector number, so that it properly "touches" the partition that is on the far end of the disk? (so that they are really next to each other with no gap in between)
Totor (21020 rep)
Apr 26, 2023, 12:34 AM • Last activity: Aug 22, 2024, 08:57 AM
0 votes
1 answers
652 views
Why does fdisk sometimes ask what kind of partition to make and sometimes not?
Today I was trying to write a script for partitioning disks using fdisk (since that seemed like the simplest option). When going through fdisk the first time and pressing `n` for new partition, the first prompt asked if I wanted to make a primary or extended partition. I `q` quit. On going back thro...
Today I was trying to write a script for partitioning disks using fdisk (since that seemed like the simplest option). When going through fdisk the first time and pressing n for new partition, the first prompt asked if I wanted to make a primary or extended partition. I q quit. On going back through the same procedure, the first prompt was for what sector I wanted to be first. Since I did not w write any changes, nothing should have changed, right? If I can't predict when fdisk will give me what prompts, then I can't reliably script it. Most stuff I read recommended sfdisk for scripting, but noted that SUN disk labels are not supported. Since I want to install ZFS on root, my understanding that won't work. So how do I predict the prompts from fdisk, or what is an alternative for scripted partitioning that supports both UEFI and ZFS? Note: I am comfortable scripting this because I have the /dev/disk/by-id/ of each device, so as not to be confounded by changing disk labels or UUIDs.
Stonecraft (869 rep)
Jun 27, 2019, 05:40 PM • Last activity: Aug 9, 2024, 07:50 PM
7 votes
5 answers
19774 views
lsblk + capture only the disks
I want to capture only the disks from **lsblk** as showing here fd0 also appears in spite its not really disk for use in this case we can just do **lsblk | grep disk | grep -v fd0** but maybe we missed some other devices that need to filter them by **grep -v** what other disk devices that could be a...
I want to capture only the disks from **lsblk** as showing here fd0 also appears in spite its not really disk for use in this case we can just do **lsblk | grep disk | grep -v fd0** but maybe we missed some other devices that need to filter them by **grep -v** what other disk devices that could be appears from **lsblk | grep disk** and not really disks ? lsblk | grep disk fd0 2:0 1 4K 0 disk sda 8:0 0 100G 0 disk sdb 8:16 0 2G 0 disk /Kol sdc 8:32 0 2G 0 disk sdd 8:48 0 2G 0 disk sde 8:64 0 2G 0 disk sdf 8:80 0 2G 0 disk lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT fd0 2:0 1 4K 0 disk sda 8:0 0 150G 0 disk ├─sda1 8:1 0 500M 0 part /boot └─sda2 8:2 0 149.5G 0 part ├─vg00-yv_root 253:0 0 19.6G 0 lvm / ├─vg00-yv_swap 253:1 0 15.6G 0 lvm [SWAP] └─vg00-yv_var 253:2 0 100G 0 lvm /var sdb 8:16 0 2G 0 disk /Kol sdc 8:32 0 2G 0 disk sdd 8:48 0 2G 0 disk sde 8:64 0 2G 0 disk sdf 8:80 0 2G 0 disk sr0 11:0 1 1024M 0 rom
yael (13936 rep)
Jan 2, 2018, 02:03 PM • Last activity: Jan 31, 2024, 12:23 PM
6 votes
2 answers
738 views
How can I list partitions in storage order?
After telling general information (capacity, sector size and the like) ```fdisk``` shows 8 columns: sdXY, Boot, begin, end, # of sectors, size, flags, type. The partitions get sorted by Y in their ```sdXY``` designations. Sometimes (i.e. when this is true) it puts a note below it, that they are not...
After telling general information (capacity, sector size and the like)
shows 8 columns: sdXY, Boot, begin, end, # of sectors, size, flags, type. The partitions get sorted by Y in their
designations. Sometimes (i.e. when this is true) it puts a note below it, that they are not listed in storage order. **How can I let
(or any other appropriate tool) list the partitions on a block oriented device sorted by start sector**, i.e. by the third column **?**
Adalbert Hanßen (303 rep)
Jan 12, 2024, 12:22 PM • Last activity: Jan 12, 2024, 03:11 PM
1 votes
2 answers
969 views
Specify partition data in sfdisk and parted
With this line: (echo o; echo n; echo p; echo 1; echo ; echo +24G; echo a; echo t; echo 7; echo w) | fdisk /dev/sda I can create a new active primary partition for NTFS, 24 Giga large. The syntax is ugly but effective. How can I do the same with `parted` or `sfdisk`?
With this line: (echo o; echo n; echo p; echo 1; echo ; echo +24G; echo a; echo t; echo 7; echo w) | fdisk /dev/sda I can create a new active primary partition for NTFS, 24 Giga large. The syntax is ugly but effective. How can I do the same with parted or sfdisk?
antonio (1533 rep)
Oct 26, 2013, 06:50 PM • Last activity: Dec 12, 2023, 08:44 PM
1 votes
1 answers
136 views
fdisk partition type shown as empy when type is an UUID
I have two systems with same versions (Debian 11.7, util-linux 2.36.1-8+deb11u1). Why one system shows partition types as UUIDS and the second doesn't and also doesn't recognize that types showing "Empty" as the type? Background: The second one booted through PXE and I'm setting the partitions table...
I have two systems with same versions (Debian 11.7, util-linux 2.36.1-8+deb11u1). Why one system shows partition types as UUIDS and the second doesn't and also doesn't recognize that types showing "Empty" as the type? Background: The second one booted through PXE and I'm setting the partitions table as a copy of the first one. To export from PC1: > $ sfdisk -d /dev/sda > "table-file.tbl" > $ cat "table-file.tbl" Notice types are UUIDS device: /dev/sda unit: sectors first-lba: 34 last-lba: 250069646 sector-size: 512 # /boot/efi /dev/sda1 : start= 2048, size= 1048576, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, uuid=A454F449-08EA-48E0-BFAD-7D1190CB1DF3 #Main: / /dev/sda2 : start= 1050624, size= 58593280, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=46A2A596-C2E9-4D3B-9518-7D1496202576 # Extra partition: /extra /dev/sda3 : start= 59643904, size= 185546752, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=FDF1C229-8C35-4324-989F-4EE98B30503B # Swap partition /dev/sda4 : start= 245190656, size= 4878336, type=0657FD6D-A4AB-43C4-84E5-0933C84B4F4F, uuid=67FE00D9-2F09-4C4C-BD07-7129872D48C0 Moved the file to a shared network dir and used it on PC2: > $ sfdisk /dev/sda fdisk -l /dev/sda Disk /dev/sda: 119.24 GiB, 128035676160 bytes, 250069680 sectors Disk model: TS128GSSD452K-I Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0xf0c0c704 Device Boot Start End Sectors Size Id Type /dev/sda1 2048 1050623 1048576 512M 0 Empty /dev/sda2 1050624 59643903 58593280 27.9G 0 Empty /dev/sda3 59643904 245190655 185546752 88.5G 0 Empty /dev/sda4 245190656 250068991 4878336 2.3G 0 Empty On the first system where I retrieve the data, the types are listed as a list with decimal value, name, UUID. On the new system, the list of known partition types hex values. (Linux 83, swap 82, uefi EF...). Types can be seen running: > $ fdisk /dev/sda PC1: Command (m for help): l 00 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris 01 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT- 02 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT- 03 XENIX usr 3c PartitionMagic 84 OS/2 hidden or c6 DRDOS/sec (FAT- ... PC2: Command (m for help): l 1 EFI System C12A7328-F81F-11D2-BA4B-00A0C93EC93B 2 MBR partition scheme 024DEE41-33E7-11D3-9D69-0008C781F39F 3 Intel Fast Flash D3BFE2DE-3DAF-11DF-BA40-E3A556D89593 4 BIOS boot 21686148-6449-6E6F-744E-656564454649 5 Sony boot partition F4019732-066E-4E12-8273-346C5641494F 6 Lenovo boot partition BFBFAFE7-A34F-448A-9A5B-6213EB736C22 7 PowerPC PReP boot 9E1A2D38-C612-4316-AA26-8B49521E5A8B ...
Noman_1 (121 rep)
Nov 9, 2023, 10:49 AM • Last activity: Nov 9, 2023, 04:05 PM
1 votes
1 answers
4109 views
How can you give a disk and a new UUID?
I just used `sfdisk` to clone my partition table to a new disk, ```shell sudo sfdisk -d /dev/nvme0n1 > /tmp/part.txt sudo sfdisk /dev/nvme1n1 < /tmp/part.txt ``` However, now both drives have the same uuid. How can I fix that and generate a new UUID for device with the cloned partition table? -----...
I just used sfdisk to clone my partition table to a new disk,
sudo sfdisk -d /dev/nvme0n1 > /tmp/part.txt
sudo sfdisk /dev/nvme1n1 <  /tmp/part.txt
However, now both drives have the same uuid. How can I fix that and generate a new UUID for device with the cloned partition table? ----- The number that are duped can be seen with sudo fdisk -l. You can see the "523436E9-4DA5-474F-87CA-D784E4BF345D" is shared as a common "Disk identifier"
Disk /dev/nvme1n1: 1.82 TiB, 2000398934016 bytes, 3907029168 sectors
[...]
Disklabel type: gpt
Disk identifier: 523436E9-4DA5-474F-87CA-D784E4BF345D
[...]


Disk /dev/nvme0n1: 1.82 TiB, 2000398934016 bytes, 3907029168 sectors
[...]
Disklabel type: gpt
Disk identifier: 523436E9-4DA5-474F-87CA-D784E4BF345D
You can also see a shared UUID with,
❯ lsblk -o +uuid
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS UUID
nvme1n1     259:0    0  1.8T  0 disk             
├─nvme1n1p1 259:2    0  512M  0 part             
└─nvme1n1p2 259:3    0  1.8T  0 part             7d78ed4b-e4aa-4270-853d-6489ea4d6c54
nvme0n1     259:1    0  1.8T  0 disk             
├─nvme0n1p1 259:4    0  512M  0 part /boot/efi   1D40-E385
└─nvme0n1p2 259:5    0  1.8T  0 part /           7d78ed4b-e4aa-4270-853d-6489ea4d6c54
On the partition "7d78ed4b-e4aa-4270-853d-6489ea4d6c54" is shared?
Evan Carroll (34663 rep)
Jul 31, 2023, 07:28 AM • Last activity: Jul 31, 2023, 04:45 PM
1 votes
1 answers
1301 views
Copying a partition table with sfdisk from a larger device to a smaller one
I'm testing a Python script intended for use on Raspberry Pi systems for reformatting and copying partition info and partition data. To get the information from the first device (often a USB memory stick), I use: sfdisk -d /dev/sda >sda_data.txt Then, to copy the same table to the destination drive,...
I'm testing a Python script intended for use on Raspberry Pi systems for reformatting and copying partition info and partition data. To get the information from the first device (often a USB memory stick), I use: sfdisk -d /dev/sda >sda_data.txt Then, to copy the same table to the destination drive, I use: sfdisk /dev/sdb
Tango (373 rep)
Jul 19, 2023, 05:55 AM • Last activity: Jul 25, 2023, 09:39 AM
10 votes
1 answers
11000 views
Forced reread of partition table: difference between BLKRRPART and BLKPG ioctl? (Linux)
When I want Linux to consider newly created partitions without rebooting, I have several tools available to force a refresh of the kernel "partition cache": - `partx -va /dev/sdX` - `kpartx -va /dev/sdX` - `hdparm -z /dev/sdX` - `blockdev --rereadpt /dev/sdX` - `sfdisk -R /dev/sdX` (deprecated) - `p...
When I want Linux to consider newly created partitions without rebooting, I have several tools available to force a refresh of the kernel "partition cache": - partx -va /dev/sdX - kpartx -va /dev/sdX - hdparm -z /dev/sdX - blockdev --rereadpt /dev/sdX - sfdisk -R /dev/sdX (deprecated) - partprobe /dev/sdX - ... I'm not sure about the difference between these techniques, but I think they don't use the same ioctl, like BLKRRPART or BLKPG. So, **what is the difference between those ioctl?**
Totor (21020 rep)
Jul 9, 2014, 08:08 AM • Last activity: Jul 24, 2023, 10:26 PM
2 votes
2 answers
1051 views
Are UUIDs and PTUUIDs important for MBR disks? If so, how do I create them on my own?
I'm studying partitioning under Linux, starting with sfdisk. If I copy a partition table from one drive to another, it'll copy the device UUID and the PTUUIDs for each partition, but if I'm creating a new device, I can specify a UUID for GPT drives, but not MBR drives. This leads me to think that UU...
I'm studying partitioning under Linux, starting with sfdisk. If I copy a partition table from one drive to another, it'll copy the device UUID and the PTUUIDs for each partition, but if I'm creating a new device, I can specify a UUID for GPT drives, but not MBR drives. This leads me to think that UUIDs and PTUUIDs are not necessary for MBR drives. What is the situation with that? And if I need a UUID for the drive, plus PTUUIDs for the partitions, how do I do that by hand? I see that sfdisk allows me to specify a UUID for GPT devices, but only a label for MBR devices. How can I create a UUID for an MBR and what can I do to make sure the partition PTUUIDs are created based on that device UUID? I can't find out how to make the primary UUID for the device or how to make PTUUIDs based on it for the partitions.
Tango (373 rep)
Jul 20, 2023, 07:14 AM • Last activity: Jul 21, 2023, 09:18 AM
0 votes
0 answers
159 views
Will sfdisk partition copy touch RAID data
A recent Ubuntu server reboot caused two of the SOFT RAID5 disk (/dev/sdd and /dev/sdf) losing its partition table (/dev/sdd1 and /dev/sdf1), I have tried to use R-Studio that can directly connect to the drive image and R-Studio scan can see the file system. there is a good chance the RAID data is s...
A recent Ubuntu server reboot caused two of the SOFT RAID5 disk (/dev/sdd and /dev/sdf) losing its partition table (/dev/sdd1 and /dev/sdf1), I have tried to use R-Studio that can directly connect to the drive image and R-Studio scan can see the file system. there is a good chance the RAID data is still there on the disk just I cannot access it. Assuming the disk RAID data is store there, if I can figure out a way to get the partition table back by cloning the partition table from other RAID member disk in the RAID (/dev/sda, /dev/sdb, /dev/sdc, identical model size) using the sfdisk command to this disk, will it 1) destroy/touch the RAID data on /dev/sdd 2) make mdadm assemble still able to use the data on the "new" /dev/sdd1 partition?
Twinkiestar (1 rep)
Mar 28, 2023, 07:16 PM • Last activity: Mar 29, 2023, 01:15 AM
2 votes
1 answers
273 views
How to replace linux distro ISO on bootable USB keeping extra data partition intact and accessible?
USB sticks are getting larger. I'd like to store data in addition to having USB bootable. And I know how: 1. write ISO to USB stick 2. Add partition via Gnome-disks (both GUI). Now I want to be able to replace ISO keeping that extra data intact and accessible. How to do that? Preferably w/out manual...
USB sticks are getting larger. I'd like to store data in addition to having USB bootable. And I know how: 1. write ISO to USB stick 2. Add partition via Gnome-disks (both GUI). Now I want to be able to replace ISO keeping that extra data intact and accessible. How to do that? Preferably w/out manual editing hex data on the disk, but this solution is better than no solution. TIA I've tried and failed as below. I've read https://unix.stackexchange.com/questions/12986/how-to-copy-the-partition-layout-of-a-whole-disk-using-standard-tools where using sfdisk was advised. Most ISO's I've encountered look as one below: sfdisk --dump linuxmint-20.2-cinnamon-64bit.iso label: dos label-id: device: linuxmint-20.2-cinnamon-64bit.iso unit: sectors sector-size: 512 linuxmint-20.2-cinnamon-64bit.iso1 : start= 0, size= 4222944, type=0, bootable linuxmint-20.2-cinnamon-64bit.iso2 : start= 640, size= 7936, type=ef That is some partition table sfdisk cannot write back (start 0 is not OK for it). But after creating a partition via gnome-disks: sudo sfdisk --dump /dev/sda label: dos label-id: device: /dev/sda unit: sectors /dev/sda1 : start= 8433664, size= 57104384, type=83 /dev/sda2 : start= 4800, size= 8496, type=ef # (note: the ISO I've tried to change from had start=4800 for ef). So I've saved that new line /dev/sda1 to say a.part, wrote new ISO to USB, created partition via gnome-disks, confirmed via sfdisk --dump, then deleted data partition via gnome-disks and did sfdisk --append /dev/sda < a.part (see part of output below). I saw "The partition table has been altered.", my data partition in new partition table. But USB stick no longer booted. /dev/sda3: Created a new partition 3 of type 'Linux' and of size 24.4 GiB. Partition #3 contains a btrfs signature. /dev/sda4: Done. New situation: Disklabel type: dos Disk identifier: Device Boot Start End Sectors Size Id Type /dev/sda2 4800 13295 8496 4.2M ef EFI (FAT-12/16/32) /dev/sda3 14368768 65538047 51169280 24.4G 83 Linux The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks. Added (about Ventoy): I'm using Ventoy already. I still want to have some USB with my favorite system so that I insert the stick, press power and the system loads unattended while I do other stuff. Also I recall Vetroy GUI glitched on some old computer, so again dedicated directly bootable stick is IMO useful. However these issues are mitigated if Ventoy has option to load default specified file (with delay like GRUB boot menu) - could not find such googling and reading https://www.ventoy.net/en/faq.html . As seems Ventoy internally uses GRUB boot I opened config file to see if I can add default boot option.
Martian2020 (1443 rep)
Dec 23, 2022, 08:57 AM • Last activity: Dec 23, 2022, 12:36 PM
0 votes
1 answers
1522 views
Looking for a way to correct Hard Drive geometry. # of cylinders is not correct
I have 2 hard drives that have become corrupted as in the # of cylinders is no longer correct. Not sure how this is happening, but have same hard drive model that I have verified the correct # of cylinders. Early versions of sfdisk use to have this option. And fdisk x has the options to modify the g...
I have 2 hard drives that have become corrupted as in the # of cylinders is no longer correct. Not sure how this is happening, but have same hard drive model that I have verified the correct # of cylinders. Early versions of sfdisk use to have this option. And fdisk x has the options to modify the geometry but the w (write) command doesn't save the changes. Found a program (Disk Genius @ $99) that says it will do the job but would hope their is a open source option? Internet searches make mention that Gparted can do it, but I have not found that option. I have used dd to zero out the HD and fdisk to remove and make new partition tables. Everything is still using the wrong cylinder data. Have tried fdisk under Linux Mint, Ubuntu and MX
Ronnie_g (1 rep)
Sep 1, 2022, 06:52 AM • Last activity: Sep 1, 2022, 11:19 AM
0 votes
1 answers
716 views
Sfdisk NVME issue, No such device or address
I have custom LFS installer which contains sfdisk, I am trying to add support for NVME disks on it. When I make partitions with sfdisk on a normal SATA disk, things go as expected but when I do the exact same on a NVME disk, it creates the partitions, but when I am trying to get the size of a partit...
I have custom LFS installer which contains sfdisk, I am trying to add support for NVME disks on it. When I make partitions with sfdisk on a normal SATA disk, things go as expected but when I do the exact same on a NVME disk, it creates the partitions, but when I am trying to get the size of a partition (with the sfdisk -s /dev/nvme0n1p1 command), it outputs No such device or address while trying to determine filesystem size. lsblk output:
NAME        MAJ:MIN SIZE TYPE
nvme0n1     259:0   1.8T disk
|nvme0n1p1  259:1   200G part
`nvme0n1p2  259:10  1.6T part
sfdisk usage:
,200G,L
,,L
/proc/partitions
major minor #blocks    name
259     0   1953514584 nvme0n1
259     2    209715200 nvme0n1p1
259     3   1743798343 nvme0n1p2
They are also listed under /dev as nvme0n1, nvme0n1p1 and nvme0n1p2. Now if I use sfdisk -s /dev/nvme0n1p1 I get the output: 209715200 and sfdisk -s /dev/nvme0n1p2 gives: No such device or address while trying to determine filesystem size. Now the strange thing is, if I create the partitions again, and I do sfdisk -s /dev/nvme0n1p1 this now gives: No such device or address while trying to determine filesystem size and sfdisk -s /dev/nvme0n1p2 gives 209715200. And if I it again over and over, it keeps changing, one partition is usable, other not, it swaps constantly. Things I tried: - Other SSD (same type), same result; - I am using a pcie adapter for the NVME disk, tried other adapter, same result; - Using the adapter in a running open suze installation, I can execute these comands with no issues; - Normal sata drive, no issues. [edit] I figured out after a reboot without the partitioning the drive again, it is possible to execute these commands, is this important to a NVME disk, but seems not to normal sata? I am quite out of ideas now what to try or what the couse of this could be, any help would be appreciated.
Bart (101 rep)
Jul 27, 2022, 08:30 AM • Last activity: Jul 27, 2022, 01:07 PM
0 votes
0 answers
186 views
Why are uuid and ptuuid different for different commands
I get the following results for the 3 commands `blkid`, `lsblk` and `sfdisk` on an Arch Linux system ``` $ lsblk --json -p -b -o+PTUUID,UUID /dev/sda1 { "blockdevices": [ { "name": "/dev/sda1", "maj:min": "8:1", "rm": false, "size": 535822336, "ro": false, "type": "part", "mountpoints": [ null ], "p...
I get the following results for the 3 commands blkid, lsblk and sfdisk on an Arch Linux system
$ lsblk --json -p -b -o+PTUUID,UUID /dev/sda1
{
   "blockdevices": [
      {
         "name": "/dev/sda1",
         "maj:min": "8:1",
         "rm": false,
         "size": 535822336,
         "ro": false,
         "type": "part",
         "mountpoints": [
             null
         ],
         "ptuuid": "772eba14-e67c-40d8-8ddd-2317d5a4156d",
         "uuid": "6BCD-C870"
      }
   ]
}
$ blkid /dev/sda1
/dev/sda1: 
UUID="6BCD-C870" 
BLOCK_SIZE="512" 
TYPE="vfat" 
PARTLABEL="primary" 
PARTUUID="47948fda-bd1d-4dee-9d9a-ab0da02b08b2"
sfdisk --json /dev/sda
{
   "partitiontable": {
      "label": "gpt",
      "id": "772EBA14-E67C-40D8-8DDD-2317D5A4156D",
      "device": "/dev/sda",
      "unit": "sectors",
      "firstlba": 34,
      "lastlba": 937701342,
      "sectorsize": 512,
      "partitions": [
         {
            "node": "/dev/sda1",
            "start": 2048,
            "size": 1046528,
            "type": "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7",
            "uuid": "47948FDA-BD1D-4DEE-9D9A-AB0DA02B08B2",
            "name": "primary"
         }
      ]
   }
}
I'm mainly interested in the UUID and PTUUID which for the above output does not seem to match between the commands.
PTUUID                                   UUID
lsblk    772eba14-e67c-40d8-8ddd-2317d5a4156d     6BCD-C870
blkid    47948fda-bd1d-4dee-9d9a-ab0da02b08b2     6BCD-C870
sfdisk                                            47948FDA-BD1D-4DEE-9D9A-AB0DA02B08B2
Could someone explain why they are different and can which one can be trusted, if any?
wasp256 (209 rep)
Jun 15, 2022, 12:09 PM
2 votes
1 answers
3099 views
fdisk or sfdisk + how to show the disks size in GIB and not in GB
we can print all disks by the following ( on our RHEL machine ) fdisk -lu | grep "Disk /dev" Disk /dev/sda: 247.0 GB, 246960619520 bytes, 482344960 sectors Disk /dev/sdb: 4294 MB, 4294967296 bytes, 8388608 sectors Disk /dev/sdc: 4294 MB, 4294967296 bytes, 8388608 sectors Disk /dev/sdd: 4294 MB, 4294...
we can print all disks by the following ( on our RHEL machine ) fdisk -lu | grep "Disk /dev" Disk /dev/sda: 247.0 GB, 246960619520 bytes, 482344960 sectors Disk /dev/sdb: 4294 MB, 4294967296 bytes, 8388608 sectors Disk /dev/sdc: 4294 MB, 4294967296 bytes, 8388608 sectors Disk /dev/sdd: 4294 MB, 4294967296 bytes, 8388608 sectors Disk /dev/sde: 4294 MB, 4294967296 bytes, 8388608 sectors as we can see above disks are in GB and not in GIB note: GB is the traditional, metric style of measurement with 1 GB equaling 1,000³ bytes. GiB is the binary method; which is the way computers measure data at 1024³ bytes. any option by using fdisk or sfdisk or maybe other manipulation in order to print the disks size with GIB ?
yael (13936 rep)
Jun 1, 2022, 11:30 AM • Last activity: Jun 1, 2022, 12:03 PM
0 votes
1 answers
794 views
Scripting the partition shrinking
I have some disk image, taken with `dd if=/dev/somedevice of=filename.img`. I was able to shrink them following [this tutorial](https://www.instructables.com/How-to-BackUp-and-Shrink-Your-Raspberry-Pi-Image/). Now I would like to script all the procedure, and I managed to perform almost everything,...
I have some disk image, taken with dd if=/dev/somedevice of=filename.img. I was able to shrink them following [this tutorial](https://www.instructables.com/How-to-BackUp-and-Shrink-Your-Raspberry-Pi-Image/) . Now I would like to script all the procedure, and I managed to perform almost everything, apart the fdisk resize part. I'm trying to resize the partition with this command
echo " , +7506944K," | sfdisk -N 2 /dev/loop14
But independently from the size I use I get an error:
/dev/loop14p2: Failed to resize partition #2.
How can i script the redefinition of the end of a partition? Why is my command failing, can I get some more information somehow?
ErniBrown (111 rep)
May 5, 2022, 02:43 PM • Last activity: May 6, 2022, 12:54 PM
0 votes
1 answers
329 views
Heredoc not working in bash script
I made a bash script that was working in Ubuntu mate but now it won't work in Manjaro. It fails on this method: #!/bin/bash dev_block="/dev/sdb" createPartitions(){ echo "Creating Partitions on "$dev_block"..." sfdisk $dev_block -uS >> Created a new GPT disklabel (GUID: 0EBA642D-3CB5-8841-A150-D18AC...
I made a bash script that was working in Ubuntu mate but now it won't work in Manjaro. It fails on this method: #!/bin/bash dev_block="/dev/sdb" createPartitions(){ echo "Creating Partitions on "$dev_block"..." sfdisk $dev_block -uS >> Created a new GPT disklabel (GUID: 0EBA642D-3CB5-8841-A150-D18AC387D65F). /dev/sdb1: Failed to add #1 partition: Invalid argument Leaving. I also tried moving the EOF back so there is no tab before it. createPartitions(){ echo "Creating Partitions on "$dev_block"..." sfdisk $dev_block -uS <<-EOF start=63, size=409600, type=c, bootable start=411648, type=af EOF } I checked and there is no tab or whitespace AFTER the closing EOF. But also in Ubuntu I didn't have to move that closing EOF back. How do I debug this? Maybe sfdisk behaves differently in Arch? Cheers.
FlexMcMurphy (433 rep)
Oct 30, 2021, 10:06 PM • Last activity: Oct 30, 2021, 10:44 PM
2 votes
1 answers
232 views
Redirecting output from within disk operations does not work
I am not able to successfully redirect STDOUT+STDERR on commands that operates with disks. Standard redirecting which always works, is *somehow* now catching the output. Two practical examples: **Example 1:** # wipefs --all --force /dev/sda >>/var/log/custom.log 2>&1 [ 20.169018 ] sda: sda1 **Exampl...
I am not able to successfully redirect STDOUT+STDERR on commands that operates with disks. Standard redirecting which always works, is *somehow* now catching the output. Two practical examples: **Example 1:** # wipefs --all --force /dev/sda >>/var/log/custom.log 2>&1 [ 20.169018 ] sda: sda1 **Example 2:** # mount --verbose --options defaults --types ext4 /dev/sda1 /path/is/here >>/var/log/custom.log 2>&1 [ 30.947410 ] EXT4-fs (sda1): mounted filesystem with ordered data mode. Opts: (null) Interesting is, that this only happens when touching disks somehow. All other redirects within the script works as expected. Any ideas?
Josef Komjati (23 rep)
Jun 14, 2021, 04:46 PM • Last activity: Jun 14, 2021, 06:13 PM
Showing page 1 of 20 total questions