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
3 answers
2756 views
sgdisk: Force alignment of end sector
I am trying to get `sgdisk` to create partitions that align on 1 MB. This is easy for the starting sector (using `-a`), and for the ending sector, if I choose the size. But if I let `sgdisk` choose the ending sector I end up with something like: ~~~ Device Start End Sectors Size Type /dev/disk/by-id...
I am trying to get sgdisk to create partitions that align on 1 MB. This is easy for the starting sector (using -a), and for the ending sector, if I choose the size. But if I let sgdisk choose the ending sector I end up with something like: ~~~ Device Start End Sectors Size Type /dev/disk/by-id/scsi-36848f690d917dc002587bfae06302a5a-part2 2048 1046527 1044480 510M EFI System /dev/disk/by-id/scsi-36848f690d917dc002587bfae06302a5a-part3 1048576 5242879 4194304 2G Solaris /usr & Apple Z /dev/disk/by-id/scsi-36848f690d917dc002587bfae06302a5a-part4 5242880 467660800 462417921 220.5G Linux filesystem ~~~ And a size of 462417921 is clearly not aligned to a 1 MB block. I would have expected something like: /dev/disk/by-id/scsi-36848f690d917dc002587bfae06302a5a-part4 5242880 466616319 461373440 220G Linux filesystem It seems -a only applies to the starting sector. How can I make it align the ending sector, too, for the rest-of-the-disk partition? The partition table is made with: sgdisk --zap-all $DISK sgdisk -n2:1M:+510M -t2:EF00 $DISK sgdisk -a 1048576 -n3:0:+2G -t3:BF01 $DISK # Use the rest of the disk for the final partition # and it is here the end sector is not aligned sgdisk -a 1048576 -n4:0:-0 -t4:BF01 $DISK
Ole Tange (37348 rep)
May 25, 2020, 10:45 PM • Last activity: Jan 11, 2025, 01:11 AM
2 votes
1 answers
1317 views
script to gdisk to create a new partition
I'm trying to script to `gdisk` to create a new partition of LVM type (for `pvcreate`) so I typed this but I does not work : diskModelName=yourDiskModel diskSerialNumber=yourDiskSerialNumber lvmPartitionNumber=2 cat<<-EOF | sudo gdisk $disk p n 8E00 c $lvmPartitionNumber $diskModelName-$diskSerialNu...
I'm trying to script to gdisk to create a new partition of LVM type (for pvcreate) so I typed this but I does not work : diskModelName=yourDiskModel diskSerialNumber=yourDiskSerialNumber lvmPartitionNumber=2 cat<<-EOF | sudo gdisk $disk p n 8E00 c $lvmPartitionNumber $diskModelName-$diskSerialNumber p w y EOF Can you help me ?
SebMa (2433 rep)
Nov 1, 2020, 07:51 PM • Last activity: Dec 29, 2022, 04:28 PM
1 votes
1 answers
232 views
Attempted to replicate partition table to replacement RAID1 disk, but source partition table now empty
I had a disk (/dev/sda) show signs of eventual failure in a RAID1 array, so I failed and then removed it from the array. I then replaced the disk, booted back up, and began the process of replicating the partition in order to add the disk to the array, however something went wrong. The final command...
I had a disk (/dev/sda) show signs of eventual failure in a RAID1 array, so I failed and then removed it from the array. I then replaced the disk, booted back up, and began the process of replicating the partition in order to add the disk to the array, however something went wrong. The final command I used was: sgdisk -R /dev/sdb /dev/sda Now lsblk shows the correct partitioning for /dev/sdb: [root@server /]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT nvme0n1 259:1 0 477G 0 disk ├─nvme0n1p3 259:4 0 7.8G 0 part │ └─md3 9:3 0 7.8G 0 raid1 /tmp ├─nvme0n1p1 259:2 0 511M 0 part /boot/efi ├─nvme0n1p4 259:5 0 7.8G 0 part [SWAP] └─nvme0n1p2 259:3 0 460.8G 0 part └─md2 9:2 0 460.8G 0 raid1 / sdb 8:16 0 3.7T 0 disk └─sdb1 8:17 0 3.7T 0 part └─md4 9:4 0 3.7T 0 raid1 /var nvme1n1 259:0 0 477G 0 disk ├─nvme1n1p4 259:9 0 7.8G 0 part [SWAP] ├─nvme1n1p2 259:7 0 460.8G 0 part │ └─md2 9:2 0 460.8G 0 raid1 / ├─nvme1n1p3 259:8 0 7.8G 0 part │ └─md3 9:3 0 7.8G 0 raid1 /tmp └─nvme1n1p1 259:6 0 511M 0 part sda 8:0 0 3.7T 0 disk However, sda does not show the same, but worse, when I run: sgdisk -p /dev/sdb It does not show me a partition table, same for /dev/sda: [root@server dev]# sgdisk -p /dev/sdb Disk /dev/sdb: 7814037168 sectors, 3.6 TiB Logical sector size: 512 bytes Disk identifier (GUID): 34DA93D9-0A46-433D-BDE3-6AF2566E2183 Partition table holds up to 128 entries First usable sector is 34, last usable sector is 7814037134 Partitions will be aligned on 2048-sector boundaries Total free space is 7814037101 sectors (3.6 TiB) Number Start (sector) End (sector) Size Code Name [root@server dev]# sgdisk -p /dev/sda Disk /dev/sda: 7814037168 sectors, 3.6 TiB Logical sector size: 512 bytes Disk identifier (GUID): EBADBC60-3D20-48F7-880B-5CCF1B645A44 Partition table holds up to 128 entries First usable sector is 34, last usable sector is 7814037134 Partitions will be aligned on 2048-sector boundaries Total free space is 7814037101 sectors (3.6 TiB) Number Start (sector) End (sector) Size Code Name [root@server dev]# When I ran partprobe, it gave me the following error: [root@server dev]# partprobe Error: Partition(s) 1 on /dev/sdb have been written, but we have been unable to inform the kernel of the change, probably because it/they are in use. As a result, the old partition(s) will remain in use. You should reboot now before making further changes. Now I am not the most experienced linux administrator (obviously), but I am guessing that somehow instead of duplicating /dev/sdb to /dev/sda I actually did the reverse and cleared the partition table for /dev/sdb. Thankfully I have not rebooted the machine, so the system is live and functioning and I would expect that there would be some way to recover the working partition table? Now the big unfortunate is that this is a production server and it going down/offline for an extended period of time would be pretty devastating. So I'm hoping someone could guide me through getting this back to normal. I'm not sure what else to share here to get help, so feel free to ask me to post results of anything. Thanks in advance.
Luke Pittman (111 rep)
Aug 17, 2020, 07:52 AM • Last activity: Aug 17, 2020, 08:15 AM
11 votes
1 answers
7741 views
Script to gdisk /dev/sdX and enter expert commands: x, z, y, y - how?
I am creating my first Arch Linux install script, and I want to automate the base installation as in the [archwiki][1] or you can find the same instructions but easier to read here: https://www.gloriouseggroll.tv/arch-linux-efi-install-guide/ I wish to wipe the partition tables, manually I have to t...
I am creating my first Arch Linux install script, and I want to automate the base installation as in the archwiki or you can find the same instructions but easier to read here: https://www.gloriouseggroll.tv/arch-linux-efi-install-guide/ I wish to wipe the partition tables, manually I have to type this: gdisk /dev/sda x z y y I want the bash script to automatically do this.
Spacecow (223 rep)
Oct 8, 2018, 06:44 PM • Last activity: Dec 3, 2019, 11:45 PM
1 votes
1 answers
1786 views
How to determine sizes using sgdisk partitioning in bash script
I'm using sgdisk in a bash script similar to this: sgdisk --clear /dev/vda --set-alignment=1 --new 1:34:2047 --typecode 1:EF02 -c 1:"grub" -g /dev/vda sgdisk --new 2:2048:16779263 --typecode 2:8300 -g /dev/vda sgdisk --new 3:16779264:20971486 --typecode 3:8200 -g /dev/vda That works only when the de...
I'm using sgdisk in a bash script similar to this: sgdisk --clear /dev/vda --set-alignment=1 --new 1:34:2047 --typecode 1:EF02 -c 1:"grub" -g /dev/vda sgdisk --new 2:2048:16779263 --typecode 2:8300 -g /dev/vda sgdisk --new 3:16779264:20971486 --typecode 3:8200 -g /dev/vda That works only when the devices are well known in advance and the sectors are hard-coded. I want to drop the hardcode the sector values. Instead, I want the script to work when the disk size is not known until the script runs. After making partition 1, I will set aside a known fixed amount to partition 3 for swap, and give the rest to partition 2. The easy way would be to make the swap partition #2. I know how to do that. However, I want to see if I can instead **do this while keeping swap on partition 3**. It means sgdisk will have to calculate a size or end sector value for partition 2 taking into account the size that will be allocated for partition 3 in the next step. Reading through the sgdisk man page hasn't given me the clues about how to do this (or even if it can be done).
BugBuddy (668 rep)
Nov 11, 2019, 06:27 AM • Last activity: Nov 11, 2019, 06:56 AM
12 votes
1 answers
10446 views
How can I quickly copy a GPT partition scheme from one hard drive to another?
On a non GPT partition table I can do sfdisk -d /dev/sda | sfdisk /dev/sdb But `sfdisk` doesn't support GPT partition tables. What can I use instead? I'm looking for a one or two command solution, not just using GNU parted to output the partition sizes and then manually making them again.
On a non GPT partition table I can do sfdisk -d /dev/sda | sfdisk /dev/sdb But sfdisk doesn't support GPT partition tables. What can I use instead? I'm looking for a one or two command solution, not just using GNU parted to output the partition sizes and then manually making them again.
Kris Harper (391 rep)
Aug 20, 2011, 12:51 AM • Last activity: Oct 8, 2018, 09:28 PM
Showing page 1 of 6 total questions