sfdisk trick for extra partitions on USB stick after install

Post questions about how to make a customized SystemRescueCd, and if you have problems to install new packages. Please read the handbook first.
tryngf
Posts: 6
Joined: 12 Aug 2013, 09:38

sfdisk trick for extra partitions on USB stick after install

Postby tryngf » 12 Aug 2013, 10:31

EDIT START Tue Apr 8 08:20:01 UTC 2014
There I often had serious malfunction when I applied this "trick".
This is *NOT* a reliable thing to do at all. I don't anymore do it.
There I am, next, about to write an explanation below, after some 3-4 old posts.
EDIT END
I just figured out how to have two more partitions on my USB stick
after installing sysresccd with regular:

Code: Select all

$ usb_install.sh

procedure.

WARNING: NO WARRANTY. Dont even attempt trying this if you don't
know what you are doing!


It works for me though. So, for the brave, here we go.

This is partly from memory (recollection), partly from real out put or existing files still on my hard disk (real).
Namely, I see no problems so far, but it's all still hot under my developing hammer ;-), so... I'll be back to tell you if there are problems...
This is the stick (real):
$ lsusb

Code: Select all

Bus 001 Device 002: ID 0930:6545 Toshiba Corp. Kingston DataTraveler 102 Flash Drive / HEMA Flash Drive 2 GB / PNY Attache 4GB Stick
...[more output, but unrelated]...
$

Upon having done install, by (recollection):

Code: Select all

$ mount systemrescuecd-x86-3.8.0-beta002.iso sysresc/
$ sysresc/usb_inst.sh

After that regular procedure explained on sysresccd.org and easy to find for newbies, I made this dump by sfdisk (Just remember that in my case, the USB was installed as /dev/sdc by the Debian OS. Substitute for anything that you have, don't try to blindly use my commands. You have been warned, and this is last time).

Code: Select all

$ sfdisk -d /dev/sdc > sdc.out

This is sdc.out:

Code: Select all

# partition table of /dev/sdc
unit: sectors

/dev/sdc1 : start=        1, size= 30481151, Id= c, bootable
/dev/sdc2 : start=        0, size=        0, Id= 0
/dev/sdc3 : start=        0, size=        0, Id= 0
/dev/sdc4 : start=        0, size=        0, Id= 0

That is where most of people keep at. Entire 16G (or whichever the size) USB solely for the fine System rescue CD program. That's fine. But I have to economize...
I fired up plain fdisk on /dev/sdc
I deleted the sole partition and made another first primary partition and two more partitions.
This I made in fdisk, but I am not indulging to explain in, I'll just show what the dump by sfdisk looked like.
Agiain, so you don't miss the point. Use fdisk to make you USB stick look like you like it. Sure I mean in such fashion to give you partitions of desirable sizes... I did it so it gives me this dump with this command.

Code: Select all

$ sfdisk -d /dev/sdc > sdc_3part.out

This is the dump sdc_3part.out

Code: Select all

# partition table of /dev/sdc
unit: sectors

/dev/sdc1 : start=     2048, size=  7997953, Id=83
/dev/sdc2 : start=  8000001, size=  7000000, Id=83
/dev/sdc3 : start= 15000001, size= 15481151, Id=83
/dev/sdc4 : start=        0, size=        0, Id= 0

And in Emacs, but surely you might use Vim, or Nano or some other editor, I just combined sdc.out and sdc_3part.out.
Yes, combined them in the dirty old fashion, wondering if my surmise will work.
I simply editied the second by combing elements from the first line of the first but retaining other elements.
This I made, with my edtor:
This is the artificial dump that worked for me in my case, and I saved it as sdc_3part_sysresc.out

Code: Select all

# partition table of /dev/sdc
unit: sectors

/dev/sdc1 : start=        1, size=  7997953, Id= c, bootable
/dev/sdc2 : start=  8000001, size=  7000000, Id=83
/dev/sdc3 : start= 15000001, size= 15481151, Id=83
/dev/sdc4 : start=        0, size=        0, Id= 0


And now I used that artificial dump to feed it to sfdisk.

This is where the magic happens.

Code: Select all

 sfdisk /dev/sdc < sdc_3part_sysresc.out


Really nothing more than that I did.

And upon rebooting, the USB stick boots just as it is expected of the great rescue OS that it is!

And I formatted partitions that I created, and I installed Tor on one of them, and am browsing and posting this post with Tor from the same USB stick, but the third of the three partitions there are now on the stick.

I hope people might find this useful.
And sure, as I promised, I will be back to tell you if anything went actually wrong, but I don't expect that to happen.

Cheers!
Miro
Last edited by tryngf on 08 Apr 2014, 08:23, edited 1 time in total.

gernot
Posts: 1127
Joined: 07 Apr 2010, 16:19

Re: sfdisk trick for extra partitions on USB stick after ins

Postby gernot » 12 Aug 2013, 13:48

nice, but why don't you use gparted.
You can boot from the stick with "docache" and then resize or create partitions.

Gernot

tryngf
Posts: 6
Joined: 12 Aug 2013, 09:38

Re: sfdisk trick for extra partitions on USB stick after ins

Postby tryngf » 12 Aug 2013, 20:09

Hi, gernot!
I always boot with 'docache'.
I don't often use gparted. I prefer these in my post above.
This to me looks like pronto extra partitions there, no hussle.
Ready-to-use whatever I put in the extra partitions, along with ready-to-use fine System Rescue CD on my USB pendrive.
Anyway, in case someone finds any of the simple steps don't work for him/her, let us know.
I can't promise to be back very soon now again, though.
Greetings!
Miroslav Rovis

gernot
Posts: 1127
Joined: 07 Apr 2010, 16:19

Re: sfdisk trick for extra partitions on USB stick after ins

Postby gernot » 13 Aug 2013, 04:45

Just a question..
Tried you to write a big file to the first partition of the stick? You should get an error.
I miss the shrink of the FAT filesystem on it like parted do.

Gernot

tryngf
Posts: 6
Joined: 12 Aug 2013, 09:38

Re: sfdisk trick for extra partitions on USB stick after ins

Postby tryngf » 14 Aug 2013, 03:10

No, the first partition is what I leave to the SysResc CD.
I don't touch it... Well I could, but I like writing on second or third partition that I formated:

Code: Select all

$ mke2fs -t ext3 /deb/sdc2

I can't boot into this one SysResc CD (made with this sfdisk trick above) now because all my systems are working, and my mind is busy figuring other things beyond me and which I need... (grsecurity, Tor, torsocks for mailing... there is so much in the free non-surveilled world that a man who wants to be free needs, SysResc CD is just great, such as fsarchiver that I learned to use lately....)...
I can remember the next time I use it and report back if I have problems.
I think in my case with my hardware, the way I did it stands just fine and does well for the users willing to engage with:
man fdisk
man sfdisk
possibly in some detail (esp. if they want to find if there are any flaws in the method).
I even think this workaround of mine is not even a dirty trick but legitimate to do.

tryngf
Posts: 6
Joined: 12 Aug 2013, 09:38

Re: sfdisk trick for extra partitions on USB stick after ins

Postby tryngf » 14 Aug 2013, 16:20

gernot wrote:Just a question..
Tried you to write a big file to the first partition of the stick? You should get an error.
I miss the shrink of the FAT filesystem on it like parted do.

Gernot

Yeah. you were right.

Here is the full story in case some newbie wants to learn how to apply this trick.

Code: Select all

# lsusb
Bus 001 Device 002: ID 0930:6545 Toshiba Corp. Kingston DataTraveler 102 Flash Drive / HEMA Flash Drive 2 GB / PNY Attache 4GB Stick
Bus 001 Device 003: ID 8564:1000
#

That Device 003 is another of my pendrives. I just installed SysrescCD with the standard procedure explained in my first post of this topic.

This time around the Kingston DataTraveler is on /dev/sdb. And again I have /dev/sdc on this newly installed, other, I think JetFlash Transcend (as SysRecs showed me upon starting usb_install.sh script, yes it is!), USB pendrive.

Code: Select all

# sfdisk -d /dev/sdc > sdc.out
# cat sdc.out
# partition table of /dev/sdc
unit: sectors

/dev/sdc1 : start=        1, size= 31703039, Id= c, bootable
/dev/sdc2 : start=        0, size=        0, Id= 0
/dev/sdc3 : start=        0, size=        0, Id= 0
/dev/sdc4 : start=        0, size=        0, Id= 0

That's vanilla SysResc install.
Now I will run fdisk.

Code: Select all

# fdisk /dev/sdc

Command (m for help): p

Disk /dev/sdc: 16.2 GB, 16231956480 bytes
255 heads, 63 sectors/track, 1973 cylinders, total 31703040 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: 0x0009b612

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1   *           1    31703039    15851519+   c  W95 FAT32 (LBA)

Command (m for help): d
Selected partition 1

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
Using default value 1
First sector (2048-31703039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-31703039, default 31703039):

That's all real output as I go.
Here I simply took that large number and devided it by 4.
Why? To use about 1/4 of the space available on the pendrive for SysResc.
Like this, in another terminal.

Code: Select all

# echo 31703039/4|bc
7925759
#
and I round it to 8 000 000 (but when typing in, surely I don't type spaces.

Code: Select all

Last sector, +sectors or +size{K,M,G} (2048-31703039, default 31703039): 8000000

Command (m for help): p

Disk /dev/sdc: 16.2 GB, 16231956480 bytes
255 heads, 63 sectors/track, 1973 cylinders, total 31703040 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: 0x0009b612

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048     8000000     3998976+  83  Linux

Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p):     
Using default response p
Partition number (1-4, default 2):
Using default value 2
First sector (8000001-31703039, default 8000001):
Using default value 8000001
Last sector, +sectors or +size{K,M,G} (8000001-31703039, default 31703039): 16000000

Command (m for help):
Command (m for help): p

Disk /dev/sdc: 16.2 GB, 16231956480 bytes
255 heads, 63 sectors/track, 1973 cylinders, total 31703040 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: 0x0009b612

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048     8000000     3998976+  83  Linux
/dev/sdc2         8000001    16000000     4000000   83  Linux

Command (m for help): n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p):
Using default response p
Partition number (1-4, default 3):
Using default value 3
First sector (16000001-31703039, default 16000001):
Using default value 16000001
Last sector, +sectors or +size{K,M,G} (16000001-31703039, default 31703039):
Using default value 31703039

Command (m for help): p

Disk /dev/sdc: 16.2 GB, 16231956480 bytes
255 heads, 63 sectors/track, 1973 cylinders, total 31703040 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: 0x0009b612

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048     8000000     3998976+  83  Linux
/dev/sdc2         8000001    16000000     4000000   83  Linux
/dev/sdc3        16000001    31703039     7851519+  83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

#

And all that is real world ongoing as I write here.
Now, certaily, I need to sfdisk-dump that setup, and do the trick which I believe I sufficiently clearly explained in the first post of this topic.

Code: Select all

# sfdisk -d /dev/sdc > sdc_fdisk_rearrange.out
# cat sdc_fdisk_rearrange.out
# partition table of /dev/sdc
unit: sectors

/dev/sdc1 : start=     2048, size=  7997953, Id=83
/dev/sdc2 : start=  8000001, size=  8000000, Id=83
/dev/sdc3 : start= 16000001, size= 15703039, Id=83
/dev/sdc4 : start=        0, size=        0, Id= 0
#

#  vi sdc.out  sdc_fdisk_rearrange.out

# cat sdc_new_sfdist_arrange.out
# partition table of /dev/sdc
unit: sectors

/dev/sdc1 : start=        1, size=  7997953, Id= c, bootable
/dev/sdc2 : start=  8000001, size=  8000000, Id=83
/dev/sdc3 : start= 16000001, size= 15703039, Id=83
/dev/sdc4 : start=        0, size=        0, Id= 0
#

# sfdisk /dev/sdc < sdc_new_sfdist_arrange.out
Checking that no-one is using this disk right now ...
OK

Disk /dev/sdc: 15480 cylinders, 64 heads, 32 sectors/track
Old situation:
Units = cylinders of 1048576 bytes, blocks of 1024 bytes, counting from 0

   Device Boot Start     End   #cyls    #blocks   Id  System
/dev/sdc1          1    3906-   3906-   3998976+  83  Linux
      start: (c,h,s) expected (1,0,1) found (0,32,33)
      end: (c,h,s) expected (1023,63,32) found (497,249,9)
/dev/sdc2       3906+   7812-   3907-   4000000   83  Linux
      start: (c,h,s) expected (1023,63,32) found (497,249,10)
      end: (c,h,s) expected (1023,63,32) found (995,243,17)
/dev/sdc3       7812+  15479    7668-   7851519+  83  Linux
      start: (c,h,s) expected (1023,63,32) found (995,243,18)
      end: (c,h,s) expected (1023,63,32) found (949,107,54)
/dev/sdc4          0       -       0          0    0  Empty
New situation:
Units = sectors of 512 bytes, counting from 0

   Device Boot    Start       End   #sectors  Id  System
/dev/sdc1   *         1   7997953    7997953   c  W95 FAT32 (LBA)
/dev/sdc2       8000001  16000000    8000000  83  Linux
/dev/sdc3      16000001  31703039   15703039  83  Linux
/dev/sdc4             0         -          0   0  Empty
Warning: partition 1 does not end at a cylinder boundary
Warning: partition 2 does not start at a cylinder boundary
Warning: partition 2 does not end at a cylinder boundary
Warning: partition 3 does not start at a cylinder boundary
Successfully wrote the new partition table

Re-reading the partition table ...

If you created or changed a DOS partition, /dev/foo7, say, then use dd(1)
to zero the first 512 bytes:  dd if=/dev/zero of=/dev/foo7 bs=512 count=1
(See fdisk(8).)
#


And this I will try to boot, but first:

Code: Select all

# mke2fs -t ext3 /dev/sdc2 ; mke2fs -t ext3 /dev/sdc3 ;

I'm sparing you the output here.

Basically all just works as with the other stick.
This one is JetFlash 16GB.
Minor issue, but it really doesn't prevent any functionality if I post this, I'm not making any more attempts. Lost my nerves all the way. Namely mistakenly taken out the stick of the first attempt, that was installed as /dev/sdb thinking that I was taking out this JetFlash new try...
And froze my Debian system...
Lost a lot of unrelated other work...
So, just the minor issue is there, and that issue doesn't prevent any functionality, if I post this it doesn't, beacuse I again installed Tor, into the second partition. And will be tor-browsing to post this.
The minor issue, the first partition mounts as if it occupies the entire stick.

Gernot, that is probably your issue, the issue that you too shortly explained for me to grasp! Sorry!
The solution is, for the newbies, just bear in mind that that is smaller partition then it shows when it mounts! That's all! AFAIK.

Cheers everybody!
Miroslav Rovis

tryngf
Posts: 6
Joined: 12 Aug 2013, 09:38

Re: sfdisk trick for extra partitions on USB stick after ins

Postby tryngf » 08 Apr 2014, 08:34

I had discovered at the time of this post on forums.grsecurity.net:
grsec: halting the system... kernel crash, the Debian side
https://forums.grsecurity.net/viewtopic ... =15#p13886
(a month and a half ago, sorry for the delay, I've really had various hardships in my life since, and still have...).
IMO, if you look at the logs that I posted there, from my /var/log/messages or /var/log/kern.log that it was, you will see various errors that may very well be related to the partition been, well, broken...
I wrote there, and am quoting:
By the way, if you DuckDuckGo.com (get your friends to collect some dung and throw it on Google wherever you see them, and instead use ddg.com!) for Miroslav Rovis and for, I think other words are 'trick', 'extra', 'partition' on systemrescuecd.org

I was referring to this topic that you are reading right now.
I hope I'm forgiven, because I really didn't offer this "trick" with any dishonest intentions whatsoever, quite the contrary, I had discovered it and thought that it would work, and used it ever since, and up unto then.
Miroslav Rovis
Zagreb, Croatia
http://www.CroatiaFidelis.hr


Return to “Customization and installing new packages”

Who is online

Users browsing this forum: No registered users and 1 guest